@qfo/qfchart 0.6.6 → 0.6.8

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,148 @@
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
+ // 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: rect with small triangle at bottom center
34
+ 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';
35
+
36
+ case 'labelleft':
37
+ // Bubble with small pointer on the left side (pointing left)
38
+ 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';
39
+
40
+ case 'labelright':
41
+ // Bubble with small pointer on the right side (pointing right)
42
+ 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';
43
+
44
+ case 'labelup':
45
+ // Bubble pointing up: small triangle at top, rect below
46
+ 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';
47
+
48
+ case 'square':
49
+ return 'rect';
50
+
51
+ case 'triangledown':
52
+ // Pointing down
53
+ return 'path://M12 21l-10-18h20z';
54
+
55
+ case 'triangleup':
56
+ // Pointing up
57
+ return 'triangle'; // Built-in is pointing up
58
+
59
+ case 'xcross':
60
+ // 'X' shape
61
+ 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';
62
+
63
+ default:
64
+ return 'circle';
65
+ }
66
+ }
67
+
68
+ public static getShapeRotation(shape: string): number {
69
+ // With custom paths defined above, we might not need rotation unless we reuse shapes.
70
+ // Built-in triangle is UP.
71
+ return 0;
72
+ }
73
+
74
+ public static getShapeSize(size: string, width?: number, height?: number): number | number[] {
75
+ // If both width and height are specified, use them directly
76
+ if (width !== undefined && height !== undefined) {
77
+ return [width, height];
78
+ }
79
+
80
+ // Base size from the size parameter
81
+ let baseSize: number;
82
+ switch (size) {
83
+ case 'tiny':
84
+ baseSize = 8;
85
+ break;
86
+ case 'small':
87
+ baseSize = 12;
88
+ break;
89
+ case 'normal':
90
+ case 'auto':
91
+ baseSize = 16;
92
+ break;
93
+ case 'large':
94
+ baseSize = 24;
95
+ break;
96
+ case 'huge':
97
+ baseSize = 32;
98
+ break;
99
+ default:
100
+ baseSize = 16;
101
+ }
102
+
103
+ // If only width is specified, preserve aspect ratio (assume square default)
104
+ if (width !== undefined) {
105
+ return [width, width];
106
+ }
107
+
108
+ // If only height is specified, preserve aspect ratio (assume square default)
109
+ if (height !== undefined) {
110
+ return [height, height];
111
+ }
112
+
113
+ // Default uniform size
114
+ return baseSize;
115
+ }
116
+
117
+ // Helper to determine label position and distance relative to shape BASED ON LOCATION
118
+ public static getLabelConfig(shape: string, location: string): { position: string; distance: number } {
119
+ // Text position should be determined by location, not shape direction
120
+
121
+ switch (location) {
122
+ case 'abovebar':
123
+ // Shape is above the candle, text should be above the shape
124
+ return { position: 'top', distance: 5 };
125
+
126
+ case 'belowbar':
127
+ // Shape is below the candle, text should be below the shape
128
+ return { position: 'bottom', distance: 5 };
129
+
130
+ case 'top':
131
+ // Shape at top of chart, text below it
132
+ return { position: 'bottom', distance: 5 };
133
+
134
+ case 'bottom':
135
+ // Shape at bottom of chart, text above it
136
+ return { position: 'top', distance: 5 };
137
+
138
+ case 'absolute':
139
+ default:
140
+ // For labelup/down, text is INSIDE the shape
141
+ if (shape === 'labelup' || shape === 'labeldown') {
142
+ return { position: 'inside', distance: 0 };
143
+ }
144
+ // For other shapes, text above by default
145
+ return { position: 'top', distance: 5 };
146
+ }
147
+ }
148
+ }