@qfo/qfchart 0.8.2 → 0.8.4
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 +10 -0
- package/dist/qfchart.min.browser.js +18 -17
- package/dist/qfchart.min.es.js +14 -13
- package/package.json +1 -1
- package/src/QFChart.ts +135 -1
- package/src/components/LayoutManager.ts +25 -11
- package/src/components/PluginManager.ts +229 -229
- package/src/components/SeriesBuilder.ts +21 -14
- package/src/components/renderers/LabelRenderer.ts +6 -3
- package/src/components/renderers/ScatterRenderer.ts +92 -54
- package/src/components/renderers/ShapeRenderer.ts +12 -0
|
@@ -1,54 +1,92 @@
|
|
|
1
|
-
import { SeriesRenderer, RenderContext } from './SeriesRenderer';
|
|
2
|
-
import { textToBase64Image } from '../../utils/CanvasUtils';
|
|
3
|
-
|
|
4
|
-
export class ScatterRenderer implements SeriesRenderer {
|
|
5
|
-
render(context: RenderContext): any {
|
|
6
|
-
const { seriesName, xAxisIndex, yAxisIndex, dataArray, colorArray, plotOptions } = context;
|
|
7
|
-
const defaultColor = '#2962ff';
|
|
8
|
-
const style = plotOptions.style; // 'circles', 'cross', 'char'
|
|
9
|
-
|
|
10
|
-
//
|
|
11
|
-
if (style === 'char') {
|
|
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
|
-
|
|
1
|
+
import { SeriesRenderer, RenderContext } from './SeriesRenderer';
|
|
2
|
+
import { textToBase64Image } from '../../utils/CanvasUtils';
|
|
3
|
+
|
|
4
|
+
export class ScatterRenderer implements SeriesRenderer {
|
|
5
|
+
render(context: RenderContext): any {
|
|
6
|
+
const { seriesName, xAxisIndex, yAxisIndex, dataArray, colorArray, plotOptions } = context;
|
|
7
|
+
const defaultColor = '#2962ff';
|
|
8
|
+
const style = plotOptions.style; // 'circles', 'cross', 'char'
|
|
9
|
+
|
|
10
|
+
// plotchar: render the Unicode character at the data point
|
|
11
|
+
if (style === 'char') {
|
|
12
|
+
const { optionsArray, candlestickData } = context;
|
|
13
|
+
const defaultChar = plotOptions.char || '•';
|
|
14
|
+
const defaultLocation = plotOptions.location || 'abovebar';
|
|
15
|
+
|
|
16
|
+
const charData = dataArray
|
|
17
|
+
.map((val, i) => {
|
|
18
|
+
if (val === null || val === undefined || (typeof val === 'number' && isNaN(val))) return null;
|
|
19
|
+
|
|
20
|
+
const pointOpts = optionsArray?.[i] || {};
|
|
21
|
+
const char = pointOpts.char || defaultChar;
|
|
22
|
+
const color = pointOpts.color || colorArray[i] || plotOptions.color || defaultColor;
|
|
23
|
+
const location = pointOpts.location || defaultLocation;
|
|
24
|
+
const size = pointOpts.size || plotOptions.size || 'normal';
|
|
25
|
+
|
|
26
|
+
// Positioning based on location
|
|
27
|
+
let yValue = val;
|
|
28
|
+
let symbolOffset: (string | number)[] = [0, 0];
|
|
29
|
+
|
|
30
|
+
if (location === 'abovebar' || location === 'AboveBar' || location === 'ab') {
|
|
31
|
+
if (candlestickData && candlestickData[i]) yValue = candlestickData[i].high;
|
|
32
|
+
symbolOffset = [0, '-150%'];
|
|
33
|
+
} else if (location === 'belowbar' || location === 'BelowBar' || location === 'bl') {
|
|
34
|
+
if (candlestickData && candlestickData[i]) yValue = candlestickData[i].low;
|
|
35
|
+
symbolOffset = [0, '150%'];
|
|
36
|
+
}
|
|
37
|
+
// absolute / top / bottom: yValue stays as-is
|
|
38
|
+
|
|
39
|
+
// Size mapping — matches TradingView's plotchar sizing
|
|
40
|
+
const sizeMap: Record<string, string> = {
|
|
41
|
+
tiny: '18px', small: '26px', normal: '34px', large: '42px', huge: '54px', auto: '28px',
|
|
42
|
+
};
|
|
43
|
+
const fontSize = sizeMap[size] || '34px';
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
value: [i, yValue],
|
|
47
|
+
symbol: `image://${textToBase64Image(char, color, fontSize)}`,
|
|
48
|
+
symbolSize: parseInt(fontSize) + 8,
|
|
49
|
+
symbolOffset: symbolOffset,
|
|
50
|
+
};
|
|
51
|
+
})
|
|
52
|
+
.filter((item) => item !== null);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
name: seriesName,
|
|
56
|
+
type: 'scatter',
|
|
57
|
+
xAxisIndex: xAxisIndex,
|
|
58
|
+
yAxisIndex: yAxisIndex,
|
|
59
|
+
z: 10, // Render in front of candles
|
|
60
|
+
data: charData,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const scatterData = dataArray
|
|
65
|
+
.map((val, i) => {
|
|
66
|
+
if (val === null) return null;
|
|
67
|
+
const pointColor = colorArray[i] || plotOptions.color || defaultColor;
|
|
68
|
+
const item: any = {
|
|
69
|
+
value: [i, val],
|
|
70
|
+
itemStyle: { color: pointColor },
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
if (style === 'cross') {
|
|
74
|
+
item.symbol = `image://${textToBase64Image('+', pointColor, '24px')}`;
|
|
75
|
+
item.symbolSize = 16;
|
|
76
|
+
} else {
|
|
77
|
+
item.symbol = 'circle';
|
|
78
|
+
item.symbolSize = 6;
|
|
79
|
+
}
|
|
80
|
+
return item;
|
|
81
|
+
})
|
|
82
|
+
.filter((item) => item !== null);
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
name: seriesName,
|
|
86
|
+
type: 'scatter',
|
|
87
|
+
xAxisIndex: xAxisIndex,
|
|
88
|
+
yAxisIndex: yAxisIndex,
|
|
89
|
+
data: scatterData,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -40,6 +40,8 @@ export class ShapeRenderer implements SeriesRenderer {
|
|
|
40
40
|
// Positioning based on location
|
|
41
41
|
let yValue = val; // Default to absolute value
|
|
42
42
|
let symbolOffset: (string | number)[] = [0, 0];
|
|
43
|
+
const isLabelUp = shape.includes('label_up') || shape === 'labelup';
|
|
44
|
+
const isLabelDown = shape.includes('label_down') || shape === 'labeldown';
|
|
43
45
|
|
|
44
46
|
if (location === 'abovebar' || location === 'AboveBar' || location === 'ab') {
|
|
45
47
|
// Shape above the candle
|
|
@@ -83,6 +85,15 @@ export class ShapeRenderer implements SeriesRenderer {
|
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
87
|
|
|
88
|
+
// Anchor labelup/labeldown so the arrow tip sits at the data point.
|
|
89
|
+
// labelup: arrow tip points up (at top of shape) → shift shape down
|
|
90
|
+
// labeldown: arrow tip points down (at bottom of shape) → shift shape up
|
|
91
|
+
if (isLabelUp) {
|
|
92
|
+
symbolOffset = [symbolOffset[0], '50%'];
|
|
93
|
+
} else if (isLabelDown) {
|
|
94
|
+
symbolOffset = [symbolOffset[0], '-50%'];
|
|
95
|
+
}
|
|
96
|
+
|
|
86
97
|
// Get label configuration based on location
|
|
87
98
|
const labelConfig = ShapeUtils.getLabelConfig(shape, location);
|
|
88
99
|
|
|
@@ -115,6 +126,7 @@ export class ShapeRenderer implements SeriesRenderer {
|
|
|
115
126
|
type: 'scatter',
|
|
116
127
|
xAxisIndex: xAxisIndex,
|
|
117
128
|
yAxisIndex: yAxisIndex,
|
|
129
|
+
z: 10, // Render shapes in front of candles (z: 5)
|
|
118
130
|
data: shapeData,
|
|
119
131
|
};
|
|
120
132
|
}
|