adaptive-linechart 1.2.2 → 1.4.0

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,29 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.4.0 (28 Nov 2026)
4
+
5
+ * New
6
+
7
+ * New parameter **ifDataMissing** in LineChart() constructor replaces **connectIfMissing** in
8
+ lineData() and applies to all lines in the chart.
9
+ * Step up to 10 years.
10
+
11
+ * Fixes
12
+
13
+ * Fix: `updateLines()` now correct removes the old legend and creates a new one from the new data.
14
+ * Fix: min/max values are determined from the raw range over all lines with a 10 % margin.
15
+ * Fix: charts with future data are handled correctly .
16
+ * Fix: decimal labels on axis-X are rounded to the step precision (no more visual garbage like 1.5999999999999999).
17
+ * Fix: in some cases prevent endless loops.
18
+ * Fix: legend item is XSS-safe and clicking on the colored tag also hides/shows the line.
19
+ * Fix: prevent creation global variables.
20
+
21
+ ## 1.3.0 (14 Aug 2023)
22
+ * The data on axis-X may be data-time or numerical values. To switch between type of chart use parameter **axisXType**.
23
+ * New parameter for line **connectIfMissing**. It define how to draw line if part of data are missing.
24
+ * All internal properties in class LineChart rename with prefix _.
25
+ * Rewrite comments by JS standard https://jsdoc.app
26
+
3
27
  ## 1.2.2 (20 Nov 2022)
4
28
  * In README change link to demo and move to new repository.
5
29
 
package/DEVELOPER.md ADDED
@@ -0,0 +1,37 @@
1
+ # Prepare files for distribution
2
+
3
+ * Update version in README, package.json, linechart.js
4
+ * Put information about changes in CHANGELOG
5
+
6
+ # Build
7
+
8
+ Terser is a devDependency of this project (see package.json). Install and
9
+ build with:
10
+
11
+ ```
12
+ npm install // once: installs terser from package.json
13
+ npm run build // runs node build.js ->
14
+ ```
15
+
16
+ `build.js` concatenates `src/chart-util.js` (first, it defines the globals)
17
+ and `src/linechart.js`, minifies them with terser, writes to `dist/linechart-all.min.js`
18
+ and copies `dist/linechart.css` writes the bundle.
19
+
20
+ # Generate API documentation in README.md
21
+
22
+ Transfer API description from JSDoc comments in the source code into the
23
+ `<!-- @API --> ... <!-- /@API -->` section of README.md:
24
+
25
+ ```
26
+ npm run updoc // runs node tools/updoc.js
27
+ ```
28
+
29
+ Internal methods/classes are marked `@private` in the code and are left out of
30
+ the generated documentation.
31
+
32
+ # Test and Upload to NPM
33
+
34
+ ```
35
+ npm pack --dry-run // Preview files to publish. Check if it correct
36
+ npm publish
37
+ ```
package/README.md CHANGED
@@ -1,101 +1,210 @@
1
- ## adaptive-linechart :chart_with_upwards_trend:
2
- :
3
- Version 1.2.2
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
-
1
+ # adaptive-linechart :chart_with_upwards_trend:
2
+ Version 1.4.0
3
+
4
+ This is a small library to draw charts in the browser. All elements of chart will be set up
5
+ automaticaly based on data. You can adjust the layout of the chart by using external CSS styles
6
+ for .nowrap .linechart, .chart-title, .chart-live-data, .chart-legend, .chart-legend-item,
7
+ .chart-legend-color. Maximal 10 lines in the chart. The values on axis-x may be Unix time-stamp
8
+ or numercal. The chart uses the global variable isMobil (Boolean). If false, live data are shown
9
+ by "mouse-over". By click on item in the legend hide/show line on chart. The library has own
10
+ simple logger that writes messages to the console. If needed, you can rewrite this logger and
11
+ redirect messages to another target.
12
+
13
+ Additional supplied function to convert CSV to time-series.
14
+
15
+
16
+ # Example
17
+
18
+ This example creates a chart with 3 lines in parent element with ID 'charts':
19
+ ```js
20
+ var chartData = [
21
+ {
22
+ obj_name: 'Stock preis',
23
+ par_name: ' Open',
24
+ values: '1565301600/138.6100;1565560800/137.0700;1565647200/136.0500;1565733600/136.3600;1565820000/134.3900'
25
+ },
26
+ {
27
+ obj_name: 'Stock preis',
28
+ par_name: ' Hight',
29
+ vaues: '1565301600/139.3800;1565560800/137.8600;1565647200/138.8000;1565733600/136.9200;1565820000/134.5800'
30
+ },
31
+ {
32
+ obj_name: 'Stock preis',
33
+ par_name: ' Low',
34
+ values: '1565301600/136.4600;1565560800/135.2400;1565647200/135.0000;1565733600/133.6700;1565820000/132.2500'
35
+ }
36
+ ];
37
+
38
+ var lchart = new LineChart(document.getElementById('charts'),null, null, 'Example Chart-Line', null);
39
+
40
+ for(i=0; i < chartData.length; i++) {
41
+ lchart.addLine(chartData[i]);
42
+ }
43
+
44
+ lchart.draw();
45
+ ```
46
+
47
+ [Live example](https://andk.dev/adaptive-linechart.html)
48
+
49
+ <!-- @API -->
50
+
51
+ ## Classes
52
+
53
+ <dl>
54
+ <dt><a href="#LineChart">LineChart</a></dt>
55
+ <dd><p>The oject represent the chart. Constructor create object and HTML code for the chart. The chart
56
+ uses external CSS styles .nowrap .linechart, .chart-title, .chart-live-data, .chart-legend,
57
+ .chart-legent-item, .chart-legent-color. The chart uses global variable isMobil (Boolean). If
58
+ false, show live data by mouse over. The line create from LineData (see above) Labels on axis X
59
+ and Y will be created automaticaly. The chart can show maximal 10 lines in different colors.</p>
60
+ </dd>
61
+ <dt><a href="#LineData">LineData</a></dt>
62
+ <dd><p>The object represent data to create one line in chart.</p>
63
+ </dd>
64
+ </dl>
65
+
66
+ <a name="LineChart"></a>
67
+
68
+ ## LineChart
69
+ The oject represent the chart. Constructor create object and HTML code for the chart. The chart
70
+ uses external CSS styles .nowrap .linechart, .chart-title, .chart-live-data, .chart-legend,
71
+ .chart-legent-item, .chart-legent-color. The chart uses global variable isMobil (Boolean). If
72
+ false, show live data by mouse over. The line create from LineData (see above) Labels on axis X
73
+ and Y will be created automaticaly. The chart can show maximal 10 lines in different colors.
74
+
75
+ **Kind**: global class
76
+
77
+ * [LineChart](#LineChart)
78
+ * [new LineChart(container, chartId, width, title, className, axisXType, ifDataMissing)](#new_LineChart_new)
79
+ * [.avgStep](#LineChart+avgStep)
80
+ * [.addLine(lineData)](#LineChart+addLine) ⇒ <code>boolean</code>
81
+ * [.updateLines(lines)](#LineChart+updateLines) ⇒ <code>boolean</code>
82
+ * [.clear()](#LineChart+clear)
83
+ * [.draw()](#LineChart+draw)
84
+ * [.resize(difWidth, difHeight)](#LineChart+resize)
85
+ * [.isEmpty()](#LineChart+isEmpty)
86
+
87
+ <a name="new_LineChart_new"></a>
88
+
89
+ ### new LineChart(container, chartId, width, title, className, axisXType, ifDataMissing)
90
+
91
+ | Param | Type | Description |
92
+ | --- | --- | --- |
93
+ | container | <code>HTMLElement</code> | parent element for the chart. If null use HTML BODY as parent element. |
94
+ | chartId | <code>number</code> | identifier for chart. Optional. If not defined use random number. |
95
+ | width | <code>number</code> | width in pixel. Optional. Default use available width in parent element. |
96
+ | title | <code>string</code> | title of chart. Optional. If null don't create title. |
97
+ | className | <code>string</code> | class for div of chart. Optional. Default "linechart" |
98
+ | axisXType | <code>string</code> | for time based values on axis X set "time" (Default). For number based values "number". |
99
+ | ifDataMissing | <code>string</code> | handling of missing values on axis X. "connect" (Default) - connect line across missing values. "noline" - don't draw line across missing values. "skip" - reserved, not yet implemented. |
100
+
101
+ <a name="LineChart+avgStep"></a>
102
+
103
+ ### lineChart.avgStep
104
+ Instead automatic, the average step on axis X may be set manual.
105
+ Several measured values are combined into fixed time windows to
106
+ flatten peaks in the graph. Value in seconds. If NaN, not used.
107
+
108
+ **Kind**: instance property of [<code>LineChart</code>](#LineChart)
109
+ <a name="LineChart+addLine"></a>
110
+
111
+ ### lineChart.addLine(lineData) ⇒ <code>boolean</code>
112
+ Add new line and create new item in legend.
113
+
114
+ **Kind**: instance method of [<code>LineChart</code>](#LineChart)
115
+ **Returns**: <code>boolean</code> - true if no problem detected, otherwise false.
116
+
117
+ | Param | Type | Description |
118
+ | --- | --- | --- |
119
+ | lineData | [<code>LineData</code>](#LineData) | object that represents the data for one line. |
120
+
121
+ <a name="LineChart+updateLines"></a>
122
+
123
+ ### lineChart.updateLines(lines) ⇒ <code>boolean</code>
124
+ Update data in chart and redraw this one. The old legend items are removed and
125
+ recreated for the new lines.
126
+
127
+ **Kind**: instance method of [<code>LineChart</code>](#LineChart)
128
+ **Returns**: <code>boolean</code> - true if no problem detected, otherwise false.
129
+
130
+ | Param | Type | Description |
131
+ | --- | --- | --- |
132
+ | lines | [<code>Array.&lt;LineData&gt;</code>](#LineData) | array of lineData objects; replaces all current lines. |
133
+
134
+ <a name="LineChart+clear"></a>
135
+
136
+ ### lineChart.clear()
137
+ Clear all on graphic. Legend stay visible.
138
+
139
+ **Kind**: instance method of [<code>LineChart</code>](#LineChart)
140
+ <a name="LineChart+draw"></a>
141
+
142
+ ### lineChart.draw()
143
+ Draw graphic with all elements.
144
+
145
+ **Kind**: instance method of [<code>LineChart</code>](#LineChart)
146
+ <a name="LineChart+resize"></a>
147
+
148
+ ### lineChart.resize(difWidth, difHeight)
149
+ Change size of chart and redraw. May be used if size of parent panel changed but data
150
+ in lines stay the same.
151
+
152
+ **Kind**: instance method of [<code>LineChart</code>](#LineChart)
153
+
154
+ | Param | Type | Description |
155
+ | --- | --- | --- |
156
+ | difWidth | <code>number</code> | difference in width (pixel). |
157
+ | difHeight | <code>number</code> | difference in height (pixel). |
158
+
159
+ <a name="LineChart+isEmpty"></a>
160
+
161
+ ### lineChart.isEmpty()
162
+ Return true if all lines are empty
163
+
164
+ **Kind**: instance method of [<code>LineChart</code>](#LineChart)
165
+ <a name="LineData"></a>
166
+
167
+ ## LineData
168
+ The object represent data to create one line in chart.
169
+
170
+ **Kind**: global class
171
+ <a name="new_LineData_new"></a>
172
+
173
+ ### new LineData(obj_name, par_name, par_id, values)
174
+
175
+ | Param | Type | Description |
176
+ | --- | --- | --- |
177
+ | obj_name | <code>string</code> | name of the object, shown in the legend. |
178
+ | par_name | <code>string</code> | name of the parameter, shown in the legend. |
179
+ | par_id | <code>number</code> | internal id of the line. Optional. May be used to request data from a backend. |
180
+ | values | <code>string</code> | measurement data, elements separated by ";". Each element contains the value on axis-X and the measuring value separated by "/", e.g. "161111145730/3.48;161111145843/3.50;161111150013/". - Axis-X value: Unix time-stamp in seconds for axisXType "time", any decimal number for axisXType "number" (e.g. "0.001/5"). - Measuring value: any number (positive or negative). An empty measuring value marks a missing value (gap); there the line is interrupted or connected according to ifDataMissing. |
181
+
182
+ **Example**
183
+ ```js
184
+ line = {
185
+ obj_name:"Proxy Server",
186
+ par_name:"CpuTotal",
187
+ par_id:"2452",
188
+ values: "161111145730/3.48;161111145843/3.50;161111150013/"
189
+ }
190
+ ```
191
+
192
+ <!-- /@API -->
193
+
194
+ ## Utility
195
+
196
+ **`scvToTimeSeries(csv)`** - process CSV and return array of objects
197
+
198
+ `{name: "Name of serie", data: "Unix-Timestamp/Value;Unix-Timestamp/Value"}`.
199
+
200
+ Assume the first column contains data-time as string. The CSV may contain many columns. Name of
201
+ serie taken from header. Values may be empty. This function needs the package [Moment.js](https://momentjs.com)
202
+
203
+ ## Contact
204
+
205
+ If you have any questions, please contact me `adaptive-linechart@my.mail.de`
206
+
207
+ ## License
208
+
209
+ [MIT](https://opensource.org/licenses/MIT) © Andrej Koslov
210
+
package/build.js ADDED
@@ -0,0 +1,36 @@
1
+ // Build script for adaptive-linechart.
2
+ // Concatenates src/chart-util.js and src/linechart.js (in this order, because
3
+ // chart-util.js defines the global helpers used by linechart.js), minifies
4
+ // them with terser and writes dist/linechart-all.min.js. The CSS is copied
5
+ // unchanged.
6
+ //
7
+ // Usage: npm run build (or: node build.js)
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+ const terser = require('terser');
11
+
12
+ (async function () {
13
+ const src = path.join(__dirname, 'src');
14
+ const dist = path.join(__dirname, 'dist');
15
+
16
+ // Order matters: chart-util.js first, it defines the globals (logger,
17
+ // addNewElement, getAvgValue, ...) used by linechart.js.
18
+ const code = [
19
+ fs.readFileSync(path.join(src, 'chart-util.js'), 'utf8'),
20
+ fs.readFileSync(path.join(src, 'linechart.js'), 'utf8')
21
+ ].join('\n'); // Separator between files
22
+
23
+ // Default options: top-level names (LineChart, logger, scvToTimeSeries,
24
+ // ...) stay untouched, so the public API keeps working.
25
+ const result = await terser.minify(code, {});
26
+ if (result.error) {
27
+ console.error('terser error:', result.error);
28
+ process.exit(1);
29
+ }
30
+
31
+ fs.writeFileSync(path.join(dist, 'linechart-all.min.js'), result.code);
32
+ fs.copyFileSync(path.join(src, 'linechart.css'), path.join(dist, 'linechart.css'));
33
+
34
+ console.log('dist/linechart-all.min.js ' + (result.code.length / 1024).toFixed(1) + ' KB');
35
+ console.log('dist/linechart.css ' + (fs.statSync(path.join(dist, 'linechart.css')).size / 1024).toFixed(1) + ' KB');
36
+ })();
@@ -1,2 +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
- 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
+ if(void 0===logger)var logger={info:function(t){console.info(t)},warn:function(t){console.warn(t)},error:function(t){console.error(t)},debug:function(t){console.debug(t)}};function addNewElement(t,e,i){if(null==i&&(i={}),null!=i.id?null!=document.getElementById(i.id)&&(newElementCounter++,i.id=newElementCounter.toString()+"_"+(new Date).getTime().toString()):(newElementCounter++,i.id=newElementCounter.toString()+"_"+(new Date).getTime().toString()),null==e)var a=document.createElement("div");else a=document.createElement(e);for(var n in i)a.setAttribute(n,i[n]);return null!=i.innerText&&(a.innerText=i.innerText),null!=i.innerHTML&&(a.innerHTML=i.innerHTML),null==t?document.body.appendChild(a):t.appendChild(a),document.getElementById(i.id)}var newElementCounter=0;function getAvgValue(t,e){if(null==t||0==t.length)return NaN;(null==e||isNaN(e))&&(e=2);for(var i=0,a=0,n=0;n<t.length;n++)isNaN(t[n])||(i+=t[n],a+=1);return 0==a?NaN:(i/a).toFixed(e)}function getRandomInt(){return 1e17*Math.random()}function isString(t){return"string"==typeof t||t instanceof String}function roundTo(t,e){if(null==t||isNaN(t))return t;(null==e||e<0)&&(e=0);var i=Math.pow(10,e);return Math.round(t*i)/i}function scvToTimeSeries(t){let e=[];if(null==t)return e;let i=t.split(/\r?\n/);if(i.length<2)return e;var a=i[0].split(",");for(let t=1;t<a.length;t++){let n={name:a[t],data:""};for(let e=i.length-1;e>0;e--){let s=i[e].split(",");s.length==a.length&&(n.data+=moment(s[0]).format("X")+"/"+s[t]+";")}n.data=n.data.slice(0,-1),e.push(n)}return e}Date.prototype.separate=function(){var t={};return t.year=this.getFullYear(),t.month=this.getMonth()+1,t.mday=this.getDate(),t.hour=this.getHours(),t.min=this.getMinutes(),t.sec=this.getSeconds(),t.msec=this.getMilliseconds(),t.month<10&&(t.month="0"+t.month),t.mday<10&&(t.mday="0"+t.mday),t.hour<10&&(t.hour="0"+t.hour),t.min<10&&(t.min="0"+t.min),t.sec<10&&(t.sec="0"+t.sec),t.msec<10?t.msec="00"+t.msec:t.msec<100&&(t.msec="0"+t.msec),t},Date.prototype.formatISOLocal=function(){var t=this.separate();return t.year+"-"+t.month+"-"+t.mday+" "+t.hour+":"+t.min+":"+t.sec};class LineChart{constructor(t,e,i,a,n,s,h){if(null==t&&(t=document.getElementsByTagName("BODY")[0]),null==e&&(e=getRandomInt()),null==n&&(n="linechart"),null==i&&(i=t.clientWidth),this.chartDiv=addNewElement(t,"div",{class:n,id:"chart_"+e,chart_id:e,style:"float:left; width:"+i+"px; padding-bottom:8px;"}),null!=a){addNewElement(this.chartDiv,"label",{class:"chart-title nowrap",style:"width:"+(i-20)+"px; text-align:center; display:block; margin-left:10px; margin-top:10px"}).innerHTML=a}var r=i-30,l=300;isMobil?l=220:i<200?l=200:i<300?l=220:i<400?l=240:i<500?l=260:i<600&&(l=280),this._canvas=addNewElement(this.chartDiv,"canvas",{id:"chart_"+e+"_canvas",width:r,height:l,style:"margin: 15px 17px 3px 13px;"}),null!=s||void 0===s?"number"==s?this.axisXType="number":("time"==s||logger.warn(`Unknow value axisXType=${s}. Set default "time".`),this.axisXType="time"):this.axisXType="time",null==h?this.ifDataMissing="connect":"connect"==h||"noline"==h||"skip"==h?this.ifDataMissing=h:(logger.warn(`Unknow value ifDataMissing=${h}. Set default "connect".`),this.ifDataMissing="connect"),this._canvas.dataset.axisXType=this.axisXType,this._canvas.dataset.ifDataMissing=this.ifDataMissing,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 if(i=i<100?i.toFixed(2):i<200?i.toFixed(1):Math.round(i),"time"==this.dataset.axisXType){var a=parseInt(this.dataset.minTs)+Math.round((t.offsetX-parseInt(this.dataset.paddingLeft))/parseFloat(this.dataset.coefTs));if(isNaN(a))return void(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>"}else{var n=parseFloat(this.dataset.minTs)+Math.round((t.offsetX-parseInt(this.dataset.paddingLeft))/parseFloat(this.dataset.coefTs));e.innerHTML="Axis-X <b>"+n+"</b> Axis-Y <b>"+i+"</b>"}}}),addNewElement(this.chartDiv,"div",{class:"chart-live-data, nowrap",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=Number.MAX_SAFE_INTEGER,this._maxTs=0,this._minValRaw=1/0,this._maxValRaw=-1/0,this._minVal=1/0,this._maxVal=-1/0,this._axeYLabelStep=null,this._axeYLabelHeightDefault=30,this._axeXLabelWidthDefault=80,this._coefX=null,this._coefY=null,this._padding={left:50,bottom:35},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):(this._createLegendItem(e,t),this.lines.push(e),!0)}_createLegendItem(t,e){t.legend=addNewElement(this._legendDiv,"div",{class:"chart-legend-item nowrap",id:`chart_${this.chartId}_legend_${e.par_id}`,style:`cursor: pointer; max-width:${this.chartDiv.clientWidth-20}px;`}),addNewElement(t.legend,"span",{class:"chart-legend-color",style:`background-color:${t.color}; color:${t.color};`,innerHTML:"--"}),t.legend.appendChild(document.createTextNode(t.objName+" / "+t.parName)),t.legend.addEventListener("click",function(e){var i=e.currentTarget.querySelector(".chart-legend-color");null!=i&&(0==t.hidden?(t.hidden=!0,i.style.backgroundColor="white"):(t.hidden=!1,i.style.backgroundColor=t.color),e.currentTarget.chart.draw())}),t.legend.chart=this}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;if(null!=this._legendDiv)for(;null!=this._legendDiv.firstChild;)this._legendDiv.removeChild(this._legendDiv.firstChild);this.lines=[],this._minTs=Number.MAX_SAFE_INTEGER,this._maxTs=0,this._minValRaw=1/0,this._maxValRaw=-1/0,this._minVal=1/0,this._maxVal=-1/0,this._axeYLabelStep=null,this._coefX=null,this._coefY=null;for(var e=0;e<t.length;e++){var i=this._createLine(t[e]);null!=i&&(this._createLegendItem(i,t[e]),this.lines.push(i))}return this.draw(),!0}_createLine(t){var e=new SingleLine(t,this.colors[this.lines.length]);if(null==t.par_id&&(t.par_id=this.lines.length),0==t.values.length)return e;for(var i=t.values.split(";"),a=i.length,n=0;n<a;++n){var s=i[n].split("/");if(""!=s[0])if(isNaN(s[0]))logger.warn("LineChart._createLine(). Item "+n+'. Element for axis-x is not a number "'+s[0]+'".');else{var h={ts:null,val:null};"number"==this.axisXType?h.ts=parseFloat(s[0]):h.ts=parseInt(s[0]),h.val=parseFloat(s[1]),e.real.push(h),isNaN(h.val)||(h.val<this._minValRaw&&(this._minValRaw=h.val),h.val>this._maxValRaw&&(this._maxValRaw=h.val)),h.ts<this._minTs&&(this._minTs=h.ts),h.ts>this._maxTs&&(this._maxTs=h.ts)}else logger.warn("LineChart._createLine(). Item "+n+". Element for axis-x is empty.")}if(0==e.real.length)return e;e.isEmpty=!1,this._minValRaw===1/0&&(this._minValRaw=0,this._maxValRaw=1);var r=this._getLabelWidth(this._minValRaw),l=this._getLabelWidth(this._maxValRaw);return this._padding.left=r<l?Math.round(l)+23:Math.round(r)+23,e}clear(){this._context.clearRect(0,0,this._canvas.width,this._canvas.height)}draw(){if(this._context.clearRect(0,0,this._canvas.width,this._canvas.height),!this.isEmpty()){var t=this._maxValRaw-this._minValRaw;if(0==t)this._minVal=this._minValRaw-1,this._maxVal=this._maxValRaw+1;else{var e=.1*t;this._minVal=this._minValRaw-e,this._maxVal=this._maxValRaw+e}this._coefX=this._getCoefX(),this._coefY=this._getCoefY(),"time"==this.axisXType?this._drawAxeXTime():this._drawAxeXNum(),this._drawAxeY();for(var i=0;i<this.lines.length;i++)this._drawLine(i);this._canvas.dataset.minTs=this._minTs.toString(),this._canvas.dataset.coefTs=this._coefX.toString(),this._canvas.dataset.maxVal=this._maxVal.toString(),this._canvas.dataset.coefVal=this._coefY.toString(),this._canvas.dataset.paddingLeft=this._padding.left.toString(),this._canvas.dataset.paddingBottom=this._padding.bottom.toString()}}_getCoefX(){return(this._canvas.width-this._padding.left)/(this._maxTs-this._minTs)}_getCoefY(){return(this._canvas.height-this._padding.bottom)/(this._maxVal-this._minVal)}_getLabelWidth(t){var e=Math.abs(t)<10?t.toFixed(2):Math.round(t).toString();return this._context.measureText(e).width}resize(t,e){this._canvas.width=this._canvas.width+t,this._canvas.height=this._canvas.height+e,this._context.translate(.5,.5),this.draw()}_drawAxeXTime(){var t;this._drawAxeXBasic();var e=Math.round(this._axeXLabelWidthDefault/this._coefX);if(e<=1)e=1;else{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}}for(var a=e>=2592e3?this._getBeginOfYearFromUnixTs(this._minTs):this._getBeginOfDayFromUnixTs(this._minTs);a<this._minTs;)a+=e;for(var n,s,h=[];a<this._maxTs;)n=this._convertTs2PosX(a),s=this._formatTsForLabel(a,this._maxTs-this._minTs),h.push({X:n,str:s}),a+=e;this._context.beginPath(),this._context.strokeStyle="#e6e6e6";var r=Math.round(e*this._coefX/2),l=this._canvas.height-this._padding.bottom;t=h.length;for(i=0;i<t;i++)this._context.moveTo(h[i].X,0),this._context.lineTo(h[i].X,l+10),h[i].X-r>this._padding.left+2&&(this._context.moveTo(h[i].X-r,0),this._context.lineTo(h[i].X-r,l));for(null!=h[i-1]&&h[i-1].X+r<=this._canvas.width&&(this._context.moveTo(h[i-1].X+r,0),this._context.lineTo(h[i-1].X+r,l)),this._context.stroke(),this._context.font="12px arial",t=h.length,i=0;i<t;i++)this._context.fillText(h[i].str.hm,h[i].X-17,l+17),(0==i||h[i].str.dm!=h[i-1].str.dm)&&this._context.fillText(h[i].str.dm,h[i].X-17,l+32);this._context.closePath()}_drawAxeXNum(){let t;this._drawAxeXBasic();let e=this._axeXLabelWidthDefault/this._coefX;if(e=this._getNextPreferedNumber(e),null==e||e<=0)return;let i=this._getNextPreferedNumber(this._minTs);null==i&&(i=this._minTs);let a=Math.max(0,Math.ceil(-Math.log10(e)));i=roundTo(i,a);let n=[];for(;i<this._maxTs;)n.push({X:this._convertTs2PosX(i),str:i}),i=roundTo(i+e,a);this._context.beginPath(),this._context.strokeStyle="#e6e6e6";let s=Math.round(e*this._coefX/2),h=this._canvas.height-this._padding.bottom;t=n.length;for(let e=0;e<t;e++)this._context.moveTo(n[e].X,0),this._context.lineTo(n[e].X,h+10),n[e].X-s>this._padding.left+2&&(this._context.moveTo(n[e].X-s,0),this._context.lineTo(n[e].X-s,h));null!=n[n.length-1]&&n[n.length-1].X+s<=this._canvas.width&&(this._context.moveTo(n[n.length-1].X+s,0),this._context.lineTo(n[n.length-1].X+s,h)),this._context.stroke(),this._context.font="12px arial",t=n.length;for(let e=0;e<t;e++)this._context.fillText(n[e].str,n[e].X,h+20);this._context.closePath()}_drawAxeXBasic(){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()}_drawAxeY(){if(null==this._coefX||null==this._coefY)return;var t,e=(this._canvas.height-this._padding.bottom)/this._axeYLabelHeightDefault;this._axeYLabelStep=(this._maxVal-this._minVal)/e,this._axeYLabelStep=this._getNextPreferedNumber(this._axeYLabelStep);var i=0;if(this._minVal<0)for(;i>this._minVal&&!(i<=this._minVal);)i-=this._axeYLabelStep;else if(this._minVal>0)for(;i<this._maxVal&&!(i>=this._minVal);)i+=this._axeYLabelStep;var a=this._canvas.height-this._padding.bottom,n=[];let s=0;for(var h,r;s<33&&(r=i+this._axeYLabelStep*s,(this._axeYLabelStep<1||2.5==this._axeYLabelStep)&&(r=r.toFixed(2)),!((h=this._convertVal2PosY(r))<0));){if(h<a){var l={value:r,Y:h};n.push(l)}s++}if(0!=n.length){var o;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=n.length,s=0;s<t;s++)(o=n[s].Y+Math.round(this._coefY*this._axeYLabelStep/2))<this._canvas.height-this._padding.bottom&&(this._context.moveTo(this._padding.left,o),this._context.lineTo(this._canvas.width,o)),n[s].Y>=this._canvas.height-this._padding.bottom||(this._context.moveTo(this._padding.left,n[s].Y),this._context.lineTo(this._canvas.width,n[s].Y));for((o=n[n.length-1].Y-Math.round(this._coefY*this._axeYLabelStep/2))>0&&(this._context.moveTo(this._padding.left,o),this._context.lineTo(this._canvas.width,o)),this._context.stroke(),this._context.font="12px arial",this._context.strokeStyle=this.colorDefault,t=n.length,s=0;s<t;s++)this._context.fillText(n[s].value,0,n[s].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=[],n=-1,s=[],h=[];if(!isNaN(this.avgStep)){for(var r=this._getBeginOfDayFromUnixTs(e.real[0].ts);r<e.real[0].ts;)r+=this.avgStep;i=e.real.length;for(var l=0;l<i;l++)if(e.real[l].ts<r)s.push(e.real[l].val);else{for(var o=0;e.real[l].ts>r+this.avgStep;)if(r+=this.avgStep,++o>1e3)return void logger.warn("drawLine(). Can't calculate average values for this line. "+new Date(1e3*e.real[l].ts).formatISOLocal()+"/"+e.real[l].val);var d={ts:r,val:getAvgValue(s,2)};h.push(d),(s=[]).push(e.real[l].val),r+=this.avgStep}if(s.length>0){d={ts:r,val:getAvgValue(s,2)};h.push(d)}}s=[],0==h.length&&(h=e.real),i=h.length;for(var _=0;_<i;_++){(d={X:NaN,Y:NaN}).X=this._convertTs2PosX(h[_].ts),isNaN(h[_].val)||(d.Y=this._convertVal2PosY(h[_].val)),d.X!=n?(n=d.X,s.length>0&&_>0&&(s.push(a[a.length-1].Y),a[a.length-1].Y=getAvgValue(s,2),s=[]),a.push(d)):s.push(d.Y)}for(this._context.strokeStyle=this.colors[t],this._context.lineWidth=1,this._context.beginPath(),i=a.length,_=0;_<i;_++)if(!isNaN(a[_].Y)){this._context.moveTo(a[_].X,a[_].Y),_++;break}for(;_<i;)if(isNaN(a[_].Y))if("noline"!=this.ifDataMissing)for(;_<a.length&&isNaN(a[_].Y);)_++;else for(this._context.stroke(),this._context.beginPath();_<a.length&&isNaN(a[_].Y);)_++;else this._context.lineTo(a[_].X,a[_].Y),_++;this._context.stroke()}}else logger.error("Function LineChart.drawLine(lineId). The line with ID "+t+" not found!")}_getNextPreferedNumber(t){if(0==t)return 0;let e=t<0?-1:1;t=Math.abs(t);let i,a,n=[1e-9,2e-9,5e-9,1e-8],s=1;for(;s<1e18;){for(var h=0;h<n.length-1;h++)if(i=n[h]*s,a=n[h+1]*s,i<=t&&t<=a)return e>0?a:-i;s*=10}return null}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._coefX)}_convertVal2PosY(t){return Math.round((this._maxVal-t)*this._coefY)}_formatTsForLabel(t,e){let i=new Date(1e3*t);e/=86400;let a=i.getFullYear(),n=i.getMonth()+1;n<10&&(n="0"+n.toString());let s=i.getDate();parseInt(s)<10&&(s="0"+s.toString());let h=i.getHours();parseInt(h)<10&&(h="0"+h);let r=i.getMinutes();parseInt(r)<10&&(r="0"+r.toString());let l={};return l=e<3?{dm:s+"."+n,hm:h+":"+r}:e>=3&&e<180?{dm:a,hm:s+"."+n}:{dm:a,hm:" "+n},l}_getBeginOfDayFromUnixTs(t){var e=new Date(1e3*t);return(e=new Date(e.getFullYear(),e.getMonth(),e.getDate())).getTime()/1e3}_getBeginOfYearFromUnixTs(t){var e=new Date(1e3*t);return(e=new Date(e.getFullYear(),0,1)).getTime()/1e3}colors=["#0044CC","#008000","#FF8533","#6A6A6A","#C71585","#8B4513","#1E90FF","#FF4500","#00FF00","#8A2BE2"];colorDefault="#657585";stepsX=[1,2,5,10,20,30,60,120,300,600,900,1200,1800,3600,7200,14400,21600,43200,86400,172800,259200,345600,432e3,604800,864e3,1296e3,1728e3,2592e3,5184e3,7776e3,10368e3,15552e3,31536e3,63072e3,15768e4,31536e4]}class SingleLine{constructor(t,e){this.parId=t.par_id,this.parName=null!=t.par_name?t.par_name:"",this.objName=null!=t.obj_name?t.obj_name:"",this.real=[],this.isEmpty=!0,this.hidden=!1,this.color=null==e?"black":e,this.legend=null}}class LineData{constructor(t,e,i,a){this.obj_name=t,this.par_name=e,this.par_id=i,this.values=a}}
@@ -11,7 +11,7 @@
11
11
  }
12
12
 
13
13
  .chart-title {
14
- font-size: x-large;
14
+ font-size:large;
15
15
  }
16
16
 
17
17
  .chart-live-data {