adaptive-linechart 1.0.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.2 (20 Nov 2022)
4
+ * In README change link to demo and move to new repository.
5
+
6
+ ## 1.2.0 (01 Nov 2020)
7
+ * New feature:
8
+ - By click on legend item hide/show line on chart.
9
+ * Fix bug:
10
+ - In some case label on axe-y below axe-x.
11
+
12
+ ## 1.1.0 (21 May 2020)
13
+ Allowed negative and positive values in randge from -9007199254740991 till 9007199254740991.
14
+
3
15
  ## 1.0.1 (4 May 2020)
4
16
  - Add README.md
5
17
  - Add directory **src** (files for development) and **dist** (ready to use minified files)
package/README.md CHANGED
@@ -1,14 +1,16 @@
1
- ## adaptive-linechart
1
+ ## adaptive-linechart :chart_with_upwards_trend:
2
+ :
3
+ Version 1.2.2
2
4
 
3
- This is a small library to draw charts in the browser. It automatically creates a legend and labels
4
- thes axes x and y depending on available space (width/height) and supplied data. Maximal 10 lines.
5
- The current version processes only positive values.
5
+ This is a small library to draw charts in the browser. Why is it "adaptive"? Because it automaticaly
6
+ adjust chart to available size depend on min/max values on and timespan. Additional you
7
+ can adjust the layout of the chart. The chart uses the external CSS styles .nowrap .linechart,
8
+ .chart-title, .chart-live-data, .chart-legend, .chart-legend-item, .chart-legend-color.
6
9
 
7
- The name “adaptive” indicates that you can adjust the layout of the chart. The chart uses the
8
- external CSS styles .nowrap .linechart, .chart-title, .chart-live-data, .chart-legend,
9
- .chart-legent-item, .chart-legent-color. The chart uses the global variable isMobil (Boolean). If
10
- true, live data are shown by "mouse-over". By click on item in legend called external
11
- function **`processSelectLegendItem(chartId, amount-of-lines, parameter-id)`**.
10
+ Maximal 10 lines. Since version 1.1.0 allowed negative and positive values in randge from
11
+ -9007199254740991 till 9007199254740991. The chart uses the global variable isMobil (Boolean). If
12
+ false, live data are shown by "mouse-over". By click on item in the legend hide/show line on chart
13
+ and switch colored tag of item.
12
14
 
13
15
  The chart accepts data as time-series in the format (string) "Unix-Timestamp/Value;Unix-Timestamp/Value;..".
14
16
  Additional (chart-util) supplied function to convert CSV (with header) to time-series.
@@ -49,6 +51,8 @@ for(let i=0; i < arTimeSeries.length; i++) {
49
51
  lchart.draw();
50
52
  ```
51
53
 
54
+ [Live example](https://www.softdorado.com/adaptive-linechart.html)
55
+
52
56
  ## Public methods
53
57
 
54
58
  **`LineChart(container, chartId, width, title, className)`** - create an object of type LineChart
@@ -68,7 +72,7 @@ Return true if no problem detected, otherwise false.
68
72
  - **par_id** - Integer. Optional ID of this line. May be used to request data from backend.
69
73
  - **values** - String. Time-series in format "Unix-Timestamp/Value;Unix-Timestamp/Value;.."
70
74
 
71
- **`draw()`** - draw graphic. Skeep lines if properties hidden=true or isEmpty=true.
75
+ **`draw()`** - draw graphic. Skip lines if properties hidden=true or isEmpty=true.
72
76
 
73
77
  **`clear()`** - clear graphic. Legend stays visible.
74
78
 
@@ -82,11 +86,15 @@ Return true if no problem detected, otherwise false.
82
86
 
83
87
  **`scvToTimeSeries(csv)`** - process CSV and return array of objects
84
88
 
85
- `{name: "Name of serie", data: "Unix-Timestamp/Value;Unix-Timestam/Value"}`.
89
+ `{name: "Name of serie", data: "Unix-Timestamp/Value;Unix-Timestamp/Value"}`.
86
90
 
87
91
  Assume the first column contains data-time as string. The CSV may contain many columns. Name of
88
92
  serie taken from header. Values may be empty. This function needs the package [Moment.js](https://momentjs.com)
89
93
 
94
+ ## Contact
95
+
96
+ If you have any questions, please contact me `adaptive-linechart@my.mail.de`
97
+
90
98
  ## License
91
99
 
92
100
  [MIT](https://opensource.org/licenses/MIT) © Andrej Koslov
@@ -1,2 +1,2 @@
1
- class LineChart{constructor(t,e,i,a,s){null==t&&(t=document.getElementsByTagName("BODY")[0]),null==e&&(e=getRandomInt()),null==s&&(s="linechart"),null==i&&(i=t.clientWidth),this.chartDiv=addNewElement(t,"div",{class:s,id:"chart_"+e,chart_id:e,style:"float:left; width:"+i+"px; padding-bottom:8px;"}),null!=a?(this.title=addNewElement(this.chartDiv,"label",{class:"chart-title nowrap",style:"width:"+(i-20)+"px; text-align:center; display:block; margin-left:10px; margin-top:10px"}),this.title.innerHTML=a):this.title=null;var n=i-30,h=300;isMobil?h=220:i<200?h=200:i<300?h=220:i<400?h=240:i<500?h=260:i<600&&(h=280),this.canvas=addNewElement(this.chartDiv,"canvas",{id:"chart_"+e+"_canvas",width:n,height:h,style:"margin: 15px 17px 3px 13px;"}),this.canvas.dataset.chartId=e.toString(),this.context=this.canvas.getContext("2d"),this.context.translate(.5,.5),isMobil||(this.canvas.addEventListener("mouseout",(function(t){var e=document.getElementById("chart_"+this.dataset.chartId+"_livedata");null!=e&&(e.innerText="-")})),this.canvas.addEventListener("mousemove",(function(t){var e=document.getElementById("chart_"+this.dataset.chartId+"_livedata");if(null!=e)if(this.height-t.offsetY<this.dataset.paddingBottom||t.offsetX<this.dataset.paddingLeft)e.innerText="-";else{var i=this.dataset.maxVal-t.offsetY/parseFloat(this.dataset.coefVal);if(isNaN(i))e.innerText="-";else{i=i<100?i.toFixed(2):i<200?i.toFixed(1):Math.round(i);var a=parseInt(this.dataset.minTs)+Math.round((t.offsetX-parseInt(this.dataset.paddingLeft))/parseFloat(this.dataset.coefTs));isNaN(a)?e.innerText="-":(a=new Date(1e3*a).separate(),e.innerHTML="Date <b>"+a.mday+"."+a.month+"."+a.year+"</b> Time <b>"+a.hour+":"+a.min+"</b> Value <b>"+i+"</b>")}}})),addNewElement(this.chartDiv,"div",{class:"chart-live-data",id:"chart_"+e+"_livedata",style:"margin-left: 12px; margin-right: 12px; margin-bottom: 4px; max-width:95%;",innerText:"-"})),this.legendDiv=addNewElement(this.chartDiv,"div",{class:"chart-legend",id:"chart_"+e+"_legend"}),this.chartId=e,this.lines=[],this.minTs=99999999999999,this.maxTs=0,this.minVal=999999999999999,this.maxVal=0,this.axeYLabelStep=null,this.axeYLabelHeight=30,this.axeXLabelWidth=80,this.coefTs=null,this.coefVal=null,this.padding={left:50,bottom:35},this.endDate=null,this.avgStep=NaN}addLine(t){if(null==t.values)return logger.error("Function LineChart.newLine(). DataString is null."),!1;if(!isString(t.values))return logger.error("Function LineChart.newLine(). DataString is not a string."),!1;var e=this._createLine(t);if(null==e)return logger.error("Function LineChart.newLine(). Function _createLine() return null."),!1;e.objName=t.obj_name,e.parName=t.par_name,e.parId=t.par_id;var i=this.colors[this.lines.length];return isMobil,e.legend=addNewElement(this.legendDiv,"div",{class:"chart-legend-item nowrap",id:"chart_"+this.chartId+"_legend_"+t.par_id,style:"max-width:"+(this.chartDiv.clientWidth-20)+"px;",onclick:"processSelectLegendItem("+this.chartId+","+this.lines.length+","+e.parId+")",innerHTML:'<span class="chart-legend-color" style="background-color:'+i+"; color:"+i+';">--</span>'+e.objName+" / "+e.parName}),this.lines.push(e),!0}updateLines(t){if(null==t)return logger.error("Function LineChart.updateLines(). Parameter lines is null."),!1;if(!Array.isArray(t))return logger.error("Function LineChart.updateLines(). Parameter lines is not a array."),!1;for(var e in this.lines=[],this.minTs=99999999999999,this.maxTs=0,this.minVal=999999999999999,this.maxVal=0,this.axeYLabelStep=null,this.coefTs=null,this.coefVal=null,t){var i=this._createLine(t[e]);null!=i&&this.lines.push(i)}return this.draw(),!0}_createLine(t){var e=new SingleLine(t),i=!0;if(0==t.values.length)return e;for(var a=t.values.split(";"),s=a.length,n=0;n<s;++n){var h=a[n].split("/");if(""!=h[0])if(isNaN(h[0]))logger.warn("LineChart._createLine(). Item "+n+' contains invalid time-stamp "'+h[0]+'".');else{var l={ts:null,val:null};if(l.ts=parseInt(h[0]),l.val=parseFloat(h[1]),l.val<0)return logger.error("LineChart._createLine(). Negative values not supported! ts="+l.ts+" val="+l.val),null;e.real.push(l),isNaN(l.val)||(l.val<this.minVal&&(this.minVal=Math.floor(.95*l.val)),l.val>this.maxVal&&(this.maxVal=Math.ceil(1.05*l.val)),i=!1),l.ts<this.minTs&&(this.minTs=l.ts),l.ts>this.maxTs&&(this.maxTs=l.ts)}else logger.warn("LineChart._createLine(). Item "+n+" time-stamp is empty.")}if(0==e.real.length)return e;e.isEmpty=!1,(0==this.maxVal&&0==this.minVal||i)&&(this.minVal=0,this.maxVal=1);var r=this.context.measureText(this.minVal.toString()),o=this.context.measureText(this.maxVal.toString());return r.width<o.width?this.padding.left=Math.round(o.width)+23:this.padding.left=Math.round(r.width)+23,e}clear(){this.context.clearRect(0,0,this.canvas.width,this.canvas.height)}draw(){if(this.coefTs=(this.canvas.width-this.padding.left)/(this.maxTs-this.minTs),this.coefVal=(this.canvas.height-this.padding.bottom)/(this.maxVal-this.minVal),this.context.clearRect(0,0,this.canvas.width,this.canvas.height),!this.isEmpty()){this._drawAxeX(),this._drawAxeY();for(var t=0;t<this.lines.length;t++)this.drawLine(t);this.canvas.dataset.minTs=this.minTs.toString(),this.canvas.dataset.coefTs=this.coefTs.toString(),this.canvas.dataset.maxVal=this.maxVal.toString(),this.canvas.dataset.coefVal=this.coefVal.toString(),this.canvas.dataset.paddingLeft=this.padding.left.toString(),this.canvas.dataset.paddingBottom=this.padding.bottom.toString()}}resize(t,e){this.canvas.width=this.canvas.width+t,this.canvas.height=this.canvas.height+e,this.context.translate(.5,.5)}_drawAxeX(){this.context.strokeStyle=this.colorDefault,this.context.lineWidth=1,this.context.beginPath(),this.context.moveTo(this.padding.left,this.canvas.height-this.padding.bottom),this.context.lineTo(this.canvas.width,this.canvas.height-this.padding.bottom),this.context.stroke();var t,e=Math.round(this.axeXLabelWidth/this.coefTs/60);t=this.stepsX.length-1;for(var i=0;i<t;i++)if(e>this.stepsX[i]&&e<this.stepsX[i+1]){e=this.stepsX[i];break}e*=60;for(var a=this._getBeginOfDayFromUnixTs(this.minTs),s=(new Date).getTime()/1e3;a<s;){if(a>this.minTs){!0;break}a+=e}for(var n,h,l=[];a<this.maxTs;)n=this._convertTs2PosX(a),h=this._formatTsForLabel(a,this.maxTs-this.minTs),l.push({X:n,str:h}),a+=e;this.context.beginPath(),this.context.strokeStyle="#e6e6e6";var r=Math.round(e*this.coefTs/2),o=this.canvas.height-this.padding.bottom;t=l.length;for(i=0;i<t;i++)this.context.moveTo(l[i].X,0),this.context.lineTo(l[i].X,o),l[i].X-r>this.padding.left+2&&(this.context.moveTo(l[i].X-r,0),this.context.lineTo(l[i].X-r,o));for(null!=l[i-1]&&l[i-1].X+r<=this.canvas.width&&(this.context.moveTo(l[i-1].X+r,0),this.context.lineTo(l[i-1].X+r,o)),this.context.stroke(),this.context.font="12px arial",t=l.length,i=0;i<t;i++)this.context.fillText(l[i].str.hm,l[i].X-17,o+17),(0==i||l[i].str.dm!=l[i-1].str.dm)&&this.context.fillText(l[i].str.dm,l[i].X-17,o+32);this.context.closePath()}_drawAxeY(){if(null!=this.coefTs&&null!=this.coefVal){var t,e=(this.canvas.height-this.padding.bottom)/this.axeYLabelHeight;this.axeYLabelStep=(this.maxVal-this.minVal)/e;for(var i,a,s=1,n=!1;s<1e11;){for(var h=0;h<this.stepsY.length-1;h++)if(i=this.stepsY[h]*s,a=this.stepsY[h+1]*s,i<=this.axeYLabelStep&&this.axeYLabelStep<=a){this.axeYLabelStep=a,n=!0;break}if(n)break;s*=10}var l=0;if(this.minVal<0)for(;l>this.minVal&&!(l<=this.minVal);)l-=this.axeYLabelStep;else if(this.minVal>0)for(;l<this.maxVal&&!(l>=this.minVal);)l+=this.axeYLabelStep;var r,o,d,c=[];for(h=0;h<33&&(o=l+this.axeYLabelStep*h,(this.axeYLabelStep<1||2.5==this.axeYLabelStep)&&(o=o.toFixed(2)),!((r=this._convertVal2PosY(o))<0));){var g={value:o,Y:r};c.push(g),h++}for(this.context.lineWidth=1,this.context.beginPath(),this.context.strokeStyle=this.colorDefault,this.context.moveTo(this.padding.left,0),this.context.lineTo(this.padding.left,this.canvas.height-this.padding.bottom),this.context.stroke(),this.context.beginPath(),this.context.strokeStyle="#e6e6e6",t=c.length,h=0;h<t;h++)(d=c[h].Y+Math.round(this.coefVal*this.axeYLabelStep/2))<this.canvas.height-this.padding.bottom&&(this.context.moveTo(this.padding.left,d),this.context.lineTo(this.canvas.width,d)),c[h].Y>=this.canvas.height-this.padding.bottom||(this.context.moveTo(this.padding.left,c[h].Y),this.context.lineTo(this.canvas.width,c[h].Y));for((d=c[c.length-1].Y-Math.round(this.coefVal*this.axeYLabelStep/2))>0&&(this.context.moveTo(this.padding.left,d),this.context.lineTo(this.canvas.width,d)),this.context.stroke(),this.context.font="12px arial",this.context.strokeStyle=this.colorDefault,t=c.length,h=0;h<t;h++)this.context.fillText(c[h].value,0,c[h].Y+10)}}drawLine(t){var e=this.lines[t];if(null!=e){if(1!=e.isEmpty&&0!=e.real.length&&!e.hidden){var i,a=[],s=-1,n=[],h=[];if(!isNaN(this.avgStep)){for(var l=this._getBeginOfDayFromUnixTs(e.real[0].ts);l<e.real[0].ts;)l+=this.avgStep;i=e.real.length;for(var r=0;r<i;r++)if(e.real[r].ts<l)n.push(e.real[r].val);else{for(var o=0;e.real[r].ts>l+this.avgStep;)if(l+=this.avgStep,++o>1e3)return void logger.warn("drawLine(). Can't calculate average values for this line. "+new Date(1e3*e.real[r].ts).formatISOLocal()+"/"+e.real[r].val);var d={ts:l,val:getAvgValue(n,2)};h.push(d),(n=[]).push(e.real[r].val),l+=this.avgStep}if(n.length>0){d={ts:l,val:getAvgValue(n,2)};h.push(d)}}n=[],0==h.length&&(h=e.real),i=h.length;for(var c=0;c<i;c++){(d={X:NaN,Y:NaN}).X=this._convertTs2PosX(h[c].ts),isNaN(h[c].val)||(d.Y=this._convertVal2PosY(h[c].val)),d.X!=s?(s=d.X,n.length>0&&c>0&&(n.push(a[a.length-1].Y),a[a.length-1].Y=getAvgValue(n,2),n=[]),a.push(d)):n.push(d.Y)}for(this.context.strokeStyle=this.colors[t],this.context.lineWidth=1,this.context.beginPath(),i=a.length,c=0;c<i;c++)if(!isNaN(a[c].Y)){this.context.moveTo(a[c].X,a[c].Y),c++;break}for(;c<i;)if(isNaN(a[c].Y))for(this.context.stroke(),c++;c<a.length;){if(!isNaN(a[c].Y)){c++;break}c++}else this.context.lineTo(a[c].X,a[c].Y),c++;this.context.stroke()}}else logger.error("Function LineChart.drawLine(lineId). The line with ID "+t+" not found!")}isEmpty(){for(var t=!0,e=0;e<this.lines.length;e++)this.lines[e].isEmpty||(t=!1);return t}_convertTs2PosX(t){return this.canvas.width-Math.round((this.maxTs-t)*this.coefTs)}_convertVal2PosY(t){return Math.round((this.maxVal-t)*this.coefVal)}_formatTsForLabel(t,e){let i=new Date(1e3*t);e/=86400;let a=i.getFullYear(),s=i.getMonth()+1;s<10&&(s="0"+s.toString());let n=i.getDate();parseInt(n)<10&&(n="0"+n.toString());let h=i.getHours();parseInt(h)<10&&(h="0"+h);let l=i.getMinutes();parseInt(l)<10&&(l="0"+l.toString());let r={};return r=e<3?{dm:n+"."+s,hm:h+":"+l}:e>=3&&e<180?{dm:a,hm:n+"."+s}:{dm:a,hm:" "+s},r}_getBeginOfDayFromUnixTs(t){var e=new Date(1e3*t);return(e=new Date(e.getFullYear(),e.getMonth(),e.getDate())).setMinutes(59),e.setSeconds(59),e.setMilliseconds(1e3),e.getTime()/1e3}colors=["#0044CC","#008000","#FF8533","#6A6A6A","#C71585","#8B4513","#1E90FF","#FF4500","#00FF00","#8A2BE2"];colorDefault="#657585";stepsX=[2,5,10,15,20,30,60,90,120,240,300,360,720,1440,2880,4320,5760,7200,10080,14400,21600,28800,43200,64800,86400,129600,172800];stepsY=[.01,.02,.05,.1]}class SingleLine{constructor(t){this.parId=t.par_id,this.parName=t.par_name,this.objName=t.obj_name,this.real=[],this.isEmpty=!0,this.hidden=!1}}
1
+ class LineChart{constructor(t,e,i,a,s){null==t&&(t=document.getElementsByTagName("BODY")[0]),null==e&&(e=getRandomInt()),null==s&&(s="linechart"),null==i&&(i=t.clientWidth),this.chartDiv=addNewElement(t,"div",{class:s,id:"chart_"+e,chart_id:e,style:"float:left; width:"+i+"px; padding-bottom:8px;"}),null!=a?(this.title=addNewElement(this.chartDiv,"label",{class:"chart-title nowrap",style:"width:"+(i-20)+"px; text-align:center; display:block; margin-left:10px; margin-top:10px"}),this.title.innerHTML=a):this.title=null;var n=i-30,h=300;isMobil?h=220:i<200?h=200:i<300?h=220:i<400?h=240:i<500?h=260:i<600&&(h=280),this.canvas=addNewElement(this.chartDiv,"canvas",{id:"chart_"+e+"_canvas",width:n,height:h,style:"margin: 15px 17px 3px 13px;"}),this.canvas.dataset.chartId=e.toString(),this.context=this.canvas.getContext("2d"),this.context.translate(.5,.5),isMobil||(this.canvas.addEventListener("mouseout",(function(t){var e=document.getElementById("chart_"+this.dataset.chartId+"_livedata");null!=e&&(e.innerText="-")})),this.canvas.addEventListener("mousemove",(function(t){var e=document.getElementById("chart_"+this.dataset.chartId+"_livedata");if(null!=e)if(this.height-t.offsetY<this.dataset.paddingBottom||t.offsetX<this.dataset.paddingLeft)e.innerText="-";else{var i=this.dataset.maxVal-t.offsetY/parseFloat(this.dataset.coefVal);if(isNaN(i))e.innerText="-";else{i=i<100?i.toFixed(2):i<200?i.toFixed(1):Math.round(i);var a=parseInt(this.dataset.minTs)+Math.round((t.offsetX-parseInt(this.dataset.paddingLeft))/parseFloat(this.dataset.coefTs));isNaN(a)?e.innerText="-":(a=new Date(1e3*a).separate(),e.innerHTML="Date <b>"+a.mday+"."+a.month+"."+a.year+"</b> Time <b>"+a.hour+":"+a.min+"</b> Value <b>"+i+"</b>")}}})),addNewElement(this.chartDiv,"div",{class:"chart-live-data",id:"chart_"+e+"_livedata",style:"margin-left: 12px; margin-right: 12px; margin-bottom: 4px; max-width:95%;",innerText:"-"})),this.legendDiv=addNewElement(this.chartDiv,"div",{class:"chart-legend",id:"chart_"+e+"_legend"}),this.chartId=e,this.lines=[],this.minTs=99999999999999,this.maxTs=0,this.minVal=Number.MAX_SAFE_INTEGER,this.maxVal=Number.MIN_SAFE_INTEGER,this.axeYLabelStep=null,this.axeYLabelHeight=30,this.axeXLabelWidth=80,this.coefTs=null,this.coefVal=null,this.padding={left:50,bottom:35},this.endDate=null,this.avgStep=NaN}addLine(t){if(null==t.values)return logger.error("Function LineChart.newLine(). DataString is null."),!1;if(!isString(t.values))return logger.error("Function LineChart.newLine(). DataString is not a string."),!1;var e=this._createLine(t);return null==e?(logger.error("Function LineChart.newLine(). Function _createLine() return null."),!1):(e.objName=t.obj_name,e.parName=t.par_name,e.parId=t.par_id,e.color=this.colors[this.lines.length],e.legend=addNewElement(this.legendDiv,"div",{class:"chart-legend-item nowrap",id:`chart_${this.chartId}_legend_${t.par_id}`,style:`cursor: pointer; max-width:${this.chartDiv.clientWidth-20}px;`,innerHTML:`<span class="chart-legend-color" style="background-color:${e.color}; color:${e.color};">--</span>${e.objName} / ${e.parName}`}),e.legend.addEventListener("click",(function(t){var i=t.target.getElementsByClassName("chart-legend-color")[0];null!=i&&(0==e.hidden?(e.hidden=!0,i.style.backgroundColor="white"):(e.hidden=!1,i.style.backgroundColor=e.color),t.target.chart.draw())})),e.legend.chart=this,this.lines.push(e),!0)}updateLines(t){if(null==t)return logger.error("Function LineChart.updateLines(). Parameter lines is null."),!1;if(!Array.isArray(t))return logger.error("Function LineChart.updateLines(). Parameter lines is not a array."),!1;for(var e in this.lines=[],this.minTs=99999999999999,this.maxTs=0,this.minVal=999999999999999,this.maxVal=0,this.axeYLabelStep=null,this.coefTs=null,this.coefVal=null,t){var i=this._createLine(t[e]);null!=i&&this.lines.push(i)}return this.draw(),!0}_processSelectLegentItem=function(){console.info("Prozess legent item")};_createLine(t){var e=new SingleLine(t),i=!0;if(null==t.par_id&&(t.par_id=this.lines.length),0==t.values.length)return e;for(var a=t.values.split(";"),s=a.length,n=0;n<s;++n){var h=a[n].split("/");if(""!=h[0])if(isNaN(h[0]))logger.warn("LineChart._createLine(). Item "+n+' contains invalid time-stamp "'+h[0]+'".');else{var l={ts:null,val:null};l.ts=parseInt(h[0]),l.val=parseFloat(h[1]),e.real.push(l),isNaN(l.val)||(l.val<0?Math.floor(1.1*l.val)<this.minVal&&(this.minVal=Math.floor(1.1*l.val)):Math.floor(.9*l.val)<this.minVal&&(this.minVal=Math.floor(.9*l.val)),Math.ceil(1.1*l.val)>this.maxVal&&(this.maxVal=Math.ceil(1.1*l.val)),i=!1),l.ts<this.minTs&&(this.minTs=l.ts),l.ts>this.maxTs&&(this.maxTs=l.ts)}else logger.warn("LineChart._createLine(). Item "+n+" time-stamp is empty.")}if(0==e.real.length)return e;e.isEmpty=!1,(0==this.maxVal&&0==this.minVal||i)&&(this.minVal=0,this.maxVal=1);var r=this.context.measureText(this.minVal.toString()),o=this.context.measureText(this.maxVal.toString());return r.width<o.width?this.padding.left=Math.round(o.width)+23:this.padding.left=Math.round(r.width)+23,e}clear(){this.context.clearRect(0,0,this.canvas.width,this.canvas.height)}draw(){if(this.coefTs=(this.canvas.width-this.padding.left)/(this.maxTs-this.minTs),this.coefVal=(this.canvas.height-this.padding.bottom)/(this.maxVal-this.minVal),this.context.clearRect(0,0,this.canvas.width,this.canvas.height),!this.isEmpty()){this._drawAxeX(),this._drawAxeY();for(var t=0;t<this.lines.length;t++)this.drawLine(t);this.canvas.dataset.minTs=this.minTs.toString(),this.canvas.dataset.coefTs=this.coefTs.toString(),this.canvas.dataset.maxVal=this.maxVal.toString(),this.canvas.dataset.coefVal=this.coefVal.toString(),this.canvas.dataset.paddingLeft=this.padding.left.toString(),this.canvas.dataset.paddingBottom=this.padding.bottom.toString()}}resize(t,e){this.canvas.width=this.canvas.width+t,this.canvas.height=this.canvas.height+e,this.context.translate(.5,.5)}_drawAxeX(){this.context.strokeStyle=this.colorDefault,this.context.lineWidth=1,this.context.beginPath(),this.context.moveTo(this.padding.left,this.canvas.height-this.padding.bottom),this.context.lineTo(this.canvas.width,this.canvas.height-this.padding.bottom),this.context.stroke();var t,e=Math.round(this.axeXLabelWidth/this.coefTs/60);t=this.stepsX.length-1;for(var i=0;i<t;i++)if(e>this.stepsX[i]&&e<this.stepsX[i+1]){e=this.stepsX[i];break}e*=60;for(var a=this._getBeginOfDayFromUnixTs(this.minTs),s=(new Date).getTime()/1e3;a<s;){if(a>this.minTs){!0;break}a+=e}for(var n,h,l=[];a<this.maxTs;)n=this._convertTs2PosX(a),h=this._formatTsForLabel(a,this.maxTs-this.minTs),l.push({X:n,str:h}),a+=e;this.context.beginPath(),this.context.strokeStyle="#e6e6e6";var r=Math.round(e*this.coefTs/2),o=this.canvas.height-this.padding.bottom;t=l.length;for(i=0;i<t;i++)this.context.moveTo(l[i].X,0),this.context.lineTo(l[i].X,o),l[i].X-r>this.padding.left+2&&(this.context.moveTo(l[i].X-r,0),this.context.lineTo(l[i].X-r,o));for(null!=l[i-1]&&l[i-1].X+r<=this.canvas.width&&(this.context.moveTo(l[i-1].X+r,0),this.context.lineTo(l[i-1].X+r,o)),this.context.stroke(),this.context.font="12px arial",t=l.length,i=0;i<t;i++)this.context.fillText(l[i].str.hm,l[i].X-17,o+17),(0==i||l[i].str.dm!=l[i-1].str.dm)&&this.context.fillText(l[i].str.dm,l[i].X-17,o+32);this.context.closePath()}_drawAxeY(){if(null!=this.coefTs&&null!=this.coefVal){var t,e=(this.canvas.height-this.padding.bottom)/this.axeYLabelHeight;this.axeYLabelStep=(this.maxVal-this.minVal)/e;for(var i,a,s=1,n=!1;s<1e11;){for(var h=0;h<this.stepsY.length-1;h++)if(i=this.stepsY[h]*s,a=this.stepsY[h+1]*s,i<=this.axeYLabelStep&&this.axeYLabelStep<=a){this.axeYLabelStep=a,n=!0;break}if(n)break;s*=10}var l=0;if(this.minVal<0)for(;l>this.minVal&&!(l<=this.minVal);)l-=this.axeYLabelStep;else if(this.minVal>0)for(;l<this.maxVal&&!(l>=this.minVal);)l+=this.axeYLabelStep;var r,o,c,d=this.canvas.height-this.padding.bottom,g=[];for(h=0;h<33&&(o=l+this.axeYLabelStep*h,(this.axeYLabelStep<1||2.5==this.axeYLabelStep)&&(o=o.toFixed(2)),!((r=this._convertVal2PosY(o))<0));){if(r<d){var m={value:o,Y:r};g.push(m)}h++}for(this.context.lineWidth=1,this.context.beginPath(),this.context.strokeStyle=this.colorDefault,this.context.moveTo(this.padding.left,0),this.context.lineTo(this.padding.left,this.canvas.height-this.padding.bottom),this.context.stroke(),this.context.beginPath(),this.context.strokeStyle="#e6e6e6",t=g.length,h=0;h<t;h++)(c=g[h].Y+Math.round(this.coefVal*this.axeYLabelStep/2))<this.canvas.height-this.padding.bottom&&(this.context.moveTo(this.padding.left,c),this.context.lineTo(this.canvas.width,c)),g[h].Y>=this.canvas.height-this.padding.bottom||(this.context.moveTo(this.padding.left,g[h].Y),this.context.lineTo(this.canvas.width,g[h].Y));for((c=g[g.length-1].Y-Math.round(this.coefVal*this.axeYLabelStep/2))>0&&(this.context.moveTo(this.padding.left,c),this.context.lineTo(this.canvas.width,c)),this.context.stroke(),this.context.font="12px arial",this.context.strokeStyle=this.colorDefault,t=g.length,h=0;h<t;h++)this.context.fillText(g[h].value,0,g[h].Y+10)}}drawLine(t){var e=this.lines[t];if(null!=e){if(1!=e.isEmpty&&0!=e.real.length&&!e.hidden){var i,a=[],s=-1,n=[],h=[];if(!isNaN(this.avgStep)){for(var l=this._getBeginOfDayFromUnixTs(e.real[0].ts);l<e.real[0].ts;)l+=this.avgStep;i=e.real.length;for(var r=0;r<i;r++)if(e.real[r].ts<l)n.push(e.real[r].val);else{for(var o=0;e.real[r].ts>l+this.avgStep;)if(l+=this.avgStep,++o>1e3)return void logger.warn("drawLine(). Can't calculate average values for this line. "+new Date(1e3*e.real[r].ts).formatISOLocal()+"/"+e.real[r].val);var c={ts:l,val:getAvgValue(n,2)};h.push(c),(n=[]).push(e.real[r].val),l+=this.avgStep}if(n.length>0){c={ts:l,val:getAvgValue(n,2)};h.push(c)}}n=[],0==h.length&&(h=e.real),i=h.length;for(var d=0;d<i;d++){(c={X:NaN,Y:NaN}).X=this._convertTs2PosX(h[d].ts),isNaN(h[d].val)||(c.Y=this._convertVal2PosY(h[d].val)),c.X!=s?(s=c.X,n.length>0&&d>0&&(n.push(a[a.length-1].Y),a[a.length-1].Y=getAvgValue(n,2),n=[]),a.push(c)):n.push(c.Y)}for(this.context.strokeStyle=this.colors[t],this.context.lineWidth=1,this.context.beginPath(),i=a.length,d=0;d<i;d++)if(!isNaN(a[d].Y)){this.context.moveTo(a[d].X,a[d].Y),d++;break}for(;d<i;)if(isNaN(a[d].Y))for(this.context.stroke(),d++;d<a.length;){if(!isNaN(a[d].Y)){d++;break}d++}else this.context.lineTo(a[d].X,a[d].Y),d++;this.context.stroke()}}else logger.error("Function LineChart.drawLine(lineId). The line with ID "+t+" not found!")}isEmpty(){for(var t=!0,e=0;e<this.lines.length;e++)this.lines[e].isEmpty||(t=!1);return t}_convertTs2PosX(t){return this.canvas.width-Math.round((this.maxTs-t)*this.coefTs)}_convertVal2PosY(t){return Math.round((this.maxVal-t)*this.coefVal)}_formatTsForLabel(t,e){let i=new Date(1e3*t);e/=86400;let a=i.getFullYear(),s=i.getMonth()+1;s<10&&(s="0"+s.toString());let n=i.getDate();parseInt(n)<10&&(n="0"+n.toString());let h=i.getHours();parseInt(h)<10&&(h="0"+h);let l=i.getMinutes();parseInt(l)<10&&(l="0"+l.toString());let r={};return r=e<3?{dm:n+"."+s,hm:h+":"+l}:e>=3&&e<180?{dm:a,hm:n+"."+s}:{dm:a,hm:" "+s},r}_getBeginOfDayFromUnixTs(t){var e=new Date(1e3*t);return(e=new Date(e.getFullYear(),e.getMonth(),e.getDate())).setMinutes(59),e.setSeconds(59),e.setMilliseconds(1e3),e.getTime()/1e3}colors=["#0044CC","#008000","#FF8533","#6A6A6A","#C71585","#8B4513","#1E90FF","#FF4500","#00FF00","#8A2BE2"];colorDefault="#657585";stepsX=[2,5,10,15,20,30,60,90,120,240,300,360,720,1440,2880,4320,5760,7200,10080,14400,21600,28800,43200,64800,86400,129600,172800];stepsY=[.01,.02,.05,.1]}class SingleLine{constructor(t){this.parId=t.par_id,this.parName=t.par_name,this.objName=t.obj_name,this.real=[],this.isEmpty=!0,this.hidden=!1,this.color="black"}}var allCharts=[];LineChart.prototype.Version="1.2.0";
2
2
  if("notdefined"!=typeof logger)var logger={info:function(e){console.info(e)},warn:function(e){console.warn(e)},error:function(e){console.error(e)},debug:function(e){console.debug(bessage)}};function addNewElement(e,n,t){if(null==t&&(t={}),null!=t.id?null!=document.getElementById(t.id)&&(newElementCounter++,t.id=newElementCounter.toString()+"_"+(new Date).getTime().toString()):(newElementCounter++,t.id=newElementCounter.toString()+"_"+(new Date).getTime().toString()),null==n)var r=document.createElement("div");else r=document.createElement(n);for(var i in t)r.setAttribute(i,t[i]);return null!=t.innerText&&(r.innerText=t.innerText),null!=t.innerHTML&&(r.innerHTML=t.innerHTML),null==e?document.body.appendChild(r):e.appendChild(r),document.getElementById(t.id)}var newElementCounter=0;function getAvgValue(e,n){if(null==e||0==e.length)return NaN;(null==n||isNaN(n))&&(n=2);for(var t=0,r=0,i=0;i<e.length;i++)isNaN(e[i])||(t+=e[i],r+=1);return 0==r?NaN:(t/r).toFixed(n)}function getRandomInt(){return 1e17*Math.random()}function isString(e){return"string"==typeof e||e instanceof String}function scvToTimeSeries(e){let n=[];if(null==e)return n;let t=e.split(/\r?\n/);if(t.length<2)return n;var r=t[0].split(",");for(let e=1;e<r.length;e++){let i={name:r[e],data:""};for(let n=t.length-1;n>0;n--){let o=t[n].split(",");o.length==r.length&&(i.data+=moment(o[0]).format("X")+"/"+o[e]+";")}i.data=i.data.slice(0,-1),n.push(i)}return n}Date.prototype.separate=function(){var e={};return e.year=this.getFullYear(),e.month=this.getMonth()+1,e.mday=this.getDate(),e.hour=this.getHours(),e.min=this.getMinutes(),e.sec=this.getSeconds(),e.msec=this.getMilliseconds(),e.month<10&&(e.month="0"+e.month),e.mday<10&&(e.mday="0"+e.mday),e.hour<10&&(e.hour="0"+e.hour),e.min<10&&(e.min="0"+e.min),e.sec<10&&(e.sec="0"+e.sec),e.msec<10?e.msec="00"+e.msec:e.msec<100&&(e.msec="0"+e.msec),e};
@@ -1,101 +1,101 @@
1
- timestamp,open,high,low,close,volume
2
- 2019-12-31,156.7700,157.7700,156.4500,157.7000,17426549
3
- 2019-12-30,158.9865,159.0200,156.7300,157.5900,16356720
4
- 2019-12-27,159.4500,159.5500,158.2200,158.9600,18414352
5
- 2019-12-26,157.5511,158.7300,157.4000,158.6700,14526927
6
- 2019-12-24,157.4800,157.7100,157.1150,157.3800,8989150
7
- 2019-12-23,158.1200,158.1200,157.2700,157.4100,17726283
8
- 2019-12-20,157.3500,158.4900,156.2900,157.4100,53599613
9
- 2019-12-19,154.0000,155.7700,153.7500,155.7100,25813825
10
- 2019-12-18,154.3000,155.4800,154.1800,154.3700,24132379
11
- 2019-12-17,155.4500,155.7100,154.4500,154.6900,25443527
12
- 2019-12-16,155.1100,155.9000,154.8200,155.5300,24152770
13
- 2019-12-13,153.1106,154.8900,152.8300,154.5300,23850062
14
- 2019-12-12,151.6500,153.4400,151.0200,153.2400,24645366
15
- 2019-12-11,151.5400,151.8700,150.3300,151.7000,18860001
16
- 2019-12-10,151.2900,151.8900,150.7650,151.1300,16481060
17
- 2019-12-09,151.0700,152.2100,150.9100,151.3600,16741350
18
- 2019-12-06,150.9900,151.8700,150.2700,151.7500,16410400
19
- 2019-12-05,150.0500,150.3200,149.4800,149.9300,17880601
20
- 2019-12-04,150.1400,150.1799,149.2000,149.8500,17580617
21
- 2019-12-03,147.4900,149.4300,146.6500,149.3100,25192145
22
- 2019-12-02,151.8100,151.8300,148.3200,149.5500,27473616
23
- 2019-11-29,152.1000,152.3000,151.2800,151.3800,11977300
24
- 2019-11-27,152.3300,152.5000,151.5200,152.3200,15201293
25
- 2019-11-26,151.3600,152.4200,151.3200,152.0300,24635100
26
- 2019-11-25,150.0000,151.3500,149.9200,151.2300,22428585
27
- 2019-11-22,150.0700,150.3000,148.8200,149.5900,15841680
28
- 2019-11-21,149.4000,149.8000,148.5010,149.4800,18576083
29
- 2019-11-20,150.3100,150.8400,148.4600,149.6200,25720060
30
- 2019-11-19,150.8800,151.3300,150.1950,150.3900,23960164
31
- 2019-11-18,150.0700,150.5500,148.9800,150.3400,21554762
32
- 2019-11-15,148.9300,149.9900,148.2700,149.9700,23508807
33
- 2019-11-14,147.0200,148.4100,147.0000,148.0600,19755100
34
- 2019-11-13,146.7400,147.4625,146.2800,147.3100,17444230
35
- 2019-11-12,146.2800,147.5700,146.0600,147.0700,18648712
36
- 2019-11-11,145.3400,146.4200,144.7300,146.1100,14370178
37
- 2019-11-08,143.9800,145.9900,143.7600,145.9600,16752939
38
- 2019-11-07,143.8400,144.8800,143.7700,144.2600,17786715
39
- 2019-11-06,144.3700,144.5200,143.2000,144.0600,16575798
40
- 2019-11-05,144.9700,145.0200,143.9050,144.4600,18250172
41
- 2019-11-04,144.8300,145.0000,144.1600,144.5500,16911999
42
- 2019-11-01,144.2600,144.4200,142.9650,143.7200,33128366
43
- 2019-10-31,144.9000,144.9300,142.9900,143.3700,24605135
44
- 2019-10-30,143.5200,145.0000,142.7900,144.6100,18496591
45
- 2019-10-29,144.0800,144.5000,142.6500,142.8300,20589469
46
- 2019-10-28,144.4000,145.6700,143.5100,144.1900,34912902
47
- 2019-10-25,139.3400,141.1400,139.2000,140.7300,25959724
48
- 2019-10-24,139.3900,140.4200,138.6700,139.9400,37278399
49
- 2019-10-23,136.8800,137.4500,135.6100,137.2400,31380309
50
- 2019-10-22,138.9700,140.0100,136.2600,136.3700,27935270
51
- 2019-10-21,138.4500,138.5000,137.0100,138.4300,20078066
52
- 2019-10-18,139.7600,140.0000,136.5600,137.4100,30650850
53
- 2019-10-17,140.9500,141.4200,139.0200,139.6900,22102797
54
- 2019-10-16,140.7900,140.9900,139.5300,140.4100,20841687
55
- 2019-10-15,140.0600,141.7900,139.8100,141.5750,19917762
56
- 2019-10-14,139.6900,140.2900,139.5200,139.5500,13591639
57
- 2019-10-11,140.1200,141.0300,139.5000,139.6800,25551065
58
- 2019-10-10,138.4900,139.6699,138.2500,139.1000,18396605
59
- 2019-10-09,137.4600,138.7000,136.9700,138.2400,20178482
60
- 2019-10-08,137.0800,137.7600,135.6200,135.6700,26783336
61
- 2019-10-07,137.1400,138.1800,137.0200,137.1200,16601284
62
- 2019-10-04,136.7500,138.2500,136.4200,138.1200,23839548
63
- 2019-10-03,134.9500,136.7500,133.2200,136.2800,26379798
64
- 2019-10-02,136.2500,136.3700,133.5799,134.6500,32001763
65
- 2019-10-01,139.6600,140.2500,137.0000,137.0700,22581929
66
- 2019-09-30,138.0500,139.2150,137.7800,139.0300,18430390
67
- 2019-09-27,140.1500,140.3600,136.6450,137.7300,22498958
68
- 2019-09-26,139.4400,140.1800,138.4400,139.5400,17813512
69
- 2019-09-25,137.5000,139.9580,136.0300,139.3600,22544054
70
- 2019-09-24,140.3600,140.6900,136.8800,137.3800,30016670
71
- 2019-09-23,139.2300,139.6300,138.4400,139.1400,17408374
72
- 2019-09-20,141.0100,141.6500,138.2500,139.4400,40040766
73
- 2019-09-19,140.3000,142.3700,140.0736,141.0700,36095413
74
- 2019-09-18,137.3600,138.6700,136.5299,138.5200,24473386
75
- 2019-09-17,136.9600,137.5200,136.4250,137.3900,17976285
76
- 2019-09-16,135.8300,136.7000,135.6600,136.3300,16731440
77
- 2019-09-13,137.7800,138.0600,136.5700,137.3200,23363057
78
- 2019-09-12,137.8500,138.4200,136.8700,137.5200,27009981
79
- 2019-09-11,135.9100,136.2700,135.0900,136.1200,24726117
80
- 2019-09-10,136.8000,136.8862,134.5100,136.0800,28903378
81
- 2019-09-09,139.5900,139.7500,136.4600,137.5200,25773932
82
- 2019-09-06,140.0300,140.1800,138.2000,139.1000,20824504
83
- 2019-09-05,139.1100,140.3837,138.7600,140.0500,26119520
84
- 2019-09-04,137.3000,137.6900,136.4800,137.6300,18015310
85
- 2019-09-03,136.6100,137.2000,135.7000,136.0400,18880773
86
- 2019-08-30,139.1500,139.1800,136.2700,137.8600,23946123
87
- 2019-08-29,137.2500,138.4400,136.9100,138.1200,20179716
88
- 2019-08-28,134.8800,135.7600,133.5500,135.5600,17343042
89
- 2019-08-27,136.3900,136.7200,134.6600,135.7400,23115635
90
- 2019-08-26,134.9900,135.5600,133.9000,135.4500,20325271
91
- 2019-08-23,137.1897,138.3500,132.8000,133.3900,38515386
92
- 2019-08-22,138.6600,139.2000,136.2900,137.7800,18709662
93
- 2019-08-21,138.5500,139.4935,138.0000,138.7900,14982314
94
- 2019-08-20,138.2100,138.7100,137.2400,137.2600,21188998
95
- 2019-08-19,137.8550,138.5500,136.8850,138.4100,24370543
96
- 2019-08-16,134.8800,136.4600,134.7200,136.1300,25026151
97
- 2019-08-15,134.3900,134.5800,132.2500,133.6800,28125416
98
- 2019-08-14,136.3600,136.9200,133.6700,133.9800,32527251
99
- 2019-08-13,136.0500,138.8000,135.0000,138.6000,25496593
100
- 2019-08-12,137.0700,137.8600,135.2400,135.7900,20484348
1
+ timestamp,open,high,low,close,volume
2
+ 2019-12-31,156.7700,157.7700,156.4500,157.7000,17426549
3
+ 2019-12-30,158.9865,159.0200,156.7300,157.5900,16356720
4
+ 2019-12-27,159.4500,159.5500,158.2200,158.9600,18414352
5
+ 2019-12-26,157.5511,158.7300,157.4000,158.6700,14526927
6
+ 2019-12-24,157.4800,157.7100,157.1150,157.3800,8989150
7
+ 2019-12-23,158.1200,158.1200,157.2700,157.4100,17726283
8
+ 2019-12-20,157.3500,158.4900,156.2900,157.4100,53599613
9
+ 2019-12-19,154.0000,155.7700,153.7500,155.7100,25813825
10
+ 2019-12-18,154.3000,155.4800,154.1800,154.3700,24132379
11
+ 2019-12-17,155.4500,155.7100,154.4500,154.6900,25443527
12
+ 2019-12-16,155.1100,155.9000,154.8200,155.5300,24152770
13
+ 2019-12-13,153.1106,154.8900,152.8300,154.5300,23850062
14
+ 2019-12-12,151.6500,153.4400,151.0200,153.2400,24645366
15
+ 2019-12-11,151.5400,151.8700,150.3300,151.7000,18860001
16
+ 2019-12-10,151.2900,151.8900,150.7650,151.1300,16481060
17
+ 2019-12-09,151.0700,152.2100,150.9100,151.3600,16741350
18
+ 2019-12-06,150.9900,151.8700,150.2700,151.7500,16410400
19
+ 2019-12-05,150.0500,150.3200,149.4800,149.9300,17880601
20
+ 2019-12-04,150.1400,150.1799,149.2000,149.8500,17580617
21
+ 2019-12-03,147.4900,149.4300,146.6500,149.3100,25192145
22
+ 2019-12-02,151.8100,151.8300,148.3200,149.5500,27473616
23
+ 2019-11-29,152.1000,152.3000,151.2800,151.3800,11977300
24
+ 2019-11-27,152.3300,152.5000,151.5200,152.3200,15201293
25
+ 2019-11-26,151.3600,152.4200,151.3200,152.0300,24635100
26
+ 2019-11-25,150.0000,151.3500,149.9200,151.2300,22428585
27
+ 2019-11-22,150.0700,150.3000,148.8200,149.5900,15841680
28
+ 2019-11-21,149.4000,149.8000,148.5010,149.4800,18576083
29
+ 2019-11-20,150.3100,150.8400,148.4600,149.6200,25720060
30
+ 2019-11-19,150.8800,151.3300,150.1950,150.3900,23960164
31
+ 2019-11-18,150.0700,150.5500,148.9800,150.3400,21554762
32
+ 2019-11-15,148.9300,149.9900,148.2700,149.9700,23508807
33
+ 2019-11-14,147.0200,148.4100,147.0000,148.0600,19755100
34
+ 2019-11-13,146.7400,147.4625,146.2800,147.3100,17444230
35
+ 2019-11-12,146.2800,147.5700,146.0600,147.0700,18648712
36
+ 2019-11-11,145.3400,146.4200,144.7300,146.1100,14370178
37
+ 2019-11-08,143.9800,145.9900,143.7600,145.9600,16752939
38
+ 2019-11-07,143.8400,144.8800,143.7700,144.2600,17786715
39
+ 2019-11-06,144.3700,144.5200,143.2000,144.0600,16575798
40
+ 2019-11-05,144.9700,145.0200,143.9050,144.4600,18250172
41
+ 2019-11-04,144.8300,145.0000,144.1600,144.5500,16911999
42
+ 2019-11-01,144.2600,144.4200,142.9650,143.7200,33128366
43
+ 2019-10-31,144.9000,144.9300,142.9900,143.3700,24605135
44
+ 2019-10-30,143.5200,145.0000,142.7900,144.6100,18496591
45
+ 2019-10-29,144.0800,144.5000,142.6500,142.8300,20589469
46
+ 2019-10-28,144.4000,145.6700,143.5100,144.1900,34912902
47
+ 2019-10-25,139.3400,141.1400,139.2000,140.7300,25959724
48
+ 2019-10-24,139.3900,140.4200,138.6700,139.9400,37278399
49
+ 2019-10-23,136.8800,137.4500,135.6100,137.2400,31380309
50
+ 2019-10-22,138.9700,140.0100,136.2600,136.3700,27935270
51
+ 2019-10-21,138.4500,138.5000,137.0100,138.4300,20078066
52
+ 2019-10-18,139.7600,140.0000,136.5600,137.4100,30650850
53
+ 2019-10-17,140.9500,141.4200,139.0200,139.6900,22102797
54
+ 2019-10-16,140.7900,140.9900,139.5300,140.4100,20841687
55
+ 2019-10-15,140.0600,141.7900,139.8100,141.5750,19917762
56
+ 2019-10-14,139.6900,140.2900,139.5200,139.5500,13591639
57
+ 2019-10-11,140.1200,141.0300,139.5000,139.6800,25551065
58
+ 2019-10-10,138.4900,139.6699,138.2500,139.1000,18396605
59
+ 2019-10-09,137.4600,138.7000,136.9700,138.2400,20178482
60
+ 2019-10-08,137.0800,137.7600,135.6200,135.6700,26783336
61
+ 2019-10-07,137.1400,138.1800,137.0200,137.1200,16601284
62
+ 2019-10-04,136.7500,138.2500,136.4200,138.1200,23839548
63
+ 2019-10-03,134.9500,136.7500,133.2200,136.2800,26379798
64
+ 2019-10-02,136.2500,136.3700,133.5799,134.6500,32001763
65
+ 2019-10-01,139.6600,140.2500,137.0000,137.0700,22581929
66
+ 2019-09-30,138.0500,139.2150,137.7800,139.0300,18430390
67
+ 2019-09-27,140.1500,140.3600,136.6450,137.7300,22498958
68
+ 2019-09-26,139.4400,140.1800,138.4400,139.5400,17813512
69
+ 2019-09-25,137.5000,139.9580,136.0300,139.3600,22544054
70
+ 2019-09-24,140.3600,140.6900,136.8800,137.3800,30016670
71
+ 2019-09-23,139.2300,139.6300,138.4400,139.1400,17408374
72
+ 2019-09-20,141.0100,141.6500,138.2500,139.4400,40040766
73
+ 2019-09-19,140.3000,142.3700,140.0736,141.0700,36095413
74
+ 2019-09-18,137.3600,138.6700,136.5299,138.5200,24473386
75
+ 2019-09-17,136.9600,137.5200,136.4250,137.3900,17976285
76
+ 2019-09-16,135.8300,136.7000,135.6600,136.3300,16731440
77
+ 2019-09-13,137.7800,138.0600,136.5700,137.3200,23363057
78
+ 2019-09-12,137.8500,138.4200,136.8700,137.5200,27009981
79
+ 2019-09-11,135.9100,136.2700,135.0900,136.1200,24726117
80
+ 2019-09-10,136.8000,136.8862,134.5100,136.0800,28903378
81
+ 2019-09-09,139.5900,139.7500,136.4600,137.5200,25773932
82
+ 2019-09-06,140.0300,140.1800,138.2000,139.1000,20824504
83
+ 2019-09-05,139.1100,140.3837,138.7600,140.0500,26119520
84
+ 2019-09-04,137.3000,137.6900,136.4800,137.6300,18015310
85
+ 2019-09-03,136.6100,137.2000,135.7000,136.0400,18880773
86
+ 2019-08-30,139.1500,139.1800,136.2700,137.8600,23946123
87
+ 2019-08-29,137.2500,138.4400,136.9100,138.1200,20179716
88
+ 2019-08-28,134.8800,135.7600,133.5500,135.5600,17343042
89
+ 2019-08-27,136.3900,136.7200,134.6600,135.7400,23115635
90
+ 2019-08-26,134.9900,135.5600,133.9000,135.4500,20325271
91
+ 2019-08-23,137.1897,138.3500,132.8000,133.3900,38515386
92
+ 2019-08-22,138.6600,139.2000,136.2900,137.7800,18709662
93
+ 2019-08-21,138.5500,139.4935,138.0000,138.7900,14982314
94
+ 2019-08-20,138.2100,138.7100,137.2400,137.2600,21188998
95
+ 2019-08-19,137.8550,138.5500,136.8850,138.4100,24370543
96
+ 2019-08-16,134.8800,136.4600,134.7200,136.1300,25026151
97
+ 2019-08-15,134.3900,134.5800,132.2500,133.6800,28125416
98
+ 2019-08-14,136.3600,136.9200,133.6700,133.9800,32527251
99
+ 2019-08-13,136.0500,138.8000,135.0000,138.6000,25496593
100
+ 2019-08-12,137.0700,137.8600,135.2400,135.7900,20484348
101
101
  2019-08-09,138.6100,139.3800,136.4600,137.7100,23466701
@@ -4,37 +4,36 @@ document.addEventListener('DOMContentLoaded', function () {
4
4
 
5
5
  var isMobil = false;
6
6
  var request;
7
+ var charts = [];
7
8
 
8
9
  // Example time-series. Semicolon separated pairs "Unix-Timestamp/Value;Unix-Timestamp/Value;.."
9
10
  // The values may be empty. The last element may be withoud value. It Indicate end of timespane
10
11
  // of this line.
11
12
  var arTimeSeries = [
12
13
  {
13
- name: 'Open',
14
- data: '1565301600/138.6100;1565560800/137.0700;1565647200/136.0500;1565733600/136.3600;1565820000/134.3900;1565906400/134.8800;1566165600/137.8550;1566252000/138.2100;1566338400/138.5500;1566424800/138.6600;1566511200/137.1897;1566770400/134.9900;1566856800/136.3900;1566943200/134.8800;1567029600/137.2500;1567116000/139.1500;1567461600/136.6100;1567548000/137.3000;1567634400/139.1100;1567720800/140.0300'
14
+ name: 'Example one',
15
+ data: '1565301600/-11.2;1565560800/-9;1565647200/-7.2;1565733600/-5.89;1565820000/-5.2;1565906400/-2.50;1566165600/-1.21;1566252000/0.20;1566338400/-2;1566424800/-4.5;1566511200/-6.2;1566770400/-8.3;1566856800/-10.0;1566943200/-11;1567029600/-13.8;1567116000/-15.8;1567461600/-12.9;1567548000/-8.9;1567634400/-8.94;1567720800/-10.96'
15
16
  },
16
17
  {
17
- name: 'Hight',
18
- data: '1565301600/139.3800;1565560800/137.8600;1565647200/138.8000;1565733600/136.9200;1565820000/134.5800;1565906400/136.4600;1566165600/138.5500;1566252000/138.7100;1566338400/139.4935;1566424800/139.2000;1566511200/138.3500;1566770400/135.5600;1566856800/136.7200;1566943200/135.7600;1567029600/138.4400;1567116000/139.1800;1567461600/137.2000;1567548000/137.6900;1567634400/140.3837;1567720800/140.1800'
18
+ name: 'Example Two',
19
+ data: '1565301600/11.2;1565560800/6;1565647200/4;1565733600/2;1565820000/-2;1565906400/-3;1566165600/-4;1566252000/-6;1566338400/-7;1566424800/-8;1566511200/-8;1566770400/-5.5;1566856800/-3.6;1566943200/-0.6;1567029600/1.8;1567116000/3.8;1567461600/4.2;1567548000/5.4;1567634400/6.94;1567720800/7.96'
19
20
  },
20
21
  {
21
- name: ' Low',
22
- data: '1565301600/136.4600;1565560800/135.2400;1565647200/135.0000;1565733600/133.6700;1565820000/132.2500;1565906400/134.7200;1566165600/136.8850;1566252000/137.2400;1566338400/138.0000;1566424800/136.2900;1566511200/132.8000;1566770400/133.9000;1566856800/134.6600;1566943200/133.5500;1567029600/136.9100;1567116000/136.2700;1567461600/135.7000;1567548000/136.4800;1567634400/138.7600;1567720800/138.2000'
23
- },
24
- {
25
- name: 'Close',
26
- data: '1565301600/137.7100;1565560800/135.7900;1565647200/138.6000;1565733600/133.9800;1565820000/133.6800;1565906400/136.1300;1566165600/138.4100;1566252000/137.2600;1566338400/138.7900;1566424800/137.7800;1566511200/133.3900;1566770400/135.4500;1566856800/135.7400;1566943200/135.5600;1567029600/138.1200;1567116000/137.8600;1567461600/136.0400;1567548000/137.6300;1567634400/140.0500;1567720800/139.1000'
22
+ name: 'Example Two',
23
+ data: '1565301000/0;1565560200/-0.4;1565646600/-1.1;1565733000/-2;1565819400/-0.5;1565905800/-0.01;1566165000/0.2;1566252000/0.3;1566337800/2.2;1566424200/4.2;1566510600/5.2;1566779800/6.1;1566856200/7.4;1566942600/8;1567029000/8.2;1567115400/8.8;1567461000/9.2;1567547400/11.4;1567633800/12.94;1567720200/11.96'
27
24
  }
28
25
  ];
29
26
 
30
27
  function createCharts () {
31
28
 
32
29
  // Create first chart in div id "charts"
33
- let lchart = new LineChart(document.getElementById('charts'),null, null, 'Example Chart-Line', null);
30
+ let lchart;
31
+
32
+ lchart = new LineChart(document.getElementById('charts'),null, null, 'Example Chart-Line', null);
34
33
 
35
34
  for(let i=0; i < arTimeSeries.length; i++) {
36
35
  let line = {
37
- obj_name: 'Stock preis',
36
+ obj_name: 'Chart',
38
37
  par_name: arTimeSeries[i].name,
39
38
  values: arTimeSeries[i].data
40
39
  };
@@ -43,13 +42,15 @@ function createCharts () {
43
42
 
44
43
  lchart.draw();
45
44
 
45
+ charts.push(lchart);
46
+
46
47
  // Example convert CSV to time-series
47
48
  request = new XMLHttpRequest();
48
49
  request.open("GET","example.csv");
49
50
  request.addEventListener('load', function(event) {
50
51
  if (request.status == 200) {
51
52
 
52
- //Convert SCV to format suitable for chart.
53
+ // Convert SCV to format suitable for chart.
53
54
  let arTimeSeries = scvToTimeSeries(request.responseText);
54
55
 
55
56
  // Create next chart in div id "charts"
@@ -65,9 +66,11 @@ function createCharts () {
65
66
  }
66
67
 
67
68
  lchart.draw();
69
+
70
+ charts.push(lchart);
68
71
  } else {
69
72
 
70
- console.warn(request.statusText, request.responseText);
73
+ console.warn("Request CSV failed status "+ request.statusText+ " Responce "+ request.responseText);
71
74
  }
72
75
  });
73
76
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adaptive-linechart",
3
- "version": "1.0.1",
3
+ "version": "1.2.2",
4
4
  "description": "Independent library to draw line-chart in browser.",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -8,7 +8,7 @@
8
8
  "browser": "dist/linechart-all.min.js",
9
9
  "author": "Andrej Koslov",
10
10
  "license": "MIT",
11
- "homepage": "https://github.com/andrejkoslov/adaptive-linechart",
11
+ "homepage": "https://gitlab.com/softdorado/linechart",
12
12
  "keywords": [
13
13
  "line",
14
14
  "chart",
@@ -16,6 +16,6 @@
16
16
  ],
17
17
  "repository": {
18
18
  "type": "git",
19
- "url": "git+https://github.com/andrejkoslov/adaptive-linechart.git"
19
+ "url": "git+https://gitlab.com/softdorado/linechart.git"
20
20
  }
21
21
  }
package/src/linechart.js CHANGED
@@ -1,7 +1,8 @@
1
+ // Version 1.2.2
1
2
  // The oject represent line-chart. Constructor create HTML code for the chart. The chart
2
3
  // uses external CSS styles .nowrap .linechart, .chart-title, .chart-live-data, .chart-legend,
3
4
  // .chart-legent-item, .chart-legent-color. The chart uses global variable isMobil (Boolean).
4
- // If true show live data by mouse over. By click on item in legend called external function
5
+ // If false, show live data by mouse over. By click on item in legend called external function
5
6
  // processSelectLegendItem(chartId, amount-of-lines, parId). Only positive values allowed.
6
7
  // Labels on axe-X and -Y will be created automaticaly. The chart can show maximal 10 lines
7
8
  // in different colors.
@@ -147,9 +148,9 @@ class LineChart {
147
148
  // Integer. End of time that show chart. Sec. Unix Time-stamp.
148
149
  this.maxTs = 0;
149
150
  // Minimal measuring value.
150
- this.minVal = 999999999999999;
151
+ this.minVal = Number.MAX_SAFE_INTEGER;
151
152
  // Maximal measuring value.
152
- this.maxVal = 0;
153
+ this.maxVal = Number.MIN_SAFE_INTEGER;
153
154
  // Difference between two labels on axe Y. Real value, not a pix!
154
155
  this.axeYLabelStep = null;
155
156
  // Default and minimal distance (pixel) between labels on axe-y.
@@ -165,7 +166,7 @@ class LineChart {
165
166
  // Indicate selected in calender end-date. This parmeter used in SingleChart.
166
167
  this.endDate = null;
167
168
  // Average step. Seconds. If is valid number used to calculate step by drawing the chart.
168
- // If NaN, not used.
169
+ // If NaN, not used. This variable may be set manual.
169
170
  this.avgStep = NaN;
170
171
 
171
172
  // End consctructor object LineChart.
@@ -176,7 +177,7 @@ class LineChart {
176
177
  // line.obj_name:"Proxy Server"
177
178
  // line.par_name:"CpuTotal"
178
179
  // line.par_id:"2452"
179
- // line.values: Example data-string "161111145730/3.48;161111145843/3.50;161111150013/""
180
+ // line.values: Example data-string "161111145730/3.48;161111145843/3.50;161111150013/"
180
181
  // @return Boolean. True if no problem detected. Else false.
181
182
  addLine (lineData) {
182
183
  if (lineData.values == null) {
@@ -199,26 +200,38 @@ class LineChart {
199
200
  line.objName = lineData.obj_name;
200
201
  line.parName = lineData.par_name;
201
202
  line.parId = lineData.par_id;
202
- var color = this.colors[this.lines.length];
203
- // Reference to legend-item as dom-element. Set function called by click on element
204
- // to hide/show line on chart.
205
- if (isMobil) {
206
- line.legend = addNewElement(this.legendDiv, 'div', {
207
- class: 'chart-legend-item nowrap',
208
- id: 'chart_' + this.chartId + '_legend_' + lineData.par_id,
209
- style: 'max-width:' + (this.chartDiv.clientWidth - 20) + 'px;',
210
- onclick: 'processSelectLegendItem(' + this.chartId + ',' + this.lines.length + ',' + line.parId + ')',
211
- innerHTML: '<span class="chart-legend-color" style="background-color:' + color + '; color:' + color + ';">--</span>' + line.objName + ' / ' + line.parName
212
- });
213
- } else {
214
- line.legend = addNewElement(this.legendDiv, 'div', {
215
- class: 'chart-legend-item nowrap',
216
- id: 'chart_' + this.chartId + '_legend_' + lineData.par_id,
217
- style: 'max-width:' + (this.chartDiv.clientWidth - 20) + 'px;',
218
- onclick: 'processSelectLegendItem(' + this.chartId + ',' + this.lines.length + ',' + line.parId + ')',
219
- innerHTML: '<span class="chart-legend-color" style="background-color:' + color + '; color:' + color + ';">--</span>' + line.objName + ' / ' + line.parName
220
- });
221
- }
203
+ line.color = this.colors[this.lines.length];
204
+ // Create legend-item as dom-element.
205
+ line.legend = addNewElement(this.legendDiv, 'div', {
206
+ class: 'chart-legend-item nowrap',
207
+ id: `chart_${this.chartId}_legend_${lineData.par_id}`,
208
+ style: `cursor: pointer; max-width:${this.chartDiv.clientWidth - 20}px;`,
209
+ innerHTML: `<span class="chart-legend-color" style="background-color:${line.color}; color:${line.color};">--</span>${line.objName} / ${line.parName}`
210
+ });
211
+ // Set function called by click on element to hide/show line on chart.
212
+ line.legend.addEventListener('click', function (event) {
213
+
214
+ // First sub-element of class chart-legend-color is colored tag for this legend item.
215
+ // This element used to swith color by click on legent item.
216
+ var legendColor = event.target.getElementsByClassName('chart-legend-color')[0];
217
+
218
+ // By click on colored tag this varibale is null. In this case only exit.
219
+ if(legendColor == null) return;
220
+
221
+ if(line.hidden == false) {
222
+ line.hidden = true;
223
+ legendColor.style.backgroundColor = 'white';
224
+ } else {
225
+ line.hidden = false;
226
+ legendColor.style.backgroundColor = line.color;
227
+ }
228
+
229
+ event.target.chart.draw();
230
+ });
231
+
232
+ // Link to parent chart in the legend item. Need to process click on legend item.
233
+ line.legend.chart = this;
234
+
222
235
  // Put new line array of lines.
223
236
  this.lines.push(line);
224
237
  return true;
@@ -256,10 +269,13 @@ class LineChart {
256
269
  return true;
257
270
  }
258
271
 
259
- // Create line from object that represent one line of backend's response. Only measuring
260
- // values >= 0 supported! If found one negative value return null and output error in logger.
261
- // If data-string is empty, create line with flag isEmpty=true. The function also update some
262
- // variables of chart chart-minTs, maxTs, minVal, maxVal.
272
+ _processSelectLegentItem = function() {
273
+ console.info("Prozess legent item");
274
+ }
275
+
276
+ // Create line from object that represent one line of backend's response. If found one negative
277
+ // value return null and output error in logger. If data-string is empty, create line with flag
278
+ // isEmpty=true. The function also update some variables of chart minTs, maxTs, minVal, maxVal.
263
279
  // Example data-string "161111145730/3.48;161111145843/;161111150013/"
264
280
  // Each element separated by ";" in each element time-stamp separated from value by "/".
265
281
  // Value may be empty! Always in last item the element without value. It indicate only
@@ -267,41 +283,68 @@ class LineChart {
267
283
  _createLine (lineData) {
268
284
  // Create object empty line.
269
285
  var line = new SingleLine(lineData);
286
+
270
287
  // Flag. True if value of all items are NaN. In this case set min/max 0/1
271
288
  var isAllNaN = true;
289
+
290
+ // If par_id is missing, set number of line in the chart as par_id
291
+ if(lineData.par_id == null)
292
+ lineData.par_id = this.lines.length;
293
+
272
294
  // If data-string is empty, return line with flag isEmpty=true.
273
295
  if (lineData.values.length == 0)
274
296
  return line;
297
+
275
298
  // Split in array and loop over all elements.
276
299
  var ar = lineData.values.split(";");
277
- // Variable used by efficiently loop over big array.
300
+
301
+ // Variable used efficiently by loop over big array.
278
302
  var arLen = ar.length;
279
303
  for (var i = 0; i < arLen; ++i) {
304
+
280
305
  var item = ar[i].split('/');
306
+
281
307
  if (item[0] == "") {
282
308
  logger.warn('LineChart._createLine(). Item ' + i + ' time-stamp is empty.');
283
309
  continue;
284
310
  }
311
+
285
312
  if (isNaN(item[0])) {
286
313
  logger.warn('LineChart._createLine(). Item ' + i + ' contains invalid time-stamp "' + item[0] + '".');
287
314
  continue;
288
315
  }
316
+
289
317
  var elem = { ts: null, val: null };
290
318
  elem.ts = parseInt(item[0]);
291
319
  elem.val = parseFloat(item[1]);
292
- if (elem.val < 0) {
293
- logger.error('LineChart._createLine(). Negative values not supported! ts=' + elem.ts + ' val=' + elem.val);
294
- return null;
295
- }
320
+
296
321
  line.real.push(elem);
297
- // If value is valid number, update min/max set to false flag isAllNaN
322
+
323
+ // If value is valid number, update min/max and set false isAllNaN.
298
324
  if (!isNaN(elem.val)) {
299
- if (elem.val < this.minVal)
300
- this.minVal = Math.floor(elem.val * 0.95);
301
- if (elem.val > this.maxVal)
302
- this.maxVal = Math.ceil(elem.val * 1.05);
325
+
326
+ // Update mininal value. Positive and negative values process differently.
327
+ if(elem.val < 0) {
328
+
329
+ if(Math.floor(elem.val * 1.1) < this.minVal) {
330
+ this.minVal = Math.floor(elem.val * 1.1);
331
+ }
332
+
333
+ } else {
334
+
335
+ if(Math.floor(elem.val * 0.9) < this.minVal) {
336
+ this.minVal = Math.floor(elem.val * 0.9);
337
+ }
338
+ }
339
+
340
+ // Update maximal value.
341
+ if (Math.ceil(elem.val * 1.1) > this.maxVal) {
342
+ this.maxVal = Math.ceil(elem.val * 1.1);
343
+ }
344
+
303
345
  isAllNaN = false;
304
346
  }
347
+
305
348
  // Update min/max time-stamp
306
349
  if (elem.ts < this.minTs)
307
350
  this.minTs = elem.ts;
@@ -312,13 +355,15 @@ class LineChart {
312
355
  // If line is empty skip next operations.
313
356
  if (line.real.length == 0)
314
357
  return line;
358
+
315
359
  line.isEmpty = false;
316
360
  // Adjust min/max values if both 0 or all values NaN
317
361
  if ((this.maxVal == 0 && this.minVal == 0) || isAllNaN) {
318
362
  this.minVal = 0;
319
363
  this.maxVal = 1;
320
364
  }
321
- // Calculate padding. This area used for labels.
365
+
366
+ // Calculate padding. This area used for labels. Both are type of object TextMetrics.
322
367
  var minValText = this.context.measureText(this.minVal.toString());
323
368
  var maxValText = this.context.measureText(this.maxVal.toString());
324
369
  // Set place for label using biggest value.
@@ -327,6 +372,7 @@ class LineChart {
327
372
  } else {
328
373
  this.padding.left = Math.round(minValText.width) + 23;
329
374
  }
375
+
330
376
  return line;
331
377
  }
332
378
 
@@ -511,23 +557,40 @@ class LineChart {
511
557
  labelMinVal += this.axeYLabelStep;
512
558
  }
513
559
  }
560
+ // Calculate maximal hight of axe-y. This value used to prevent labels on axe-y
561
+ // below axe-x. This may happy some times if this.minVal is negative.
562
+ var axeYHight = this.canvas.height - this.padding.bottom;
563
+
514
564
  // Create array of labels. Each item in array contains {value:value, Y:position-Y}
515
565
  // It will be used to draw labels and help-lines. The loop limit to 33 labels to
516
566
  // prevent infinite loop.
517
567
  var axeY = [];
518
568
  i = 0;
519
569
  var labelPosY, labelValue;
570
+
520
571
  while (i < 33) {
572
+
521
573
  labelValue = labelMinVal + (this.axeYLabelStep * i);
522
- // If step less as 1, format values of label to two decimal digits
574
+
575
+ // If step less as 1 or =2.5, format values of label to two decimal digits
523
576
  if (this.axeYLabelStep < 1 || this.axeYLabelStep == 2.5)
524
577
  labelValue = labelValue.toFixed(2);
525
- labelPosY = this._convertVal2PosY(labelValue);
526
- if (labelPosY < 0)
527
- break;
578
+
579
+ labelPosY = this._convertVal2PosY(labelValue);
580
+
581
+ // End loop if reach uper border of axe-y.
582
+ if (labelPosY < 0)
583
+ break;
584
+
585
+ // Some time if this.minVal is negative, label at the bottom placed below axe-x.
586
+ // To prevent it add label to array only if label's position is smaler as available
587
+ // hight of chart.
588
+ if(labelPosY < axeYHight) {
528
589
  var label = { value: labelValue, Y: labelPosY };
529
590
  axeY.push(label);
530
- i++;
591
+ }
592
+
593
+ i++;
531
594
  }
532
595
  // Begin drawing.
533
596
  this.context.lineWidth = 1;
@@ -645,19 +708,25 @@ class LineChart {
645
708
  }
646
709
  // Clean temporary array
647
710
  avgY = [];
648
- // If array with average values not empty set reference to real-data instead.
649
- if (lineData.length == 0) {
711
+
712
+ // If array with average values is empty set reference to real-data instead.
713
+ if (lineData.length == 0)
650
714
  lineData = line.real;
651
- }
715
+
716
+ // Prepare position x/y for points/items in line.
652
717
  arLen = lineData.length;
653
718
  for (var i = 0; i < arLen; i++) {
719
+
720
+ // Create empty point/item in line.
654
721
  var item = { X: NaN, Y: NaN };
655
- // Convert Time-stamp to coordinate X
722
+
723
+ // Convert time-stamp to coordinate X
656
724
  item.X = this._convertTs2PosX(lineData[i].ts);
725
+
657
726
  // Convert value to coordinate Y
658
- if (!isNaN(lineData[i].val)) {
727
+ if (!isNaN(lineData[i].val))
659
728
  item.Y = this._convertVal2PosY(lineData[i].val);
660
- }
729
+
661
730
  // By items with the same position X calculate average value.
662
731
  if (item.X == lastX) {
663
732
  avgY.push(item.Y);
@@ -797,7 +866,7 @@ class LineChart {
797
866
  '#FF4500', // OrangeRed
798
867
  '#00FF00', // Lime
799
868
  '#8A2BE2' // BlueViolet
800
- ];
869
+ ]
801
870
 
802
871
  // Default color used in some elements
803
872
  colorDefault = '#657585';
@@ -831,5 +900,12 @@ class SingleLine {
831
900
  // Fill with data later, because need update min/max parsmeter of chart.
832
901
  this.isEmpty = true; // Flag indicate that line contains no data.
833
902
  this.hidden = false; // Property uses to hide line in chart by click on legend item.
903
+ this.color = "black" // Default color for line
834
904
  }
835
905
  }
906
+
907
+ var allCharts = [];
908
+
909
+ // Version
910
+ LineChart.prototype.Version = "1.2.0";
911
+