@baron1996/klinecharts-adapter 0.9.2 → 0.9.3
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"price-measurement.d.ts","sourceRoot":"","sources":["../../src/extensions/price-measurement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGnD,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"price-measurement.d.ts","sourceRoot":"","sources":["../../src/extensions/price-measurement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGnD,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;AA4BlE,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AAED,yCAAyC;AACzC,wBAAgB,6BAA6B,CAC5C,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,GACpB,uBAAuB,CA4BzB;AAED,wCAAwC;AACxC,eAAO,MAAM,uBAAuB,EAAE,oBAuFrC,CAAC"}
|
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import { SceneError } from '@baron1996/kline-scene-schema';
|
|
2
|
+
const MEASUREMENT_FILL_OPACITY = 0.15;
|
|
3
|
+
function withOpacity(color, opacity) {
|
|
4
|
+
const rgb = color.match(/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)(?:\s*,\s*[\d.]+)?\s*\)$/i);
|
|
5
|
+
if (rgb !== null) {
|
|
6
|
+
return `rgba(${rgb[1]}, ${rgb[2]}, ${rgb[3]}, ${opacity})`;
|
|
7
|
+
}
|
|
8
|
+
const hex = color.match(/^#([\da-f]{3}|[\da-f]{6})$/i)?.[1];
|
|
9
|
+
if (hex !== undefined) {
|
|
10
|
+
const normalized = hex.length === 3
|
|
11
|
+
? [...hex].map((value) => `${value}${value}`).join('')
|
|
12
|
+
: hex;
|
|
13
|
+
return `rgba(${Number.parseInt(normalized.slice(0, 2), 16)}, ${Number.parseInt(normalized.slice(2, 4), 16)}, ${Number.parseInt(normalized.slice(4, 6), 16)}, ${opacity})`;
|
|
14
|
+
}
|
|
15
|
+
return color;
|
|
16
|
+
}
|
|
2
17
|
function signedFixed(value, precision) {
|
|
3
18
|
const prefix = value > 0 ? '+' : '';
|
|
4
19
|
return `${prefix}${value.toFixed(precision)}`;
|
|
@@ -46,22 +61,61 @@ export const priceMeasurementOverlay = {
|
|
|
46
61
|
return [];
|
|
47
62
|
}
|
|
48
63
|
const pricePrecision = chart.getSymbol()?.pricePrecision ?? 0;
|
|
49
|
-
const { label } = derivePriceMeasurementDisplay(startPoint.value, endPoint.value, pricePrecision);
|
|
64
|
+
const { absoluteChange, label } = derivePriceMeasurementDisplay(startPoint.value, endPoint.value, pricePrecision);
|
|
65
|
+
const candleColors = chart.getStyles().candle.bar;
|
|
66
|
+
const measurementColor = absoluteChange > 0
|
|
67
|
+
? candleColors.upColor
|
|
68
|
+
: candleColors.downColor;
|
|
69
|
+
const measurementFill = withOpacity(measurementColor, MEASUREMENT_FILL_OPACITY);
|
|
70
|
+
// 默认端点和坐标轴投影也读取 Overlay styles;这里只修改引擎显示样式,
|
|
71
|
+
// Scene 导出仍使用 source styles,因此涨跌色不会被持久化为用户样式。
|
|
72
|
+
overlay.styles = {
|
|
73
|
+
...overlay.styles,
|
|
74
|
+
point: {
|
|
75
|
+
...overlay.styles?.point,
|
|
76
|
+
color: measurementColor,
|
|
77
|
+
borderColor: measurementColor,
|
|
78
|
+
activeColor: measurementColor,
|
|
79
|
+
activeBorderColor: measurementColor,
|
|
80
|
+
},
|
|
81
|
+
rect: {
|
|
82
|
+
...overlay.styles?.rect,
|
|
83
|
+
color: measurementFill,
|
|
84
|
+
borderColor: measurementColor,
|
|
85
|
+
},
|
|
86
|
+
text: {
|
|
87
|
+
...overlay.styles?.text,
|
|
88
|
+
backgroundColor: measurementColor,
|
|
89
|
+
borderColor: measurementColor,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
const left = Math.min(startCoordinate.x, endCoordinate.x);
|
|
93
|
+
const top = Math.min(startCoordinate.y, endCoordinate.y);
|
|
94
|
+
const width = Math.abs(endCoordinate.x - startCoordinate.x);
|
|
95
|
+
const height = Math.abs(endCoordinate.y - startCoordinate.y);
|
|
50
96
|
return [
|
|
51
97
|
{
|
|
52
|
-
key: 'measurement-
|
|
53
|
-
type: '
|
|
54
|
-
attrs: {
|
|
98
|
+
key: 'measurement-range',
|
|
99
|
+
type: 'rect',
|
|
100
|
+
attrs: { x: left, y: top, width, height },
|
|
101
|
+
styles: {
|
|
102
|
+
color: measurementFill,
|
|
103
|
+
borderColor: measurementColor,
|
|
104
|
+
},
|
|
55
105
|
},
|
|
56
106
|
{
|
|
57
107
|
key: 'measurement-label',
|
|
58
108
|
type: 'text',
|
|
59
109
|
attrs: {
|
|
60
|
-
x:
|
|
61
|
-
y:
|
|
110
|
+
x: left + width / 2,
|
|
111
|
+
y: top + height / 2,
|
|
62
112
|
text: label,
|
|
63
|
-
align: '
|
|
64
|
-
baseline: '
|
|
113
|
+
align: 'center',
|
|
114
|
+
baseline: 'middle',
|
|
115
|
+
},
|
|
116
|
+
styles: {
|
|
117
|
+
backgroundColor: measurementColor,
|
|
118
|
+
borderColor: measurementColor,
|
|
65
119
|
},
|
|
66
120
|
ignoreEvent: true,
|
|
67
121
|
},
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED