svghmi/widget_meter.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Wed, 30 Jun 2021 15:51:59 +0200
branchsvghmi
changeset 3267 5f20f391ae31
parent 3241 fe945f1f48b7
child 3275 1fd8bef23f67
permissions -rw-r--r--
SVGHMI: Prepare accepting multiple clients on multiple HMI: Use POULibrary new capability to add variables to PLC Configuration. Now heartbeat and HMI tree root are added by the library part of SVGHMI, and not by each instance.
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
    If "value" labeled text is found, then its content is replaced by 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
    15
    ||
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
    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
    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="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
    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
    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
    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
    // TODO: add printf-like format
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
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
    25
    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
    26
    
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
    27
}
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
    28
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
    29
widget_class("Metter"){
3045
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
        frequency = 10;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    32
        origin = undefined;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    33
        range = undefined;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    34
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    35
        dispatch(value) {
3104
14d15712fcca SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    36
            this.display_val = value;
14d15712fcca SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    37
            this.request_animate();
14d15712fcca SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    38
        }
14d15712fcca SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    39
14d15712fcca SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    40
        animate(){
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    41
            if(this.value_elt)
3104
14d15712fcca SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    42
                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
    43
            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
    44
            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
    45
            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
    46
            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
    47
        }
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    48
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    49
        init() {
3104
14d15712fcca SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    50
            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
    51
                Number(elt.textContent) :
14d15712fcca SVGHMI: Meter widget: use animate() + cosmetic changes
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3045
diff changeset
    52
                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
    53
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    54
            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
    55
            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
    56
        }
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    57
    ||
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2883
diff changeset
    58
}
2790
8fab1886ebec SVGHI: compute hmitree variables ordered index in xslt
Edouard Tisserant
parents: 2789
diff changeset
    59
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
    60
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
    61
    labels("needle range");
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
    62
    optional_labels("value min max");
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
    63
}
2810
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
    64
63b9a37b73c7 SVGHMI: various insignificant code moves, commenting and typos fixes.
Edouard Tisserant
parents: 2808
diff changeset
    65