@qfo/qfchart 0.7.3 → 0.8.1

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.
Files changed (59) hide show
  1. package/dist/index.d.ts +368 -14
  2. package/dist/qfchart.min.browser.js +34 -16
  3. package/dist/qfchart.min.es.js +34 -16
  4. package/package.json +1 -1
  5. package/src/QFChart.ts +460 -311
  6. package/src/components/AbstractPlugin.ts +234 -104
  7. package/src/components/DrawingEditor.ts +297 -248
  8. package/src/components/DrawingRendererRegistry.ts +13 -0
  9. package/src/components/GraphicBuilder.ts +284 -263
  10. package/src/components/LayoutManager.ts +72 -55
  11. package/src/components/SeriesBuilder.ts +110 -6
  12. package/src/components/TableCanvasRenderer.ts +467 -0
  13. package/src/components/TableOverlayRenderer.ts +38 -9
  14. package/src/components/TooltipFormatter.ts +97 -97
  15. package/src/components/renderers/BackgroundRenderer.ts +59 -47
  16. package/src/components/renderers/BoxRenderer.ts +113 -17
  17. package/src/components/renderers/FillRenderer.ts +118 -3
  18. package/src/components/renderers/LabelRenderer.ts +35 -9
  19. package/src/components/renderers/OHLCBarRenderer.ts +171 -161
  20. package/src/components/renderers/PolylineRenderer.ts +26 -19
  21. package/src/index.ts +17 -6
  22. package/src/plugins/ABCDPatternTool/ABCDPatternDrawingRenderer.ts +112 -0
  23. package/src/plugins/ABCDPatternTool/ABCDPatternTool.ts +136 -0
  24. package/src/plugins/ABCDPatternTool/index.ts +2 -0
  25. package/src/plugins/CypherPatternTool/CypherPatternDrawingRenderer.ts +80 -0
  26. package/src/plugins/CypherPatternTool/CypherPatternTool.ts +84 -0
  27. package/src/plugins/CypherPatternTool/index.ts +2 -0
  28. package/src/plugins/FibSpeedResistanceFanTool/FibSpeedResistanceFanDrawingRenderer.ts +163 -0
  29. package/src/plugins/FibSpeedResistanceFanTool/FibSpeedResistanceFanTool.ts +210 -0
  30. package/src/plugins/FibSpeedResistanceFanTool/index.ts +2 -0
  31. package/src/plugins/FibTrendExtensionTool/FibTrendExtensionDrawingRenderer.ts +141 -0
  32. package/src/plugins/FibTrendExtensionTool/FibTrendExtensionTool.ts +188 -0
  33. package/src/plugins/FibTrendExtensionTool/index.ts +2 -0
  34. package/src/plugins/FibonacciChannelTool/FibonacciChannelDrawingRenderer.ts +128 -0
  35. package/src/plugins/FibonacciChannelTool/FibonacciChannelTool.ts +231 -0
  36. package/src/plugins/FibonacciChannelTool/index.ts +2 -0
  37. package/src/plugins/FibonacciTool/FibonacciDrawingRenderer.ts +107 -0
  38. package/src/plugins/{FibonacciTool.ts → FibonacciTool/FibonacciTool.ts} +195 -192
  39. package/src/plugins/FibonacciTool/index.ts +2 -0
  40. package/src/plugins/HeadAndShouldersTool/HeadAndShouldersDrawingRenderer.ts +95 -0
  41. package/src/plugins/HeadAndShouldersTool/HeadAndShouldersTool.ts +97 -0
  42. package/src/plugins/HeadAndShouldersTool/index.ts +2 -0
  43. package/src/plugins/LineTool/LineDrawingRenderer.ts +49 -0
  44. package/src/plugins/{LineTool.ts → LineTool/LineTool.ts} +161 -190
  45. package/src/plugins/LineTool/index.ts +2 -0
  46. package/src/plugins/{MeasureTool.ts → MeasureTool/MeasureTool.ts} +324 -344
  47. package/src/plugins/MeasureTool/index.ts +1 -0
  48. package/src/plugins/ThreeDrivesPatternTool/ThreeDrivesPatternDrawingRenderer.ts +106 -0
  49. package/src/plugins/ThreeDrivesPatternTool/ThreeDrivesPatternTool.ts +98 -0
  50. package/src/plugins/ThreeDrivesPatternTool/index.ts +2 -0
  51. package/src/plugins/ToolGroup.ts +211 -0
  52. package/src/plugins/TrianglePatternTool/TrianglePatternDrawingRenderer.ts +107 -0
  53. package/src/plugins/TrianglePatternTool/TrianglePatternTool.ts +98 -0
  54. package/src/plugins/TrianglePatternTool/index.ts +2 -0
  55. package/src/plugins/XABCDPatternTool/XABCDPatternDrawingRenderer.ts +178 -0
  56. package/src/plugins/XABCDPatternTool/XABCDPatternTool.ts +213 -0
  57. package/src/plugins/XABCDPatternTool/index.ts +2 -0
  58. package/src/types.ts +39 -4
  59. package/src/utils/ColorUtils.ts +1 -1
package/dist/index.d.ts CHANGED
@@ -95,6 +95,7 @@ interface QFChartOptions {
95
95
  };
96
96
  dataZoom?: {
97
97
  visible?: boolean;
98
+ pannable?: boolean;
98
99
  position?: 'top' | 'bottom';
99
100
  height?: number;
100
101
  start?: number;
@@ -105,9 +106,18 @@ interface QFChartOptions {
105
106
  position: 'floating' | 'left' | 'right';
106
107
  triggerOn?: 'mousemove' | 'click' | 'none';
107
108
  };
109
+ grid?: {
110
+ show?: boolean;
111
+ lineColor?: string;
112
+ lineOpacity?: number;
113
+ borderColor?: string;
114
+ borderShow?: boolean;
115
+ };
108
116
  layout?: {
109
- mainPaneHeight: string;
110
- gap: number;
117
+ mainPaneHeight?: string;
118
+ gap?: number;
119
+ left?: string;
120
+ right?: string;
111
121
  };
112
122
  watermark?: boolean;
113
123
  }
@@ -138,8 +148,10 @@ interface ChartContext {
138
148
  updateDrawing(drawing: DrawingElement): void;
139
149
  lockChart(): void;
140
150
  unlockChart(): void;
151
+ registerDrawingRenderer(renderer: DrawingRenderer): void;
152
+ snapToCandle(point: Coordinate): Coordinate;
141
153
  }
142
- type DrawingType = 'line' | 'fibonacci';
154
+ type DrawingType = string;
143
155
  interface DrawingElement {
144
156
  id: string;
145
157
  type: DrawingType;
@@ -150,6 +162,21 @@ interface DrawingElement {
150
162
  lineWidth?: number;
151
163
  };
152
164
  }
165
+ interface DrawingRenderContext {
166
+ drawing: DrawingElement;
167
+ /** Pixel coords for each point, in the same order as drawing.points */
168
+ pixelPoints: [number, number][];
169
+ /** Whether this drawing is currently selected */
170
+ isSelected: boolean;
171
+ /** The ECharts custom series api object */
172
+ api: any;
173
+ }
174
+ interface DrawingRenderer {
175
+ /** The drawing type this renderer handles */
176
+ type: string;
177
+ /** Return an ECharts custom series renderItem group element */
178
+ render(ctx: DrawingRenderContext): any;
179
+ }
153
180
  interface PluginConfig {
154
181
  id: string;
155
182
  name?: string;
@@ -244,6 +271,7 @@ declare class QFChart implements ChartContext {
244
271
  private countdownInterval;
245
272
  private selectedDrawingId;
246
273
  private drawings;
274
+ private drawingRenderers;
247
275
  coordinateConversion: {
248
276
  pixelToData: (point: {
249
277
  x: number;
@@ -267,6 +295,12 @@ declare class QFChart implements ChartContext {
267
295
  private readonly defaultPadding;
268
296
  private padding;
269
297
  private dataIndexOffset;
298
+ private _paddingPoints;
299
+ private readonly LAZY_MIN_PADDING;
300
+ private readonly LAZY_MAX_PADDING;
301
+ private readonly LAZY_CHUNK_SIZE;
302
+ private readonly LAZY_EDGE_THRESHOLD;
303
+ private _expandScheduled;
270
304
  private rootContainer;
271
305
  private layoutContainer;
272
306
  private toolbarContainer;
@@ -275,6 +309,9 @@ declare class QFChart implements ChartContext {
275
309
  private chartContainer;
276
310
  private overlayContainer;
277
311
  private _lastTables;
312
+ private _tableGraphicIds;
313
+ private _baseGraphics;
314
+ private _labelTooltipEl;
278
315
  private _lastLayout;
279
316
  private _mainHeightOverride;
280
317
  private _paneDragState;
@@ -290,6 +327,14 @@ declare class QFChart implements ChartContext {
290
327
  getOptions(): QFChartOptions;
291
328
  disableTools(): void;
292
329
  registerPlugin(plugin: Plugin): void;
330
+ registerDrawingRenderer(renderer: DrawingRenderer): void;
331
+ snapToCandle(point: {
332
+ x: number;
333
+ y: number;
334
+ }): {
335
+ x: number;
336
+ y: number;
337
+ };
293
338
  addDrawing(drawing: DrawingElement): void;
294
339
  removeDrawing(id: string): void;
295
340
  getDrawing(id: string): DrawingElement | undefined;
@@ -363,9 +408,38 @@ declare class QFChart implements ChartContext {
363
408
  removeIndicator(id: string): void;
364
409
  toggleIndicator(id: string, action?: 'collapse' | 'maximize' | 'fullscreen'): void;
365
410
  resize(): void;
411
+ /**
412
+ * Build table canvas graphic elements from the current _lastTables.
413
+ * Must be called AFTER setOption so grid rects are available from ECharts.
414
+ * Returns an array of ECharts graphic elements.
415
+ */
416
+ private _buildTableGraphics;
417
+ /**
418
+ * Render table overlays after a non-replacing setOption (updateData, resize).
419
+ * Uses replaceMerge to cleanly replace all graphic elements without disrupting
420
+ * other interactive components (dataZoom, tooltip, etc.).
421
+ */
366
422
  private _renderTableOverlays;
367
423
  destroy(): void;
368
424
  private rebuildTimeIndex;
425
+ /**
426
+ * Expand symmetric padding to the given number of points per side.
427
+ * No-op if newPaddingPoints <= current. Performs a full render() and
428
+ * restores the viewport position so there is no visual jump.
429
+ */
430
+ expandPadding(newPaddingPoints: number): void;
431
+ /**
432
+ * Resize symmetric padding to the given number of points per side.
433
+ * Works for both growing and shrinking. Clamps to [min, max].
434
+ * Uses merge-mode setOption to preserve drag/interaction state.
435
+ */
436
+ private _resizePadding;
437
+ /**
438
+ * Check if user scrolled near an edge (expand) or away from edges (contract).
439
+ * Uses requestAnimationFrame to avoid cascading re-renders inside
440
+ * the ECharts dataZoom event callback.
441
+ */
442
+ private _checkEdgeAndExpand;
369
443
  private render;
370
444
  }
371
445
 
@@ -375,6 +449,13 @@ declare abstract class AbstractPlugin implements Plugin {
375
449
  icon?: string;
376
450
  protected context: ChartContext;
377
451
  private eventListeners;
452
+ private _snapIndicator;
453
+ private _snapMoveHandler;
454
+ private _snapKeyDownHandler;
455
+ private _snapKeyUpHandler;
456
+ private _snapBlurHandler;
457
+ private _snapActive;
458
+ private _lastMouseEvent;
378
459
  constructor(config: PluginConfig);
379
460
  init(context: ChartContext): void;
380
461
  /**
@@ -417,6 +498,16 @@ declare abstract class AbstractPlugin implements Plugin {
417
498
  * Access to market data.
418
499
  */
419
500
  protected get marketData(): OHLCV[];
501
+ /**
502
+ * Get the event point coordinates, snapping to nearest candle OHLC if Ctrl is held.
503
+ * Use this instead of [params.offsetX, params.offsetY] in click/mousemove handlers.
504
+ */
505
+ protected getPoint(params: any): [number, number];
506
+ private _bindSnapIndicator;
507
+ private _unbindSnapIndicator;
508
+ private _removeSnapGraphic;
509
+ private _showSnapAt;
510
+ private _hideSnap;
420
511
  }
421
512
 
422
513
  declare class MeasureTool extends AbstractPlugin {
@@ -432,7 +523,7 @@ declare class MeasureTool extends AbstractPlugin {
432
523
  private lineH;
433
524
  private arrowStart;
434
525
  private arrowEnd;
435
- constructor(options: {
526
+ constructor(options?: {
436
527
  name?: string;
437
528
  icon?: string;
438
529
  });
@@ -461,7 +552,7 @@ declare class LineTool extends AbstractPlugin {
461
552
  private line;
462
553
  private startCircle;
463
554
  private endCircle;
464
- constructor(options: {
555
+ constructor(options?: {
465
556
  name?: string;
466
557
  icon?: string;
467
558
  });
@@ -469,20 +560,18 @@ declare class LineTool extends AbstractPlugin {
469
560
  protected onActivate(): void;
470
561
  protected onDeactivate(): void;
471
562
  protected onDestroy(): void;
472
- private onMouseDown;
473
- private onChartInteraction;
474
563
  private onClick;
475
- private saveDataCoordinates;
476
- private updateGraphicFromData;
477
- private enableClearListeners;
478
- private clearHandlers;
479
- private disableClearListeners;
480
564
  private onMouseMove;
481
565
  private initGraphic;
482
566
  private removeGraphic;
483
567
  private updateGraphic;
484
568
  }
485
569
 
570
+ declare class LineDrawingRenderer implements DrawingRenderer {
571
+ type: string;
572
+ render(ctx: DrawingRenderContext): any;
573
+ }
574
+
486
575
  declare class FibonacciTool extends AbstractPlugin {
487
576
  private startPoint;
488
577
  private endPoint;
@@ -494,6 +583,37 @@ declare class FibonacciTool extends AbstractPlugin {
494
583
  name?: string;
495
584
  icon?: string;
496
585
  });
586
+ protected onInit(): void;
587
+ onActivate(): void;
588
+ onDeactivate(): void;
589
+ private bindEvents;
590
+ private unbindEvents;
591
+ private onClick;
592
+ private onMouseMove;
593
+ private initGraphic;
594
+ private removeGraphic;
595
+ private updateGraphic;
596
+ private saveDrawing;
597
+ }
598
+
599
+ declare class FibonacciDrawingRenderer implements DrawingRenderer {
600
+ type: string;
601
+ render(ctx: DrawingRenderContext): any;
602
+ }
603
+
604
+ declare class FibonacciChannelTool extends AbstractPlugin {
605
+ private startPoint;
606
+ private endPoint;
607
+ private widthPoint;
608
+ private state;
609
+ private graphicGroup;
610
+ private readonly levels;
611
+ private readonly colors;
612
+ constructor(options?: {
613
+ name?: string;
614
+ icon?: string;
615
+ });
616
+ protected onInit(): void;
497
617
  onActivate(): void;
498
618
  onDeactivate(): void;
499
619
  private bindEvents;
@@ -506,5 +626,239 @@ declare class FibonacciTool extends AbstractPlugin {
506
626
  private saveDrawing;
507
627
  }
508
628
 
509
- export { AbstractPlugin, FibonacciTool, LineTool, MeasureTool, QFChart };
510
- export type { ChartContext, Coordinate, DataCoordinate, DrawingElement, DrawingType, Indicator$1 as Indicator, IndicatorOptions, IndicatorPlot, IndicatorPoint, IndicatorStyle, OHLCV, Plugin, PluginConfig, QFChartOptions };
629
+ declare class FibonacciChannelDrawingRenderer implements DrawingRenderer {
630
+ type: string;
631
+ render(ctx: DrawingRenderContext): any;
632
+ }
633
+
634
+ declare class FibSpeedResistanceFanTool extends AbstractPlugin {
635
+ private startPoint;
636
+ private endPoint;
637
+ private state;
638
+ private graphicGroup;
639
+ constructor(options?: {
640
+ name?: string;
641
+ icon?: string;
642
+ });
643
+ protected onInit(): void;
644
+ protected onActivate(): void;
645
+ protected onDeactivate(): void;
646
+ private bindEvents;
647
+ private unbindEvents;
648
+ private onClick;
649
+ private onMouseMove;
650
+ private initGraphic;
651
+ private removeGraphic;
652
+ private updateGraphic;
653
+ private saveDrawing;
654
+ }
655
+
656
+ declare class FibSpeedResistanceFanDrawingRenderer implements DrawingRenderer {
657
+ type: string;
658
+ render(ctx: DrawingRenderContext): any;
659
+ }
660
+
661
+ declare class FibTrendExtensionTool extends AbstractPlugin {
662
+ private points;
663
+ private state;
664
+ private graphicGroup;
665
+ constructor(options?: {
666
+ name?: string;
667
+ icon?: string;
668
+ });
669
+ protected onInit(): void;
670
+ protected onActivate(): void;
671
+ protected onDeactivate(): void;
672
+ private bindEvents;
673
+ private unbindEvents;
674
+ private onClick;
675
+ private onMouseMove;
676
+ private initGraphic;
677
+ private removeGraphic;
678
+ private updateGraphic;
679
+ private saveDrawing;
680
+ }
681
+
682
+ declare class FibTrendExtensionDrawingRenderer implements DrawingRenderer {
683
+ type: string;
684
+ render(ctx: DrawingRenderContext): any;
685
+ }
686
+
687
+ declare class XABCDPatternTool extends AbstractPlugin {
688
+ private points;
689
+ private state;
690
+ private graphicGroup;
691
+ constructor(options?: {
692
+ name?: string;
693
+ icon?: string;
694
+ });
695
+ protected onInit(): void;
696
+ protected onActivate(): void;
697
+ protected onDeactivate(): void;
698
+ private bindEvents;
699
+ private unbindEvents;
700
+ private onClick;
701
+ private onMouseMove;
702
+ private initGraphic;
703
+ private removeGraphic;
704
+ private updateGraphic;
705
+ private saveDrawing;
706
+ }
707
+
708
+ declare class XABCDPatternDrawingRenderer implements DrawingRenderer {
709
+ type: string;
710
+ render(ctx: DrawingRenderContext): any;
711
+ }
712
+
713
+ declare class ABCDPatternTool extends AbstractPlugin {
714
+ private points;
715
+ private state;
716
+ private graphicGroup;
717
+ constructor(options?: {
718
+ name?: string;
719
+ icon?: string;
720
+ });
721
+ protected onInit(): void;
722
+ protected onActivate(): void;
723
+ protected onDeactivate(): void;
724
+ private onClick;
725
+ private onMouseMove;
726
+ private initGraphic;
727
+ private removeGraphic;
728
+ private updateGraphic;
729
+ private saveDrawing;
730
+ }
731
+
732
+ declare class ABCDPatternDrawingRenderer implements DrawingRenderer {
733
+ type: string;
734
+ render(ctx: DrawingRenderContext): any;
735
+ }
736
+
737
+ declare class CypherPatternTool extends AbstractPlugin {
738
+ private points;
739
+ private state;
740
+ private graphicGroup;
741
+ constructor(options?: {
742
+ name?: string;
743
+ icon?: string;
744
+ });
745
+ protected onInit(): void;
746
+ protected onActivate(): void;
747
+ protected onDeactivate(): void;
748
+ private onClick;
749
+ private onMouseMove;
750
+ private initGraphic;
751
+ private removeGraphic;
752
+ private updateGraphic;
753
+ private saveDrawing;
754
+ }
755
+
756
+ declare class CypherPatternDrawingRenderer implements DrawingRenderer {
757
+ type: string;
758
+ render(ctx: DrawingRenderContext): any;
759
+ }
760
+
761
+ declare class HeadAndShouldersTool extends AbstractPlugin {
762
+ private points;
763
+ private state;
764
+ private graphicGroup;
765
+ constructor(options?: {
766
+ name?: string;
767
+ icon?: string;
768
+ });
769
+ protected onInit(): void;
770
+ protected onActivate(): void;
771
+ protected onDeactivate(): void;
772
+ private onClick;
773
+ private onMouseMove;
774
+ private initGraphic;
775
+ private removeGraphic;
776
+ private updateGraphic;
777
+ private saveDrawing;
778
+ }
779
+
780
+ declare class HeadAndShouldersDrawingRenderer implements DrawingRenderer {
781
+ type: string;
782
+ render(ctx: DrawingRenderContext): any;
783
+ }
784
+
785
+ declare class TrianglePatternTool extends AbstractPlugin {
786
+ private points;
787
+ private state;
788
+ private graphicGroup;
789
+ constructor(options?: {
790
+ name?: string;
791
+ icon?: string;
792
+ });
793
+ protected onInit(): void;
794
+ protected onActivate(): void;
795
+ protected onDeactivate(): void;
796
+ private onClick;
797
+ private onMouseMove;
798
+ private initGraphic;
799
+ private removeGraphic;
800
+ private updateGraphic;
801
+ private saveDrawing;
802
+ }
803
+
804
+ declare class TrianglePatternDrawingRenderer implements DrawingRenderer {
805
+ type: string;
806
+ render(ctx: DrawingRenderContext): any;
807
+ }
808
+
809
+ declare class ThreeDrivesPatternTool extends AbstractPlugin {
810
+ private points;
811
+ private state;
812
+ private graphicGroup;
813
+ constructor(options?: {
814
+ name?: string;
815
+ icon?: string;
816
+ });
817
+ protected onInit(): void;
818
+ protected onActivate(): void;
819
+ protected onDeactivate(): void;
820
+ private onClick;
821
+ private onMouseMove;
822
+ private initGraphic;
823
+ private removeGraphic;
824
+ private updateGraphic;
825
+ private saveDrawing;
826
+ }
827
+
828
+ declare class ThreeDrivesPatternDrawingRenderer implements DrawingRenderer {
829
+ type: string;
830
+ render(ctx: DrawingRenderContext): any;
831
+ }
832
+
833
+ interface ToolGroupConfig extends Omit<PluginConfig, 'id'> {
834
+ id?: string;
835
+ name: string;
836
+ icon?: string;
837
+ }
838
+ declare class ToolGroup extends AbstractPlugin {
839
+ private plugins;
840
+ private activeSubPlugin;
841
+ private menuElement;
842
+ private buttonElement;
843
+ private originalIcon;
844
+ private arrowSvg;
845
+ constructor(config: ToolGroupConfig);
846
+ add(plugin: Plugin): void;
847
+ protected onInit(): void;
848
+ protected onActivate(): void;
849
+ protected onDeactivate(): void;
850
+ protected onDestroy(): void;
851
+ private showMenu;
852
+ private hideMenu;
853
+ private handleOutsideClick;
854
+ private activateSubPlugin;
855
+ }
856
+
857
+ declare class DrawingRendererRegistry {
858
+ private renderers;
859
+ register(renderer: DrawingRenderer): void;
860
+ get(type: string): DrawingRenderer | undefined;
861
+ }
862
+
863
+ export { ABCDPatternDrawingRenderer, ABCDPatternTool, AbstractPlugin, CypherPatternDrawingRenderer, CypherPatternTool, DrawingRendererRegistry, FibSpeedResistanceFanDrawingRenderer, FibSpeedResistanceFanTool, FibTrendExtensionDrawingRenderer, FibTrendExtensionTool, FibonacciChannelDrawingRenderer, FibonacciChannelTool, FibonacciDrawingRenderer, FibonacciTool, HeadAndShouldersDrawingRenderer, HeadAndShouldersTool, LineDrawingRenderer, LineTool, MeasureTool, QFChart, ThreeDrivesPatternDrawingRenderer, ThreeDrivesPatternTool, ToolGroup, TrianglePatternDrawingRenderer, TrianglePatternTool, XABCDPatternDrawingRenderer, XABCDPatternTool };
864
+ export type { ChartContext, Coordinate, DataCoordinate, DrawingElement, DrawingRenderContext, DrawingRenderer, DrawingType, Indicator$1 as Indicator, IndicatorOptions, IndicatorPlot, IndicatorPoint, IndicatorStyle, OHLCV, Plugin, PluginConfig, QFChartOptions, ToolGroupConfig };