forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsymbol.tsx
More file actions
165 lines (153 loc) · 4.97 KB
/
symbol.tsx
File metadata and controls
165 lines (153 loc) · 4.97 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import { getComputedStyleValue } from './styles';
import chart_echarts_BackgroundColor from '@patternfly/react-tokens/dist/esm/chart_echarts_BackgroundColor';
const enum SymbolType {
arrow = 'arrow',
circle = 'circle',
diamond = 'diamond',
emptyArrow = 'emptyArrow',
emptyCircle = 'emptyCircle',
emptyDiamond = 'emptyDiamond',
emptyPin = 'emptyPin',
emptyRect = 'emptyRect',
emptyRoundRect = 'emptyRoundRect',
emptySquare = 'emptySquare',
emptyTriangle = 'emptyTriangle',
pin = 'pin',
rect = 'rect',
roundRect = 'roundRect',
square = 'square',
triangle = 'triangle'
}
// ECharts icon types -- see https://svg-path.com/
const symbols = {
arrow: 'M12.5 7L19.9667 18.2L12.5 15.4L5.0333 18.2L12.5 7Z',
circle: 'M18.1 7A5.6 5.6 0 1 1 18.1 6.9994Z',
diamond: 'M12.5 1.4L18.1 7L12.5 12.6L6.9 7Z',
emptyArrow: 'M12.5 7L19.9667 18.2L12.5 15.4L5.0333 18.2L12.5 7Z',
emptyCircle: 'M18.1 7A5.6 5.6 0 1 1 18.1 6.9994Z',
emptyDiamond: 'M12.5 1.4L18.1 7L12.5 12.6L6.9 7Z',
emptyPin:
'M9.4642 2.04A3.36 3.36 0 1 1 15.5358 2.04C14.6718 3.8615 12.5 4.648 12.5 7C12.5 4.648 10.3282 3.8615 9.4642 2.04Z',
emptyRect: 'M6.9,1.4 l14.2,0 l0,11.2 l-14.2,0 Z',
emptyRoundRect:
'M9.7,1.4 L18.3,1.4 A2.8,2.8,0,0,1,21.1,4.2 L21.1,9.8 A2.8,2.8,0,0,1,18.3,12.6 L9.7,12.6 A2.8,2.8,0,0,1,6.9,9.8 L6.9,4.2 A2.8,2.8,0,0,1,9.7,1.4 Z',
emptySquare: 'M6.9 1.4l11.2 0l0 11.2l-11.2 0Z',
emptyTriangle: 'M12.5 1.4L18.1 12.5L12.5 12.5L6.9 12.5Z',
pin: 'M9.4642 2.04A3.36 3.36 0 1 1 15.5358 2.04C14.6718 3.8615 12.5 4.648 12.5 7C12.5 4.648 10.3282 3.8615 9.4642 2.04Z',
rect: 'M6.9,1.4 l18.2,0 l0,11.2 l-18.2,0 Z',
roundRect:
'M9.7,1.4 L22.3,1.4 A2.8,2.8,0,0,1,25.1,4.2 L25.1,9.8 A2.8,2.8,0,0,1,22.3,12.6 L9.7,12.6 A2.8,2.8,0,0,1,6.9,9.8 L6.9,4.2 A2.8,2.8,0,0,1,9.7,1.4 Z',
square: 'M6.9 1.4l11.2 0l0 11.2l-11.2 0Z',
triangle: 'M12.5 1.4L18.1 12.5L12.5 12.5L6.9 12.5Z'
};
/**
* Returns marker -- see https://github.com/apache/echarts/issues/19826
*
* @param serie
* @param symbol
* @param color
* @private Not intended as public API and subject to change
*/
export const getMarker = (serie: any, symbol: string, color: string = '') => {
const size = 18;
let path;
let pathStyle = `fill:${color};`;
const svgStyle = 'vertical-align: middle;';
let transform;
// Set marker type
switch (symbol) {
case SymbolType.arrow:
case SymbolType.circle:
case SymbolType.diamond:
case SymbolType.emptyArrow:
case SymbolType.emptyCircle:
case SymbolType.emptyDiamond:
case SymbolType.emptyPin:
case SymbolType.emptyRect:
case SymbolType.emptyRoundRect:
case SymbolType.emptySquare:
case SymbolType.emptyTriangle:
case SymbolType.pin:
case SymbolType.rect:
case SymbolType.roundRect:
case SymbolType.square:
case SymbolType.triangle:
path = symbols[symbol];
break;
default:
path = symbols.square;
break;
}
// Set path style for EChart symbols
switch (symbol) {
case SymbolType.emptyArrow:
case SymbolType.emptyCircle:
case SymbolType.emptyDiamond:
case SymbolType.emptyPin:
case SymbolType.emptyRect:
case SymbolType.emptyRoundRect:
case SymbolType.emptySquare:
case SymbolType.emptyTriangle:
pathStyle = `fill:${getComputedStyleValue(chart_echarts_BackgroundColor)}; stroke:${color}; stroke-width:2`;
break;
default:
pathStyle = `fill:${color}; margin-left:-50px;`;
}
// Set SVG style for EChart symbols
switch (symbol) {
case SymbolType.arrow:
case SymbolType.emptyArrow:
transform = `translate(-5 -5)`;
break;
case SymbolType.emptyDiamond:
transform = `translate(-5 5)`;
break;
case SymbolType.emptyRect:
case SymbolType.emptyRoundRect:
transform = `translate(-5 0)`;
break;
case SymbolType.pin:
transform = `translate(-5 5)`;
break;
case SymbolType.rect:
transform = `translate(-7 0)`;
break;
case SymbolType.roundRect:
transform = `translate(-7 0)`;
break;
default:
transform = `translate(-5 0)`;
break;
}
const marker = `<path d="${path}" style="${pathStyle}" transform="${transform}" />`;
const svg = `<svg viewBox="0 0 ${size} ${size}" height="${size}px" width="${size}px" style="${svgStyle}">${marker}</svg>`;
return svg;
};
/**
* Returns default symbol
*
* @param series
* @param seriesIndex
* @param echart
* @private Not intended as public API and subject to change
*/
export const getSymbol = (series: any, seriesIndex: number, echart: any) => {
const ase = echart?.getModel().findComponents({ mainType: 'series' });
const data = ase[seriesIndex].getData();
const symbol = data?.getVisual('symbol')?.replace(/"/g, '');
if (!symbol) {
const serie = series[seriesIndex];
if (serie?.symbol) {
return serie?.symbol;
}
switch (serie?.type) {
case 'bar':
return SymbolType.rect;
case 'line':
return SymbolType.square;
default:
break;
}
}
return symbol;
};