@gravity-ui/chartkit 0.9.1 → 0.10.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 +13 -0
- package/build/components/ChartKit.css +23 -0
- package/build/components/ChartKit.d.ts +0 -1
- package/build/components/ChartKit.js +4 -5
- package/build/i18n/keysets/en.json +60 -0
- package/build/i18n/keysets/ru.json +62 -0
- package/build/libs/chartkit-error/chartkit-error.d.ts +1 -0
- package/build/libs/chartkit-error/chartkit-error.js +1 -0
- package/build/libs/settings/__tests__/settings.test.js +1 -1
- package/build/libs/settings/settings.d.ts +6 -3
- package/build/libs/settings/settings.js +4 -2
- package/build/plugins/highcharts/__stories__/AreaRange.stories.d.ts +4 -0
- package/build/plugins/highcharts/__stories__/AreaRange.stories.js +22 -0
- package/build/plugins/highcharts/__stories__/Line.stories.d.ts +4 -0
- package/build/plugins/highcharts/__stories__/Line.stories.js +21 -0
- package/build/plugins/highcharts/__stories__/mocks/area-range.d.ts +2 -0
- package/build/plugins/highcharts/__stories__/mocks/area-range.js +61 -0
- package/build/plugins/highcharts/__stories__/mocks/holidays.d.ts +7070 -0
- package/build/plugins/highcharts/__stories__/mocks/holidays.js +7065 -0
- package/build/plugins/highcharts/__stories__/mocks/line.d.ts +2 -0
- package/build/plugins/highcharts/__stories__/mocks/line.js +129 -0
- package/build/plugins/highcharts/index.d.ts +2 -0
- package/build/plugins/highcharts/index.js +5 -0
- package/build/plugins/highcharts/renderer/HighchartsWidget.d.ts +23 -0
- package/build/plugins/highcharts/renderer/HighchartsWidget.js +6 -0
- package/build/plugins/highcharts/renderer/components/HighchartsComponent.css +4 -0
- package/build/plugins/highcharts/renderer/components/HighchartsComponent.d.ts +575 -0
- package/build/plugins/highcharts/renderer/components/HighchartsComponent.js +115 -0
- package/build/plugins/highcharts/renderer/components/StyledSplitPane/StyledSplitPane.css +50 -0
- package/build/plugins/highcharts/renderer/components/StyledSplitPane/StyledSplitPane.d.ts +10 -0
- package/build/plugins/highcharts/renderer/components/StyledSplitPane/StyledSplitPane.js +32 -0
- package/build/plugins/highcharts/renderer/components/withSplitPane/WithSplitPane.css +4 -0
- package/build/plugins/highcharts/renderer/components/withSplitPane/withSplitPane.d.ts +10 -0
- package/build/plugins/highcharts/renderer/components/withSplitPane/withSplitPane.js +207 -0
- package/build/plugins/highcharts/renderer/helpers/add-holidays.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/add-holidays.js +43 -0
- package/build/plugins/highcharts/renderer/helpers/comments/drawing.d.ts +11 -0
- package/build/plugins/highcharts/renderer/helpers/comments/drawing.js +571 -0
- package/build/plugins/highcharts/renderer/helpers/config/config.d.ts +575 -0
- package/build/plugins/highcharts/renderer/helpers/config/config.js +1483 -0
- package/build/plugins/highcharts/renderer/helpers/config/handleLegendItemClick.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/handleLegendItemClick.js +57 -0
- package/build/plugins/highcharts/renderer/helpers/config/options.d.ts +465 -0
- package/build/plugins/highcharts/renderer/helpers/config/options.js +350 -0
- package/build/plugins/highcharts/renderer/helpers/config/types.d.ts +6 -0
- package/build/plugins/highcharts/renderer/helpers/config/types.js +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/addShowInNavigatorToSeries.d.ts +10 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/addShowInNavigatorToSeries.js +42 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/addShowInNavigatorToSeries.test.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/addShowInNavigatorToSeries.test.js +99 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/buildNavigatorFallback.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/buildNavigatorFallback.js +17 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/buildNavigatorFallback.test.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/buildNavigatorFallback.test.js +28 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/calculatePrecision.d.ts +5 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/calculatePrecision.js +20 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/calculatePrecision.test.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/calculatePrecision.test.js +27 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/concatStrings.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/concatStrings.js +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getChartKitFormattedValue.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getChartKitFormattedValue.js +15 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getFormatOptionsFromLine.d.ts +3 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getFormatOptionsFromLine.js +15 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getFormatOptionsFromLine.test.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getFormatOptionsFromLine.test.js +11 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getXAxisThresholdValue.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getXAxisThresholdValue.js +9 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getXAxisThresholdValue.test.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/getXAxisThresholdValue.test.js +20 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/index.d.ts +13 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/index.js +13 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/isNavigatorSeries.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/isNavigatorSeries.js +3 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/isSafari.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/isSafari.js +12 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/isTooltipShared.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/isTooltipShared.js +8 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/isTooltipShared.test.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/isTooltipShared.test.js +31 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/localStorage.d.ts +5 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/localStorage.js +23 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/mergeArrayWithObject.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/mergeArrayWithObject.js +10 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/numberFormat.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/numberFormat.js +19 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/numberFormat.test.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/numberFormat.test.js +20 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/setNavigatorDefaultPeriod.d.ts +13 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/setNavigatorDefaultPeriod.js +27 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/setNavigatorDefaultPeriod.test.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/config/utils/setNavigatorDefaultPeriod.test.js +45 -0
- package/build/plugins/highcharts/renderer/helpers/constants.d.ts +28 -0
- package/build/plugins/highcharts/renderer/helpers/constants.js +30 -0
- package/build/plugins/highcharts/renderer/helpers/graph.css +89 -0
- package/build/plugins/highcharts/renderer/helpers/graph.d.ts +552 -0
- package/build/plugins/highcharts/renderer/helpers/graph.js +85 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/colors.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/colors.js +17 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/highcharts.d.ts +4 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/highcharts.js +346 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/utils/calcucalteClosestPointManually.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/utils/calcucalteClosestPointManually.js +19 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/utils/calculateClosestPointManually.test.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/utils/calculateClosestPointManually.test.js +42 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/utils/index.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/highcharts/utils/index.js +1 -0
- package/build/plugins/highcharts/renderer/helpers/init-highcharts-modules.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/init-highcharts-modules.js +49 -0
- package/build/plugins/highcharts/renderer/helpers/prepare-data.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/prepare-data.js +175 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/constants.d.ts +13 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/constants.js +14 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/helpers.d.ts +1 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/helpers.js +5 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/index.d.ts +13 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/index.js +253 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/index.d.ts +6 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/index.js +22 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/DashDotLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/DashDotLineIcon.js +20 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/DashLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/DashLineIcon.js +25 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/DotLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/DotLineIcon.js +20 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/LongDashDotDotLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/LongDashDotDotLineIcon.js +18 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/LongDashDotLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/LongDashDotLineIcon.js +18 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/LongDashLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/LongDashLineIcon.js +15 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDashDotDotLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDashDotDotLineIcon.js +18 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDashDotLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDashDotLineIcon.js +18 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDashLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDashLineIcon.js +18 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDotLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/ShortDotLineIcon.js +20 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/SolidLineIcon.d.ts +2 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/SolidLineIcon.js +13 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/index.d.ts +11 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/template-icons/index.js +11 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/types.d.ts +4 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/types.js +1 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/utils.d.ts +7 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/render-shape-icon/utils.js +5 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/tooltip.css +367 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/types.d.ts +85 -0
- package/build/plugins/highcharts/renderer/helpers/tooltip/types.js +1 -0
- package/build/plugins/highcharts/renderer/helpers/types.d.ts +22 -0
- package/build/plugins/highcharts/renderer/helpers/types.js +1 -0
- package/build/plugins/highcharts/types/comments.d.ts +51 -0
- package/build/plugins/highcharts/types/comments.js +1 -0
- package/build/plugins/highcharts/types/highcharts-extends.d.ts +38 -0
- package/build/plugins/highcharts/types/index.d.ts +4 -0
- package/build/plugins/highcharts/types/index.js +1 -0
- package/build/plugins/highcharts/types/lib.d.ts +1 -0
- package/build/plugins/highcharts/types/lib.js +1 -0
- package/build/plugins/highcharts/types/misc.d.ts +19 -0
- package/build/plugins/highcharts/types/misc.js +1 -0
- package/build/plugins/highcharts/types/widget.d.ts +47 -0
- package/build/plugins/highcharts/types/widget.js +1 -0
- package/build/plugins/index.d.ts +4 -2
- package/build/plugins/index.js +1 -0
- package/build/plugins/indicator/renderer/IndicatorItem.d.ts +3 -2
- package/build/plugins/indicator/renderer/IndicatorWidget.d.ts +10 -2
- package/build/plugins/indicator/renderer/IndicatorWidget.js +1 -1
- package/build/plugins/indicator/types.d.ts +0 -6
- package/build/plugins/shared/format-number/format-number.d.ts +4 -0
- package/build/plugins/shared/format-number/format-number.js +88 -0
- package/build/plugins/shared/format-number/format-number.test.d.ts +1 -0
- package/build/plugins/shared/format-number/format-number.test.js +14 -0
- package/build/plugins/shared/format-number/i18n/en.json +17 -0
- package/build/plugins/shared/format-number/i18n/i18n.d.ts +5 -0
- package/build/plugins/shared/format-number/i18n/i18n.js +8 -0
- package/build/plugins/shared/format-number/i18n/ru.json +17 -0
- package/build/plugins/shared/format-number/types.d.ts +14 -0
- package/build/plugins/shared/format-number/types.js +1 -0
- package/build/plugins/shared/index.d.ts +2 -0
- package/build/plugins/shared/index.js +1 -0
- package/build/plugins/yagr/renderer/YagrWidget.d.ts +11 -3
- package/build/plugins/yagr/renderer/YagrWidget.js +2 -1
- package/build/plugins/yagr/types.d.ts +0 -7
- package/build/types/index.d.ts +1 -2
- package/build/types/misc.d.ts +4 -0
- package/build/types/misc.js +1 -0
- package/build/types/widget.d.ts +17 -0
- package/package.json +4 -1
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
/* eslint-disable complexity */
|
|
2
|
+
import { __rest } from "tslib";
|
|
3
|
+
const DOT_RADIUS = 5;
|
|
4
|
+
const DOT_MARGIN = DOT_RADIUS * 3;
|
|
5
|
+
const DOT_HALF_MARGIN = DOT_MARGIN / 2;
|
|
6
|
+
const HIGHCHARTS_COMMENT = 'highcharts-comment';
|
|
7
|
+
const HIGHCHARTS_RENDERER_COMMENT = 'highcharts-renderer-comment';
|
|
8
|
+
const DEFAULT_COLOR = '#ffcc00';
|
|
9
|
+
const DEFAULT_TEXT_COLOR = 'white';
|
|
10
|
+
const DEFAULT_FILL_COLOR = 'black';
|
|
11
|
+
const Z_INDEX = 10;
|
|
12
|
+
const TYPES = {
|
|
13
|
+
FLAG_X: 'flag-x',
|
|
14
|
+
LINE_X: 'line-x',
|
|
15
|
+
BAND_X: 'band-x',
|
|
16
|
+
DOT_XY: 'dot-x-y',
|
|
17
|
+
};
|
|
18
|
+
function convertDateToX(date) {
|
|
19
|
+
return new Date(date).valueOf();
|
|
20
|
+
}
|
|
21
|
+
export function extendComment(_a, chart) {
|
|
22
|
+
var { meta } = _a, rest = __rest(_a, ["meta"]);
|
|
23
|
+
const extended = Object.assign({}, rest, meta);
|
|
24
|
+
const { userOptions: { _config: { comments: { ignoreScale } = {} } = {} }, xAxis: [xAxis], } = chart;
|
|
25
|
+
if (extended.dateUntil) {
|
|
26
|
+
extended.from = convertDateToX(extended.date);
|
|
27
|
+
extended.to = convertDateToX(extended.dateUntil);
|
|
28
|
+
}
|
|
29
|
+
else if (extended.date) {
|
|
30
|
+
extended.x = convertDateToX(extended.date);
|
|
31
|
+
}
|
|
32
|
+
let isFit;
|
|
33
|
+
if (extended.x) {
|
|
34
|
+
isFit = extended.x >= xAxis.min && extended.x <= xAxis.max;
|
|
35
|
+
if (ignoreScale === false && isFit) {
|
|
36
|
+
isFit = xAxis.series.some(({ xData }) => xData.indexOf(extended.x) !== -1);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
isFit = extended.from <= xAxis.max && extended.to >= xAxis.min;
|
|
41
|
+
if (ignoreScale === false && isFit) {
|
|
42
|
+
isFit = xAxis.series.some(({ xData }) => xData.some((x) => extended.from <= x && x <= extended.to));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
extended.isFit = isFit;
|
|
46
|
+
return extended;
|
|
47
|
+
}
|
|
48
|
+
function drawFlagX(chart, { isFit, x, text, y, shape, color = DEFAULT_COLOR }) {
|
|
49
|
+
if (!isFit) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
chart.addSeries({
|
|
53
|
+
className: HIGHCHARTS_COMMENT,
|
|
54
|
+
type: 'flags',
|
|
55
|
+
data: [{ x, text, title: text }],
|
|
56
|
+
y: y || -30,
|
|
57
|
+
shape: shape || 'circlepin',
|
|
58
|
+
color,
|
|
59
|
+
// lineWidth: 2,
|
|
60
|
+
showInLegend: false,
|
|
61
|
+
zIndex: Z_INDEX,
|
|
62
|
+
}, false, false);
|
|
63
|
+
}
|
|
64
|
+
function drawLineX(chart, { isFit, x, color = DEFAULT_COLOR, width, dashStyle, text }) {
|
|
65
|
+
if (!isFit) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const line = chart.xAxis[0].addPlotLine({
|
|
69
|
+
className: HIGHCHARTS_COMMENT,
|
|
70
|
+
value: x,
|
|
71
|
+
color,
|
|
72
|
+
width: width || 2,
|
|
73
|
+
dashStyle,
|
|
74
|
+
label: {
|
|
75
|
+
className: HIGHCHARTS_COMMENT,
|
|
76
|
+
text,
|
|
77
|
+
},
|
|
78
|
+
id: Math.random().toFixed(3).toString(),
|
|
79
|
+
zIndex: Z_INDEX,
|
|
80
|
+
});
|
|
81
|
+
line.svgElem.element.classList.add(HIGHCHARTS_COMMENT);
|
|
82
|
+
}
|
|
83
|
+
function drawBandX(chart, options, onlyRenderer) {
|
|
84
|
+
if (!options.isFit) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const xAxis = chart.xAxis[0];
|
|
88
|
+
const yAxis = chart.yAxis[0];
|
|
89
|
+
const xExtremes = xAxis.getExtremes();
|
|
90
|
+
const yExtremes = yAxis.getExtremes();
|
|
91
|
+
let from;
|
|
92
|
+
let to;
|
|
93
|
+
let xFromPx;
|
|
94
|
+
let yFromPx;
|
|
95
|
+
let width = 0;
|
|
96
|
+
let half;
|
|
97
|
+
while (Math.abs(width) < 3) {
|
|
98
|
+
half = half === undefined ? xAxis.closestPointRange / 2 : half * 1.5;
|
|
99
|
+
from = Math.max(options.from || options.x, xExtremes.dataMin) - half;
|
|
100
|
+
to = Math.min(options.to || options.x, xExtremes.dataMax) + half;
|
|
101
|
+
xFromPx = Math.max(xAxis.toPixels(from), chart.plotLeft);
|
|
102
|
+
yFromPx = yAxis.toPixels(yExtremes.max);
|
|
103
|
+
const xToPx = Math.min(xAxis.toPixels(to), chart.plotLeft + chart.plotWidth);
|
|
104
|
+
width = xToPx - xFromPx;
|
|
105
|
+
}
|
|
106
|
+
if (options.visible && !onlyRenderer) {
|
|
107
|
+
xAxis.addPlotBand({
|
|
108
|
+
from: from,
|
|
109
|
+
to: to,
|
|
110
|
+
color: options.color || DEFAULT_COLOR,
|
|
111
|
+
zIndex: options.zIndex || 0,
|
|
112
|
+
className: ' highcharts-plot-band_comment ' + HIGHCHARTS_COMMENT,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
if (yFromPx) {
|
|
116
|
+
chart.renderer
|
|
117
|
+
.rect(xFromPx, yFromPx, width, 4, 0)
|
|
118
|
+
.attr({
|
|
119
|
+
fill: options.color || DEFAULT_COLOR,
|
|
120
|
+
zIndex: 1,
|
|
121
|
+
opacity: 0.8,
|
|
122
|
+
class: HIGHCHARTS_RENDERER_COMMENT,
|
|
123
|
+
})
|
|
124
|
+
.add();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function getDotLabelPositions(options) {
|
|
128
|
+
const width = options.width;
|
|
129
|
+
const height = options.height;
|
|
130
|
+
const pointX = options.pointX;
|
|
131
|
+
const pointY = options.pointY;
|
|
132
|
+
const plotRight = options.plotRight;
|
|
133
|
+
const plotBottom = options.plotBottom;
|
|
134
|
+
const widthPlusMargin = width + DOT_MARGIN;
|
|
135
|
+
const widthMinusMargin = width - DOT_MARGIN;
|
|
136
|
+
const heightPlusMargin = height + DOT_MARGIN;
|
|
137
|
+
const heightMinusMargin = height - DOT_MARGIN;
|
|
138
|
+
const halfWidth = width / 2;
|
|
139
|
+
const halfHeight = height / 2;
|
|
140
|
+
const positions = [];
|
|
141
|
+
let x;
|
|
142
|
+
let y;
|
|
143
|
+
let anchor;
|
|
144
|
+
// top
|
|
145
|
+
if (pointY > heightPlusMargin) {
|
|
146
|
+
y = pointY - heightPlusMargin;
|
|
147
|
+
anchor = [
|
|
148
|
+
'M',
|
|
149
|
+
pointX,
|
|
150
|
+
pointY - DOT_HALF_MARGIN,
|
|
151
|
+
'L',
|
|
152
|
+
pointX - DOT_RADIUS,
|
|
153
|
+
pointY - DOT_MARGIN,
|
|
154
|
+
pointX + DOT_RADIUS,
|
|
155
|
+
pointY - DOT_MARGIN,
|
|
156
|
+
'Z',
|
|
157
|
+
];
|
|
158
|
+
// top-left
|
|
159
|
+
if (pointX > widthMinusMargin) {
|
|
160
|
+
positions.push({
|
|
161
|
+
x: pointX - widthMinusMargin,
|
|
162
|
+
y: y,
|
|
163
|
+
w: width,
|
|
164
|
+
h: height,
|
|
165
|
+
anchor: anchor,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
// top-right
|
|
169
|
+
if (pointX + widthMinusMargin < plotRight) {
|
|
170
|
+
positions.push({
|
|
171
|
+
x: pointX - DOT_MARGIN,
|
|
172
|
+
y: y,
|
|
173
|
+
w: width,
|
|
174
|
+
h: height,
|
|
175
|
+
anchor: anchor,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
// top-mid
|
|
179
|
+
if (pointX > halfWidth && pointX + halfWidth < plotRight) {
|
|
180
|
+
positions.push({
|
|
181
|
+
x: pointX - halfWidth,
|
|
182
|
+
y: y,
|
|
183
|
+
w: width,
|
|
184
|
+
h: height,
|
|
185
|
+
anchor: anchor,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// right
|
|
190
|
+
if (pointX + widthPlusMargin < plotRight) {
|
|
191
|
+
x = pointX + DOT_MARGIN;
|
|
192
|
+
anchor = [
|
|
193
|
+
'M',
|
|
194
|
+
pointX + DOT_HALF_MARGIN,
|
|
195
|
+
pointY,
|
|
196
|
+
'L',
|
|
197
|
+
pointX + DOT_MARGIN,
|
|
198
|
+
pointY + DOT_RADIUS,
|
|
199
|
+
pointX + DOT_MARGIN,
|
|
200
|
+
pointY - DOT_RADIUS,
|
|
201
|
+
'Z',
|
|
202
|
+
];
|
|
203
|
+
// right-top
|
|
204
|
+
if (pointY > heightMinusMargin) {
|
|
205
|
+
positions.push({
|
|
206
|
+
x: x,
|
|
207
|
+
y: pointY - heightMinusMargin,
|
|
208
|
+
w: width,
|
|
209
|
+
h: height,
|
|
210
|
+
anchor: anchor,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
// right-bottom
|
|
214
|
+
if (pointY + heightMinusMargin < plotBottom) {
|
|
215
|
+
positions.push({
|
|
216
|
+
x: x,
|
|
217
|
+
y: pointY - DOT_MARGIN,
|
|
218
|
+
w: width,
|
|
219
|
+
h: height,
|
|
220
|
+
anchor: anchor,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
// right-mid
|
|
224
|
+
if (pointY > halfHeight && pointY + halfHeight < plotBottom) {
|
|
225
|
+
positions.push({
|
|
226
|
+
x: x,
|
|
227
|
+
y: pointY - halfHeight,
|
|
228
|
+
w: width,
|
|
229
|
+
h: height,
|
|
230
|
+
anchor: anchor,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// bottom
|
|
235
|
+
if (pointY + heightPlusMargin < plotBottom) {
|
|
236
|
+
y = pointY + DOT_MARGIN;
|
|
237
|
+
anchor = [
|
|
238
|
+
'M',
|
|
239
|
+
pointX,
|
|
240
|
+
pointY + DOT_HALF_MARGIN,
|
|
241
|
+
'L',
|
|
242
|
+
pointX - DOT_RADIUS,
|
|
243
|
+
pointY + DOT_MARGIN,
|
|
244
|
+
pointX + DOT_RADIUS,
|
|
245
|
+
pointY + DOT_MARGIN,
|
|
246
|
+
'Z',
|
|
247
|
+
];
|
|
248
|
+
// bottom-left
|
|
249
|
+
if (pointX > widthMinusMargin) {
|
|
250
|
+
positions.push({
|
|
251
|
+
x: pointX - widthMinusMargin,
|
|
252
|
+
y: y,
|
|
253
|
+
w: width,
|
|
254
|
+
h: height,
|
|
255
|
+
anchor: anchor,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
// bottom-right
|
|
259
|
+
if (pointX + widthMinusMargin < plotRight) {
|
|
260
|
+
positions.push({
|
|
261
|
+
x: pointX - DOT_MARGIN,
|
|
262
|
+
y: y,
|
|
263
|
+
w: width,
|
|
264
|
+
h: height,
|
|
265
|
+
anchor: anchor,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
// bottom-mid
|
|
269
|
+
if (pointX > halfWidth && pointX + halfWidth < plotRight) {
|
|
270
|
+
positions.push({
|
|
271
|
+
x: pointX - halfWidth,
|
|
272
|
+
y: y,
|
|
273
|
+
w: width,
|
|
274
|
+
h: height,
|
|
275
|
+
anchor: anchor,
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
// left
|
|
280
|
+
if (pointX > widthPlusMargin) {
|
|
281
|
+
x = pointX - widthPlusMargin;
|
|
282
|
+
anchor = [
|
|
283
|
+
'M',
|
|
284
|
+
pointX - DOT_HALF_MARGIN,
|
|
285
|
+
pointY,
|
|
286
|
+
'L',
|
|
287
|
+
pointX - DOT_MARGIN,
|
|
288
|
+
pointY + DOT_RADIUS,
|
|
289
|
+
pointX - DOT_MARGIN,
|
|
290
|
+
pointY - DOT_RADIUS,
|
|
291
|
+
'Z',
|
|
292
|
+
];
|
|
293
|
+
// left-top
|
|
294
|
+
if (pointY > heightMinusMargin) {
|
|
295
|
+
positions.push({
|
|
296
|
+
x: x,
|
|
297
|
+
y: pointY - heightMinusMargin,
|
|
298
|
+
w: width,
|
|
299
|
+
h: height,
|
|
300
|
+
anchor: anchor,
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
// left-bottom
|
|
304
|
+
if (pointY + heightMinusMargin < plotBottom) {
|
|
305
|
+
positions.push({
|
|
306
|
+
x: x,
|
|
307
|
+
y: pointY - DOT_MARGIN,
|
|
308
|
+
w: width,
|
|
309
|
+
h: height,
|
|
310
|
+
anchor: anchor,
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
// left-mid
|
|
314
|
+
if (pointY > halfHeight && pointY + halfHeight < plotBottom) {
|
|
315
|
+
positions.push({
|
|
316
|
+
x: x,
|
|
317
|
+
y: pointY - halfHeight,
|
|
318
|
+
w: width,
|
|
319
|
+
h: height,
|
|
320
|
+
anchor: anchor,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return positions;
|
|
325
|
+
}
|
|
326
|
+
function drawDot(chart, options) {
|
|
327
|
+
if (!options.isFit) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
const seriesIndex = chart.series.findIndex(({ name, userOptions: { id }, visible }) => options.graphId === (id || name) && visible);
|
|
331
|
+
if (seriesIndex === -1) {
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
const point = chart.series[seriesIndex].data.find((_point) => _point && _point.x === options.x);
|
|
335
|
+
const color = options.color || chart.series[seriesIndex].color;
|
|
336
|
+
if (!point) {
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
point.update({
|
|
340
|
+
marker: {
|
|
341
|
+
enabled: true,
|
|
342
|
+
radius: DOT_RADIUS,
|
|
343
|
+
fillColor: color,
|
|
344
|
+
states: {
|
|
345
|
+
hover: {
|
|
346
|
+
fillColor: color,
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
}, false, false);
|
|
351
|
+
}
|
|
352
|
+
function drawDotLabel(chart, options) {
|
|
353
|
+
if (!options.visible || !options.isFit) {
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
const seriesIndex = chart.series.findIndex(({ name, userOptions: { id }, visible }) => options.graphId === (id || name) && visible);
|
|
357
|
+
if (seriesIndex === -1) {
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
const point = chart.series[seriesIndex]
|
|
361
|
+
.getValidPoints()
|
|
362
|
+
.find((_point) => _point && _point.x === options.x);
|
|
363
|
+
if (!point) {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
const pointX = point.plotX + chart.plotLeft;
|
|
367
|
+
const pointY = point.plotY + chart.plotTop;
|
|
368
|
+
const label = chart.renderer
|
|
369
|
+
.label(options.text, pointX, pointY, 'callout')
|
|
370
|
+
.css({
|
|
371
|
+
color: options.textColor || DEFAULT_TEXT_COLOR,
|
|
372
|
+
width: 150,
|
|
373
|
+
fontSize: 10,
|
|
374
|
+
})
|
|
375
|
+
.attr({
|
|
376
|
+
fill: options.fillColor || DEFAULT_FILL_COLOR,
|
|
377
|
+
padding: 8,
|
|
378
|
+
opacity: 0.7,
|
|
379
|
+
r: 8,
|
|
380
|
+
zIndex: 6,
|
|
381
|
+
class: HIGHCHARTS_RENDERER_COMMENT,
|
|
382
|
+
})
|
|
383
|
+
.add();
|
|
384
|
+
const positions = getDotLabelPositions({
|
|
385
|
+
width: label.width,
|
|
386
|
+
height: label.height,
|
|
387
|
+
pointX: pointX,
|
|
388
|
+
pointY: pointY,
|
|
389
|
+
plotRight: chart.plotWidth + chart.plotLeft,
|
|
390
|
+
plotBottom: chart.plotHeight + chart.plotTop,
|
|
391
|
+
});
|
|
392
|
+
if (positions.length === 0) {
|
|
393
|
+
label.destroy();
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
return { label: label, positions: positions, fillColor: options.fillColor };
|
|
397
|
+
}
|
|
398
|
+
function isRectsIntersects(ax1, ax2, ay1, ay2, bx1, bx2, by1, by2) {
|
|
399
|
+
return ax1 < bx2 && ax2 > bx1 && ay1 < by2 && ay2 > by1;
|
|
400
|
+
}
|
|
401
|
+
function translateDotsLabels(chart, notTranslatedDotsLabels) {
|
|
402
|
+
const translatedDotsLabels = [];
|
|
403
|
+
notTranslatedDotsLabels
|
|
404
|
+
.sort((a, b) => {
|
|
405
|
+
return a.label.x - b.label.x;
|
|
406
|
+
})
|
|
407
|
+
.forEach((label, index) => {
|
|
408
|
+
const available = label.positions
|
|
409
|
+
.map((position) => {
|
|
410
|
+
return {
|
|
411
|
+
previous: translatedDotsLabels.filter((translated) => {
|
|
412
|
+
return isRectsIntersects(position.x, position.x + position.w, position.y, position.y + position.h, translated.x, translated.x + translated.w, translated.y, translated.y + translated.h);
|
|
413
|
+
}).length,
|
|
414
|
+
next: notTranslatedDotsLabels
|
|
415
|
+
.slice(index + 1, notTranslatedDotsLabels.length)
|
|
416
|
+
.filter((notTranslated) => {
|
|
417
|
+
return (notTranslated.label.x > position.x &&
|
|
418
|
+
notTranslated.label.x < position.x + position.w &&
|
|
419
|
+
notTranslated.label.y > position.y &&
|
|
420
|
+
notTranslated.label.y < position.y + position.h);
|
|
421
|
+
})
|
|
422
|
+
.map((notTranslated) => {
|
|
423
|
+
return notTranslated.positions.filter((notPosition) => {
|
|
424
|
+
return isRectsIntersects(notPosition.x, notPosition.x + notPosition.w, notPosition.y, notPosition.y + notPosition.h, position.x, position.x + position.w, position.y, position.y + position.h);
|
|
425
|
+
}).length;
|
|
426
|
+
})
|
|
427
|
+
.reduce((sum, current) => {
|
|
428
|
+
return sum + current;
|
|
429
|
+
}, 0),
|
|
430
|
+
position: position,
|
|
431
|
+
};
|
|
432
|
+
})
|
|
433
|
+
.sort((a, b) => {
|
|
434
|
+
return a.previous === b.previous ? a.next - b.next : a.previous - b.previous;
|
|
435
|
+
});
|
|
436
|
+
label.label.translate(available[0].position.x, available[0].position.y);
|
|
437
|
+
chart.renderer
|
|
438
|
+
.path(available[0].position.anchor)
|
|
439
|
+
.attr({
|
|
440
|
+
strokeWidth: 1,
|
|
441
|
+
stroke: label.fillColor || DEFAULT_FILL_COLOR,
|
|
442
|
+
fill: label.fillColor || DEFAULT_FILL_COLOR,
|
|
443
|
+
opacity: 0.7,
|
|
444
|
+
zIndex: 6,
|
|
445
|
+
class: HIGHCHARTS_RENDERER_COMMENT,
|
|
446
|
+
})
|
|
447
|
+
.add();
|
|
448
|
+
translatedDotsLabels.push({
|
|
449
|
+
x: available[0].position.x,
|
|
450
|
+
y: available[0].position.y,
|
|
451
|
+
w: available[0].position.w,
|
|
452
|
+
h: available[0].position.h,
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
export function drawComments(chart, comments, settings, force) {
|
|
457
|
+
if (force) {
|
|
458
|
+
settings.hideComments = false;
|
|
459
|
+
}
|
|
460
|
+
else if (settings.hideComments) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
if (comments) {
|
|
464
|
+
const notTranslatedDotsLabels = [];
|
|
465
|
+
comments.forEach((comment) => {
|
|
466
|
+
const extendedComment = extendComment(comment, chart);
|
|
467
|
+
switch (comment.type) {
|
|
468
|
+
case TYPES.FLAG_X:
|
|
469
|
+
drawFlagX(chart, extendedComment);
|
|
470
|
+
break;
|
|
471
|
+
case TYPES.LINE_X:
|
|
472
|
+
drawLineX(chart, extendedComment);
|
|
473
|
+
break;
|
|
474
|
+
case TYPES.BAND_X:
|
|
475
|
+
drawBandX(chart, extendedComment, false);
|
|
476
|
+
break;
|
|
477
|
+
case TYPES.DOT_XY: {
|
|
478
|
+
drawDot(chart, extendedComment);
|
|
479
|
+
const metaDotLabel = drawDotLabel(chart, extendedComment);
|
|
480
|
+
if (metaDotLabel) {
|
|
481
|
+
notTranslatedDotsLabels.push(metaDotLabel);
|
|
482
|
+
}
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
translateDotsLabels(chart, notTranslatedDotsLabels);
|
|
488
|
+
if (comments.some((comment) => comment.type === TYPES.DOT_XY || comment.type === TYPES.FLAG_X)) {
|
|
489
|
+
chart.redraw();
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
export function drawOnlyRendererComments(chart, comments = [], settings) {
|
|
494
|
+
if (settings.hideComments) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
const notTranslatedDotsLabels = [];
|
|
498
|
+
if (comments && comments.length && chart.container) {
|
|
499
|
+
chart.container
|
|
500
|
+
.querySelectorAll(`.${HIGHCHARTS_RENDERER_COMMENT}`)
|
|
501
|
+
.forEach((elem) => elem.remove());
|
|
502
|
+
comments.forEach((comment) => {
|
|
503
|
+
const extendedComment = extendComment(comment, chart);
|
|
504
|
+
switch (comment.type) {
|
|
505
|
+
case TYPES.BAND_X:
|
|
506
|
+
drawBandX(chart, extendedComment, true);
|
|
507
|
+
break;
|
|
508
|
+
case TYPES.DOT_XY: {
|
|
509
|
+
const metaDotLabel = drawDotLabel(chart, extendedComment);
|
|
510
|
+
if (metaDotLabel) {
|
|
511
|
+
notTranslatedDotsLabels.push(metaDotLabel);
|
|
512
|
+
}
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
translateDotsLabels(chart, notTranslatedDotsLabels);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
export function hideComments(chart, comments, settings, force) {
|
|
521
|
+
if (chart && chart.container && comments && comments.length) {
|
|
522
|
+
chart.container.querySelectorAll(`.${HIGHCHARTS_COMMENT}`).forEach((elem) => elem.remove());
|
|
523
|
+
chart.container
|
|
524
|
+
.querySelectorAll(`.${HIGHCHARTS_RENDERER_COMMENT}`)
|
|
525
|
+
.forEach((elem) => elem.remove());
|
|
526
|
+
chart.series.forEach((serie) => serie.options.type === 'flags' && serie.remove(false, false, false));
|
|
527
|
+
comments.forEach((comment) => {
|
|
528
|
+
const extendedComment = extendComment(comment, chart);
|
|
529
|
+
if (extendedComment.type === TYPES.DOT_XY) {
|
|
530
|
+
const seriesIndex = chart.series.findIndex((graph) => (graph.userOptions.id || graph.name) === extendedComment.graphId);
|
|
531
|
+
if (seriesIndex !== -1) {
|
|
532
|
+
const point = chart.series[seriesIndex].data.find((_point) => _point && _point.x === extendedComment.x);
|
|
533
|
+
if (point) {
|
|
534
|
+
point.update({ marker: {} }, false, false);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
if (force) {
|
|
540
|
+
settings.hideComments = true;
|
|
541
|
+
}
|
|
542
|
+
chart.redraw();
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
export function getCommentsOnLine(xLine, comments, chart) {
|
|
546
|
+
const xComments = [];
|
|
547
|
+
const xyComments = [];
|
|
548
|
+
if (comments) {
|
|
549
|
+
comments.forEach((_comment) => {
|
|
550
|
+
const comment = extendComment(_comment, chart);
|
|
551
|
+
if (comment.x && comment.x === xLine.x) {
|
|
552
|
+
if (comment.graphId) {
|
|
553
|
+
xyComments[comment.graphId] = { text: comment.text };
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
const text = comment.title
|
|
557
|
+
? comment.title + '\r\n' + (comment.text || '')
|
|
558
|
+
: comment.text;
|
|
559
|
+
xComments.push({ text: text, color: comment.color || DEFAULT_COLOR });
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
else if (comment.from &&
|
|
563
|
+
comment.from <= xLine.x &&
|
|
564
|
+
xLine.x <= comment.to &&
|
|
565
|
+
comment.isFit) {
|
|
566
|
+
xComments.push({ text: comment.text, color: comment.color || DEFAULT_COLOR });
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
return { xComments, xyComments };
|
|
571
|
+
}
|