@baron1996/klinecharts-adapter 0.2.1 → 0.2.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/adapter.d.ts.map +1 -1
- package/dist/adapter.js +81 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,UAAU,EACV,cAAc,EACd,YAAY,EACZ,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEN,UAAU,EACV,MAAM,+BAA+B,CAAC;AAUvC,OAAO,EAIN,KAAK,oBAAoB,EAGzB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,UAAU,EACV,cAAc,EACd,YAAY,EACZ,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEN,UAAU,EACV,MAAM,+BAA+B,CAAC;AAUvC,OAAO,EAIN,KAAK,oBAAoB,EAGzB,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAEN,KAAK,gBAAgB,EAErB,KAAK,eAAe,EACpB,MAAM,8BAA8B,CAAC;AAGtC,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,aAAa,CAAC;AAClD,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,QAAQ,CAAC;AAClD,MAAM,MAAM,uBAAuB,GAChC,QAAQ,GACR,gBAAgB,GAChB,aAAa,GACb,SAAS,GACT,kBAAkB,CAAC;AAEtB,MAAM,WAAW,wBAAwB;IACxC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IACtC,QAAQ,CA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QAAQ,EAAE,yBAAyB,GAAG,MAAM,IAAI;IAQ1D,WAAW,IAAI,UAAU;IAenB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IA0C3D,YAAY,CAClB,KAAK,EAAE;QAAE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAC7D,MAAM,CAAC,EAAE,MAAM,GACb,eAAe;IAMX,cAAc,CAAC,KAAK,EAAE,eAAe,GAAG,gBAAgB,GAAG,IAAI;IAK/D,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,YAAY;IAiE7C,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,YAAY;IAIhD,mBAAmB,CACzB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,GAC5B,YAAY;IAQR,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IA0BlC,mBAAmB,CAAC,OAAO,EAAE,qBAAqB,GAAG,MAAM;IAqC3D,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAMhD,YAAY,IAAI,SAAS,YAAY,EAAE;IAKvC,OAAO,IAAI,eAAe;IA+B1B,OAAO,IAAI,IAAI;CAatB"}
|
package/dist/adapter.js
CHANGED
|
@@ -4,6 +4,7 @@ import { registerProjectOverlays } from './extensions/register.js';
|
|
|
4
4
|
import { createEngineIdMap, } from './conversion/id-map.js';
|
|
5
5
|
import { applyPanes, overrideSceneYAxis } from './conversion/panes.js';
|
|
6
6
|
import { createSceneOverlays, fromEngineOverlay, toEngineOverlay, toEngineOverlayDrawing, } from './conversion/overlays.js';
|
|
7
|
+
import { normalizePriceValue } from './conversion/price.js';
|
|
7
8
|
import { applyViewport } from './conversion/viewport.js';
|
|
8
9
|
import { createDragCandidate, } from './interaction/dragging.js';
|
|
9
10
|
import { hitTestOverlayGeometries, } from './interaction/hit-testing.js';
|
|
@@ -49,6 +50,8 @@ export class KLineChartsSceneAdapter {
|
|
|
49
50
|
#selectedOverlayId = null;
|
|
50
51
|
/** 当前受控拖动事务;progress 永不写入 #scene。 */
|
|
51
52
|
#pointerInteraction;
|
|
53
|
+
/** 当前交互式量度的首锚点;只用于补偿引擎丢弃快速第二击,不进入 Scene。 */
|
|
54
|
+
#interactivePriceMeasurement;
|
|
52
55
|
/** 确定性 opaque 交互 ID 序号。 */
|
|
53
56
|
#interactionSequence = 0;
|
|
54
57
|
constructor(container, scene, handle, idMap, originalBackground) {
|
|
@@ -136,6 +139,10 @@ export class KLineChartsSceneAdapter {
|
|
|
136
139
|
#overlayCallbacks(source, drawing = false) {
|
|
137
140
|
return {
|
|
138
141
|
onDrawEnd: ({ overlay }) => {
|
|
142
|
+
if (drawing &&
|
|
143
|
+
this.#interactivePriceMeasurement?.source.id === source.id) {
|
|
144
|
+
this.#interactivePriceMeasurement = undefined;
|
|
145
|
+
}
|
|
139
146
|
this.#safelyCommitEngineOverlay(overlay, source, drawing ? 'created' : 'updated');
|
|
140
147
|
},
|
|
141
148
|
onPressedMoveStart: ({ overlay }) => {
|
|
@@ -162,6 +169,9 @@ export class KLineChartsSceneAdapter {
|
|
|
162
169
|
}
|
|
163
170
|
},
|
|
164
171
|
onRemoved: ({ overlay }) => {
|
|
172
|
+
if (this.#interactivePriceMeasurement?.source.id === overlay.id) {
|
|
173
|
+
this.#interactivePriceMeasurement = undefined;
|
|
174
|
+
}
|
|
165
175
|
if (this.#scene.overlays.some((candidate) => candidate.id === overlay.id)) {
|
|
166
176
|
this.#scene = parseChartScene({
|
|
167
177
|
...structuredClone(this.#scene),
|
|
@@ -232,6 +242,45 @@ export class KLineChartsSceneAdapter {
|
|
|
232
242
|
}
|
|
233
243
|
return { dataIndex: value.dataIndex, value: value.value };
|
|
234
244
|
}
|
|
245
|
+
#measurementAnchor(point, paneId, path) {
|
|
246
|
+
const converted = this.#chart.convertFromPixel([point], this.#primaryAxisFilter(paneId));
|
|
247
|
+
const value = converted[0];
|
|
248
|
+
if (!Number.isSafeInteger(value?.timestamp) ||
|
|
249
|
+
!Number.isFinite(value?.value) ||
|
|
250
|
+
!this.#scene.data.some((bar) => bar.timestamp === value?.timestamp)) {
|
|
251
|
+
throw new SceneError('INVALID_REFERENCE', path, 'Pointer does not map to a finite price and an embedded market-data timestamp.');
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
timestamp: value.timestamp,
|
|
255
|
+
value: normalizePriceValue(value.value, this.#scene.symbol.pricePrecision, `${path}/value`),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
#completeInteractivePriceMeasurement(drawing, end) {
|
|
259
|
+
const { text: _text, ...source } = drawing.source;
|
|
260
|
+
const candidate = parseChartScene({
|
|
261
|
+
...structuredClone(this.#scene),
|
|
262
|
+
overlays: [
|
|
263
|
+
...structuredClone(this.#scene.overlays),
|
|
264
|
+
{
|
|
265
|
+
...structuredClone(source),
|
|
266
|
+
start: structuredClone(drawing.start),
|
|
267
|
+
end: structuredClone(end),
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
});
|
|
271
|
+
const index = candidate.overlays.length - 1;
|
|
272
|
+
const overlay = candidate.overlays[index];
|
|
273
|
+
this.#interactivePriceMeasurement = undefined;
|
|
274
|
+
if (!this.#chart.removeOverlay({ id: overlay.id })) {
|
|
275
|
+
throw new SceneError('RUNTIME_INIT_FAILED', `/overlays/${index}`, `KLineCharts failed to replace in-progress Overlay ${overlay.id}.`);
|
|
276
|
+
}
|
|
277
|
+
const result = this.#chart.createOverlay(toEngineOverlay(overlay, this.#idMap, `/overlays/${index}`, this.#overlayCallbacks(overlay)));
|
|
278
|
+
if (result !== overlay.id) {
|
|
279
|
+
throw new SceneError('RUNTIME_INIT_FAILED', `/overlays/${index}`, `KLineCharts failed to commit interactive Overlay ${overlay.id}.`);
|
|
280
|
+
}
|
|
281
|
+
this.#scene = candidate;
|
|
282
|
+
this.#emit({ type: 'overlay-created', overlay });
|
|
283
|
+
}
|
|
235
284
|
#overlayGeometries() {
|
|
236
285
|
const geometries = [];
|
|
237
286
|
for (let sceneIndex = 0; sceneIndex < this.#scene.overlays.length; sceneIndex++) {
|
|
@@ -335,6 +384,29 @@ export class KLineChartsSceneAdapter {
|
|
|
335
384
|
return;
|
|
336
385
|
}
|
|
337
386
|
const coordinate = this.#pointerCoordinate(event);
|
|
387
|
+
const measurement = this.#interactivePriceMeasurement;
|
|
388
|
+
if (measurement !== undefined) {
|
|
389
|
+
try {
|
|
390
|
+
const point = this.#measurementAnchor(coordinate, measurement.source.paneId, measurement.start === undefined ? '/overlays/start' : '/overlays/end');
|
|
391
|
+
if (measurement.start === undefined) {
|
|
392
|
+
measurement.start = point;
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
event.preventDefault();
|
|
396
|
+
event.stopImmediatePropagation();
|
|
397
|
+
this.#completeInteractivePriceMeasurement(measurement, point);
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
catch (error) {
|
|
401
|
+
if (error instanceof SceneError) {
|
|
402
|
+
event.preventDefault();
|
|
403
|
+
event.stopImmediatePropagation();
|
|
404
|
+
this.#emit({ type: 'scene-error', issues: structuredClone(error.issues) });
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
throw error;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
338
410
|
const hit = hitTestOverlayGeometries(coordinate, this.#overlayGeometries());
|
|
339
411
|
if (hit === null) {
|
|
340
412
|
const selected = this.#scene.overlays.find((overlay) => overlay.id === this.#selectedOverlayId);
|
|
@@ -596,6 +668,14 @@ export class KLineChartsSceneAdapter {
|
|
|
596
668
|
throw new SceneError('RUNTIME_INIT_FAILED', '/overlays', `KLineCharts failed to start drawing Overlay ${request.id}.`);
|
|
597
669
|
}
|
|
598
670
|
this.#scene = candidate;
|
|
671
|
+
if (request.type === 'priceMeasurement') {
|
|
672
|
+
this.#interactivePriceMeasurement = {
|
|
673
|
+
source: {
|
|
674
|
+
...structuredClone(request),
|
|
675
|
+
type: 'priceMeasurement',
|
|
676
|
+
},
|
|
677
|
+
};
|
|
678
|
+
}
|
|
599
679
|
return request.id;
|
|
600
680
|
}
|
|
601
681
|
getOverlay(id) {
|
|
@@ -638,6 +718,7 @@ export class KLineChartsSceneAdapter {
|
|
|
638
718
|
return;
|
|
639
719
|
}
|
|
640
720
|
this.#cancelInteraction('destroy');
|
|
721
|
+
this.#interactivePriceMeasurement = undefined;
|
|
641
722
|
this.#disposed = true;
|
|
642
723
|
this.#removeInteractionListeners();
|
|
643
724
|
this.#listeners.clear();
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baron1996/klinecharts-adapter",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Controlled ChartScene adapter for KLineCharts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@baron1996/kline-scene-schema": "0.2.
|
|
41
|
+
"@baron1996/kline-scene-schema": "0.2.2",
|
|
42
42
|
"klinecharts": "10.0.0"
|
|
43
43
|
}
|
|
44
44
|
}
|