Drawing in color in Rebol/Red - draw

In the following code from: http://business-programming.com/business_programming.html , I want to add a button to convert line being drawn in blue rather than in white color. I have tried to add color: blue at various places but it is not working:
view center-face layout [
; color: blue ; does not work.
s: area black 650x350 feel [
engage: func [f a e] [
; color: blue ; does not work here also.
if a = 'over [
append s/effect/draw e/offset
show s
]
if a = 'up [append s/effect/draw 'line] ; tried adding "'pen 'blue" here before 'line
]
] effect [draw [line]]
b: btn "Save" [
save/png %a.png to-image s
alert "Saved 'a.png'"
]
btn "Clear" [
s/effect/draw: copy [line]
show s]
]
How can I make the line to draw in blue rather than white?

modify
] effect [draw [line]]
to
] effect [draw [pen blue line]]
see REBOL 2: View Draw Dialect

Related

Remove spacing between bar in bar graph( react-chart-js)

issue that i am facing is, i have my bar graph made using react-chart-js. i want to remove space between the bar and center align the bar's . The bar's should have Thickness equal to 50
I try using dummy data ,that way i got the desired output but that is not the correct way of doing . Also I try using barPercentage , categoryPercentage option but didnt get the desired output
Link for CodeSandbox
I don't know if this actually works out of the box. There is nothing in the documentation about this use case either.
You could do it with ghost values to extend the chart in general.
This is not really a solution, but it may be an option.
const labels = ["","","January", "February", "March","",""];
export const data = {
labels,
datasets: [
{
label: "Dataset 1",
data: labels.map((elem, index) => {
if (index > 1 && index < 5)
return faker.datatype.number({ min: 0, max: 1000 })
}),
backgroundColor: "rgba(255, 99, 132, 0.5)",
barThickness: 50
}
]
};

How to draw a graphicLines in InDesign using CEP / ExtendScript?

I saw that there was a similar question but my problem is not the same :
This is how I create my graphicLines :
var myArr = [
[x1, y1],
[x2, y2],
...
]
// Get the active document
var doc = app.activeDocument;
// Get item from the page
var page = doc.pages.item(0);
var line = page.graphicLines.add();
line.paths.item(0).entirePath = myArr;
I should have this (the line circled in blue) :
But I get this (the rectangle circled in blue) :
This rectangle appears when I click on the focus, otherwise it is nonexistent.
The rectangle seems to be the size of the line and is well positioned but I did not get the line I wanted. What did I forget ?
Try to add this line at the end of your snippet:
line.strokeWeight = 1;

Hovering on one sentence should highlight matching sentence in another panel in Angular

I have 2 different JSON arrays displayed separately using a simple *ngFor loop on the same page. Ex-
json1: [ {
"order": 1,
"similarity": 0.82,
"sentence": "I would like to speak with :name:.",
"matching_sentence": "Hello, I would like to speak with Luke.",
"matching_line": 0
}]
json2: [ {
"order": 0,
"similarity": 0.82,
"sentence": "Hello, I would like to speak with Luke.",
"matching_sentence": "I would like to speak with :name:.",
"matching_line": 1,
"channel": 1,
"timeFrom": 15,
"timeTo": 20
}]
So, order property from json1 matches matching_line property of json2 and vice versa. So, what I need to achieve is that on mouse hover of json1, json2 should also be highlighted and on mouse hover of json2, json1 should also be highlighted.
This code is written in Angular 11 so, any solution whether it is by css or typescript is welcome.
You can achieve it using mouse enter leave events and keeping track of the active class
<div
*ngFor="let item of json1"
[ngClass]="{'highlight': item.order === activeHover}"
(mouseenter)="onHoverChange(item.order)"
(mouseleave)="onHoverChange(null)">
{{item.sentence}}
</div>
<div
*ngFor="let item of json2"
[ngClass]="{'highlight': item.matching_line === activeHover}"
(mouseenter)="onHoverChange(item.matching_line)"
(mouseleave)="onHoverChange(null)">
{{item.sentence}}
</div>
// in ts file
onHoverChange(value: number | null) {
this.activeHover = value;
}
Running sandbox link

Octave, barplot, only one row

I need to plot a bar graph in Octave. The following code:
clf;
data = rand(4, 5);
h1 = bar(data(1, :), "stacked");
l1 = legend("Col1", "Col2", "Col3", "Col4", "Col5");
legend(l1, "location", "northeastoutside");
figure
h4 = bar(data, "stacked");
l4 = legend("Col1", "Col2", "Col3", "Col4", "Col5");
legend(l4, "location", "northeastoutside");
does it. The second plot produces exactly what I need:
The first one, however, does not work as I would assume it would:
Is there any way to have a one-row bar plot that produces a graph with only one column in the style of the first plot?
Thanks in advance.
Rodrigo
This is not an elegant solution, but it can work in most of the cases.
The idea is to plot an additional bar (in x=2), and then hide it changing the
limits of the x axis (let's say [0.05, 1.95]):
M=zeros(2,4);
M(1,:)=rand(1,4);
bar(M, "stacked");
xlim([0.05 1.95]);
l1 = legend("Col1", "Col2", "Col3", "Col4", "Col5");
legend(l1, "location", "northeastoutside");

GUI elements from a function not being displayed in Red language

I am using following code to try to get GUI elements from a function:
mypanelfn: func[] [
collect[
repeat i 10 [
print append copy "i in loop: " i
keep [t: text] keep append copy "message: " i
keep [field "entry"
button "Click" [t/text: "clicked"] return]]]]
view [
do [mypanelfn]]
There are no error messages and loop go on all right and a windows is also displayed. But this is only a small empty windows without any text, fields or buttons.
What is wrong with this code?
Edit: putting probe before collect shows (I have added line breaks for clarity):
[t: text "message: 1" field "entry" button "Click" [t/text: "clicked"] return
t: text "message: 2" field "entry" button "Click" [t/text: "clicked"] return
t: text "message: 3" field "entry" button "Click" [t/text: "clicked"] return
t: text "message: 4" field "entry" button "Click" [t/text: "clicked"] return
t: text "message: 5" field "entry" button "Click" [t/text: "clicked"] return
This method does not require setting any variables—it works by containing each iteration of faces within a common parent (panel):
view collect [
keep [below space 0x0]
repeat i 10 [
keep compose/deep [
panel [
origin 0x0
text (rejoin ["Message Number: " i])
field "entry"
button "Click" [face/parent/pane/1/text: "clicked"]
]
]
]
]
face/parent is the panel face whose first child (pane/1) is the text box (origin does not create a face).
You don't necessarily need the function there, however:
view mypanelfn
Works.
Note: the equivalent code in Rebol requires layout: view layout mypanelfn
The reason this happens is because view processes blocks! (anything inside []). So you don't have to do it.
In general, it's better to think of Red as a functional, message passing language. Everything is an expression, in contrast to imperative languages with procedures and statements.
once again; you need unique names for elements you want to address. Here a solution with reduce instead of compose
mypanelfn: func[] [
collect[
repeat i 10 [
tname: to-word rejoin ['t i]
print append copy "i in loop: " i
keep reduce [to-set-word tname 'text] keep append copy "message: " i
keep reduce [
'field "entry" 'button "Click" reduce [
to-set-path reduce [
tname 'text ]
"clicked" ]
'return ] ] ] ]
I recommend that you use the commands in the console to see what they do. E.g.
rejoin ['t i] creates a string "t1"with t and the (reduced/get-)value of i.
to-word changes that to a Red(bol) word t1
to-setword tname creates a set-word t1:
to-set-path reduce [tname 'text ]creates a set-path t1/text:
this works for me in rebol/view:
lay: mypanelfn
insert head lay 'across
view layout lay
I think while you're learning this stuff you need to look at the generated VID code to check that there are no problems before trying to View it.