1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | "use strict";
|
14 |
|
15 | import BarsHandler from './bars';
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | var CustomBarsHandler = function() {
|
22 | };
|
23 |
|
24 | CustomBarsHandler.prototype = new BarsHandler();
|
25 |
|
26 |
|
27 | CustomBarsHandler.prototype.extractSeries = function(rawData, i, options) {
|
28 |
|
29 | var series = [];
|
30 | var x, y, point;
|
31 | const seriesLabel = options.get("labels")[i];
|
32 | const logScale = options.getForSeries("logscale", seriesLabel);
|
33 | for ( var j = 0; j < rawData.length; j++) {
|
34 | x = rawData[j][0];
|
35 | point = rawData[j][i];
|
36 | if (logScale && point !== null) {
|
37 |
|
38 |
|
39 | if (point[0] <= 0 || point[1] <= 0 || point[2] <= 0) {
|
40 | point = null;
|
41 | }
|
42 | }
|
43 |
|
44 | if (point !== null) {
|
45 | y = point[1];
|
46 | if (y !== null && !isNaN(y)) {
|
47 | series.push([ x, y, [ point[0], point[2] ] ]);
|
48 | } else {
|
49 | series.push([ x, y, [ y, y ] ]);
|
50 | }
|
51 | } else {
|
52 | series.push([ x, null, [ null, null ] ]);
|
53 | }
|
54 | }
|
55 | return series;
|
56 | };
|
57 |
|
58 |
|
59 | CustomBarsHandler.prototype.rollingAverage =
|
60 | function(originalData, rollPeriod, options, i) {
|
61 | rollPeriod = Math.min(rollPeriod, originalData.length);
|
62 | var rollingData = [];
|
63 | var y, low, high, mid,count, i, extremes;
|
64 |
|
65 | low = 0;
|
66 | mid = 0;
|
67 | high = 0;
|
68 | count = 0;
|
69 | for (i = 0; i < originalData.length; i++) {
|
70 | y = originalData[i][1];
|
71 | extremes = originalData[i][2];
|
72 | rollingData[i] = originalData[i];
|
73 |
|
74 | if (y !== null && !isNaN(y)) {
|
75 | low += extremes[0];
|
76 | mid += y;
|
77 | high += extremes[1];
|
78 | count += 1;
|
79 | }
|
80 | if (i - rollPeriod >= 0) {
|
81 | var prev = originalData[i - rollPeriod];
|
82 | if (prev[1] !== null && !isNaN(prev[1])) {
|
83 | low -= prev[2][0];
|
84 | mid -= prev[1];
|
85 | high -= prev[2][1];
|
86 | count -= 1;
|
87 | }
|
88 | }
|
89 | if (count) {
|
90 | rollingData[i] = [
|
91 | originalData[i][0],
|
92 | 1.0 * mid / count,
|
93 | [ 1.0 * low / count,
|
94 | 1.0 * high / count ] ];
|
95 | } else {
|
96 | rollingData[i] = [ originalData[i][0], null, [ null, null ] ];
|
97 | }
|
98 | }
|
99 |
|
100 | return rollingData;
|
101 | };
|
102 |
|
103 | export default CustomBarsHandler;
|