svghmi/widget_circularbar.ysl2
author Edouard Tisserant
Thu, 03 Sep 2020 11:16:08 +0200
branchsvghmi
changeset 3052 ffce85221ea5
parent 3045 f6d428330e04
child 3105 8819c8b66a42
permissions -rw-r--r--
SVGHMI: Better error message when inkscape is not installed.
2944
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
     1
// widget_circularbar.ysl2
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
     2
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
     3
template "widget[@type='CircularBar']", mode="widget_class"{
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
     4
    ||
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
     5
    class CircularBarWidget extends Widget{
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
     6
        frequency = 10;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
     7
        range = undefined;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
     8
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
     9
        dispatch(value) {
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    10
            if(this.value_elt)
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    11
                this.value_elt.textContent = String(value);
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    12
            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
    13
            let [cx,cy] = this.center;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    14
            let [rx,ry] = this.proportions;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    15
            let tip = start + (end-start)*Number(value)/(max-min);
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    16
            let size = 0;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    17
            if (tip-start > Math.PI) {
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    18
                size = 1;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    19
            } else {
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    20
                size = 0;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    21
            }
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    22
            this.path_elt.setAttribute('d', "M "+(cx+rx*Math.cos(start))+","+(cy+ry*Math.sin(start))+" A "+rx+","+ry+" 0 "+size+" 1 "+(cx+rx*Math.cos(tip))+","+(cy+ry*Math.sin(tip)));
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
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    25
        init() {
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    26
            let start = Number(this.path_elt.getAttribute('sodipodi:start'));
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    27
            let end = Number(this.path_elt.getAttribute('sodipodi:end'));
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    28
            let cx = Number(this.path_elt.getAttribute('sodipodi:cx'));
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    29
            let cy = Number(this.path_elt.getAttribute('sodipodi:cy'));
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    30
            let rx = Number(this.path_elt.getAttribute('sodipodi:rx'));
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    31
            let ry = Number(this.path_elt.getAttribute('sodipodi:ry'));
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    32
            if (ry == 0) {
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    33
                ry = rx;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    34
            }
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    35
            if (start > end) {
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    36
                end = end + 2*Math.PI;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    37
            }
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    38
            let min = this.min_elt ?
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    39
                      Number(this.min_elt.textContent) :
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    40
                      this.args.length >= 1 ? this.args[0] : 0;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    41
            let max = this.max_elt ?
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    42
                      Number(this.max_elt.textContent) :
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    43
                      this.args.length >= 2 ? this.args[1] : 100;
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    44
            this.range = [min, max, start, end];
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    45
            this.center = [cx, cy];
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    46
            this.proportions = [rx, ry];
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    47
        }
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    48
    }
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    49
    ||
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    50
}
2944
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
    51
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
    52
template "widget[@type='CircularBar']", mode="widget_defs" {
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
    53
    param "hmi_element";
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
    54
    labels("path");
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
    55
    optional_labels("value min max");
3045
f6d428330e04 All widgets reworked to use widget class and animate function if needed
usveticic
parents: 2944
diff changeset
    56
    |,
2944
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
    57
}