@qfo/qfchart 0.6.7 → 0.7.1

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,140 +1,156 @@
1
- export class ShapeUtils {
2
- public static getShapeSymbol(shape: string): string {
3
- // SVG Paths need to be:
4
- // 1. Valid SVG path data strings
5
- // 2. Ideally centered around the origin or a standard box (e.g., 0 0 24 24)
6
- // 3. ECharts path:// format expects just the path data usually, but complex shapes might need 'image://' or better paths.
7
- // For simple shapes, standard ECharts symbols or simple paths work.
8
-
9
- switch (shape) {
10
- case 'arrowdown':
11
- // Blocky arrow down
12
- return 'path://M12 24l-12-12h8v-12h8v12h8z';
13
-
14
- case 'arrowup':
15
- // Blocky arrow up
16
- return 'path://M12 0l12 12h-8v12h-8v-12h-8z';
17
-
18
- case 'circle':
19
- return 'circle';
20
-
21
- case 'cross':
22
- // Plus sign (+)
23
- return 'path://M11 2h2v9h9v2h-9v9h-2v-9h-9v-2h9z';
24
-
25
- case 'diamond':
26
- return 'diamond'; // Built-in
27
-
28
- case 'flag':
29
- // Flag on a pole
30
- return 'path://M6 2v20h2v-8h12l-2-6 2-6h-12z';
31
-
32
- case 'labeldown':
33
- // Bubble pointing down: Rounded rect with a triangle at bottom
34
- return 'path://M4 2h16a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-6l-2 4l-2 -4h-6a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2z';
35
-
36
- case 'labelup':
37
- // Bubble pointing up: Rounded rect with triangle at top
38
- return 'path://M12 2l2 4h6a2 2 0 0 1 2 2v12a2 2 0 0 1 -2 2h-16a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h6z';
39
-
40
- case 'square':
41
- return 'rect';
42
-
43
- case 'triangledown':
44
- // Pointing down
45
- return 'path://M12 21l-10-18h20z';
46
-
47
- case 'triangleup':
48
- // Pointing up
49
- return 'triangle'; // Built-in is pointing up
50
-
51
- case 'xcross':
52
- // 'X' shape
53
- return 'path://M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z';
54
-
55
- default:
56
- return 'circle';
57
- }
58
- }
59
-
60
- public static getShapeRotation(shape: string): number {
61
- // With custom paths defined above, we might not need rotation unless we reuse shapes.
62
- // Built-in triangle is UP.
63
- return 0;
64
- }
65
-
66
- public static getShapeSize(size: string, width?: number, height?: number): number | number[] {
67
- // If both width and height are specified, use them directly
68
- if (width !== undefined && height !== undefined) {
69
- return [width, height];
70
- }
71
-
72
- // Base size from the size parameter
73
- let baseSize: number;
74
- switch (size) {
75
- case 'tiny':
76
- baseSize = 8;
77
- break;
78
- case 'small':
79
- baseSize = 12;
80
- break;
81
- case 'normal':
82
- case 'auto':
83
- baseSize = 16;
84
- break;
85
- case 'large':
86
- baseSize = 24;
87
- break;
88
- case 'huge':
89
- baseSize = 32;
90
- break;
91
- default:
92
- baseSize = 16;
93
- }
94
-
95
- // If only width is specified, preserve aspect ratio (assume square default)
96
- if (width !== undefined) {
97
- return [width, width];
98
- }
99
-
100
- // If only height is specified, preserve aspect ratio (assume square default)
101
- if (height !== undefined) {
102
- return [height, height];
103
- }
104
-
105
- // Default uniform size
106
- return baseSize;
107
- }
108
-
109
- // Helper to determine label position and distance relative to shape BASED ON LOCATION
110
- public static getLabelConfig(shape: string, location: string): { position: string; distance: number } {
111
- // Text position should be determined by location, not shape direction
112
-
113
- switch (location) {
114
- case 'abovebar':
115
- // Shape is above the candle, text should be above the shape
116
- return { position: 'top', distance: 5 };
117
-
118
- case 'belowbar':
119
- // Shape is below the candle, text should be below the shape
120
- return { position: 'bottom', distance: 5 };
121
-
122
- case 'top':
123
- // Shape at top of chart, text below it
124
- return { position: 'bottom', distance: 5 };
125
-
126
- case 'bottom':
127
- // Shape at bottom of chart, text above it
128
- return { position: 'top', distance: 5 };
129
-
130
- case 'absolute':
131
- default:
132
- // For labelup/down, text is INSIDE the shape
133
- if (shape === 'labelup' || shape === 'labeldown') {
134
- return { position: 'inside', distance: 0 };
135
- }
136
- // For other shapes, text above by default
137
- return { position: 'top', distance: 5 };
138
- }
139
- }
140
- }
1
+ export class ShapeUtils {
2
+ public static getShapeSymbol(shape: string): string {
3
+ // SVG Paths need to be:
4
+ // 1. Valid SVG path data strings
5
+ // 2. Ideally centered around the origin or a standard box (e.g., 0 0 24 24)
6
+ // 3. ECharts path:// format expects just the path data usually, but complex shapes might need 'image://' or better paths.
7
+ // For simple shapes, standard ECharts symbols or simple paths work.
8
+
9
+ switch (shape) {
10
+ case 'arrowdown':
11
+ case 'shape_arrow_down':
12
+ return 'path://M12 24l-12-12h8v-12h8v12h8z';
13
+
14
+ case 'arrowup':
15
+ case 'shape_arrow_up':
16
+ return 'path://M12 0l12 12h-8v12h-8v-12h-8z';
17
+
18
+ case 'circle':
19
+ case 'shape_circle':
20
+ return 'circle';
21
+
22
+ case 'cross':
23
+ case 'shape_cross':
24
+ return 'path://M11 2h2v9h9v2h-9v9h-2v-9h-9v-2h9z';
25
+
26
+ case 'diamond':
27
+ case 'shape_diamond':
28
+ return 'diamond';
29
+
30
+ case 'flag':
31
+ case 'shape_flag':
32
+ return 'path://M6 2v20h2v-8h12l-2-6 2-6h-12z';
33
+
34
+ case 'labeldown':
35
+ case 'shape_label_down':
36
+ return 'path://M2 1h20a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-8l-2 3-2-3h-8a1 1 0 0 1-1-1v-14a1 1 0 0 1 1-1z';
37
+
38
+ case 'labelleft':
39
+ case 'shape_label_left':
40
+ return 'path://M0 10l3-3v-5a1 1 0 0 1 1-1h18a1 1 0 0 1 1 1v16a1 1 0 0 1-1 1h-18a1 1 0 0 1-1-1v-5z';
41
+
42
+ case 'labelright':
43
+ case 'shape_label_right':
44
+ return 'path://M24 10l-3-3v-5a1 1 0 0 0-1-1h-18a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h18a1 1 0 0 0 1-1v-5z';
45
+
46
+ case 'labelup':
47
+ case 'shape_label_up':
48
+ return 'path://M12 1l2 3h8a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-20a1 1 0 0 1-1-1v-14a1 1 0 0 1 1-1h8z';
49
+
50
+ case 'square':
51
+ case 'shape_square':
52
+ return 'rect';
53
+
54
+ case 'triangledown':
55
+ case 'shape_triangle_down':
56
+ return 'path://M12 21l-10-18h20z';
57
+
58
+ case 'triangleup':
59
+ case 'shape_triangle_up':
60
+ return 'triangle';
61
+
62
+ case 'xcross':
63
+ case 'shape_xcross':
64
+ return 'path://M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z';
65
+
66
+ default:
67
+ return 'circle';
68
+ }
69
+ }
70
+
71
+ public static getShapeRotation(shape: string): number {
72
+ // With custom paths defined above, we might not need rotation unless we reuse shapes.
73
+ // Built-in triangle is UP.
74
+ return 0;
75
+ }
76
+
77
+ public static getShapeSize(size: string, width?: number, height?: number): number | number[] {
78
+ // If both width and height are specified, use them directly
79
+ if (width !== undefined && height !== undefined) {
80
+ return [width, height];
81
+ }
82
+
83
+ // Base size from the size parameter
84
+ let baseSize: number;
85
+ switch (size) {
86
+ case 'tiny':
87
+ baseSize = 8;
88
+ break;
89
+ case 'small':
90
+ baseSize = 12;
91
+ break;
92
+ case 'normal':
93
+ case 'auto':
94
+ baseSize = 16;
95
+ break;
96
+ case 'large':
97
+ baseSize = 24;
98
+ break;
99
+ case 'huge':
100
+ baseSize = 32;
101
+ break;
102
+ default:
103
+ baseSize = 16;
104
+ }
105
+
106
+ // If only width is specified, preserve aspect ratio (assume square default)
107
+ if (width !== undefined) {
108
+ return [width, width];
109
+ }
110
+
111
+ // If only height is specified, preserve aspect ratio (assume square default)
112
+ if (height !== undefined) {
113
+ return [height, height];
114
+ }
115
+
116
+ // Default uniform size
117
+ return baseSize;
118
+ }
119
+
120
+ // Helper to determine label position and distance relative to shape BASED ON LOCATION
121
+ public static getLabelConfig(shape: string, location: string): { position: string; distance: number } {
122
+ // Text position should be determined by location, not shape direction
123
+
124
+ switch (location) {
125
+ case 'abovebar':
126
+ case 'AboveBar':
127
+ // Shape is above the candle, text should be above the shape
128
+ return { position: 'top', distance: 5 };
129
+
130
+ case 'belowbar':
131
+ case 'BelowBar':
132
+ // Shape is below the candle, text should be below the shape
133
+ return { position: 'bottom', distance: 5 };
134
+
135
+ case 'top':
136
+ case 'Top':
137
+ // Shape at top of chart, text below it
138
+ return { position: 'bottom', distance: 5 };
139
+
140
+ case 'bottom':
141
+ case 'Bottom':
142
+ // Shape at bottom of chart, text above it
143
+ return { position: 'top', distance: 5 };
144
+
145
+ case 'absolute':
146
+ case 'Absolute':
147
+ default:
148
+ // For labelup/down, text is INSIDE the shape
149
+ if (shape === 'labelup' || shape === 'labeldown' || shape === 'shape_label_up' || shape === 'shape_label_down') {
150
+ return { position: 'inside', distance: 0 };
151
+ }
152
+ // For other shapes, text above by default
153
+ return { position: 'top', distance: 5 };
154
+ }
155
+ }
156
+ }