-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathshape-helpers.ts
More file actions
71 lines (60 loc) · 2.32 KB
/
shape-helpers.ts
File metadata and controls
71 lines (60 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import type {Highcharts} from '@gravity-ui/chartkit/highcharts';
import type {ExtendedSeriesLineOptions, ServerShapesConfig} from '../../../../../../shared';
import {getServerShapesOrder} from '../../../../../../shared';
const SHAPES_IN_ORDER = getServerShapesOrder();
type MapAndShapeGraphArgs = {
graphs: ExtendedSeriesLineOptions[];
shapesConfig: ServerShapesConfig;
isSegmentsExists: boolean;
isShapesDefault: boolean;
};
export const mapAndShapeGraph = ({
graphs,
isSegmentsExists,
shapesConfig,
isShapesDefault,
}: MapAndShapeGraphArgs) => {
const knownValues: (string | undefined)[] = [];
graphs.forEach((graph, i) => {
const value = graph.shapeValue;
const title = value || graph.legendTitle || graph.name;
if (
shapesConfig &&
shapesConfig.mountedShapes &&
title &&
shapesConfig.mountedShapes[title] &&
shapesConfig.mountedShapes[title] !== 'auto'
) {
graph.dashStyle = shapesConfig.mountedShapes[title] as Highcharts.DashStyleValue;
} else if (isShapesDefault) {
graph.dashStyle = SHAPES_IN_ORDER[0];
} else {
let shapeIndex =
graph.yAxis === 0 || !graph.shapeValue || isSegmentsExists
? knownValues.indexOf(value)
: i;
if (shapeIndex === -1) {
knownValues.push(value);
shapeIndex = knownValues.length - 1;
}
graph.dashStyle = SHAPES_IN_ORDER[shapeIndex % SHAPES_IN_ORDER.length];
}
// Determine line width: use individual line width if set, otherwise fall back to chart-level width
let lineWidth: number | undefined;
if (title && shapesConfig?.mountedShapesLineWidths?.[title]) {
// Individual line has a specific width set
lineWidth = shapesConfig.mountedShapesLineWidths[title];
} else if (shapesConfig?.lineWidth !== undefined) {
// Fall back to chart-level line width
lineWidth = shapesConfig.lineWidth;
}
if (lineWidth !== undefined) {
graph.lineWidth = lineWidth;
graph.states = {
hover: {
lineWidth: lineWidth + 2,
},
};
}
});
};