author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Tue, 01 Aug 2023 21:04:00 +0200 | |
changeset 3840 | c2b6354f036f |
parent 3330 | c3b1a4bfdf0a |
permissions | -rw-r--r-- |
2883
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
1 |
// widget_meter.ysl2 |
2792
0c0d3895b036
SVGHMI: moved/fixed some templates, avoided namespace problems, added parsing of HMI:* inkscape labels
Edouard Tisserant
parents:
2791
diff
changeset
|
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("Meter") { |
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 |
Meter widget moves the end of "needle" labeled path along "range" labeled |
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 |
path, according 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 |
Needle is reduced to a single segment. If "min" a "max" labeled texts |
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 |
are provided, or if first and second argument are given, then they are used |
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 |
as 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
|
12 |
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
|
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 |
|
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 |
shortdesc > Moves "needle" along "range" |
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
|
16 |
|
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
|
17 |
arg name="min" count="optional" accepts="int,real" > minimum value |
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 |
arg name="max" count="optional" accepts="int,real" > maximum value |
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 |
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
|
22 |
|
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
|
23 |
} |
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
|
24 |
|
3275
1fd8bef23f67
SVGHMI: fixed bug introduced in 7bdb766c2a4d, typo breaking meter widget
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3241
diff
changeset
|
25 |
widget_class("Meter"){ |
3045
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2883
diff
changeset
|
26 |
|| |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2883
diff
changeset
|
27 |
frequency = 10; |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2883
diff
changeset
|
28 |
origin = undefined; |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2883
diff
changeset
|
29 |
range = undefined; |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2883
diff
changeset
|
30 |
|
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2883
diff
changeset
|
31 |
dispatch(value) { |
3104
14d15712fcca
SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
32 |
this.display_val = value; |
14d15712fcca
SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
33 |
this.request_animate(); |
14d15712fcca
SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
34 |
} |
14d15712fcca
SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
35 |
|
14d15712fcca
SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
36 |
animate(){ |
3045
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2883
diff
changeset
|
37 |
if(this.value_elt) |
3104
14d15712fcca
SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
38 |
this.value_elt.textContent = String(this.display_val); |
3045
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2883
diff
changeset
|
39 |
let [min,max,totallength] = this.range; |
3104
14d15712fcca
SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
40 |
let length = Math.max(0,Math.min(totallength,(Number(this.display_val)-min)*totallength/(max-min))); |
3045
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2883
diff
changeset
|
41 |
let tip = this.range_elt.getPointAtLength(length); |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2883
diff
changeset
|
42 |
this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y); |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2883
diff
changeset
|
43 |
} |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2883
diff
changeset
|
44 |
|
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2883
diff
changeset
|
45 |
init() { |
3104
14d15712fcca
SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
46 |
let [min,max] = [[this.min_elt,0],[this.max_elt,100]].map(([elt,def],i)=>elt? |
14d15712fcca
SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
47 |
Number(elt.textContent) : |
14d15712fcca
SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
48 |
this.args.length >= i+1 ? this.args[i] : def); |
14d15712fcca
SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3045
diff
changeset
|
49 |
|
3045
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2883
diff
changeset
|
50 |
this.range = [min, max, this.range_elt.getTotalLength()] |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2883
diff
changeset
|
51 |
this.origin = this.needle_elt.getPointAtLength(0); |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2883
diff
changeset
|
52 |
} |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2883
diff
changeset
|
53 |
|| |
f6d428330e04
All widgets reworked to use widget class and animate function if needed
usveticic
parents:
2883
diff
changeset
|
54 |
} |
2790
8fab1886ebec
SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents:
2789
diff
changeset
|
55 |
|
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:
3104
diff
changeset
|
56 |
widget_defs("Meter") { |
2883
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
57 |
labels("needle range"); |
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:
3275
diff
changeset
|
58 |
optional_labels("min max"); |
2883
8e3d130399b0
SVGHMI: created widget_*.ysl2. Renamed widget_common in widgets_common, so that it doesn't match globing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2882
diff
changeset
|
59 |
} |
2810
63b9a37b73c7
SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents:
2808
diff
changeset
|
60 |
|
63b9a37b73c7
SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents:
2808
diff
changeset
|
61 |