author | Edouard Tisserant <edouard@beremiz.fr> |
Fri, 06 Dec 2024 12:16:07 +0100 | |
changeset 4062 | 1994928ce3d2 |
parent 3330 | c3b1a4bfdf0a |
permissions | -rw-r--r-- |
2944 | 1 |
// widget_circularbar.ysl2 |
2 |
||
3241
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
3 |
widget_desc("CircularBar") { |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
4 |
longdesc |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
5 |
|| |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
6 |
CircularBar widget changes the end angle of a "path" labeled arc according |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
7 |
to value of the single accepted variable. |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
8 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
9 |
If "min" a "max" labeled texts are provided, then they are used as |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
10 |
respective minimum and maximum value. Otherwise, value is expected to be |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
11 |
in between 0 and 100. |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
12 |
|| |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
13 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
14 |
shortdesc > Change end angle of Inkscape's arc |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
15 |
|
3330
c3b1a4bfdf0a
SVGHMI: remove "value" element in meter and circularbar widget. Adding support for printf like formating make widget label too heavy. It is better to use Display widget instead.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3241
diff
changeset
|
16 |
arg name="min" count="optional" accepts="int,real" > minimum value |
c3b1a4bfdf0a
SVGHMI: remove "value" element in meter and circularbar widget. Adding support for printf like formating make widget label too heavy. It is better to use Display widget instead.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3241
diff
changeset
|
17 |
arg name="max" count="optional" accepts="int,real" > maximum value |
3241
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
18 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
19 |
path name="value" accepts="HMI_INT,HMI_REAL" > Value to display |
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
20 |
|
fe945f1f48b7
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3232
diff
changeset
|
21 |
} |
3232
7bdb766c2a4d
SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3105
diff
changeset
|
22 |
widget_class("CircularBar") { |
3045
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
23 |
|| |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
24 |
frequency = 10; |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
25 |
range = undefined; |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
26 |
|
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
27 |
dispatch(value) { |
3105
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
28 |
this.display_val = value; |
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
29 |
this.request_animate(); |
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
30 |
} |
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
31 |
|
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
32 |
animate(){ |
3045
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
33 |
if(this.value_elt) |
3105
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
34 |
this.value_elt.textContent = String(this.display_val); |
3045
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
35 |
let [min,max,start,end] = this.range; |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
36 |
let [cx,cy] = this.center; |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
37 |
let [rx,ry] = this.proportions; |
3105
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
38 |
let tip = start + (end-start)*Number(this.display_val)/(max-min); |
3045
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
39 |
let size = 0; |
3105
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
40 |
|
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
41 |
if (tip-start > Math.PI) |
3045
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
42 |
size = 1; |
3105
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
43 |
else |
3045
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
44 |
size = 0; |
3105
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
45 |
|
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
46 |
this.path_elt.setAttribute('d', "M "+(cx+rx*Math.cos(start))+","+(cy+ry*Math.sin(start))+ |
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
47 |
" A "+rx+","+ry+ |
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
48 |
" 0 "+size+ |
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
49 |
" 1 "+(cx+rx*Math.cos(tip))+","+(cy+ry*Math.sin(tip))); |
3045
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
50 |
} |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
51 |
|
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
52 |
init() { |
3330
c3b1a4bfdf0a
SVGHMI: remove "value" element in meter and circularbar widget. Adding support for printf like formating make widget label too heavy. It is better to use Display widget instead.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3241
diff
changeset
|
53 |
if(this.args.length >= 2) |
c3b1a4bfdf0a
SVGHMI: remove "value" element in meter and circularbar widget. Adding support for printf like formating make widget label too heavy. It is better to use Display widget instead.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3241
diff
changeset
|
54 |
[this.min, this.max]=this.args; |
c3b1a4bfdf0a
SVGHMI: remove "value" element in meter and circularbar widget. Adding support for printf like formating make widget label too heavy. It is better to use Display widget instead.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3241
diff
changeset
|
55 |
|
3105
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
56 |
let [start, end, cx, cy, rx, ry] = ["start", "end", "cx", "cy", "rx", "ry"]. |
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
57 |
map(tag=>Number(this.path_elt.getAttribute('sodipodi:'+tag))) |
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
58 |
|
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
59 |
if (ry == 0) |
3045
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
60 |
ry = rx; |
3105
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
61 |
|
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
62 |
if (start > end) |
3045
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
63 |
end = end + 2*Math.PI; |
3105
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
64 |
|
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
65 |
let [min,max] = [[this.min_elt,0],[this.max_elt,100]].map(([elt,def],i)=>elt? |
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
66 |
Number(elt.textContent) : |
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
67 |
this.args.length >= i+1 ? this.args[i] : def); |
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
68 |
|
3045
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
69 |
this.range = [min, max, start, end]; |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
70 |
this.center = [cx, cy]; |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
71 |
this.proportions = [rx, ry]; |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
72 |
} |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
73 |
|| |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2944
diff
changeset
|
74 |
} |
2944 | 75 |
|
3232
7bdb766c2a4d
SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3105
diff
changeset
|
76 |
widget_defs("CircularBar") { |
2944 | 77 |
labels("path"); |
3330
c3b1a4bfdf0a
SVGHMI: remove "value" element in meter and circularbar widget. Adding support for printf like formating make widget label too heavy. It is better to use Display widget instead.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3241
diff
changeset
|
78 |
optional_labels("min max"); |
3105
8819c8b66a42
SVGHMI: CircularBar: use animate() + cormetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
79 |
} |