adaptive-linechart 1.0.0 → 1.2.1
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 +21 -0
- package/LICENSE +21 -0
- package/README.md +101 -0
- package/dist/linechart-all.min.js +2 -0
- package/{linechart.css → dist/linechart.css} +0 -0
- package/example/example.csv +100 -100
- package/example/example.js +17 -14
- package/example/index.html +2 -3
- package/package.json +9 -5
- package/{chart-util.js → src/chart-util.js} +0 -0
- package/src/linechart.css +34 -0
- package/{linechart.js → src/linechart.js} +130 -55
- package/chart-util.min.js +0 -1
- package/linechart.min.js +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.2.1 (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
|
+
|
|
15
|
+
## 1.0.1 (4 May 2020)
|
|
16
|
+
- Add README.md
|
|
17
|
+
- Add directory **src** (files for development) and **dist** (ready to use minified files)
|
|
18
|
+
|
|
19
|
+
## 1.0.0 (26 April 2020)
|
|
20
|
+
- First Version
|
|
21
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 andrejkoslov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
## adaptive-linechart :chart_with_upwards_trend:
|
|
2
|
+
:
|
|
3
|
+
Version 1.2.0.0
|
|
4
|
+
|
|
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.
|
|
9
|
+
|
|
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.
|
|
14
|
+
|
|
15
|
+
The chart accepts data as time-series in the format (string) "Unix-Timestamp/Value;Unix-Timestamp/Value;..".
|
|
16
|
+
Additional (chart-util) supplied function to convert CSV (with header) to time-series.
|
|
17
|
+
|
|
18
|
+
The library uses its own simple logger that writes messages to the console. If needed, you can
|
|
19
|
+
rewrite this object and redirect messages to another target.
|
|
20
|
+
|
|
21
|
+
## Example
|
|
22
|
+
|
|
23
|
+
This example creates a chart with 3 lines in parent element with ID 'charts':
|
|
24
|
+
```js
|
|
25
|
+
var arTimeSeries = [
|
|
26
|
+
{
|
|
27
|
+
name: 'Open',
|
|
28
|
+
data: '1565301600/138.6100;1565560800/137.0700;1565647200/136.0500;1565733600/136.3600;1565820000/134.3900'
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'Hight',
|
|
32
|
+
data: '1565301600/139.3800;1565560800/137.8600;1565647200/138.8000;1565733600/136.9200;1565820000/134.5800'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: ' Low',
|
|
36
|
+
data: '1565301600/136.4600;1565560800/135.2400;1565647200/135.0000;1565733600/133.6700;1565820000/132.2500'
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
var lchart = new LineChart(document.getElementById('charts'),null, null, 'Example Chart-Line', null);
|
|
41
|
+
|
|
42
|
+
for(let i=0; i < arTimeSeries.length; i++) {
|
|
43
|
+
let line = {
|
|
44
|
+
obj_name: 'Stock preis',
|
|
45
|
+
par_name: arTimeSeries[i].name,
|
|
46
|
+
values: arTimeSeries[i].data
|
|
47
|
+
};
|
|
48
|
+
lchart.addLine(line);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
lchart.draw();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
[Live example](https://www.softdorado.com/adaptive-linechart.html)
|
|
55
|
+
|
|
56
|
+
## Public methods
|
|
57
|
+
|
|
58
|
+
**`LineChart(container, chartId, width, title, className)`** - create an object of type LineChart
|
|
59
|
+
and create HTML code for the chart.
|
|
60
|
+
- **container** - Reference to parent element for chart. If null: use BODY as parent element.
|
|
61
|
+
- **chartId** - String. Identifier for chart. Optional. If not defined use random integer.
|
|
62
|
+
- **width** - Integer. Width in pixel. Optional. Default use available width in parent element.
|
|
63
|
+
- **title** - String. Title of chart. Optional. If null: don't create title.
|
|
64
|
+
- **className** - String. Class for div of chart. Optional. Default "linechart".
|
|
65
|
+
|
|
66
|
+
**`addLine(lineData)`** - add data for a new line and automatically create a new item in the legend.
|
|
67
|
+
Return true if no problem detected, otherwise false.
|
|
68
|
+
|
|
69
|
+
**`lineData`** - The object represents data for one line in the chart.
|
|
70
|
+
- **obj_name** - String. Name of object related to the chart. Used in legend.
|
|
71
|
+
- **par_name** - String. Name of the parameter that represents the current line. Used in legend.
|
|
72
|
+
- **par_id** - Integer. Optional ID of this line. May be used to request data from backend.
|
|
73
|
+
- **values** - String. Time-series in format "Unix-Timestamp/Value;Unix-Timestamp/Value;.."
|
|
74
|
+
|
|
75
|
+
**`draw()`** - draw graphic. Skip lines if properties hidden=true or isEmpty=true.
|
|
76
|
+
|
|
77
|
+
**`clear()`** - clear graphic. Legend stays visible.
|
|
78
|
+
|
|
79
|
+
**`resize(difWidth, difHeight)`** - set a new size. E.g. if the size of parent element is changed.
|
|
80
|
+
- **difWidth** - Signed integer. Difference in width.
|
|
81
|
+
- **difHeight** - Signed integer. Difference in height.
|
|
82
|
+
|
|
83
|
+
**`isEmpty()`** Return true if all lines are empty
|
|
84
|
+
|
|
85
|
+
## Utility
|
|
86
|
+
|
|
87
|
+
**`scvToTimeSeries(csv)`** - process CSV and return array of objects
|
|
88
|
+
|
|
89
|
+
`{name: "Name of serie", data: "Unix-Timestamp/Value;Unix-Timestamp/Value"}`.
|
|
90
|
+
|
|
91
|
+
Assume the first column contains data-time as string. The CSV may contain many columns. Name of
|
|
92
|
+
serie taken from header. Values may be empty. This function needs the package [Moment.js](https://momentjs.com)
|
|
93
|
+
|
|
94
|
+
## Contact
|
|
95
|
+
|
|
96
|
+
If you have any questions, please contact me `adaptive-linechart@my.mail.de`
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
[MIT](https://opensource.org/licenses/MIT) © Andrej Koslov
|
|
101
|
+
|
|
@@ -0,0 +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=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
|
+
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};
|
|
File without changes
|
package/example/example.csv
CHANGED
|
@@ -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
|
package/example/example.js
CHANGED
|
@@ -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: '
|
|
14
|
-
data: '1565301600
|
|
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: '
|
|
18
|
-
data: '1565301600/
|
|
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: '
|
|
22
|
-
data:
|
|
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
|
|
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: '
|
|
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
|
|
73
|
+
console.warn("Request CSV failed status "+ request.statusText+ " Responce "+ request.responseText);
|
|
71
74
|
}
|
|
72
75
|
});
|
|
73
76
|
|
package/example/index.html
CHANGED
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
|
|
6
6
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
|
7
7
|
<title>Example LineCharts</title>
|
|
8
|
-
<link type="text/css" rel="stylesheet" href="../linechart.css" >
|
|
8
|
+
<link type="text/css" rel="stylesheet" href="../dist/linechart.css" >
|
|
9
9
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
|
|
10
|
-
<script src="../linechart.min.js"></script>
|
|
11
|
-
<script src="../chart-util.min.js"></script>
|
|
10
|
+
<script src="../dist/linechart-all.min.js"></script>
|
|
12
11
|
<script src="example.js"></script>
|
|
13
12
|
</head>
|
|
14
13
|
|
package/package.json
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adaptive-linechart",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Independent library to draw line-chart in browser.",
|
|
5
|
-
"main": "linechart.js",
|
|
6
5
|
"scripts": {
|
|
7
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
7
|
},
|
|
8
|
+
"browser": "dist/linechart-all.min.js",
|
|
9
|
+
"author": "Andrej Koslov",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"homepage": "https://gitlab.com/softdorado/linechart",
|
|
9
12
|
"keywords": [
|
|
10
13
|
"line",
|
|
11
14
|
"chart",
|
|
12
15
|
"graphic"
|
|
13
16
|
],
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://gitlab.com/softdorado/linechart.git"
|
|
20
|
+
}
|
|
17
21
|
}
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
/* Don't wrap text. E.g. used in chart title.*/
|
|
3
|
+
.nowrap {
|
|
4
|
+
white-space: nowrap;
|
|
5
|
+
overflow: hidden;
|
|
6
|
+
text-overflow: ellipsis;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.linechart {
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.chart-title {
|
|
14
|
+
font-size: x-large;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.chart-live-data {
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.chart-legend {
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.chart-legend-item {
|
|
26
|
+
margin: 0px 5px 5px 10px;
|
|
27
|
+
height: 18px; display:
|
|
28
|
+
inline-block;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.chart-legend-color {
|
|
32
|
+
margin-right: 5px;
|
|
33
|
+
}
|
|
34
|
+
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
// Version 1.2.1
|
|
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
|
|
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.
|
|
8
9
|
// @consructor:
|
|
9
10
|
// @param container - Reference to parent element for chart. If null use HTML BODY as parent element.
|
|
10
|
-
// @param chartId -
|
|
11
|
+
// @param chartId - String. Identifier for chart. Optional. If not defined use random integer.
|
|
11
12
|
// @param width - Integer. Width in pixel. Optional. Default use available width in parent element.
|
|
12
13
|
// @param title - String. Title of chart. Optional. If null don't create title.
|
|
13
14
|
// @param className - String. Class for div of chart. Optinal. Default "linechart"
|
|
@@ -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 =
|
|
151
|
+
this.minVal = Number.MAX_SAFE_INTEGER;
|
|
151
152
|
// Maximal measuring value.
|
|
152
|
-
this.maxVal =
|
|
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.
|
|
@@ -173,11 +174,10 @@ class LineChart {
|
|
|
173
174
|
|
|
174
175
|
// Add data for new line. Automaticaly create new item in legend.
|
|
175
176
|
// @parameter lineData Object. The object represent data for one line in chart.
|
|
176
|
-
// line.obj_id:"101"
|
|
177
177
|
// line.obj_name:"Proxy Server"
|
|
178
|
-
// line.par_id:"2452"
|
|
179
178
|
// line.par_name:"CpuTotal"
|
|
180
|
-
// line.
|
|
179
|
+
// line.par_id:"2452"
|
|
180
|
+
// line.values: Example data-string "161111145730/3.48;161111145843/3.50;161111150013/"
|
|
181
181
|
// @return Boolean. True if no problem detected. Else false.
|
|
182
182
|
addLine (lineData) {
|
|
183
183
|
if (lineData.values == null) {
|
|
@@ -200,26 +200,38 @@ class LineChart {
|
|
|
200
200
|
line.objName = lineData.obj_name;
|
|
201
201
|
line.parName = lineData.par_name;
|
|
202
202
|
line.parId = lineData.par_id;
|
|
203
|
-
|
|
204
|
-
//
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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
|
+
|
|
223
235
|
// Put new line array of lines.
|
|
224
236
|
this.lines.push(line);
|
|
225
237
|
return true;
|
|
@@ -257,10 +269,13 @@ class LineChart {
|
|
|
257
269
|
return true;
|
|
258
270
|
}
|
|
259
271
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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.
|
|
264
279
|
// Example data-string "161111145730/3.48;161111145843/;161111150013/"
|
|
265
280
|
// Each element separated by ";" in each element time-stamp separated from value by "/".
|
|
266
281
|
// Value may be empty! Always in last item the element without value. It indicate only
|
|
@@ -268,41 +283,68 @@ class LineChart {
|
|
|
268
283
|
_createLine (lineData) {
|
|
269
284
|
// Create object empty line.
|
|
270
285
|
var line = new SingleLine(lineData);
|
|
286
|
+
|
|
271
287
|
// Flag. True if value of all items are NaN. In this case set min/max 0/1
|
|
272
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
|
+
|
|
273
294
|
// If data-string is empty, return line with flag isEmpty=true.
|
|
274
295
|
if (lineData.values.length == 0)
|
|
275
296
|
return line;
|
|
297
|
+
|
|
276
298
|
// Split in array and loop over all elements.
|
|
277
299
|
var ar = lineData.values.split(";");
|
|
278
|
-
|
|
300
|
+
|
|
301
|
+
// Variable used efficiently by loop over big array.
|
|
279
302
|
var arLen = ar.length;
|
|
280
303
|
for (var i = 0; i < arLen; ++i) {
|
|
304
|
+
|
|
281
305
|
var item = ar[i].split('/');
|
|
306
|
+
|
|
282
307
|
if (item[0] == "") {
|
|
283
308
|
logger.warn('LineChart._createLine(). Item ' + i + ' time-stamp is empty.');
|
|
284
309
|
continue;
|
|
285
310
|
}
|
|
311
|
+
|
|
286
312
|
if (isNaN(item[0])) {
|
|
287
313
|
logger.warn('LineChart._createLine(). Item ' + i + ' contains invalid time-stamp "' + item[0] + '".');
|
|
288
314
|
continue;
|
|
289
315
|
}
|
|
316
|
+
|
|
290
317
|
var elem = { ts: null, val: null };
|
|
291
318
|
elem.ts = parseInt(item[0]);
|
|
292
319
|
elem.val = parseFloat(item[1]);
|
|
293
|
-
|
|
294
|
-
logger.error('LineChart._createLine(). Negative values not supported! ts=' + elem.ts + ' val=' + elem.val);
|
|
295
|
-
return null;
|
|
296
|
-
}
|
|
320
|
+
|
|
297
321
|
line.real.push(elem);
|
|
298
|
-
|
|
322
|
+
|
|
323
|
+
// If value is valid number, update min/max and set false isAllNaN.
|
|
299
324
|
if (!isNaN(elem.val)) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
if
|
|
303
|
-
|
|
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
|
+
|
|
304
345
|
isAllNaN = false;
|
|
305
346
|
}
|
|
347
|
+
|
|
306
348
|
// Update min/max time-stamp
|
|
307
349
|
if (elem.ts < this.minTs)
|
|
308
350
|
this.minTs = elem.ts;
|
|
@@ -313,13 +355,15 @@ class LineChart {
|
|
|
313
355
|
// If line is empty skip next operations.
|
|
314
356
|
if (line.real.length == 0)
|
|
315
357
|
return line;
|
|
358
|
+
|
|
316
359
|
line.isEmpty = false;
|
|
317
360
|
// Adjust min/max values if both 0 or all values NaN
|
|
318
361
|
if ((this.maxVal == 0 && this.minVal == 0) || isAllNaN) {
|
|
319
362
|
this.minVal = 0;
|
|
320
363
|
this.maxVal = 1;
|
|
321
364
|
}
|
|
322
|
-
|
|
365
|
+
|
|
366
|
+
// Calculate padding. This area used for labels. Both are type of object TextMetrics.
|
|
323
367
|
var minValText = this.context.measureText(this.minVal.toString());
|
|
324
368
|
var maxValText = this.context.measureText(this.maxVal.toString());
|
|
325
369
|
// Set place for label using biggest value.
|
|
@@ -328,6 +372,7 @@ class LineChart {
|
|
|
328
372
|
} else {
|
|
329
373
|
this.padding.left = Math.round(minValText.width) + 23;
|
|
330
374
|
}
|
|
375
|
+
|
|
331
376
|
return line;
|
|
332
377
|
}
|
|
333
378
|
|
|
@@ -512,23 +557,40 @@ class LineChart {
|
|
|
512
557
|
labelMinVal += this.axeYLabelStep;
|
|
513
558
|
}
|
|
514
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
|
+
|
|
515
564
|
// Create array of labels. Each item in array contains {value:value, Y:position-Y}
|
|
516
565
|
// It will be used to draw labels and help-lines. The loop limit to 33 labels to
|
|
517
566
|
// prevent infinite loop.
|
|
518
567
|
var axeY = [];
|
|
519
568
|
i = 0;
|
|
520
569
|
var labelPosY, labelValue;
|
|
570
|
+
|
|
521
571
|
while (i < 33) {
|
|
572
|
+
|
|
522
573
|
labelValue = labelMinVal + (this.axeYLabelStep * i);
|
|
523
|
-
|
|
574
|
+
|
|
575
|
+
// If step less as 1 or =2.5, format values of label to two decimal digits
|
|
524
576
|
if (this.axeYLabelStep < 1 || this.axeYLabelStep == 2.5)
|
|
525
577
|
labelValue = labelValue.toFixed(2);
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
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) {
|
|
529
589
|
var label = { value: labelValue, Y: labelPosY };
|
|
530
590
|
axeY.push(label);
|
|
531
|
-
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
i++;
|
|
532
594
|
}
|
|
533
595
|
// Begin drawing.
|
|
534
596
|
this.context.lineWidth = 1;
|
|
@@ -646,19 +708,25 @@ class LineChart {
|
|
|
646
708
|
}
|
|
647
709
|
// Clean temporary array
|
|
648
710
|
avgY = [];
|
|
649
|
-
|
|
650
|
-
|
|
711
|
+
|
|
712
|
+
// If array with average values is empty set reference to real-data instead.
|
|
713
|
+
if (lineData.length == 0)
|
|
651
714
|
lineData = line.real;
|
|
652
|
-
|
|
715
|
+
|
|
716
|
+
// Prepare position x/y for points/items in line.
|
|
653
717
|
arLen = lineData.length;
|
|
654
718
|
for (var i = 0; i < arLen; i++) {
|
|
719
|
+
|
|
720
|
+
// Create empty point/item in line.
|
|
655
721
|
var item = { X: NaN, Y: NaN };
|
|
656
|
-
|
|
722
|
+
|
|
723
|
+
// Convert time-stamp to coordinate X
|
|
657
724
|
item.X = this._convertTs2PosX(lineData[i].ts);
|
|
725
|
+
|
|
658
726
|
// Convert value to coordinate Y
|
|
659
|
-
if (!isNaN(lineData[i].val))
|
|
727
|
+
if (!isNaN(lineData[i].val))
|
|
660
728
|
item.Y = this._convertVal2PosY(lineData[i].val);
|
|
661
|
-
|
|
729
|
+
|
|
662
730
|
// By items with the same position X calculate average value.
|
|
663
731
|
if (item.X == lastX) {
|
|
664
732
|
avgY.push(item.Y);
|
|
@@ -798,7 +866,7 @@ class LineChart {
|
|
|
798
866
|
'#FF4500', // OrangeRed
|
|
799
867
|
'#00FF00', // Lime
|
|
800
868
|
'#8A2BE2' // BlueViolet
|
|
801
|
-
]
|
|
869
|
+
]
|
|
802
870
|
|
|
803
871
|
// Default color used in some elements
|
|
804
872
|
colorDefault = '#657585';
|
|
@@ -832,5 +900,12 @@ class SingleLine {
|
|
|
832
900
|
// Fill with data later, because need update min/max parsmeter of chart.
|
|
833
901
|
this.isEmpty = true; // Flag indicate that line contains no data.
|
|
834
902
|
this.hidden = false; // Property uses to hide line in chart by click on legend item.
|
|
903
|
+
this.color = "black" // Default color for line
|
|
835
904
|
}
|
|
836
905
|
}
|
|
906
|
+
|
|
907
|
+
var allCharts = [];
|
|
908
|
+
|
|
909
|
+
// Version
|
|
910
|
+
LineChart.prototype.Version = "1.2.0";
|
|
911
|
+
|
package/chart-util.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
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};
|
package/linechart.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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}}
|