@qfo/qfchart 0.8.0 → 0.8.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 +524 -12
- package/dist/qfchart.min.browser.js +34 -18
- package/dist/qfchart.min.es.js +34 -18
- package/package.json +1 -1
- package/src/QFChart.ts +109 -272
- package/src/components/AbstractPlugin.ts +234 -104
- package/src/components/DrawingEditor.ts +297 -248
- package/src/components/DrawingRendererRegistry.ts +13 -0
- package/src/components/GraphicBuilder.ts +2 -2
- package/src/components/LayoutManager.ts +92 -52
- package/src/components/SeriesBuilder.ts +10 -10
- package/src/components/TooltipFormatter.ts +1 -1
- package/src/index.ts +25 -6
- package/src/plugins/ABCDPatternTool/ABCDPatternDrawingRenderer.ts +112 -0
- package/src/plugins/ABCDPatternTool/ABCDPatternTool.ts +136 -0
- package/src/plugins/ABCDPatternTool/index.ts +2 -0
- package/src/plugins/CrossLineTool/CrossLineDrawingRenderer.ts +49 -0
- package/src/plugins/CrossLineTool/CrossLineTool.ts +52 -0
- package/src/plugins/CrossLineTool/index.ts +2 -0
- package/src/plugins/CypherPatternTool/CypherPatternDrawingRenderer.ts +80 -0
- package/src/plugins/CypherPatternTool/CypherPatternTool.ts +84 -0
- package/src/plugins/CypherPatternTool/index.ts +2 -0
- package/src/plugins/ExtendedLineTool/ExtendedLineDrawingRenderer.ts +73 -0
- package/src/plugins/ExtendedLineTool/ExtendedLineTool.ts +173 -0
- package/src/plugins/ExtendedLineTool/index.ts +2 -0
- package/src/plugins/FibSpeedResistanceFanTool/FibSpeedResistanceFanDrawingRenderer.ts +163 -0
- package/src/plugins/FibSpeedResistanceFanTool/FibSpeedResistanceFanTool.ts +210 -0
- package/src/plugins/FibSpeedResistanceFanTool/index.ts +2 -0
- package/src/plugins/FibTrendExtensionTool/FibTrendExtensionDrawingRenderer.ts +141 -0
- package/src/plugins/FibTrendExtensionTool/FibTrendExtensionTool.ts +188 -0
- package/src/plugins/FibTrendExtensionTool/index.ts +2 -0
- package/src/plugins/FibonacciChannelTool/FibonacciChannelDrawingRenderer.ts +128 -0
- package/src/plugins/FibonacciChannelTool/FibonacciChannelTool.ts +231 -0
- package/src/plugins/FibonacciChannelTool/index.ts +2 -0
- package/src/plugins/FibonacciTool/FibonacciDrawingRenderer.ts +107 -0
- package/src/plugins/{FibonacciTool.ts → FibonacciTool/FibonacciTool.ts} +195 -192
- package/src/plugins/FibonacciTool/index.ts +2 -0
- package/src/plugins/HeadAndShouldersTool/HeadAndShouldersDrawingRenderer.ts +95 -0
- package/src/plugins/HeadAndShouldersTool/HeadAndShouldersTool.ts +97 -0
- package/src/plugins/HeadAndShouldersTool/index.ts +2 -0
- package/src/plugins/HorizontalLineTool/HorizontalLineDrawingRenderer.ts +54 -0
- package/src/plugins/HorizontalLineTool/HorizontalLineTool.ts +52 -0
- package/src/plugins/HorizontalLineTool/index.ts +2 -0
- package/src/plugins/HorizontalRayTool/HorizontalRayDrawingRenderer.ts +34 -0
- package/src/plugins/HorizontalRayTool/HorizontalRayTool.ts +52 -0
- package/src/plugins/HorizontalRayTool/index.ts +2 -0
- package/src/plugins/InfoLineTool/InfoLineDrawingRenderer.ts +72 -0
- package/src/plugins/InfoLineTool/InfoLineTool.ts +130 -0
- package/src/plugins/InfoLineTool/index.ts +2 -0
- package/src/plugins/LineTool/LineDrawingRenderer.ts +49 -0
- package/src/plugins/{LineTool.ts → LineTool/LineTool.ts} +161 -190
- package/src/plugins/LineTool/index.ts +2 -0
- package/src/plugins/{MeasureTool.ts → MeasureTool/MeasureTool.ts} +324 -344
- package/src/plugins/MeasureTool/index.ts +1 -0
- package/src/plugins/RayTool/RayDrawingRenderer.ts +69 -0
- package/src/plugins/RayTool/RayTool.ts +162 -0
- package/src/plugins/RayTool/index.ts +2 -0
- package/src/plugins/ThreeDrivesPatternTool/ThreeDrivesPatternDrawingRenderer.ts +106 -0
- package/src/plugins/ThreeDrivesPatternTool/ThreeDrivesPatternTool.ts +98 -0
- package/src/plugins/ThreeDrivesPatternTool/index.ts +2 -0
- package/src/plugins/ToolGroup.ts +211 -0
- package/src/plugins/TrendAngleTool/TrendAngleDrawingRenderer.ts +87 -0
- package/src/plugins/TrendAngleTool/TrendAngleTool.ts +176 -0
- package/src/plugins/TrendAngleTool/index.ts +2 -0
- package/src/plugins/TrianglePatternTool/TrianglePatternDrawingRenderer.ts +107 -0
- package/src/plugins/TrianglePatternTool/TrianglePatternTool.ts +98 -0
- package/src/plugins/TrianglePatternTool/index.ts +2 -0
- package/src/plugins/VerticalLineTool/VerticalLineDrawingRenderer.ts +35 -0
- package/src/plugins/VerticalLineTool/VerticalLineTool.ts +52 -0
- package/src/plugins/VerticalLineTool/index.ts +2 -0
- package/src/plugins/XABCDPatternTool/XABCDPatternDrawingRenderer.ts +178 -0
- package/src/plugins/XABCDPatternTool/XABCDPatternTool.ts +213 -0
- package/src/plugins/XABCDPatternTool/index.ts +2 -0
- package/src/types.ts +39 -11
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { DrawingRenderer, DrawingRenderContext } from '../../types';
|
|
2
|
+
|
|
3
|
+
export class CrossLineDrawingRenderer implements DrawingRenderer {
|
|
4
|
+
type = 'cross-line';
|
|
5
|
+
|
|
6
|
+
render(ctx: DrawingRenderContext): any {
|
|
7
|
+
const { drawing, pixelPoints, isSelected, coordSys } = ctx;
|
|
8
|
+
const [px, py] = pixelPoints[0];
|
|
9
|
+
const color = drawing.style?.color || '#d1d4dc';
|
|
10
|
+
|
|
11
|
+
const left = coordSys.x;
|
|
12
|
+
const right = coordSys.x + coordSys.width;
|
|
13
|
+
const top = coordSys.y;
|
|
14
|
+
const bottom = coordSys.y + coordSys.height;
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
type: 'group',
|
|
18
|
+
children: [
|
|
19
|
+
// Horizontal line
|
|
20
|
+
{
|
|
21
|
+
type: 'line',
|
|
22
|
+
name: 'line-h',
|
|
23
|
+
shape: { x1: left, y1: py, x2: right, y2: py },
|
|
24
|
+
style: {
|
|
25
|
+
stroke: color,
|
|
26
|
+
lineWidth: drawing.style?.lineWidth || 1,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
// Vertical line
|
|
30
|
+
{
|
|
31
|
+
type: 'line',
|
|
32
|
+
name: 'line-v',
|
|
33
|
+
shape: { x1: px, y1: top, x2: px, y2: bottom },
|
|
34
|
+
style: {
|
|
35
|
+
stroke: color,
|
|
36
|
+
lineWidth: drawing.style?.lineWidth || 1,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
// Center point
|
|
40
|
+
{
|
|
41
|
+
type: 'circle',
|
|
42
|
+
name: 'point-0',
|
|
43
|
+
shape: { cx: px, cy: py, r: 4 },
|
|
44
|
+
style: { fill: '#fff', stroke: color, lineWidth: 1, opacity: isSelected ? 1 : 0 },
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { AbstractPlugin } from '../../components/AbstractPlugin';
|
|
2
|
+
import { CrossLineDrawingRenderer } from './CrossLineDrawingRenderer';
|
|
3
|
+
|
|
4
|
+
export class CrossLineTool extends AbstractPlugin {
|
|
5
|
+
private zr!: any;
|
|
6
|
+
|
|
7
|
+
constructor(options: { name?: string; icon?: string } = {}) {
|
|
8
|
+
super({
|
|
9
|
+
id: 'cross-line-tool',
|
|
10
|
+
name: options?.name || 'Cross Line',
|
|
11
|
+
icon: options?.icon || `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="2" x2="12" y2="22"/><line x1="2" y1="12" x2="22" y2="12"/></svg>`,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
protected onInit(): void {
|
|
16
|
+
this.zr = this.chart.getZr();
|
|
17
|
+
this.context.registerDrawingRenderer(new CrossLineDrawingRenderer());
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
protected onActivate(): void {
|
|
21
|
+
this.chart.getZr().setCursorStyle('crosshair');
|
|
22
|
+
this.zr.on('click', this.onClick);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
protected onDeactivate(): void {
|
|
26
|
+
this.chart.getZr().setCursorStyle('default');
|
|
27
|
+
this.zr.off('click', this.onClick);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected onDestroy(): void {}
|
|
31
|
+
|
|
32
|
+
private onClick = (params: any) => {
|
|
33
|
+
const point = this.getPoint(params);
|
|
34
|
+
if (!point) return;
|
|
35
|
+
|
|
36
|
+
const data = this.context.coordinateConversion.pixelToData({
|
|
37
|
+
x: point[0], y: point[1],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (data) {
|
|
41
|
+
this.context.addDrawing({
|
|
42
|
+
id: `crossline-${Date.now()}`,
|
|
43
|
+
type: 'cross-line',
|
|
44
|
+
points: [data],
|
|
45
|
+
paneIndex: data.paneIndex || 0,
|
|
46
|
+
style: { color: '#d1d4dc', lineWidth: 1 },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this.context.disableTools();
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { DrawingRenderer, DrawingRenderContext } from '../../types';
|
|
2
|
+
|
|
3
|
+
const LABELS = ['X', 'A', 'B', 'C', 'D'];
|
|
4
|
+
const LEG_COLORS = ['#00bcd4', '#e91e63', '#8bc34a', '#ff5722'];
|
|
5
|
+
|
|
6
|
+
export class CypherPatternDrawingRenderer implements DrawingRenderer {
|
|
7
|
+
type = 'cypher_pattern';
|
|
8
|
+
|
|
9
|
+
render(ctx: DrawingRenderContext): any {
|
|
10
|
+
const { drawing, pixelPoints, isSelected } = ctx;
|
|
11
|
+
const color = drawing.style?.color || '#3b82f6';
|
|
12
|
+
if (pixelPoints.length < 2) return;
|
|
13
|
+
|
|
14
|
+
const children: any[] = [];
|
|
15
|
+
|
|
16
|
+
// Fill triangles XAB and BCD
|
|
17
|
+
if (pixelPoints.length >= 3) {
|
|
18
|
+
children.push({ type: 'polygon', name: 'line', shape: { points: pixelPoints.slice(0, 3).map(([x, y]) => [x, y]) }, style: { fill: 'rgba(0, 188, 212, 0.08)' } });
|
|
19
|
+
}
|
|
20
|
+
if (pixelPoints.length >= 5) {
|
|
21
|
+
children.push({ type: 'polygon', name: 'line', shape: { points: pixelPoints.slice(2, 5).map(([x, y]) => [x, y]) }, style: { fill: 'rgba(233, 30, 99, 0.08)' } });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Legs
|
|
25
|
+
for (let i = 0; i < pixelPoints.length - 1; i++) {
|
|
26
|
+
const [x1, y1] = pixelPoints[i];
|
|
27
|
+
const [x2, y2] = pixelPoints[i + 1];
|
|
28
|
+
children.push({ type: 'line', name: 'line', shape: { x1, y1, x2, y2 }, style: { stroke: LEG_COLORS[i % LEG_COLORS.length], lineWidth: drawing.style?.lineWidth || 2 } });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Dashed connectors X→B, X→C, A→D
|
|
32
|
+
const connectors: [number, number][] = [[0, 2], [0, 3], [1, 4]];
|
|
33
|
+
for (const [from, to] of connectors) {
|
|
34
|
+
if (from < pixelPoints.length && to < pixelPoints.length) {
|
|
35
|
+
children.push({ type: 'line', shape: { x1: pixelPoints[from][0], y1: pixelPoints[from][1], x2: pixelPoints[to][0], y2: pixelPoints[to][1] }, style: { stroke: '#555', lineWidth: 1, lineDash: [4, 4] }, silent: true });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Ratios
|
|
40
|
+
const pts = drawing.points;
|
|
41
|
+
if (pts.length >= 3) {
|
|
42
|
+
const xa = Math.abs(pts[1].value - pts[0].value);
|
|
43
|
+
const ab = Math.abs(pts[2].value - pts[1].value);
|
|
44
|
+
if (xa !== 0) {
|
|
45
|
+
const r = (ab / xa).toFixed(3);
|
|
46
|
+
children.push({ type: 'text', style: { text: r, x: (pixelPoints[1][0] + pixelPoints[2][0]) / 2 + 8, y: (pixelPoints[1][1] + pixelPoints[2][1]) / 2, fill: '#e91e63', fontSize: 10 }, silent: true });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (pts.length >= 4) {
|
|
50
|
+
const xa = Math.abs(pts[1].value - pts[0].value);
|
|
51
|
+
const xc = Math.abs(pts[3].value - pts[0].value);
|
|
52
|
+
if (xa !== 0) {
|
|
53
|
+
const r = (xc / xa).toFixed(3);
|
|
54
|
+
children.push({ type: 'text', style: { text: `XC/XA: ${r}`, x: (pixelPoints[0][0] + pixelPoints[3][0]) / 2 + 8, y: (pixelPoints[0][1] + pixelPoints[3][1]) / 2, fill: '#8bc34a', fontSize: 10 }, silent: true });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (pts.length >= 5) {
|
|
58
|
+
const xc = Math.abs(pts[3].value - pts[0].value);
|
|
59
|
+
const cd = Math.abs(pts[4].value - pts[3].value);
|
|
60
|
+
if (xc !== 0) {
|
|
61
|
+
const r = (cd / xc).toFixed(3);
|
|
62
|
+
children.push({ type: 'text', style: { text: r, x: (pixelPoints[3][0] + pixelPoints[4][0]) / 2 + 8, y: (pixelPoints[3][1] + pixelPoints[4][1]) / 2, fill: '#ff5722', fontSize: 10 }, silent: true });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Labels
|
|
67
|
+
for (let i = 0; i < pixelPoints.length && i < LABELS.length; i++) {
|
|
68
|
+
const [px, py] = pixelPoints[i];
|
|
69
|
+
const isHigh = (i === 0 || py <= pixelPoints[i - 1][1]) && (i === pixelPoints.length - 1 || py <= pixelPoints[i + 1]?.[1]);
|
|
70
|
+
children.push({ type: 'text', style: { text: LABELS[i], x: px, y: isHigh ? py - 14 : py + 16, fill: '#e2e8f0', fontSize: 12, fontWeight: 'bold', align: 'center', verticalAlign: 'middle' }, silent: true });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Control points
|
|
74
|
+
for (let i = 0; i < pixelPoints.length; i++) {
|
|
75
|
+
children.push({ type: 'circle', name: `point-${i}`, shape: { cx: pixelPoints[i][0], cy: pixelPoints[i][1], r: 4 }, style: { fill: '#fff', stroke: color, lineWidth: 1, opacity: isSelected ? 1 : 0 }, z: 100 });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return { type: 'group', children };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as echarts from 'echarts';
|
|
2
|
+
import { AbstractPlugin } from '../../components/AbstractPlugin';
|
|
3
|
+
import { CypherPatternDrawingRenderer } from './CypherPatternDrawingRenderer';
|
|
4
|
+
|
|
5
|
+
const LABELS = ['X', 'A', 'B', 'C', 'D'];
|
|
6
|
+
const LEG_COLORS = ['#00bcd4', '#e91e63', '#8bc34a', '#ff5722'];
|
|
7
|
+
const TOTAL_POINTS = 5;
|
|
8
|
+
|
|
9
|
+
export class CypherPatternTool extends AbstractPlugin {
|
|
10
|
+
private points: number[][] = [];
|
|
11
|
+
private state: 'idle' | 'drawing' | 'finished' = 'idle';
|
|
12
|
+
private graphicGroup: any = null;
|
|
13
|
+
|
|
14
|
+
constructor(options: { name?: string; icon?: string } = {}) {
|
|
15
|
+
super({
|
|
16
|
+
id: 'cypher-pattern-tool',
|
|
17
|
+
name: options.name || 'Cypher Pattern',
|
|
18
|
+
icon: options.icon || `<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="#e3e3e3" stroke-width="1.5"><polyline points="2,16 7,4 11,12 17,2 22,14"/><circle cx="2" cy="16" r="1.5" fill="#e3e3e3"/><circle cx="7" cy="4" r="1.5" fill="#e3e3e3"/><circle cx="11" cy="12" r="1.5" fill="#e3e3e3"/><circle cx="17" cy="2" r="1.5" fill="#e3e3e3"/><circle cx="22" cy="14" r="1.5" fill="#e3e3e3"/></svg>`,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
protected onInit(): void { this.context.registerDrawingRenderer(new CypherPatternDrawingRenderer()); }
|
|
23
|
+
|
|
24
|
+
protected onActivate(): void {
|
|
25
|
+
this.state = 'idle'; this.points = [];
|
|
26
|
+
this.context.getChart().getZr().setCursorStyle('crosshair');
|
|
27
|
+
const zr = this.context.getChart().getZr();
|
|
28
|
+
zr.on('click', this.onClick); zr.on('mousemove', this.onMouseMove);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected onDeactivate(): void {
|
|
32
|
+
this.state = 'idle'; this.points = []; this.removeGraphic();
|
|
33
|
+
const zr = this.context.getChart().getZr();
|
|
34
|
+
zr.off('click', this.onClick); zr.off('mousemove', this.onMouseMove);
|
|
35
|
+
zr.setCursorStyle('default');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private onClick = (params: any) => {
|
|
39
|
+
const pt = this.getPoint(params);
|
|
40
|
+
if (this.state === 'idle') {
|
|
41
|
+
this.state = 'drawing'; this.points = [pt, [...pt]]; this.initGraphic(); this.updateGraphic();
|
|
42
|
+
} else if (this.state === 'drawing') {
|
|
43
|
+
this.points[this.points.length - 1] = pt;
|
|
44
|
+
if (this.points.length >= TOTAL_POINTS) {
|
|
45
|
+
this.state = 'finished'; this.updateGraphic(); this.saveDrawing(); this.removeGraphic(); this.context.disableTools();
|
|
46
|
+
} else { this.points.push([...pt]); this.updateGraphic(); }
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
private onMouseMove = (params: any) => {
|
|
51
|
+
if (this.state !== 'drawing' || this.points.length < 2) return;
|
|
52
|
+
this.points[this.points.length - 1] = this.getPoint(params); this.updateGraphic();
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
private initGraphic() { this.graphicGroup = new echarts.graphic.Group(); this.context.getChart().getZr().add(this.graphicGroup); }
|
|
56
|
+
private removeGraphic() { if (this.graphicGroup) { this.context.getChart().getZr().remove(this.graphicGroup); this.graphicGroup = null; } }
|
|
57
|
+
|
|
58
|
+
private updateGraphic() {
|
|
59
|
+
if (!this.graphicGroup) return;
|
|
60
|
+
this.graphicGroup.removeAll();
|
|
61
|
+
const pts = this.points;
|
|
62
|
+
|
|
63
|
+
if (pts.length >= 3) this.graphicGroup.add(new echarts.graphic.Polygon({ shape: { points: pts.slice(0, 3) }, style: { fill: 'rgba(0,188,212,0.08)' }, silent: true }));
|
|
64
|
+
if (pts.length >= 5) this.graphicGroup.add(new echarts.graphic.Polygon({ shape: { points: pts.slice(2, 5) }, style: { fill: 'rgba(233,30,99,0.08)' }, silent: true }));
|
|
65
|
+
|
|
66
|
+
for (let i = 0; i < pts.length - 1; i++) {
|
|
67
|
+
this.graphicGroup.add(new echarts.graphic.Line({ shape: { x1: pts[i][0], y1: pts[i][1], x2: pts[i + 1][0], y2: pts[i + 1][1] }, style: { stroke: LEG_COLORS[i % LEG_COLORS.length], lineWidth: 2 }, silent: true }));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
for (let i = 0; i < pts.length && i < LABELS.length; i++) {
|
|
71
|
+
const [px, py] = pts[i];
|
|
72
|
+
const isHigh = (i === 0 || py <= pts[i - 1][1]) && (i === pts.length - 1 || py <= pts[i + 1]?.[1]);
|
|
73
|
+
this.graphicGroup.add(new echarts.graphic.Text({ style: { text: LABELS[i], x: px, y: isHigh ? py - 14 : py + 16, fill: '#e2e8f0', fontSize: 12, fontWeight: 'bold', align: 'center', verticalAlign: 'middle' }, silent: true }));
|
|
74
|
+
this.graphicGroup.add(new echarts.graphic.Circle({ shape: { cx: px, cy: py, r: 4 }, style: { fill: '#fff', stroke: '#3b82f6', lineWidth: 1.5 }, z: 101, silent: true }));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private saveDrawing() {
|
|
79
|
+
const dataPoints = this.points.map((pt) => this.context.coordinateConversion.pixelToData({ x: pt[0], y: pt[1] }));
|
|
80
|
+
if (dataPoints.every((p) => p !== null)) {
|
|
81
|
+
this.context.addDrawing({ id: `cypher-${Date.now()}`, type: 'cypher_pattern', points: dataPoints as any[], paneIndex: dataPoints[0]!.paneIndex || 0, style: { color: '#3b82f6', lineWidth: 2 } });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { DrawingRenderer, DrawingRenderContext } from '../../types';
|
|
2
|
+
|
|
3
|
+
export class ExtendedLineDrawingRenderer implements DrawingRenderer {
|
|
4
|
+
type = 'extended-line';
|
|
5
|
+
|
|
6
|
+
render(ctx: DrawingRenderContext): any {
|
|
7
|
+
const { drawing, pixelPoints, isSelected, coordSys } = ctx;
|
|
8
|
+
const [x1, y1] = pixelPoints[0];
|
|
9
|
+
const [x2, y2] = pixelPoints[1];
|
|
10
|
+
const color = drawing.style?.color || '#d1d4dc';
|
|
11
|
+
|
|
12
|
+
const dx = x2 - x1;
|
|
13
|
+
const dy = y2 - y1;
|
|
14
|
+
|
|
15
|
+
let ex1 = x1, ey1 = y1, ex2 = x2, ey2 = y2;
|
|
16
|
+
|
|
17
|
+
if (dx !== 0 || dy !== 0) {
|
|
18
|
+
const left = coordSys.x;
|
|
19
|
+
const right = coordSys.x + coordSys.width;
|
|
20
|
+
const top = coordSys.y;
|
|
21
|
+
const bottom = coordSys.y + coordSys.height;
|
|
22
|
+
|
|
23
|
+
// Extend forward (past p2)
|
|
24
|
+
[ex2, ey2] = this.extendToEdge(x1, y1, dx, dy, left, right, top, bottom);
|
|
25
|
+
// Extend backward (past p1)
|
|
26
|
+
[ex1, ey1] = this.extendToEdge(x2, y2, -dx, -dy, left, right, top, bottom);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
type: 'group',
|
|
31
|
+
children: [
|
|
32
|
+
{
|
|
33
|
+
type: 'line',
|
|
34
|
+
name: 'line',
|
|
35
|
+
shape: { x1: ex1, y1: ey1, x2: ex2, y2: ey2 },
|
|
36
|
+
style: {
|
|
37
|
+
stroke: color,
|
|
38
|
+
lineWidth: drawing.style?.lineWidth || 1,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
type: 'circle',
|
|
43
|
+
name: 'point-0',
|
|
44
|
+
shape: { cx: x1, cy: y1, r: 4 },
|
|
45
|
+
style: { fill: '#fff', stroke: color, lineWidth: 1, opacity: isSelected ? 1 : 0 },
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
type: 'circle',
|
|
49
|
+
name: 'point-1',
|
|
50
|
+
shape: { cx: x2, cy: y2, r: 4 },
|
|
51
|
+
style: { fill: '#fff', stroke: color, lineWidth: 1, opacity: isSelected ? 1 : 0 },
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private extendToEdge(
|
|
58
|
+
ox: number, oy: number, dx: number, dy: number,
|
|
59
|
+
left: number, right: number, top: number, bottom: number,
|
|
60
|
+
): [number, number] {
|
|
61
|
+
let tMax = Infinity;
|
|
62
|
+
if (dx !== 0) {
|
|
63
|
+
const tx = dx > 0 ? (right - ox) / dx : (left - ox) / dx;
|
|
64
|
+
if (tx > 0) tMax = Math.min(tMax, tx);
|
|
65
|
+
}
|
|
66
|
+
if (dy !== 0) {
|
|
67
|
+
const ty = dy > 0 ? (bottom - oy) / dy : (top - oy) / dy;
|
|
68
|
+
if (ty > 0) tMax = Math.min(tMax, ty);
|
|
69
|
+
}
|
|
70
|
+
if (!isFinite(tMax)) tMax = 1;
|
|
71
|
+
return [ox + tMax * dx, oy + tMax * dy];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { AbstractPlugin } from '../../components/AbstractPlugin';
|
|
2
|
+
import { ExtendedLineDrawingRenderer } from './ExtendedLineDrawingRenderer';
|
|
3
|
+
import * as echarts from 'echarts';
|
|
4
|
+
|
|
5
|
+
const COLOR = '#d1d4dc';
|
|
6
|
+
|
|
7
|
+
type PluginState = 'idle' | 'drawing' | 'finished';
|
|
8
|
+
|
|
9
|
+
export class ExtendedLineTool extends AbstractPlugin {
|
|
10
|
+
private zr!: any;
|
|
11
|
+
private state: PluginState = 'idle';
|
|
12
|
+
private startPoint: number[] | null = null;
|
|
13
|
+
private endPoint: number[] | null = null;
|
|
14
|
+
private group: any = null;
|
|
15
|
+
private line: any = null;
|
|
16
|
+
private dashLineForward: any = null;
|
|
17
|
+
private dashLineBackward: any = null;
|
|
18
|
+
private startCircle: any = null;
|
|
19
|
+
private endCircle: any = null;
|
|
20
|
+
|
|
21
|
+
constructor(options: { name?: string; icon?: string } = {}) {
|
|
22
|
+
super({
|
|
23
|
+
id: 'extended-line-tool',
|
|
24
|
+
name: options?.name || 'Extended Line',
|
|
25
|
+
icon: options?.icon || `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="1" y1="23" x2="23" y2="1" stroke-dasharray="2,2" opacity="0.4"/><line x1="6" y1="18" x2="18" y2="6"/></svg>`,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
protected onInit(): void {
|
|
30
|
+
this.zr = this.chart.getZr();
|
|
31
|
+
this.context.registerDrawingRenderer(new ExtendedLineDrawingRenderer());
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
protected onActivate(): void {
|
|
35
|
+
this.state = 'idle';
|
|
36
|
+
this.chart.getZr().setCursorStyle('crosshair');
|
|
37
|
+
this.zr.on('click', this.onClick);
|
|
38
|
+
this.zr.on('mousemove', this.onMouseMove);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
protected onDeactivate(): void {
|
|
42
|
+
this.state = 'idle';
|
|
43
|
+
this.chart.getZr().setCursorStyle('default');
|
|
44
|
+
this.zr.off('click', this.onClick);
|
|
45
|
+
this.zr.off('mousemove', this.onMouseMove);
|
|
46
|
+
this.removeGraphic();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
protected onDestroy(): void {
|
|
50
|
+
this.removeGraphic();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private onClick = (params: any) => {
|
|
54
|
+
if (this.state === 'idle') {
|
|
55
|
+
this.state = 'drawing';
|
|
56
|
+
this.startPoint = this.getPoint(params);
|
|
57
|
+
this.endPoint = this.getPoint(params);
|
|
58
|
+
this.initGraphic();
|
|
59
|
+
this.updateGraphic();
|
|
60
|
+
} else if (this.state === 'drawing') {
|
|
61
|
+
this.state = 'finished';
|
|
62
|
+
this.endPoint = this.getPoint(params);
|
|
63
|
+
|
|
64
|
+
if (this.startPoint && this.endPoint) {
|
|
65
|
+
const start = this.context.coordinateConversion.pixelToData({
|
|
66
|
+
x: this.startPoint[0], y: this.startPoint[1],
|
|
67
|
+
});
|
|
68
|
+
const end = this.context.coordinateConversion.pixelToData({
|
|
69
|
+
x: this.endPoint[0], y: this.endPoint[1],
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
if (start && end) {
|
|
73
|
+
this.context.addDrawing({
|
|
74
|
+
id: `extended-line-${Date.now()}`,
|
|
75
|
+
type: 'extended-line',
|
|
76
|
+
points: [start, end],
|
|
77
|
+
paneIndex: start.paneIndex || 0,
|
|
78
|
+
style: { color: COLOR, lineWidth: 1 },
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this.removeGraphic();
|
|
84
|
+
this.context.disableTools();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
private onMouseMove = (params: any) => {
|
|
89
|
+
if (this.state !== 'drawing') return;
|
|
90
|
+
this.endPoint = this.getPoint(params);
|
|
91
|
+
this.updateGraphic();
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
private initGraphic(): void {
|
|
95
|
+
if (this.group) return;
|
|
96
|
+
this.group = new echarts.graphic.Group();
|
|
97
|
+
this.line = new echarts.graphic.Line({
|
|
98
|
+
shape: { x1: 0, y1: 0, x2: 0, y2: 0 },
|
|
99
|
+
style: { stroke: COLOR, lineWidth: 1 },
|
|
100
|
+
z: 100,
|
|
101
|
+
});
|
|
102
|
+
this.dashLineForward = new echarts.graphic.Line({
|
|
103
|
+
shape: { x1: 0, y1: 0, x2: 0, y2: 0 },
|
|
104
|
+
style: { stroke: COLOR, lineWidth: 1, lineDash: [4, 4], opacity: 0.5 },
|
|
105
|
+
z: 99,
|
|
106
|
+
});
|
|
107
|
+
this.dashLineBackward = new echarts.graphic.Line({
|
|
108
|
+
shape: { x1: 0, y1: 0, x2: 0, y2: 0 },
|
|
109
|
+
style: { stroke: COLOR, lineWidth: 1, lineDash: [4, 4], opacity: 0.5 },
|
|
110
|
+
z: 99,
|
|
111
|
+
});
|
|
112
|
+
this.startCircle = new echarts.graphic.Circle({
|
|
113
|
+
shape: { cx: 0, cy: 0, r: 4 },
|
|
114
|
+
style: { fill: '#fff', stroke: COLOR, lineWidth: 1 },
|
|
115
|
+
z: 101,
|
|
116
|
+
});
|
|
117
|
+
this.endCircle = new echarts.graphic.Circle({
|
|
118
|
+
shape: { cx: 0, cy: 0, r: 4 },
|
|
119
|
+
style: { fill: '#fff', stroke: COLOR, lineWidth: 1 },
|
|
120
|
+
z: 101,
|
|
121
|
+
});
|
|
122
|
+
this.group.add(this.dashLineBackward);
|
|
123
|
+
this.group.add(this.dashLineForward);
|
|
124
|
+
this.group.add(this.line);
|
|
125
|
+
this.group.add(this.startCircle);
|
|
126
|
+
this.group.add(this.endCircle);
|
|
127
|
+
this.zr.add(this.group);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private removeGraphic(): void {
|
|
131
|
+
if (this.group) {
|
|
132
|
+
this.zr.remove(this.group);
|
|
133
|
+
this.group = null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private updateGraphic(): void {
|
|
138
|
+
if (!this.startPoint || !this.endPoint || !this.group) return;
|
|
139
|
+
const [x1, y1] = this.startPoint;
|
|
140
|
+
const [x2, y2] = this.endPoint;
|
|
141
|
+
this.line.setShape({ x1, y1, x2, y2 });
|
|
142
|
+
this.startCircle.setShape({ cx: x1, cy: y1 });
|
|
143
|
+
this.endCircle.setShape({ cx: x2, cy: y2 });
|
|
144
|
+
|
|
145
|
+
const dx = x2 - x1;
|
|
146
|
+
const dy = y2 - y1;
|
|
147
|
+
if (dx === 0 && dy === 0) return;
|
|
148
|
+
|
|
149
|
+
// Dashed extension forward (past p2)
|
|
150
|
+
const [fwX, fwY] = this.extendToEdge(x1, y1, dx, dy);
|
|
151
|
+
this.dashLineForward.setShape({ x1: x2, y1: y2, x2: fwX, y2: fwY });
|
|
152
|
+
|
|
153
|
+
// Dashed extension backward (past p1)
|
|
154
|
+
const [bwX, bwY] = this.extendToEdge(x2, y2, -dx, -dy);
|
|
155
|
+
this.dashLineBackward.setShape({ x1: x1, y1: y1, x2: bwX, y2: bwY });
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private extendToEdge(ox: number, oy: number, dx: number, dy: number): [number, number] {
|
|
159
|
+
const w = this.chart.getWidth();
|
|
160
|
+
const h = this.chart.getHeight();
|
|
161
|
+
let tMax = Infinity;
|
|
162
|
+
if (dx !== 0) {
|
|
163
|
+
const tx = dx > 0 ? (w - ox) / dx : -ox / dx;
|
|
164
|
+
if (tx > 0) tMax = Math.min(tMax, tx);
|
|
165
|
+
}
|
|
166
|
+
if (dy !== 0) {
|
|
167
|
+
const ty = dy > 0 ? (h - oy) / dy : -oy / dy;
|
|
168
|
+
if (ty > 0) tMax = Math.min(tMax, ty);
|
|
169
|
+
}
|
|
170
|
+
if (!isFinite(tMax)) tMax = 1;
|
|
171
|
+
return [ox + tMax * dx, oy + tMax * dy];
|
|
172
|
+
}
|
|
173
|
+
}
|