fhdp-charts 4.10.401 → 4.10.901

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.
@@ -1,375 +1,378 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- var fh_forms_handler_1 = require("fh-forms-handler");
17
- var konva_1 = require("konva");
18
- var ChartTime24 = /** @class */ (function (_super) {
19
- __extends(ChartTime24, _super);
20
- function ChartTime24(componentObj, parent) {
21
- var _this = _super.call(this, componentObj, parent) || this;
22
- _this.barElements = [];
23
- //? resize event
24
- _this.resizeWindowBind = _this.resizeWindow.bind(_this);
25
- //? base parameters
26
- _this.hAxisName = componentObj.haxisName || '';
27
- _this.vAxisName = componentObj.vaxisName || '';
28
- _this.bgColor = componentObj.bgColor || '#f3f2ec';
29
- _this.tooltipBgColor = componentObj.tooltipBgColor || 'black';
30
- _this.axisLabelColor = componentObj.axisLabelColor || 'black';
31
- _this.lineColor = componentObj.lineColor || 'LightSlateGrey';
32
- _this.tooltipColor = componentObj.tooltipColor || 'white';
33
- _this.fontFamily = componentObj.fontFamily || 'Calibri';
34
- _this.barElements = componentObj.bars;
35
- _this.highlightedValue = Number(componentObj.highlightedValue) || 22;
36
- _this.highlightedStroke = Number(componentObj.highlightedStroke) || 3;
37
- _this.gradation = Number(componentObj.gradation) || 2;
38
- _this.maxValueX = Number(componentObj.maxValueX) || 26;
39
- //? containers ids
40
- _this.mainElementId = componentObj.mainElementId || 'chartContainer';
41
- _this.scrollContainerId = componentObj.scrollContainerId || 'scrollContainer';
42
- //? bar
43
- _this.barBreakWidth = Number(componentObj.barBreakWidth) || 60;
44
- _this.barHeight = Number(componentObj.barHeight) || 100;
45
- _this.barBreakHeight = Number(componentObj.barBreakHeight) || 30;
46
- _this.percentDarkColorOnMove = Number(componentObj.percentDarkColorOnMove) || 20;
47
- //? base margin
48
- _this.leftMarginChart = Number(componentObj.leftMarginChart) || 100;
49
- _this.rightMarginChart = Number(componentObj.rightMarginChart) || 110;
50
- _this.topMarginChart = Number(componentObj.topMarginChart) || 50;
51
- _this.bottomMarginChart = Number(componentObj.bottomMarginChart) || 50;
52
- //? scroll container
53
- _this.scrollSizeChart = Number(componentObj.scrollSizeChart) || 23;
54
- //? lines, value lines
55
- _this.protrudingLinesHeight = Number(componentObj.protrudingLinesHeight) || 10;
56
- _this.labelTextHeight = Number(componentObj.labelTextHeight) || 3;
57
- _this.labelTextFontSize = Number(componentObj.labelTextFontSize) || 22;
58
- _this.lineStrokeWidth = Number(componentObj.lineStrokeWidth) || 1;
59
- //? legend
60
- _this.topMarginLegend = Number(componentObj.topMarginLegend) || 20;
61
- _this.legendColorWidth = Number(componentObj.legendColorWidth) || 40;
62
- _this.legendColorHeight = Number(componentObj.legendColorHeight) || 20;
63
- _this.legendFontSize = Number(componentObj.legendFontSize) || 18;
64
- _this.legendBreakColorText = Number(componentObj.legendBreakColorText) || 5;
65
- _this.legendElementBreakWidth = Number(componentObj.legendElementBreakWidth) || 25;
66
- _this.legendElementBreakHeight = Number(componentObj.legendElementBreakHeight) || 3;
67
- //? tooltip
68
- _this.tooltipOpacity = Number(componentObj.tooltipOpacity) || 0.8;
69
- _this.tooltipPointerWidth = Number(componentObj.tooltipPointerWidth) || 10;
70
- _this.tooltipPointerHeight = Number(componentObj.tooltipPointerHeight) || 20;
71
- _this.tooltipCornerRadius = Number(componentObj.tooltipCornerRadius) || 5;
72
- _this.tooltipFontSize = Number(componentObj.tooltipFontSize) || 18;
73
- _this.tooltipPadding = Number(componentObj.tooltipPadding) || 10;
74
- //? label name prop
75
- _this.labelNameFontSize = Number(componentObj.labelNameFontSize) || 22;
76
- _this.labelNameBreak = Number(componentObj.labelNameBreak) || 13;
77
- _this.resizeWindowBind = _this.resizeWindow.bind(_this);
78
- _this.initResizeWindow();
79
- return _this;
80
- }
81
- ChartTime24.prototype.create = function () {
82
- var mainElement = document.createElement('div');
83
- mainElement.id = this.mainElementId;
84
- mainElement.style.display = 'flex';
85
- this.component = mainElement;
86
- this.wrap(false, false);
87
- this.addStyles();
88
- this.display();
89
- this.buildChart(mainElement.id);
90
- this.display();
91
- };
92
- ChartTime24.prototype.initResizeWindow = function () {
93
- $(window).on('resize', this.resizeWindowBind);
94
- };
95
- ChartTime24.prototype.resizeWindow = function () {
96
- this.destroy(true);
97
- this.create();
98
- this.initResizeWindow();
99
- };
100
- ChartTime24.prototype.destroy = function (removeFromParent) {
101
- $(window).off('resize', this.resizeWindowBind);
102
- _super.prototype.destroy.call(this, removeFromParent);
103
- };
104
- ChartTime24.prototype.update = function (change) {
105
- _super.prototype.update.call(this, change);
106
- this.destroy(true);
107
- this.create();
108
- this.resizeWindowBind = this.resizeWindow.bind(this);
109
- this.initResizeWindow();
110
- };
111
- ChartTime24.prototype.buildChart = function (id) {
112
- //? create hAxisLabels numbers
113
- var _a = this.getHAxisLables(), hAxisLabels = _a.hAxisLabels, maxX = _a.maxX;
114
- var maxXFullWidth = maxX + this.leftMarginChart + this.rightMarginChart;
115
- var stageWidth = maxXFullWidth < this.htmlElement.offsetWidth ? maxXFullWidth : this.htmlElement.offsetWidth;
116
- var chartLinesHeight = (this.barElements.length + 1) * this.barBreakHeight + this.barElements.length * this.barHeight;
117
- var chartHeight = chartLinesHeight + this.protrudingLinesHeight + this.labelTextFontSize + this.labelTextHeight;
118
- var stage = new konva_1.default.Stage({
119
- container: id,
120
- width: stageWidth,
121
- });
122
- var _b = this.createStaticLayer(stageWidth, chartLinesHeight), staticLayer = _b.staticLayer, background = _b.background;
123
- var legendLayer = new konva_1.default.Layer({
124
- x: this.leftMarginChart,
125
- });
126
- stage.add(staticLayer, legendLayer);
127
- stage.draw();
128
- //? create div for scroll stage
129
- var baseContainer = document.getElementById(id);
130
- var baseConvasContainer = baseContainer.childNodes[0];
131
- var scrollLayer = this.createScrollLayer(hAxisLabels, maxX, chartLinesHeight);
132
- var _c = this.createBarsLayer(legendLayer, stageWidth), barsLayer = _c.barsLayer, tooltipLayer = _c.tooltipLayer, maxLegendY = _c.maxLegendY;
133
- var scrollContainer = document.createElement('div');
134
- scrollContainer.id = this.scrollContainerId;
135
- scrollContainer.style.overflow = 'auto';
136
- scrollContainer.style.marginLeft = this.leftMarginChart + "px";
137
- scrollContainer.style.height = chartHeight + this.scrollSizeChart + "px";
138
- scrollContainer.style.position = 'relative';
139
- scrollContainer.style.marginTop = this.topMarginChart + "px";
140
- scrollContainer.style.marginRight = this.rightMarginChart + "px";
141
- baseConvasContainer.appendChild(scrollContainer);
142
- //? Resizze Legend
143
- var legendY = chartHeight + this.scrollSizeChart + this.topMarginChart + this.topMarginLegend;
144
- legendLayer.y(legendY);
145
- var legendWidth = maxLegendY + this.legendColorHeight;
146
- var allHeight = legendY + legendWidth + this.bottomMarginChart;
147
- stage.height(allHeight);
148
- background.height(allHeight);
149
- //? scroll stage
150
- var scrollStage = new konva_1.default.Stage({
151
- container: scrollContainer.id,
152
- width: maxX,
153
- height: chartHeight,
154
- x: this.lineStrokeWidth,
155
- });
156
- scrollStage.add(scrollLayer, barsLayer, tooltipLayer);
157
- scrollStage.draw();
158
- };
159
- ChartTime24.prototype.getHAxisLables = function () {
160
- var _this = this;
161
- var maxTo = this.barElements.reduce(function (prev, curr) {
162
- return (Number(prev.to) > Number(curr.to)) ? prev : curr;
163
- });
164
- var yearStart = 1;
165
- var yearEnd = Number(maxTo.to) > this.maxValueX ? Math.ceil(Number(maxTo.to) / this.gradation) + 2 : Math.ceil(this.maxValueX / 2);
166
- var hAxisLabels = Array(yearEnd - yearStart + 1).fill(0).map(function () { return _this.gradation * yearStart++; });
167
- var baseMaxX = hAxisLabels.length * this.barBreakWidth + this.barBreakWidth;
168
- var tooltipTextBox = new konva_1.default.Text({
169
- text: maxTo.tooltipText.replace(/\\n/g, "\n"),
170
- fontFamily: this.fontFamily,
171
- fontSize: this.tooltipFontSize,
172
- });
173
- var valueOneGradation = this.barBreakWidth / this.gradation;
174
- var widthBar = (Number(maxTo.to) * valueOneGradation + this.leftMarginChart) - (Number(maxTo.from) * valueOneGradation + this.leftMarginChart);
175
- var barXMax = Number(maxTo.from) * valueOneGradation + widthBar;
176
- var maxXTooltip = barXMax + Math.ceil(tooltipTextBox.textWidth) + 2 * this.tooltipPadding + this.tooltipPointerWidth;
177
- var maxX = baseMaxX > maxXTooltip ? baseMaxX : maxXTooltip;
178
- return { hAxisLabels: hAxisLabels, maxX: maxX };
179
- };
180
- ChartTime24.prototype.createScrollLayer = function (hAxisLabels, maxX, chartHeight) {
181
- var _this = this;
182
- var scrollLayer = new konva_1.default.Layer();
183
- //? Create grid
184
- var baseGridLine = new konva_1.default.Line({
185
- points: [0, 0, 0, chartHeight, maxX, chartHeight],
186
- stroke: this.lineColor,
187
- strokeWidth: this.lineStrokeWidth,
188
- lineCap: 'round',
189
- lineJoin: 'round',
190
- });
191
- scrollLayer.add(baseGridLine);
192
- //? labels and line OX
193
- hAxisLabels.forEach(function (el, i) {
194
- var configLabel = {
195
- points: [(i + 1) * _this.barBreakWidth, 0, (i + 1) * _this.barBreakWidth, chartHeight + _this.protrudingLinesHeight],
196
- stroke: _this.lineColor,
197
- strokeWidth: _this.lineStrokeWidth,
198
- lineCap: 'round',
199
- lineJoin: 'round',
200
- };
201
- if (el === _this.highlightedValue) {
202
- configLabel.strokeWidth = _this.highlightedStroke;
203
- }
204
- var labelText = new konva_1.default.Text({
205
- x: (i + 1) * _this.barBreakWidth,
206
- y: chartHeight + _this.protrudingLinesHeight + _this.labelTextHeight,
207
- text: String(el),
208
- fontSize: _this.labelTextFontSize,
209
- fontFamily: _this.fontFamily,
210
- fill: _this.axisLabelColor,
211
- });
212
- labelText.attrs.x -= (labelText.textWidth / 2);
213
- var lineLabel = new konva_1.default.Line(configLabel);
214
- scrollLayer.add(lineLabel);
215
- scrollLayer.add(labelText);
216
- });
217
- return scrollLayer;
218
- };
219
- ChartTime24.prototype.createStaticLayer = function (width, chartHeight) {
220
- var staticLayer = new konva_1.default.Layer();
221
- //? Create background
222
- var background = new konva_1.default.Rect({
223
- width: width,
224
- fill: this.bgColor,
225
- });
226
- staticLayer.add(background);
227
- this.createAxisLabel(staticLayer, width, chartHeight);
228
- return { staticLayer: staticLayer, background: background };
229
- };
230
- ChartTime24.prototype.createAxisLabel = function (staticLayer, width, chartHeight) {
231
- //? Label X NAME
232
- var labelXName = new konva_1.default.Text({
233
- x: width - this.rightMarginChart + this.labelNameBreak,
234
- y: chartHeight + this.protrudingLinesHeight + this.labelTextHeight + this.topMarginChart,
235
- text: this.hAxisName,
236
- fontSize: this.labelNameFontSize,
237
- fontFamily: this.fontFamily,
238
- fill: this.axisLabelColor,
239
- });
240
- staticLayer.add(labelXName);
241
- //? Label Y NAME
242
- var labelYName = new konva_1.default.Text({
243
- x: this.leftMarginChart - this.labelNameBreak,
244
- y: this.topMarginChart,
245
- text: this.vAxisName,
246
- fontSize: this.labelNameFontSize,
247
- fontFamily: this.fontFamily,
248
- fill: this.axisLabelColor,
249
- });
250
- labelYName.attrs.y -= labelYName.textHeight;
251
- labelYName.attrs.x -= labelYName.textWidth;
252
- staticLayer.add(labelYName);
253
- };
254
- ChartTime24.prototype.createBarsLayer = function (legendLayer, stageWidth) {
255
- var _this = this;
256
- var legendX = 0;
257
- var legendY = 0;
258
- var barsLayer = new konva_1.default.Layer();
259
- var tooltip = new konva_1.default.Label({
260
- opacity: this.tooltipOpacity,
261
- });
262
- tooltip.add(new konva_1.default.Tag({
263
- fill: this.tooltipBgColor,
264
- pointerDirection: 'left',
265
- pointerWidth: this.tooltipPointerWidth,
266
- pointerHeight: this.tooltipPointerHeight,
267
- lineJoin: 'round',
268
- cornerRadius: this.tooltipCornerRadius,
269
- }));
270
- var tooltipTextBox = new konva_1.default.Text({
271
- text: '',
272
- fontFamily: this.fontFamily,
273
- fontSize: this.tooltipFontSize,
274
- padding: this.tooltipPadding,
275
- fill: this.tooltipColor,
276
- });
277
- tooltip.add(tooltipTextBox);
278
- tooltip.hide();
279
- this.barElements
280
- .sort(function (a, b) { return (Number(a.position) > Number(b.position) ? 1 : -1); })
281
- .forEach(function (el, i) {
282
- var fromValue = Number(el.from);
283
- var toValue = Number(el.to);
284
- var valueOneGradation = _this.barBreakWidth / _this.gradation;
285
- var barHeight = _this.barHeight;
286
- var barBreakHeight = _this.barBreakHeight;
287
- var bar = new konva_1.default.Rect({
288
- width: (toValue * valueOneGradation + _this.leftMarginChart) - (fromValue * valueOneGradation + _this.leftMarginChart),
289
- height: barHeight,
290
- fill: el.color,
291
- x: fromValue * valueOneGradation,
292
- y: barHeight * i + barBreakHeight * (i + 1),
293
- });
294
- var darkColor = _this.darkenColor(el.color, _this.percentDarkColorOnMove);
295
- bar.on('mousemove', function (e) {
296
- this.fill(darkColor);
297
- //? positioning tooltip
298
- tooltip.position({
299
- x: (fromValue * valueOneGradation) + (toValue * valueOneGradation) - (fromValue * valueOneGradation),
300
- y: barHeight * i + barBreakHeight * (i + 1) + barHeight / 2,
301
- });
302
- tooltipTextBox.text(el.tooltipText.replace(/\\n/g, "\n"));
303
- tooltip.show();
304
- });
305
- bar.on('mouseout', function () {
306
- this.fill(el.color);
307
- tooltip.hide();
308
- });
309
- barsLayer.add(bar);
310
- var legendParam = _this.createLegendByBar(legendX, legendY, el, legendLayer, darkColor, bar, tooltip, tooltipTextBox, i, fromValue, toValue, valueOneGradation, barHeight, barBreakHeight, stageWidth);
311
- legendX = legendParam.legendX;
312
- legendY = legendParam.legendY;
313
- });
314
- var tooltipLayer = new konva_1.default.Layer();
315
- tooltipLayer.add(tooltip);
316
- return { barsLayer: barsLayer, tooltipLayer: tooltipLayer, maxLegendY: legendY };
317
- };
318
- ChartTime24.prototype.createLegendByBar = function (legendX, legendY, el, legendLayer, darkColor, bar, tooltip, tooltipTextBox, iter, fromValue, toValue, valueOneGradation, barHeight, barBreakHeight, stageWidth) {
319
- var legend = new konva_1.default.Rect({
320
- width: this.legendColorWidth,
321
- height: this.legendColorHeight,
322
- fill: el.color,
323
- x: legendX,
324
- y: legendY,
325
- });
326
- var legendText = new konva_1.default.Text({
327
- x: legendX + legend.attrs.width + this.legendBreakColorText,
328
- y: legendY,
329
- height: legend.attrs.height,
330
- text: el.legendText,
331
- fontSize: this.legendFontSize,
332
- fontFamily: this.fontFamily,
333
- fill: 'black',
334
- verticalAlign: 'middle'
335
- });
336
- var sumWidthLegend = legend.attrs.width + this.legendElementBreakWidth + legendText.textWidth + this.legendBreakColorText;
337
- var widthLegend = legendX + sumWidthLegend;
338
- var scrollWidth = stageWidth - this.leftMarginChart - this.rightMarginChart;
339
- if (widthLegend > scrollWidth) {
340
- legendY += this.legendColorHeight + this.legendElementBreakHeight;
341
- legendX = 0;
342
- legend.y(legendY);
343
- legend.x(legendX);
344
- legendText.y(legendY);
345
- legendText.x(legendX + legend.attrs.width + this.legendBreakColorText);
346
- }
347
- legendX += sumWidthLegend;
348
- legendLayer.add(legend);
349
- legendLayer.add(legendText);
350
- legend.on('mousemove', function (e) {
351
- this.fill(darkColor);
352
- bar.fill(darkColor);
353
- tooltip.position({
354
- x: (fromValue * valueOneGradation) + (toValue * valueOneGradation) - (fromValue * valueOneGradation),
355
- y: barHeight * iter + barBreakHeight * (iter + 1) + barHeight / 2,
356
- });
357
- tooltipTextBox.text(el.tooltipText.replace(/\\n/g, "\n"));
358
- tooltip.show();
359
- });
360
- legend.on('mouseout', function () {
361
- this.fill(el.color);
362
- bar.fill(el.color);
363
- tooltip.hide();
364
- });
365
- return { legendX: legendX, legendY: legendY };
366
- };
367
- ChartTime24.prototype.darkenColor = function (color, percent) {
368
- var num = parseInt(color.replace("#", ""), 16), amt = Math.round(2.55 * percent), R = (num >> 16) - amt, B = (num >> 8 & 0x00FF) - amt, G = (num & 0x0000FF) - amt;
369
- return "#" + (0x1000000 + (R < 255 ? R < 1 ? 0 : R : 255) * 0x10000 + (B < 255 ? B < 1 ? 0 : B : 255) * 0x100 + (G < 255 ? G < 1 ? 0 : G : 255)).toString(16).slice(1);
370
- };
371
- ;
372
- return ChartTime24;
373
- }(fh_forms_handler_1.HTMLFormComponent));
374
- exports.ChartTime24 = ChartTime24;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ChartTime24 = void 0;
19
+ var fh_forms_handler_1 = require("fh-forms-handler");
20
+ var konva_1 = require("konva");
21
+ var ChartTime24 = /** @class */ (function (_super) {
22
+ __extends(ChartTime24, _super);
23
+ function ChartTime24(componentObj, parent) {
24
+ var _this = _super.call(this, componentObj, parent) || this;
25
+ _this.barElements = [];
26
+ //? resize event
27
+ _this.resizeWindowBind = _this.resizeWindow.bind(_this);
28
+ //? base parameters
29
+ _this.hAxisName = componentObj.haxisName || '';
30
+ _this.vAxisName = componentObj.vaxisName || '';
31
+ _this.bgColor = componentObj.bgColor || '#f3f2ec';
32
+ _this.tooltipBgColor = componentObj.tooltipBgColor || 'black';
33
+ _this.axisLabelColor = componentObj.axisLabelColor || 'black';
34
+ _this.lineColor = componentObj.lineColor || 'LightSlateGrey';
35
+ _this.tooltipColor = componentObj.tooltipColor || 'white';
36
+ _this.fontFamily = componentObj.fontFamily || 'Calibri';
37
+ _this.barElements = componentObj.bars;
38
+ _this.highlightedValue = Number(componentObj.highlightedValue) || 22;
39
+ _this.highlightedStroke = Number(componentObj.highlightedStroke) || 3;
40
+ _this.gradation = Number(componentObj.gradation) || 2;
41
+ _this.maxValueX = Number(componentObj.maxValueX) || 26;
42
+ //? containers ids
43
+ _this.mainElementId = componentObj.mainElementId || 'chartContainer';
44
+ _this.scrollContainerId = componentObj.scrollContainerId || 'scrollContainer';
45
+ //? bar
46
+ _this.barBreakWidth = Number(componentObj.barBreakWidth) || 60;
47
+ _this.barHeight = Number(componentObj.barHeight) || 100;
48
+ _this.barBreakHeight = Number(componentObj.barBreakHeight) || 30;
49
+ _this.percentDarkColorOnMove = Number(componentObj.percentDarkColorOnMove) || 20;
50
+ //? base margin
51
+ _this.leftMarginChart = Number(componentObj.leftMarginChart) || 100;
52
+ _this.rightMarginChart = Number(componentObj.rightMarginChart) || 110;
53
+ _this.topMarginChart = Number(componentObj.topMarginChart) || 50;
54
+ _this.bottomMarginChart = Number(componentObj.bottomMarginChart) || 50;
55
+ //? scroll container
56
+ _this.scrollSizeChart = Number(componentObj.scrollSizeChart) || 23;
57
+ //? lines, value lines
58
+ _this.protrudingLinesHeight = Number(componentObj.protrudingLinesHeight) || 10;
59
+ _this.labelTextHeight = Number(componentObj.labelTextHeight) || 3;
60
+ _this.labelTextFontSize = Number(componentObj.labelTextFontSize) || 22;
61
+ _this.lineStrokeWidth = Number(componentObj.lineStrokeWidth) || 1;
62
+ //? legend
63
+ _this.topMarginLegend = Number(componentObj.topMarginLegend) || 20;
64
+ _this.legendColorWidth = Number(componentObj.legendColorWidth) || 40;
65
+ _this.legendColorHeight = Number(componentObj.legendColorHeight) || 20;
66
+ _this.legendFontSize = Number(componentObj.legendFontSize) || 18;
67
+ _this.legendBreakColorText = Number(componentObj.legendBreakColorText) || 5;
68
+ _this.legendElementBreakWidth = Number(componentObj.legendElementBreakWidth) || 25;
69
+ _this.legendElementBreakHeight = Number(componentObj.legendElementBreakHeight) || 3;
70
+ //? tooltip
71
+ _this.tooltipOpacity = Number(componentObj.tooltipOpacity) || 0.8;
72
+ _this.tooltipPointerWidth = Number(componentObj.tooltipPointerWidth) || 10;
73
+ _this.tooltipPointerHeight = Number(componentObj.tooltipPointerHeight) || 20;
74
+ _this.tooltipCornerRadius = Number(componentObj.tooltipCornerRadius) || 5;
75
+ _this.tooltipFontSize = Number(componentObj.tooltipFontSize) || 18;
76
+ _this.tooltipPadding = Number(componentObj.tooltipPadding) || 10;
77
+ //? label name prop
78
+ _this.labelNameFontSize = Number(componentObj.labelNameFontSize) || 22;
79
+ _this.labelNameBreak = Number(componentObj.labelNameBreak) || 13;
80
+ _this.resizeWindowBind = _this.resizeWindow.bind(_this);
81
+ _this.initResizeWindow();
82
+ return _this;
83
+ }
84
+ ChartTime24.prototype.create = function () {
85
+ var mainElement = document.createElement('div');
86
+ mainElement.id = this.mainElementId;
87
+ mainElement.style.display = 'flex';
88
+ this.component = mainElement;
89
+ this.wrap(false, false);
90
+ this.addStyles();
91
+ this.display();
92
+ this.buildChart(mainElement.id);
93
+ this.display();
94
+ };
95
+ ChartTime24.prototype.initResizeWindow = function () {
96
+ $(window).on('resize', this.resizeWindowBind);
97
+ };
98
+ ChartTime24.prototype.resizeWindow = function () {
99
+ this.destroy(true);
100
+ this.create();
101
+ this.initResizeWindow();
102
+ };
103
+ ChartTime24.prototype.destroy = function (removeFromParent) {
104
+ $(window).off('resize', this.resizeWindowBind);
105
+ _super.prototype.destroy.call(this, removeFromParent);
106
+ };
107
+ ChartTime24.prototype.update = function (change) {
108
+ _super.prototype.update.call(this, change);
109
+ this.destroy(true);
110
+ this.create();
111
+ this.resizeWindowBind = this.resizeWindow.bind(this);
112
+ this.initResizeWindow();
113
+ };
114
+ ChartTime24.prototype.buildChart = function (id) {
115
+ //? create hAxisLabels numbers
116
+ var _a = this.getHAxisLables(), hAxisLabels = _a.hAxisLabels, maxX = _a.maxX;
117
+ var maxXFullWidth = maxX + this.leftMarginChart + this.rightMarginChart;
118
+ var stageWidth = maxXFullWidth < this.htmlElement.offsetWidth ? maxXFullWidth : this.htmlElement.offsetWidth;
119
+ var chartLinesHeight = (this.barElements.length + 1) * this.barBreakHeight + this.barElements.length * this.barHeight;
120
+ var chartHeight = chartLinesHeight + this.protrudingLinesHeight + this.labelTextFontSize + this.labelTextHeight;
121
+ var stage = new konva_1.default.Stage({
122
+ container: id,
123
+ width: stageWidth,
124
+ });
125
+ var _b = this.createStaticLayer(stageWidth, chartLinesHeight), staticLayer = _b.staticLayer, background = _b.background;
126
+ var legendLayer = new konva_1.default.Layer({
127
+ x: this.leftMarginChart,
128
+ });
129
+ stage.add(staticLayer, legendLayer);
130
+ stage.draw();
131
+ //? create div for scroll stage
132
+ var baseContainer = document.getElementById(id);
133
+ var baseConvasContainer = baseContainer.childNodes[0];
134
+ var scrollLayer = this.createScrollLayer(hAxisLabels, maxX, chartLinesHeight);
135
+ var _c = this.createBarsLayer(legendLayer, stageWidth), barsLayer = _c.barsLayer, tooltipLayer = _c.tooltipLayer, maxLegendY = _c.maxLegendY;
136
+ var scrollContainer = document.createElement('div');
137
+ scrollContainer.id = this.scrollContainerId;
138
+ scrollContainer.style.overflow = 'auto';
139
+ scrollContainer.style.marginLeft = "".concat(this.leftMarginChart, "px");
140
+ scrollContainer.style.height = "".concat(chartHeight + this.scrollSizeChart, "px");
141
+ scrollContainer.style.position = 'relative';
142
+ scrollContainer.style.marginTop = "".concat(this.topMarginChart, "px");
143
+ scrollContainer.style.marginRight = "".concat(this.rightMarginChart, "px");
144
+ baseConvasContainer.appendChild(scrollContainer);
145
+ //? Resizze Legend
146
+ var legendY = chartHeight + this.scrollSizeChart + this.topMarginChart + this.topMarginLegend;
147
+ legendLayer.y(legendY);
148
+ var legendWidth = maxLegendY + this.legendColorHeight;
149
+ var allHeight = legendY + legendWidth + this.bottomMarginChart;
150
+ stage.height(allHeight);
151
+ background.height(allHeight);
152
+ //? scroll stage
153
+ var scrollStage = new konva_1.default.Stage({
154
+ container: scrollContainer.id,
155
+ width: maxX,
156
+ height: chartHeight,
157
+ x: this.lineStrokeWidth,
158
+ });
159
+ scrollStage.add(scrollLayer, barsLayer, tooltipLayer);
160
+ scrollStage.draw();
161
+ };
162
+ ChartTime24.prototype.getHAxisLables = function () {
163
+ var _this = this;
164
+ var maxTo = this.barElements.reduce(function (prev, curr) {
165
+ return (Number(prev.to) > Number(curr.to)) ? prev : curr;
166
+ });
167
+ var yearStart = 1;
168
+ var yearEnd = Number(maxTo.to) > this.maxValueX ? Math.ceil(Number(maxTo.to) / this.gradation) + 2 : Math.ceil(this.maxValueX / 2);
169
+ var hAxisLabels = Array(yearEnd - yearStart + 1).fill(0).map(function () { return _this.gradation * yearStart++; });
170
+ var baseMaxX = hAxisLabels.length * this.barBreakWidth + this.barBreakWidth;
171
+ var tooltipTextBox = new konva_1.default.Text({
172
+ text: maxTo.tooltipText.replace(/\\n/g, "\n"),
173
+ fontFamily: this.fontFamily,
174
+ fontSize: this.tooltipFontSize,
175
+ });
176
+ var valueOneGradation = this.barBreakWidth / this.gradation;
177
+ var widthBar = (Number(maxTo.to) * valueOneGradation + this.leftMarginChart) - (Number(maxTo.from) * valueOneGradation + this.leftMarginChart);
178
+ var barXMax = Number(maxTo.from) * valueOneGradation + widthBar;
179
+ var maxXTooltip = barXMax + Math.ceil(tooltipTextBox.textWidth) + 2 * this.tooltipPadding + this.tooltipPointerWidth;
180
+ var maxX = baseMaxX > maxXTooltip ? baseMaxX : maxXTooltip;
181
+ return { hAxisLabels: hAxisLabels, maxX: maxX };
182
+ };
183
+ ChartTime24.prototype.createScrollLayer = function (hAxisLabels, maxX, chartHeight) {
184
+ var _this = this;
185
+ var scrollLayer = new konva_1.default.Layer();
186
+ //? Create grid
187
+ var baseGridLine = new konva_1.default.Line({
188
+ points: [0, 0, 0, chartHeight, maxX, chartHeight],
189
+ stroke: this.lineColor,
190
+ strokeWidth: this.lineStrokeWidth,
191
+ lineCap: 'round',
192
+ lineJoin: 'round',
193
+ });
194
+ scrollLayer.add(baseGridLine);
195
+ //? labels and line OX
196
+ hAxisLabels.forEach(function (el, i) {
197
+ var configLabel = {
198
+ points: [(i + 1) * _this.barBreakWidth, 0, (i + 1) * _this.barBreakWidth, chartHeight + _this.protrudingLinesHeight],
199
+ stroke: _this.lineColor,
200
+ strokeWidth: _this.lineStrokeWidth,
201
+ lineCap: 'round',
202
+ lineJoin: 'round',
203
+ };
204
+ if (el === _this.highlightedValue) {
205
+ configLabel.strokeWidth = _this.highlightedStroke;
206
+ }
207
+ var labelText = new konva_1.default.Text({
208
+ x: (i + 1) * _this.barBreakWidth,
209
+ y: chartHeight + _this.protrudingLinesHeight + _this.labelTextHeight,
210
+ text: String(el),
211
+ fontSize: _this.labelTextFontSize,
212
+ fontFamily: _this.fontFamily,
213
+ fill: _this.axisLabelColor,
214
+ });
215
+ labelText.attrs.x -= (labelText.textWidth / 2);
216
+ var lineLabel = new konva_1.default.Line(configLabel);
217
+ scrollLayer.add(lineLabel);
218
+ scrollLayer.add(labelText);
219
+ });
220
+ return scrollLayer;
221
+ };
222
+ ChartTime24.prototype.createStaticLayer = function (width, chartHeight) {
223
+ var staticLayer = new konva_1.default.Layer();
224
+ //? Create background
225
+ var background = new konva_1.default.Rect({
226
+ width: width,
227
+ fill: this.bgColor,
228
+ });
229
+ staticLayer.add(background);
230
+ this.createAxisLabel(staticLayer, width, chartHeight);
231
+ return { staticLayer: staticLayer, background: background };
232
+ };
233
+ ChartTime24.prototype.createAxisLabel = function (staticLayer, width, chartHeight) {
234
+ //? Label X NAME
235
+ var labelXName = new konva_1.default.Text({
236
+ x: width - this.rightMarginChart + this.labelNameBreak,
237
+ y: chartHeight + this.protrudingLinesHeight + this.labelTextHeight + this.topMarginChart,
238
+ text: this.hAxisName,
239
+ fontSize: this.labelNameFontSize,
240
+ fontFamily: this.fontFamily,
241
+ fill: this.axisLabelColor,
242
+ });
243
+ staticLayer.add(labelXName);
244
+ //? Label Y NAME
245
+ var labelYName = new konva_1.default.Text({
246
+ x: this.leftMarginChart - this.labelNameBreak,
247
+ y: this.topMarginChart,
248
+ text: this.vAxisName,
249
+ fontSize: this.labelNameFontSize,
250
+ fontFamily: this.fontFamily,
251
+ fill: this.axisLabelColor,
252
+ });
253
+ labelYName.attrs.y -= labelYName.textHeight;
254
+ labelYName.attrs.x -= labelYName.textWidth;
255
+ staticLayer.add(labelYName);
256
+ };
257
+ ChartTime24.prototype.createBarsLayer = function (legendLayer, stageWidth) {
258
+ var _this = this;
259
+ var legendX = 0;
260
+ var legendY = 0;
261
+ var barsLayer = new konva_1.default.Layer();
262
+ var tooltip = new konva_1.default.Label({
263
+ opacity: this.tooltipOpacity,
264
+ });
265
+ tooltip.add(new konva_1.default.Tag({
266
+ fill: this.tooltipBgColor,
267
+ pointerDirection: 'left',
268
+ pointerWidth: this.tooltipPointerWidth,
269
+ pointerHeight: this.tooltipPointerHeight,
270
+ lineJoin: 'round',
271
+ cornerRadius: this.tooltipCornerRadius,
272
+ }));
273
+ var tooltipTextBox = new konva_1.default.Text({
274
+ text: '',
275
+ fontFamily: this.fontFamily,
276
+ fontSize: this.tooltipFontSize,
277
+ padding: this.tooltipPadding,
278
+ fill: this.tooltipColor,
279
+ });
280
+ tooltip.add(tooltipTextBox);
281
+ tooltip.hide();
282
+ this.barElements
283
+ .sort(function (a, b) { return (Number(a.position) > Number(b.position) ? 1 : -1); })
284
+ .forEach(function (el, i) {
285
+ var fromValue = Number(el.from);
286
+ var toValue = Number(el.to);
287
+ var valueOneGradation = _this.barBreakWidth / _this.gradation;
288
+ var barHeight = _this.barHeight;
289
+ var barBreakHeight = _this.barBreakHeight;
290
+ var bar = new konva_1.default.Rect({
291
+ width: (toValue * valueOneGradation + _this.leftMarginChart) - (fromValue * valueOneGradation + _this.leftMarginChart),
292
+ height: barHeight,
293
+ fill: el.color,
294
+ x: fromValue * valueOneGradation,
295
+ y: barHeight * i + barBreakHeight * (i + 1),
296
+ });
297
+ var darkColor = _this.darkenColor(el.color, _this.percentDarkColorOnMove);
298
+ bar.on('mousemove', function (e) {
299
+ this.fill(darkColor);
300
+ //? positioning tooltip
301
+ tooltip.position({
302
+ x: (fromValue * valueOneGradation) + (toValue * valueOneGradation) - (fromValue * valueOneGradation),
303
+ y: barHeight * i + barBreakHeight * (i + 1) + barHeight / 2,
304
+ });
305
+ tooltipTextBox.text(el.tooltipText.replace(/\\n/g, "\n"));
306
+ tooltip.show();
307
+ });
308
+ bar.on('mouseout', function () {
309
+ this.fill(el.color);
310
+ tooltip.hide();
311
+ });
312
+ barsLayer.add(bar);
313
+ var legendParam = _this.createLegendByBar(legendX, legendY, el, legendLayer, darkColor, bar, tooltip, tooltipTextBox, i, fromValue, toValue, valueOneGradation, barHeight, barBreakHeight, stageWidth);
314
+ legendX = legendParam.legendX;
315
+ legendY = legendParam.legendY;
316
+ });
317
+ var tooltipLayer = new konva_1.default.Layer();
318
+ tooltipLayer.add(tooltip);
319
+ return { barsLayer: barsLayer, tooltipLayer: tooltipLayer, maxLegendY: legendY };
320
+ };
321
+ ChartTime24.prototype.createLegendByBar = function (legendX, legendY, el, legendLayer, darkColor, bar, tooltip, tooltipTextBox, iter, fromValue, toValue, valueOneGradation, barHeight, barBreakHeight, stageWidth) {
322
+ var legend = new konva_1.default.Rect({
323
+ width: this.legendColorWidth,
324
+ height: this.legendColorHeight,
325
+ fill: el.color,
326
+ x: legendX,
327
+ y: legendY,
328
+ });
329
+ var legendText = new konva_1.default.Text({
330
+ x: legendX + legend.attrs.width + this.legendBreakColorText,
331
+ y: legendY,
332
+ height: legend.attrs.height,
333
+ text: el.legendText,
334
+ fontSize: this.legendFontSize,
335
+ fontFamily: this.fontFamily,
336
+ fill: 'black',
337
+ verticalAlign: 'middle'
338
+ });
339
+ var sumWidthLegend = legend.attrs.width + this.legendElementBreakWidth + legendText.textWidth + this.legendBreakColorText;
340
+ var widthLegend = legendX + sumWidthLegend;
341
+ var scrollWidth = stageWidth - this.leftMarginChart - this.rightMarginChart;
342
+ if (widthLegend > scrollWidth) {
343
+ legendY += this.legendColorHeight + this.legendElementBreakHeight;
344
+ legendX = 0;
345
+ legend.y(legendY);
346
+ legend.x(legendX);
347
+ legendText.y(legendY);
348
+ legendText.x(legendX + legend.attrs.width + this.legendBreakColorText);
349
+ }
350
+ legendX += sumWidthLegend;
351
+ legendLayer.add(legend);
352
+ legendLayer.add(legendText);
353
+ legend.on('mousemove', function (e) {
354
+ this.fill(darkColor);
355
+ bar.fill(darkColor);
356
+ tooltip.position({
357
+ x: (fromValue * valueOneGradation) + (toValue * valueOneGradation) - (fromValue * valueOneGradation),
358
+ y: barHeight * iter + barBreakHeight * (iter + 1) + barHeight / 2,
359
+ });
360
+ tooltipTextBox.text(el.tooltipText.replace(/\\n/g, "\n"));
361
+ tooltip.show();
362
+ });
363
+ legend.on('mouseout', function () {
364
+ this.fill(el.color);
365
+ bar.fill(el.color);
366
+ tooltip.hide();
367
+ });
368
+ return { legendX: legendX, legendY: legendY };
369
+ };
370
+ ChartTime24.prototype.darkenColor = function (color, percent) {
371
+ var num = parseInt(color.replace("#", ""), 16), amt = Math.round(2.55 * percent), R = (num >> 16) - amt, B = (num >> 8 & 0x00FF) - amt, G = (num & 0x0000FF) - amt;
372
+ return "#" + (0x1000000 + (R < 255 ? R < 1 ? 0 : R : 255) * 0x10000 + (B < 255 ? B < 1 ? 0 : B : 255) * 0x100 + (G < 255 ? G < 1 ? 0 : G : 255)).toString(16).slice(1);
373
+ };
374
+ ;
375
+ return ChartTime24;
376
+ }(fh_forms_handler_1.HTMLFormComponent));
377
+ exports.ChartTime24 = ChartTime24;
375
378
  //# sourceMappingURL=ChartTime24.js.map