svghmi/widget_xygraph.ysl2
changeset 3509 b5ca17732b1e
parent 3505 a27b5862e363
child 3691 9289fdda0222
equal deleted inserted replaced
3508:14d696d7d54e 3509:b5ca17732b1e
   109             // assign created clipPath to clip-path property of curves
   109             // assign created clipPath to clip-path property of curves
   110             for(let curve of this.curves){
   110             for(let curve of this.curves){
   111                 curve.setAttribute("clip-path", "url(#" + clipPath.id + ")");
   111                 curve.setAttribute("clip-path", "url(#" + clipPath.id + ")");
   112             }
   112             }
   113 
   113 
   114             this.curves_data = this.curves.map(_unused => []);
   114             this.curves_data = [];
   115         }
   115         }
   116 
   116 
   117         dispatch(value,oldval, index) {
   117         dispatch(value,oldval, index) {
   118             // TODO: get PLC time instead of browser time
   118             // TODO: get PLC time instead of browser time
   119             let time = Date.now();
   119             let time = Date.now();
   120 
   120 
   121             // naive local buffer impl. 
   121             // naive local buffer impl. 
   122             // data is updated only when graph is visible
   122             // data is updated only when graph is visible
   123             // TODO: replace with separate recording
   123             // TODO: replace with separate recording
   124 
   124 
       
   125             if(this.curves_data[index] === undefined){
       
   126                 this.curves_data[index] = [];
       
   127             }
   125             this.curves_data[index].push([time, value]);
   128             this.curves_data[index].push([time, value]);
   126             let data_length = this.curves_data[index].length;
   129             let data_length = this.curves_data[index].length;
   127             let ymin_damaged = false;
   130             let ymin_damaged = false;
   128             let ymax_damaged = false;
   131             let ymax_damaged = false;
   129             let overflow;
   132             let overflow;
   224         }
   227         }
   225 
   228 
   226     ||
   229     ||
   227 }
   230 }
   228 
   231 
       
   232 def "func:check_curves_label_consistency" {
       
   233     param "curve_elts";
       
   234     param "number_to_check";
       
   235     const "res" choose {
       
   236         when "$curve_elts[@inkscape:label = concat('curve_', string($number_to_check))]"{
       
   237             if "$number_to_check > 0"{
       
   238                 value "func:check_curves_label_consistency($curve_elts, $number_to_check - 1)";
       
   239             }
       
   240         }
       
   241         otherwise {
       
   242             value "concat('missing curve_', string($number_to_check))";
       
   243         }
       
   244     }
       
   245     result "$res";
       
   246 }
       
   247 
   229 widget_defs("XYGraph") {
   248 widget_defs("XYGraph") {
   230     labels("/x_interval_minor_mark /x_axis_line /x_interval_major_mark /x_axis_label");
   249     labels("/x_interval_minor_mark /x_axis_line /x_interval_major_mark /x_axis_label");
   231     labels("/y_interval_minor_mark /y_axis_line /y_interval_major_mark /y_axis_label");
   250     labels("/y_interval_minor_mark /y_axis_line /y_interval_major_mark /y_axis_label");
   232 
   251 
   233     |     init_specific() {
   252     |     init_specific() {
   234 
   253 
   235     // collect all curve_n labelled children
   254     // collect all curve_n labelled children
   236     foreach "$hmi_element/*[regexp:test(@inkscape:label,'^curve_[0-9]+$')]" {
   255     const "curves","$hmi_element/*[regexp:test(@inkscape:label,'^curve_[0-9]+$')]";
       
   256     const "curves_error", "func:check_curves_label_consistency($curves,count($curves)-1)";
       
   257     if "string-length($curves_error)"
       
   258         error > XYGraph id="«@id»", label="«@inkscape:label»" : «$curves_error»
       
   259     foreach "$curves" {
   237         const "label","@inkscape:label";
   260         const "label","@inkscape:label";
   238         const "id","@id";
   261         const "_id","@id";
   239 
   262         const "curve_num", "substring(@inkscape:label, 7)";
   240         // detect non-unique names
   263     |         this.curves[«$curve_num»] = id("«@id»"); /* «@inkscape:label» */
   241         if "$hmi_element/*[not($id = @id) and @inkscape:label=$label]"{
       
   242             error > XYGraph id="«$id»", label="«$label»" : elements with data_n label must be unique.
       
   243         }
       
   244     |         this.curves[«substring(@inkscape:label, 7)»] = id("«@id»"); /* «@inkscape:label» */
       
   245     }
   264     }
   246 
   265 
   247     |     }
   266     |     }
   248 
   267 
   249 }
   268 }