@qfo/qfchart 0.6.8 → 0.7.2
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/dist/index.d.ts +3 -0
- package/dist/qfchart.min.browser.js +16 -16
- package/dist/qfchart.min.es.js +16 -16
- package/package.json +2 -2
- package/src/QFChart.ts +52 -0
- package/src/components/LayoutManager.ts +682 -679
- package/src/components/SeriesBuilder.ts +20 -6
- package/src/components/SeriesRendererFactory.ts +4 -0
- package/src/components/TableOverlayRenderer.ts +322 -0
- package/src/components/renderers/BoxRenderer.ts +258 -0
- package/src/components/renderers/DrawingLineRenderer.ts +58 -52
- package/src/components/renderers/FillRenderer.ts +138 -31
- package/src/components/renderers/LabelRenderer.ts +9 -8
- package/src/components/renderers/LinefillRenderer.ts +60 -72
- package/src/components/renderers/PolylineRenderer.ts +197 -0
- package/src/components/renderers/ShapeRenderer.ts +121 -121
- package/src/utils/ColorUtils.ts +77 -32
- package/src/utils/ShapeUtils.ts +22 -14
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { SeriesRenderer, RenderContext } from './SeriesRenderer';
|
|
2
|
+
import { ColorUtils } from '../../utils/ColorUtils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Renderer for Pine Script polyline.* drawing objects.
|
|
6
|
+
* Each polyline is defined by an array of chart.point objects, connected
|
|
7
|
+
* sequentially with straight or curved segments, optionally closed and filled.
|
|
8
|
+
*
|
|
9
|
+
* Style name: 'drawing_polyline'
|
|
10
|
+
*/
|
|
11
|
+
export class PolylineRenderer implements SeriesRenderer {
|
|
12
|
+
render(context: RenderContext): any {
|
|
13
|
+
const { seriesName, xAxisIndex, yAxisIndex, dataArray, dataIndexOffset } = context;
|
|
14
|
+
const offset = dataIndexOffset || 0;
|
|
15
|
+
|
|
16
|
+
// Collect all non-deleted polyline objects from the sparse dataArray.
|
|
17
|
+
// Same aggregation pattern as DrawingLineRenderer — objects are stored
|
|
18
|
+
// as an array in a single data entry.
|
|
19
|
+
const polyObjects: any[] = [];
|
|
20
|
+
|
|
21
|
+
for (let i = 0; i < dataArray.length; i++) {
|
|
22
|
+
const val = dataArray[i];
|
|
23
|
+
if (!val) continue;
|
|
24
|
+
|
|
25
|
+
const items = Array.isArray(val) ? val : [val];
|
|
26
|
+
for (const pl of items) {
|
|
27
|
+
if (pl && typeof pl === 'object' && !pl._deleted && pl.points && pl.points.length >= 2) {
|
|
28
|
+
polyObjects.push(pl);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (polyObjects.length === 0) {
|
|
34
|
+
return { name: seriesName, type: 'custom', xAxisIndex, yAxisIndex, data: [], silent: true };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Compute y-range across all polylines for axis scaling
|
|
38
|
+
let yMin = Infinity, yMax = -Infinity;
|
|
39
|
+
for (const pl of polyObjects) {
|
|
40
|
+
for (const pt of pl.points) {
|
|
41
|
+
const p = pt.price ?? 0;
|
|
42
|
+
if (p < yMin) yMin = p;
|
|
43
|
+
if (p > yMax) yMax = p;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Use a SINGLE data entry spanning the full x-range so renderItem is always called.
|
|
48
|
+
// ECharts filters a data item only when ALL its x-dimensions are on the same side
|
|
49
|
+
// of the visible window. With dims 0=0 and 1=lastBar the item always straddles
|
|
50
|
+
// the viewport, so renderItem fires exactly once regardless of scroll position.
|
|
51
|
+
// Dims 2/3 are yMin/yMax for axis scaling.
|
|
52
|
+
const totalBars = (context.candlestickData?.length || 0) + offset;
|
|
53
|
+
const lastBarIndex = Math.max(0, totalBars - 1);
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
name: seriesName,
|
|
57
|
+
type: 'custom',
|
|
58
|
+
xAxisIndex,
|
|
59
|
+
yAxisIndex,
|
|
60
|
+
renderItem: (params: any, api: any) => {
|
|
61
|
+
const children: any[] = [];
|
|
62
|
+
|
|
63
|
+
for (const pl of polyObjects) {
|
|
64
|
+
if (pl._deleted) continue;
|
|
65
|
+
const points = pl.points;
|
|
66
|
+
if (!points || points.length < 2) continue;
|
|
67
|
+
|
|
68
|
+
const useBi = pl.xloc === 'bi' || pl.xloc === 'bar_index';
|
|
69
|
+
const xOff = useBi ? offset : 0;
|
|
70
|
+
|
|
71
|
+
// Convert chart.point objects to pixel coordinates
|
|
72
|
+
const pixelPoints: number[][] = [];
|
|
73
|
+
for (const pt of points) {
|
|
74
|
+
const x = useBi ? (pt.index ?? 0) + xOff : (pt.time ?? 0);
|
|
75
|
+
const y = pt.price ?? 0;
|
|
76
|
+
pixelPoints.push(api.coord([x, y]));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (pixelPoints.length < 2) continue;
|
|
80
|
+
|
|
81
|
+
const lineColor = pl.line_color || '#2962ff';
|
|
82
|
+
const lineWidth = pl.line_width || 1;
|
|
83
|
+
const dashPattern = this.getDashPattern(pl.line_style);
|
|
84
|
+
|
|
85
|
+
// Fill shape (rendered behind stroke)
|
|
86
|
+
if (pl.fill_color && pl.fill_color !== '' && pl.fill_color !== 'na') {
|
|
87
|
+
const { color: fillColor, opacity: fillOpacity } = ColorUtils.parseColor(pl.fill_color);
|
|
88
|
+
|
|
89
|
+
if (pl.curved) {
|
|
90
|
+
const pathData = this.buildCurvedPath(pixelPoints, pl.closed);
|
|
91
|
+
children.push({
|
|
92
|
+
type: 'path',
|
|
93
|
+
shape: { pathData: pathData + ' Z' },
|
|
94
|
+
style: { fill: fillColor, opacity: fillOpacity, stroke: 'none' },
|
|
95
|
+
silent: true,
|
|
96
|
+
});
|
|
97
|
+
} else {
|
|
98
|
+
children.push({
|
|
99
|
+
type: 'polygon',
|
|
100
|
+
shape: { points: pixelPoints },
|
|
101
|
+
style: { fill: fillColor, opacity: fillOpacity, stroke: 'none' },
|
|
102
|
+
silent: true,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Stroke (line segments)
|
|
108
|
+
if (pl.curved) {
|
|
109
|
+
const pathData = this.buildCurvedPath(pixelPoints, pl.closed);
|
|
110
|
+
children.push({
|
|
111
|
+
type: 'path',
|
|
112
|
+
shape: { pathData },
|
|
113
|
+
style: { fill: 'none', stroke: lineColor, lineWidth, lineDash: dashPattern },
|
|
114
|
+
silent: true,
|
|
115
|
+
});
|
|
116
|
+
} else {
|
|
117
|
+
const allPoints = pl.closed ? [...pixelPoints, pixelPoints[0]] : pixelPoints;
|
|
118
|
+
children.push({
|
|
119
|
+
type: 'polyline',
|
|
120
|
+
shape: { points: allPoints },
|
|
121
|
+
style: { fill: 'none', stroke: lineColor, lineWidth, lineDash: dashPattern },
|
|
122
|
+
silent: true,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return { type: 'group', children };
|
|
128
|
+
},
|
|
129
|
+
data: [[0, lastBarIndex, yMin, yMax]],
|
|
130
|
+
clip: true,
|
|
131
|
+
encode: { x: [0, 1], y: [2, 3] },
|
|
132
|
+
z: 12,
|
|
133
|
+
silent: true,
|
|
134
|
+
emphasis: { disabled: true },
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Build an SVG path string for a smooth curve through all points
|
|
140
|
+
* using Catmull-Rom → cubic bezier conversion.
|
|
141
|
+
*/
|
|
142
|
+
private buildCurvedPath(points: number[][], closed: boolean): string {
|
|
143
|
+
const n = points.length;
|
|
144
|
+
if (n < 2) return '';
|
|
145
|
+
if (n === 2) {
|
|
146
|
+
return `M ${points[0][0]} ${points[0][1]} L ${points[1][0]} ${points[1][1]}`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Catmull-Rom tension (0.5 = centripetal)
|
|
150
|
+
const tension = 0.5;
|
|
151
|
+
let path = `M ${points[0][0]} ${points[0][1]}`;
|
|
152
|
+
|
|
153
|
+
// For closed curves, wrap around; for open, duplicate first/last
|
|
154
|
+
const getPoint = (i: number): number[] => {
|
|
155
|
+
if (closed) {
|
|
156
|
+
return points[((i % n) + n) % n];
|
|
157
|
+
}
|
|
158
|
+
if (i < 0) return points[0];
|
|
159
|
+
if (i >= n) return points[n - 1];
|
|
160
|
+
return points[i];
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const segmentCount = closed ? n : n - 1;
|
|
164
|
+
|
|
165
|
+
for (let i = 0; i < segmentCount; i++) {
|
|
166
|
+
const p0 = getPoint(i - 1);
|
|
167
|
+
const p1 = getPoint(i);
|
|
168
|
+
const p2 = getPoint(i + 1);
|
|
169
|
+
const p3 = getPoint(i + 2);
|
|
170
|
+
|
|
171
|
+
// Convert Catmull-Rom to cubic bezier control points
|
|
172
|
+
const cp1x = p1[0] + (p2[0] - p0[0]) * tension / 3;
|
|
173
|
+
const cp1y = p1[1] + (p2[1] - p0[1]) * tension / 3;
|
|
174
|
+
const cp2x = p2[0] - (p3[0] - p1[0]) * tension / 3;
|
|
175
|
+
const cp2y = p2[1] - (p3[1] - p1[1]) * tension / 3;
|
|
176
|
+
|
|
177
|
+
path += ` C ${cp1x} ${cp1y}, ${cp2x} ${cp2y}, ${p2[0]} ${p2[1]}`;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (closed) {
|
|
181
|
+
path += ' Z';
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return path;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private getDashPattern(style: string): number[] | undefined {
|
|
188
|
+
switch (style) {
|
|
189
|
+
case 'style_dotted':
|
|
190
|
+
return [2, 2];
|
|
191
|
+
case 'style_dashed':
|
|
192
|
+
return [6, 4];
|
|
193
|
+
default:
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
import { SeriesRenderer, RenderContext } from './SeriesRenderer';
|
|
2
|
-
import { ShapeUtils } from '../../utils/ShapeUtils';
|
|
3
|
-
|
|
4
|
-
export class ShapeRenderer implements SeriesRenderer {
|
|
5
|
-
render(context: RenderContext): any {
|
|
6
|
-
const { seriesName, xAxisIndex, yAxisIndex, dataArray, colorArray, optionsArray, plotOptions, candlestickData } = context;
|
|
7
|
-
const defaultColor = '#2962ff';
|
|
8
|
-
|
|
9
|
-
const shapeData = dataArray
|
|
10
|
-
.map((val, i) => {
|
|
11
|
-
// Merge global options with per-point options to get location first
|
|
12
|
-
const pointOpts = optionsArray[i] || {};
|
|
13
|
-
const globalOpts = plotOptions;
|
|
14
|
-
const location = pointOpts.location || globalOpts.location || 'absolute';
|
|
15
|
-
|
|
16
|
-
// For location="absolute", always draw the shape (ignore value)
|
|
17
|
-
// For other locations, only draw if value is truthy (TradingView behavior)
|
|
18
|
-
if (location !== 'absolute' && !val) {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// If we get here and val is null/undefined, it means location is absolute
|
|
23
|
-
// In that case, we still need a valid value for positioning
|
|
24
|
-
// Use the value if it exists, otherwise we'd need a fallback
|
|
25
|
-
// But in TradingView, absolute location still expects a value for Y position
|
|
26
|
-
if (val === null || val === undefined) {
|
|
27
|
-
return null; // Can't plot without a Y coordinate
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const color = pointOpts.color || globalOpts.color || defaultColor;
|
|
31
|
-
const shape = pointOpts.shape || globalOpts.shape || 'circle';
|
|
32
|
-
const size = pointOpts.size || globalOpts.size || 'normal';
|
|
33
|
-
const text = pointOpts.text || globalOpts.text;
|
|
34
|
-
const textColor = pointOpts.textcolor || globalOpts.textcolor || 'white';
|
|
35
|
-
|
|
36
|
-
// NEW: Get width and height
|
|
37
|
-
const width = pointOpts.width || globalOpts.width;
|
|
38
|
-
const height = pointOpts.height || globalOpts.height;
|
|
39
|
-
|
|
40
|
-
// Positioning based on location
|
|
41
|
-
let yValue = val; // Default to absolute value
|
|
42
|
-
let symbolOffset: (string | number)[] = [0, 0];
|
|
43
|
-
|
|
44
|
-
if (location === 'abovebar') {
|
|
45
|
-
// Shape above the candle
|
|
46
|
-
if (candlestickData && candlestickData[i]) {
|
|
47
|
-
yValue = candlestickData[i].high;
|
|
48
|
-
}
|
|
49
|
-
symbolOffset = [0, '-150%']; // Shift up
|
|
50
|
-
} else if (location === 'belowbar') {
|
|
51
|
-
// Shape below the candle
|
|
52
|
-
if (candlestickData && candlestickData[i]) {
|
|
53
|
-
yValue = candlestickData[i].low;
|
|
54
|
-
}
|
|
55
|
-
symbolOffset = [0, '150%']; // Shift down
|
|
56
|
-
} else if (location === 'top') {
|
|
57
|
-
// Shape at top of chart - we need to use a very high value
|
|
58
|
-
// This would require knowing the y-axis max, which we don't have here easily
|
|
59
|
-
// For now, use a placeholder approach - might need to calculate from data
|
|
60
|
-
// Or we can use a percentage of the viewport? ECharts doesn't support that directly in scatter.
|
|
61
|
-
// Best approach: use a large multiplier of current value or track max
|
|
62
|
-
// Simplified: use coordinate system max (will need enhancement)
|
|
63
|
-
yValue = val; // For now, keep absolute - would need axis max
|
|
64
|
-
symbolOffset = [0, 0];
|
|
65
|
-
} else if (location === 'bottom') {
|
|
66
|
-
// Shape at bottom of chart
|
|
67
|
-
yValue = val; // For now, keep absolute - would need axis min
|
|
68
|
-
symbolOffset = [0, 0];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const symbol = ShapeUtils.getShapeSymbol(shape);
|
|
72
|
-
const symbolSize = ShapeUtils.getShapeSize(size, width, height);
|
|
73
|
-
const rotate = ShapeUtils.getShapeRotation(shape);
|
|
74
|
-
|
|
75
|
-
// Special handling for labelup/down sizing - they contain text so they should be larger
|
|
76
|
-
let finalSize: number | number[] = symbolSize;
|
|
77
|
-
if (shape.includes('label')) {
|
|
78
|
-
// If custom size, scale it up for labels
|
|
79
|
-
if (Array.isArray(symbolSize)) {
|
|
80
|
-
finalSize = [symbolSize[0] * 2.5, symbolSize[1] * 2.5];
|
|
81
|
-
} else {
|
|
82
|
-
finalSize = symbolSize * 2.5;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Get label configuration based on location
|
|
87
|
-
const labelConfig = ShapeUtils.getLabelConfig(shape, location);
|
|
88
|
-
|
|
89
|
-
const item: any = {
|
|
90
|
-
value: [i, yValue],
|
|
91
|
-
symbol: symbol,
|
|
92
|
-
symbolSize: finalSize,
|
|
93
|
-
symbolRotate: rotate,
|
|
94
|
-
symbolOffset: symbolOffset,
|
|
95
|
-
itemStyle: {
|
|
96
|
-
color: color,
|
|
97
|
-
},
|
|
98
|
-
label: {
|
|
99
|
-
show: !!text,
|
|
100
|
-
position: labelConfig.position,
|
|
101
|
-
distance: labelConfig.distance,
|
|
102
|
-
formatter: text,
|
|
103
|
-
color: textColor,
|
|
104
|
-
fontSize: 10,
|
|
105
|
-
fontWeight: 'bold',
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
return item;
|
|
110
|
-
})
|
|
111
|
-
.filter((item) => item !== null);
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
name: seriesName,
|
|
115
|
-
type: 'scatter',
|
|
116
|
-
xAxisIndex: xAxisIndex,
|
|
117
|
-
yAxisIndex: yAxisIndex,
|
|
118
|
-
data: shapeData,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
}
|
|
1
|
+
import { SeriesRenderer, RenderContext } from './SeriesRenderer';
|
|
2
|
+
import { ShapeUtils } from '../../utils/ShapeUtils';
|
|
3
|
+
|
|
4
|
+
export class ShapeRenderer implements SeriesRenderer {
|
|
5
|
+
render(context: RenderContext): any {
|
|
6
|
+
const { seriesName, xAxisIndex, yAxisIndex, dataArray, colorArray, optionsArray, plotOptions, candlestickData } = context;
|
|
7
|
+
const defaultColor = '#2962ff';
|
|
8
|
+
|
|
9
|
+
const shapeData = dataArray
|
|
10
|
+
.map((val, i) => {
|
|
11
|
+
// Merge global options with per-point options to get location first
|
|
12
|
+
const pointOpts = optionsArray[i] || {};
|
|
13
|
+
const globalOpts = plotOptions;
|
|
14
|
+
const location = pointOpts.location || globalOpts.location || 'absolute';
|
|
15
|
+
|
|
16
|
+
// For location="absolute", always draw the shape (ignore value)
|
|
17
|
+
// For other locations, only draw if value is truthy (TradingView behavior)
|
|
18
|
+
if (location !== 'absolute' && location !== 'Absolute' && !val) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// If we get here and val is null/undefined, it means location is absolute
|
|
23
|
+
// In that case, we still need a valid value for positioning
|
|
24
|
+
// Use the value if it exists, otherwise we'd need a fallback
|
|
25
|
+
// But in TradingView, absolute location still expects a value for Y position
|
|
26
|
+
if (val === null || val === undefined) {
|
|
27
|
+
return null; // Can't plot without a Y coordinate
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const color = pointOpts.color || globalOpts.color || defaultColor;
|
|
31
|
+
const shape = pointOpts.shape || globalOpts.shape || 'circle';
|
|
32
|
+
const size = pointOpts.size || globalOpts.size || 'normal';
|
|
33
|
+
const text = pointOpts.text || globalOpts.text;
|
|
34
|
+
const textColor = pointOpts.textcolor || globalOpts.textcolor || 'white';
|
|
35
|
+
|
|
36
|
+
// NEW: Get width and height
|
|
37
|
+
const width = pointOpts.width || globalOpts.width;
|
|
38
|
+
const height = pointOpts.height || globalOpts.height;
|
|
39
|
+
|
|
40
|
+
// Positioning based on location
|
|
41
|
+
let yValue = val; // Default to absolute value
|
|
42
|
+
let symbolOffset: (string | number)[] = [0, 0];
|
|
43
|
+
|
|
44
|
+
if (location === 'abovebar' || location === 'AboveBar' || location === 'ab') {
|
|
45
|
+
// Shape above the candle
|
|
46
|
+
if (candlestickData && candlestickData[i]) {
|
|
47
|
+
yValue = candlestickData[i].high;
|
|
48
|
+
}
|
|
49
|
+
symbolOffset = [0, '-150%']; // Shift up
|
|
50
|
+
} else if (location === 'belowbar' || location === 'BelowBar' || location === 'bl') {
|
|
51
|
+
// Shape below the candle
|
|
52
|
+
if (candlestickData && candlestickData[i]) {
|
|
53
|
+
yValue = candlestickData[i].low;
|
|
54
|
+
}
|
|
55
|
+
symbolOffset = [0, '150%']; // Shift down
|
|
56
|
+
} else if (location === 'top' || location === 'Top') {
|
|
57
|
+
// Shape at top of chart - we need to use a very high value
|
|
58
|
+
// This would require knowing the y-axis max, which we don't have here easily
|
|
59
|
+
// For now, use a placeholder approach - might need to calculate from data
|
|
60
|
+
// Or we can use a percentage of the viewport? ECharts doesn't support that directly in scatter.
|
|
61
|
+
// Best approach: use a large multiplier of current value or track max
|
|
62
|
+
// Simplified: use coordinate system max (will need enhancement)
|
|
63
|
+
yValue = val; // For now, keep absolute - would need axis max
|
|
64
|
+
symbolOffset = [0, 0];
|
|
65
|
+
} else if (location === 'bottom' || location === 'Bottom') {
|
|
66
|
+
// Shape at bottom of chart
|
|
67
|
+
yValue = val; // For now, keep absolute - would need axis min
|
|
68
|
+
symbolOffset = [0, 0];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const symbol = ShapeUtils.getShapeSymbol(shape);
|
|
72
|
+
const symbolSize = ShapeUtils.getShapeSize(size, width, height);
|
|
73
|
+
const rotate = ShapeUtils.getShapeRotation(shape);
|
|
74
|
+
|
|
75
|
+
// Special handling for labelup/down sizing - they contain text so they should be larger
|
|
76
|
+
let finalSize: number | number[] = symbolSize;
|
|
77
|
+
if (shape.includes('label')) {
|
|
78
|
+
// If custom size, scale it up for labels
|
|
79
|
+
if (Array.isArray(symbolSize)) {
|
|
80
|
+
finalSize = [symbolSize[0] * 2.5, symbolSize[1] * 2.5];
|
|
81
|
+
} else {
|
|
82
|
+
finalSize = symbolSize * 2.5;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Get label configuration based on location
|
|
87
|
+
const labelConfig = ShapeUtils.getLabelConfig(shape, location);
|
|
88
|
+
|
|
89
|
+
const item: any = {
|
|
90
|
+
value: [i, yValue],
|
|
91
|
+
symbol: symbol,
|
|
92
|
+
symbolSize: finalSize,
|
|
93
|
+
symbolRotate: rotate,
|
|
94
|
+
symbolOffset: symbolOffset,
|
|
95
|
+
itemStyle: {
|
|
96
|
+
color: color,
|
|
97
|
+
},
|
|
98
|
+
label: {
|
|
99
|
+
show: !!text,
|
|
100
|
+
position: labelConfig.position,
|
|
101
|
+
distance: labelConfig.distance,
|
|
102
|
+
formatter: text,
|
|
103
|
+
color: textColor,
|
|
104
|
+
fontSize: 10,
|
|
105
|
+
fontWeight: 'bold',
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
return item;
|
|
110
|
+
})
|
|
111
|
+
.filter((item) => item !== null);
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
name: seriesName,
|
|
115
|
+
type: 'scatter',
|
|
116
|
+
xAxisIndex: xAxisIndex,
|
|
117
|
+
yAxisIndex: yAxisIndex,
|
|
118
|
+
data: shapeData,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
package/src/utils/ColorUtils.ts
CHANGED
|
@@ -1,32 +1,77 @@
|
|
|
1
|
-
export class ColorUtils {
|
|
2
|
-
/**
|
|
3
|
-
* Parse color string and extract opacity
|
|
4
|
-
* Supports: hex (#RRGGBB), named colors (green, red), rgba(r,g,b,a), rgb(r,g,b)
|
|
5
|
-
*/
|
|
6
|
-
public static parseColor(colorStr: string): { color: string; opacity: number } {
|
|
7
|
-
if (!colorStr) {
|
|
8
|
-
return { color: '#888888', opacity: 0.2 };
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// Check for rgba format
|
|
12
|
-
const rgbaMatch = colorStr.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);
|
|
13
|
-
if (rgbaMatch) {
|
|
14
|
-
const r = rgbaMatch[1];
|
|
15
|
-
const g = rgbaMatch[2];
|
|
16
|
-
const b = rgbaMatch[3];
|
|
17
|
-
const a = rgbaMatch[4] ? parseFloat(rgbaMatch[4]) : 1;
|
|
18
|
-
|
|
19
|
-
// Return rgb color and separate opacity
|
|
20
|
-
return {
|
|
21
|
-
color: `rgb(${r},${g},${b})`,
|
|
22
|
-
opacity: a,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
1
|
+
export class ColorUtils {
|
|
2
|
+
/**
|
|
3
|
+
* Parse color string and extract opacity
|
|
4
|
+
* Supports: hex (#RRGGBB, #RRGGBBAA), named colors (green, red), rgba(r,g,b,a), rgb(r,g,b)
|
|
5
|
+
*/
|
|
6
|
+
public static parseColor(colorStr: string): { color: string; opacity: number } {
|
|
7
|
+
if (!colorStr) {
|
|
8
|
+
return { color: '#888888', opacity: 0.2 };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Check for rgba format
|
|
12
|
+
const rgbaMatch = colorStr.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);
|
|
13
|
+
if (rgbaMatch) {
|
|
14
|
+
const r = rgbaMatch[1];
|
|
15
|
+
const g = rgbaMatch[2];
|
|
16
|
+
const b = rgbaMatch[3];
|
|
17
|
+
const a = rgbaMatch[4] ? parseFloat(rgbaMatch[4]) : 1;
|
|
18
|
+
|
|
19
|
+
// Return rgb color and separate opacity
|
|
20
|
+
return {
|
|
21
|
+
color: `rgb(${r},${g},${b})`,
|
|
22
|
+
opacity: a,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Check for 8-digit hex with alpha (#RRGGBBAA)
|
|
27
|
+
const hex8Match = colorStr.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);
|
|
28
|
+
if (hex8Match) {
|
|
29
|
+
const r = parseInt(hex8Match[1], 16);
|
|
30
|
+
const g = parseInt(hex8Match[2], 16);
|
|
31
|
+
const b = parseInt(hex8Match[3], 16);
|
|
32
|
+
const a = parseInt(hex8Match[4], 16) / 255;
|
|
33
|
+
return {
|
|
34
|
+
color: `rgb(${r},${g},${b})`,
|
|
35
|
+
opacity: a,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// For 6-digit hex or named colors, default opacity to 0.3 for fill areas
|
|
40
|
+
return {
|
|
41
|
+
color: colorStr,
|
|
42
|
+
opacity: 0.3,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Convert a parsed color + opacity to an rgba string.
|
|
48
|
+
*/
|
|
49
|
+
public static toRgba(color: string, opacity: number): string {
|
|
50
|
+
// If already rgba/rgb format
|
|
51
|
+
const rgbMatch = color.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);
|
|
52
|
+
if (rgbMatch) {
|
|
53
|
+
return `rgba(${rgbMatch[1]},${rgbMatch[2]},${rgbMatch[3]},${opacity})`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Handle 6-digit hex colors
|
|
57
|
+
const hexMatch = color.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);
|
|
58
|
+
if (hexMatch) {
|
|
59
|
+
const r = parseInt(hexMatch[1], 16);
|
|
60
|
+
const g = parseInt(hexMatch[2], 16);
|
|
61
|
+
const b = parseInt(hexMatch[3], 16);
|
|
62
|
+
return `rgba(${r},${g},${b},${opacity})`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Handle 8-digit hex colors (#RRGGBBAA) — use alpha from hex, override with opacity
|
|
66
|
+
const hex8Match = color.match(/^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/);
|
|
67
|
+
if (hex8Match) {
|
|
68
|
+
const r = parseInt(hex8Match[1], 16);
|
|
69
|
+
const g = parseInt(hex8Match[2], 16);
|
|
70
|
+
const b = parseInt(hex8Match[3], 16);
|
|
71
|
+
return `rgba(${r},${g},${b},${opacity})`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Fallback: return color as-is
|
|
75
|
+
return color;
|
|
76
|
+
}
|
|
77
|
+
}
|
package/src/utils/ShapeUtils.ts
CHANGED
|
@@ -8,56 +8,59 @@ export class ShapeUtils {
|
|
|
8
8
|
|
|
9
9
|
switch (shape) {
|
|
10
10
|
case 'arrowdown':
|
|
11
|
-
|
|
11
|
+
case 'shape_arrow_down':
|
|
12
12
|
return 'path://M12 24l-12-12h8v-12h8v12h8z';
|
|
13
13
|
|
|
14
14
|
case 'arrowup':
|
|
15
|
-
|
|
15
|
+
case 'shape_arrow_up':
|
|
16
16
|
return 'path://M12 0l12 12h-8v12h-8v-12h-8z';
|
|
17
17
|
|
|
18
18
|
case 'circle':
|
|
19
|
+
case 'shape_circle':
|
|
19
20
|
return 'circle';
|
|
20
21
|
|
|
21
22
|
case 'cross':
|
|
22
|
-
|
|
23
|
+
case 'shape_cross':
|
|
23
24
|
return 'path://M11 2h2v9h9v2h-9v9h-2v-9h-9v-2h9z';
|
|
24
25
|
|
|
25
26
|
case 'diamond':
|
|
26
|
-
|
|
27
|
+
case 'shape_diamond':
|
|
28
|
+
return 'diamond';
|
|
27
29
|
|
|
28
30
|
case 'flag':
|
|
29
|
-
|
|
31
|
+
case 'shape_flag':
|
|
30
32
|
return 'path://M6 2v20h2v-8h12l-2-6 2-6h-12z';
|
|
31
33
|
|
|
32
34
|
case 'labeldown':
|
|
33
|
-
|
|
35
|
+
case 'shape_label_down':
|
|
34
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';
|
|
35
37
|
|
|
36
38
|
case 'labelleft':
|
|
37
|
-
|
|
39
|
+
case 'shape_label_left':
|
|
38
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';
|
|
39
41
|
|
|
40
42
|
case 'labelright':
|
|
41
|
-
|
|
43
|
+
case 'shape_label_right':
|
|
42
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';
|
|
43
45
|
|
|
44
46
|
case 'labelup':
|
|
45
|
-
|
|
47
|
+
case 'shape_label_up':
|
|
46
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';
|
|
47
49
|
|
|
48
50
|
case 'square':
|
|
51
|
+
case 'shape_square':
|
|
49
52
|
return 'rect';
|
|
50
53
|
|
|
51
54
|
case 'triangledown':
|
|
52
|
-
|
|
55
|
+
case 'shape_triangle_down':
|
|
53
56
|
return 'path://M12 21l-10-18h20z';
|
|
54
57
|
|
|
55
58
|
case 'triangleup':
|
|
56
|
-
|
|
57
|
-
return 'triangle';
|
|
59
|
+
case 'shape_triangle_up':
|
|
60
|
+
return 'triangle';
|
|
58
61
|
|
|
59
62
|
case 'xcross':
|
|
60
|
-
|
|
63
|
+
case 'shape_xcross':
|
|
61
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';
|
|
62
65
|
|
|
63
66
|
default:
|
|
@@ -120,25 +123,30 @@ export class ShapeUtils {
|
|
|
120
123
|
|
|
121
124
|
switch (location) {
|
|
122
125
|
case 'abovebar':
|
|
126
|
+
case 'AboveBar':
|
|
123
127
|
// Shape is above the candle, text should be above the shape
|
|
124
128
|
return { position: 'top', distance: 5 };
|
|
125
129
|
|
|
126
130
|
case 'belowbar':
|
|
131
|
+
case 'BelowBar':
|
|
127
132
|
// Shape is below the candle, text should be below the shape
|
|
128
133
|
return { position: 'bottom', distance: 5 };
|
|
129
134
|
|
|
130
135
|
case 'top':
|
|
136
|
+
case 'Top':
|
|
131
137
|
// Shape at top of chart, text below it
|
|
132
138
|
return { position: 'bottom', distance: 5 };
|
|
133
139
|
|
|
134
140
|
case 'bottom':
|
|
141
|
+
case 'Bottom':
|
|
135
142
|
// Shape at bottom of chart, text above it
|
|
136
143
|
return { position: 'top', distance: 5 };
|
|
137
144
|
|
|
138
145
|
case 'absolute':
|
|
146
|
+
case 'Absolute':
|
|
139
147
|
default:
|
|
140
148
|
// For labelup/down, text is INSIDE the shape
|
|
141
|
-
if (shape === 'labelup' || shape === 'labeldown') {
|
|
149
|
+
if (shape === 'labelup' || shape === 'labeldown' || shape === 'shape_label_up' || shape === 'shape_label_down') {
|
|
142
150
|
return { position: 'inside', distance: 0 };
|
|
143
151
|
}
|
|
144
152
|
// For other shapes, text above by default
|