@363045841yyt/klinechart 0.4.0 → 0.4.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.
Files changed (68) hide show
  1. package/README.md +6 -0
  2. package/dist/index.cjs +9 -9
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +2212 -1654
  5. package/dist/klinechart.css +1 -1
  6. package/dist/src/api/data/baostock.d.ts +1 -1
  7. package/dist/src/api/data/kLine.d.ts +1 -1
  8. package/dist/src/api/data/types.d.ts +1 -1
  9. package/dist/src/api/data/unified.d.ts +1 -1
  10. package/dist/src/components/IndicatorSelector.vue.d.ts +2 -0
  11. package/dist/src/components/KLineChart.vue.d.ts +2 -2
  12. package/dist/src/components/KLineTooltip.vue.d.ts +1 -1
  13. package/dist/src/components/MarkerTooltip.vue.d.ts +1 -1
  14. package/dist/src/core/chart.d.ts +39 -13
  15. package/dist/src/core/controller/interaction.d.ts +12 -6
  16. package/dist/src/core/layout/pane.d.ts +12 -5
  17. package/dist/src/core/paneRenderer.d.ts +0 -4
  18. package/dist/src/core/renderers/Indicator/boll.d.ts +2 -2
  19. package/dist/src/core/renderers/Indicator/cci.d.ts +7 -3
  20. package/dist/src/core/renderers/Indicator/ene.d.ts +2 -2
  21. package/dist/src/core/renderers/Indicator/expma.d.ts +2 -2
  22. package/dist/src/core/renderers/Indicator/fastk.d.ts +7 -3
  23. package/dist/src/core/renderers/Indicator/index.d.ts +1 -1
  24. package/dist/src/core/renderers/Indicator/kst.d.ts +7 -3
  25. package/dist/src/core/renderers/Indicator/ma.d.ts +1 -1
  26. package/dist/src/core/renderers/Indicator/macd.d.ts +2 -2
  27. package/dist/src/core/renderers/Indicator/macdLegend.d.ts +1 -1
  28. package/dist/src/core/renderers/Indicator/mainIndicatorLegend.d.ts +1 -1
  29. package/dist/src/core/renderers/Indicator/mom.d.ts +7 -3
  30. package/dist/src/core/renderers/Indicator/rsi.d.ts +7 -3
  31. package/dist/src/core/renderers/Indicator/scale/cci_scale.d.ts +5 -0
  32. package/dist/src/core/renderers/Indicator/scale/fastk_scale.d.ts +5 -0
  33. package/dist/src/core/renderers/Indicator/scale/indicator_scale.d.ts +23 -0
  34. package/dist/src/core/renderers/Indicator/scale/kst_scale.d.ts +5 -0
  35. package/dist/src/core/renderers/Indicator/scale/macd_scale.d.ts +1 -1
  36. package/dist/src/core/renderers/Indicator/scale/mom_scale.d.ts +5 -0
  37. package/dist/src/core/renderers/Indicator/scale/rsi_scale.d.ts +5 -0
  38. package/dist/src/core/renderers/Indicator/scale/stoch_scale.d.ts +5 -0
  39. package/dist/src/core/renderers/Indicator/scale/wmsr_scale.d.ts +5 -0
  40. package/dist/src/core/renderers/Indicator/stoch.d.ts +7 -3
  41. package/dist/src/core/renderers/Indicator/wmsr.d.ts +7 -3
  42. package/dist/src/core/renderers/candle.d.ts +3 -3
  43. package/dist/src/core/renderers/crosshair.d.ts +1 -1
  44. package/dist/src/core/renderers/customMarkers.d.ts +1 -1
  45. package/dist/src/core/renderers/extremaMarkers.d.ts +1 -1
  46. package/dist/src/core/renderers/gridLines.d.ts +1 -1
  47. package/dist/src/core/renderers/lastPrice.d.ts +1 -1
  48. package/dist/src/core/renderers/paneTitle.d.ts +1 -1
  49. package/dist/src/core/renderers/subVolume.d.ts +1 -1
  50. package/dist/src/core/renderers/timeAxis.d.ts +1 -1
  51. package/dist/src/core/renderers/yAxis.d.ts +3 -2
  52. package/dist/src/core/viewport/viewport.d.ts +2 -2
  53. package/dist/src/plugin/HookSystem.d.ts +3 -3
  54. package/dist/src/plugin/PluginHost.d.ts +6 -5
  55. package/dist/src/plugin/rendererPluginManager.d.ts +6 -2
  56. package/dist/src/plugin/types.d.ts +25 -2
  57. package/dist/src/semantic/controller.d.ts +1 -1
  58. package/dist/src/utils/kLineDraw/MA.d.ts +1 -1
  59. package/dist/src/utils/kLineDraw/axis.d.ts +5 -1
  60. package/dist/src/utils/kLineDraw/grid.d.ts +1 -1
  61. package/dist/src/utils/kLineDraw/kLine.d.ts +1 -1
  62. package/dist/src/utils/kline/format.d.ts +2 -2
  63. package/dist/src/utils/kline/ma.d.ts +1 -1
  64. package/dist/src/utils/kline/viewport.d.ts +1 -1
  65. package/dist/src/utils/mock/genRandomPriceData.d.ts +1 -1
  66. package/dist/src/utils/volumePrice.d.ts +2 -2
  67. package/package.json +1 -1
  68. /package/dist/{semantic → src/semantic}/schema.json.d.ts +0 -0
@@ -1,5 +1,5 @@
1
- import { RendererPlugin } from '../../../../plugin';
2
- import { KLineData } from '../../../../types/price';
1
+ import { RendererPluginWithHost, BaseIndicatorState } from '../../../plugin';
2
+ import { KLineData } from '../../../types/price';
3
3
  export interface STOCHConfig {
4
4
  /** K 周期(默认 9) */
5
5
  n?: number;
@@ -14,6 +14,10 @@ interface STOCHPoint {
14
14
  k: number;
15
15
  d: number;
16
16
  }
17
+ export interface STOCHRenderState extends BaseIndicatorState {
18
+ valueMin: number;
19
+ valueMax: number;
20
+ }
17
21
  export interface STOCHRendererOptions {
18
22
  /** 目标 pane ID(默认 'sub') */
19
23
  paneId?: string;
@@ -23,7 +27,7 @@ export interface STOCHRendererOptions {
23
27
  /**
24
28
  * 创建 STOCH 渲染器插件
25
29
  */
26
- export declare function createSTOCHRendererPlugin(options?: STOCHRendererOptions): RendererPlugin;
30
+ export declare function createSTOCHRendererPlugin(options?: STOCHRendererOptions): RendererPluginWithHost;
27
31
  /**
28
32
  * 计算指定索引处的 STOCH 值
29
33
  */
@@ -1,11 +1,15 @@
1
- import { RendererPlugin } from '../../../../plugin';
2
- import { KLineData } from '../../../../types/price';
1
+ import { RendererPluginWithHost, BaseIndicatorState } from '../../../plugin';
2
+ import { KLineData } from '../../../types/price';
3
3
  export interface WMSRConfig {
4
4
  /** 周期(默认 14) */
5
5
  period?: number;
6
6
  /** 是否显示 WMSR 线 */
7
7
  showWMSR?: boolean;
8
8
  }
9
+ export interface WMSRRenderState extends BaseIndicatorState {
10
+ valueMin: number;
11
+ valueMax: number;
12
+ }
9
13
  export interface WMSRRendererOptions {
10
14
  /** 目标 pane ID(默认 'sub') */
11
15
  paneId?: string;
@@ -15,7 +19,7 @@ export interface WMSRRendererOptions {
15
19
  /**
16
20
  * 创建 WMSR 渲染器插件
17
21
  */
18
- export declare function createWMSRRendererPlugin(options?: WMSRRendererOptions): RendererPlugin;
22
+ export declare function createWMSRRendererPlugin(options?: WMSRRendererOptions): RendererPluginWithHost;
19
23
  /**
20
24
  * 计算指定索引处的 WMSR 值
21
25
  */
@@ -1,6 +1,6 @@
1
- import { RendererPlugin } from '../../../plugin';
2
- import { VolumePriceRelation } from '../../../types/volumePrice';
3
- import { MarkerManager } from '../../../core/marker/registry';
1
+ import { RendererPlugin } from '../../plugin';
2
+ import { VolumePriceRelation } from '../../types/volumePrice';
3
+ import { MarkerManager } from '../marker/registry';
4
4
  /**
5
5
  * 创建 K 线蜡烛图渲染器插件
6
6
  */
@@ -1,4 +1,4 @@
1
- import { RendererPlugin } from '../../../plugin';
1
+ import { RendererPlugin } from '../../plugin';
2
2
  /**
3
3
  * 创建十字线渲染器插件
4
4
  * 垂直线绘制到所有面板,水平线只绘制到活跃面板
@@ -1,4 +1,4 @@
1
- import { RendererPlugin } from '../../../plugin';
1
+ import { RendererPlugin } from '../../plugin';
2
2
  /**
3
3
  * 创建自定义标记渲染器插件
4
4
  * 负责渲染 semanticConfig 中配置的 customMarkers
@@ -1,4 +1,4 @@
1
- import { RendererPlugin } from '../../../plugin';
1
+ import { RendererPlugin } from '../../plugin';
2
2
  /**
3
3
  * 创建可视区最高/最低价标注渲染器插件
4
4
  */
@@ -1,4 +1,4 @@
1
- import { RendererPlugin } from '../../../plugin';
1
+ import { RendererPlugin } from '../../plugin';
2
2
  /**
3
3
  * 创建网格线渲染器插件
4
4
  * 横向按像素均分铺满整个绘图区高度,纵向按月分割(使用预计算的月边界,网格线对齐到K线实体中部)
@@ -1,4 +1,4 @@
1
- import { RendererPlugin } from '../../../plugin';
1
+ import { RendererPlugin } from '../../plugin';
2
2
  /**
3
3
  * 创建最新价虚线渲染器插件
4
4
  */
@@ -1,4 +1,4 @@
1
- import { RendererPlugin } from '../../../plugin';
1
+ import { RendererPlugin } from '../../plugin';
2
2
  /**
3
3
  * 单个数值项
4
4
  */
@@ -1,4 +1,4 @@
1
- import { RendererPlugin } from '../../../plugin';
1
+ import { RendererPlugin } from '../../plugin';
2
2
  export interface VolumeRendererOptions {
3
3
  /** 目标 pane ID(默认 'sub') */
4
4
  paneId?: string;
@@ -1,4 +1,4 @@
1
- import { RendererPlugin } from '../../../plugin';
1
+ import { RendererPlugin } from '../../plugin';
2
2
  /** 时间轴面板 ID(特殊标识,用于单独渲染) */
3
3
  export declare const TIME_AXIS_PANE_ID: unique symbol;
4
4
  /**
@@ -1,7 +1,7 @@
1
- import { RendererPlugin } from '../../../plugin';
1
+ import { RendererPlugin } from '../../plugin';
2
2
  /**
3
3
  * 创建 Y 轴渲染器插件
4
- * 渲染到所有面板的 Y 轴区域
4
+ * pane capability 决定是否绘制刻度与价格标签
5
5
  */
6
6
  export declare function createYAxisRendererPlugin(options: {
7
7
  axisWidth: number;
@@ -9,5 +9,6 @@ export declare function createYAxisRendererPlugin(options: {
9
9
  getCrosshair?: () => {
10
10
  y: number;
11
11
  price: number;
12
+ activePaneId: string | null;
12
13
  } | null;
13
14
  }): RendererPlugin;
@@ -1,5 +1,5 @@
1
- import { KLineData } from '../../../types/price';
2
- import { PriceRange } from '../../../core/scale/price';
1
+ import { KLineData } from '../../types/price';
2
+ import { PriceRange } from '../scale/price';
3
3
  /**
4
4
  * 计算当前视口可见的 K 线索引范围(使用物理像素对齐)。
5
5
  *
@@ -1,4 +1,4 @@
1
- import { HookFn } from './types';
1
+ import { HookCallOptions, HookFn } from './types';
2
2
  export declare class HookSystem {
3
3
  private hooks;
4
4
  /**
@@ -12,11 +12,11 @@ export declare class HookSystem {
12
12
  /**
13
13
  * 触发钩子(异步)
14
14
  */
15
- call<T = unknown, R = unknown>(hookName: string, context: T): Promise<R[]>;
15
+ call<T = unknown, R = unknown>(hookName: string, context: T, options?: HookCallOptions): Promise<R[]>;
16
16
  /**
17
17
  * 触发钩子(同步)
18
18
  */
19
- callSync<T = unknown, R = unknown>(hookName: string, context: T): R[];
19
+ callSync<T = unknown, R = unknown>(hookName: string, context: T, options?: HookCallOptions): R[];
20
20
  /**
21
21
  * 清除所有钩子
22
22
  */
@@ -1,4 +1,4 @@
1
- import { Plugin, PluginConfig, PluginHost, PluginState, BaseIndicatorState } from './types';
1
+ import { Plugin, PluginConfig, PluginHost, PluginState, BaseIndicatorState, PluginLogger, HookCallOptions } from './types';
2
2
  export declare class PluginHostImpl implements PluginHost {
3
3
  private registry;
4
4
  private eventBus;
@@ -6,7 +6,8 @@ export declare class PluginHostImpl implements PluginHost {
6
6
  private configManager;
7
7
  private stateStore;
8
8
  private isDestroyed;
9
- constructor();
9
+ private logger;
10
+ constructor(logger?: PluginLogger);
10
11
  readonly events: {
11
12
  on: <T = unknown>(event: string, handler: (data: T) => void) => void;
12
13
  off: <T = unknown>(event: string, handler: (data: T) => void) => void;
@@ -16,8 +17,8 @@ export declare class PluginHostImpl implements PluginHost {
16
17
  readonly hooks: {
17
18
  tap: <T = unknown, R = unknown>(hookName: string, fn: (context: T) => R | Promise<R>, priority?: number) => void;
18
19
  untap: (hookName: string, fn: (context: unknown) => unknown) => void;
19
- call: <T = unknown, R = unknown>(hookName: string, context: T) => Promise<R[]>;
20
- callSync: <T = unknown, R = unknown>(hookName: string, context: T) => R[];
20
+ call: <T = unknown, R = unknown>(hookName: string, context: T, options?: HookCallOptions) => Promise<R[]>;
21
+ callSync: <T = unknown, R = unknown>(hookName: string, context: T, options?: HookCallOptions) => R[];
21
22
  };
22
23
  getConfig<K = unknown>(pluginName: string, key: string, defaultValue?: K): K;
23
24
  setConfig(pluginName: string, key: string, value: unknown): void;
@@ -50,4 +51,4 @@ export declare class PluginHostImpl implements PluginHost {
50
51
  destroy(): Promise<void>;
51
52
  private ensureNotDestroyed;
52
53
  }
53
- export declare function createPluginHost(): PluginHostImpl;
54
+ export declare function createPluginHost(logger?: PluginLogger): PluginHostImpl;
@@ -34,8 +34,8 @@ export declare class RendererPluginManager {
34
34
  addKnownPaneId(paneId: string): void;
35
35
  /** 移除 paneId */
36
36
  removeKnownPaneId(paneId: string): void;
37
- /** 获取所有已知的 paneId */
38
- getKnownPaneIds(): string[];
37
+ /** 覆盖已知 paneId 集合 */
38
+ setKnownPaneIds(paneIds: string[]): void;
39
39
  /** 注册渲染器插件 */
40
40
  register(plugin: RendererPlugin | RendererPluginWithHost): void;
41
41
  /** 移除渲染器插件 */
@@ -49,6 +49,10 @@ export declare class RendererPluginManager {
49
49
  private mergeSorted;
50
50
  /** 重建缓存(统一管理所有缓存逻辑) */
51
51
  private rebuildCache;
52
+ /** 判断渲染器是否启用 */
53
+ private isRendererEnabled;
54
+ /** 获取指定 pane 的合并渲染器(包含 system 渲染器) */
55
+ private getMergedRenderers;
52
56
  /** 获取指定 pane 的渲染器(已缓存,无穿透) */
53
57
  getRenderers(paneId: string): RendererPlugin[];
54
58
  /** 渲染指定 pane(带错误隔离) */
@@ -36,6 +36,10 @@ export interface PluginDescriptor {
36
36
  }
37
37
  /** Hook 函数类型 */
38
38
  export type HookFn<T = unknown, R = unknown> = (context: T) => R | Promise<R>;
39
+ /** Hook 调用选项 */
40
+ export interface HookCallOptions {
41
+ throwOnError?: boolean;
42
+ }
39
43
  /** Hook 描述符 */
40
44
  export interface HookDescriptor<T = unknown, R = unknown> {
41
45
  name: string;
@@ -44,6 +48,12 @@ export interface HookDescriptor<T = unknown, R = unknown> {
44
48
  }
45
49
  /** 事件处理器 */
46
50
  export type EventHandler<T = unknown> = (data: T) => void;
51
+ /** 插件日志器 */
52
+ export interface PluginLogger {
53
+ info(message?: unknown, ...optionalParams: unknown[]): void;
54
+ warn(message?: unknown, ...optionalParams: unknown[]): void;
55
+ error(message?: unknown, ...optionalParams: unknown[]): void;
56
+ }
47
57
  /** 插件宿主接口(暴露给插件使用的 API) */
48
58
  export interface PluginHost {
49
59
  /** 事件总线 */
@@ -57,8 +67,8 @@ export interface PluginHost {
57
67
  readonly hooks: {
58
68
  tap<T = unknown, R = unknown>(hookName: string, fn: HookFn<T, R>, priority?: number): void;
59
69
  untap(hookName: string, fn: HookFn): void;
60
- call<T = unknown, R = unknown>(hookName: string, context: T): Promise<R[]>;
61
- callSync<T = unknown, R = unknown>(hookName: string, context: T): R[];
70
+ call<T = unknown, R = unknown>(hookName: string, context: T, options?: HookCallOptions): Promise<R[]>;
71
+ callSync<T = unknown, R = unknown>(hookName: string, context: T, options?: HookCallOptions): R[];
62
72
  };
63
73
  /** 获取配置 */
64
74
  getConfig<K = unknown>(pluginName: string, key: string, defaultValue?: K): K;
@@ -79,9 +89,20 @@ export interface PluginHost {
79
89
  /** 按拥有者清除状态 */
80
90
  clearByOwner(ownerId: string): void;
81
91
  }
92
+ /** Pane 角色 */
93
+ export type PaneRole = 'price' | 'indicator' | 'auxiliary';
94
+ /** Pane 能力开关 */
95
+ export interface PaneCapabilities {
96
+ showPriceAxisTicks: boolean;
97
+ showCrosshairPriceLabel: boolean;
98
+ candleHitTest: boolean;
99
+ supportsPriceTranslate: boolean;
100
+ }
82
101
  /** Pane 信息接口 */
83
102
  export interface PaneInfo {
84
103
  id: string;
104
+ role: PaneRole;
105
+ capabilities: PaneCapabilities;
85
106
  top: number;
86
107
  height: number;
87
108
  yAxis: {
@@ -106,6 +127,8 @@ export interface PaneInfo {
106
127
  */
107
128
  export declare function wrapPaneInfo(pane: {
108
129
  id: string;
130
+ role: PaneRole;
131
+ capabilities: PaneCapabilities;
109
132
  top: number;
110
133
  height: number;
111
134
  yAxis: PaneInfo['yAxis'];
@@ -1,4 +1,4 @@
1
- import { Chart } from '../../core/chart';
1
+ import { Chart } from '../core/chart';
2
2
  import { SemanticChartConfig, ApplyResult } from './types';
3
3
  /** 状态事件类型 */
4
4
  export type SemanticEventType = 'config:loading' | 'config:ready' | 'config:error';
@@ -1,4 +1,4 @@
1
- import { KLineData } from '../../../types/price';
1
+ import { KLineData } from '../../types/price';
2
2
  import { drawOption, PriceRange } from './kLine';
3
3
  export declare const MA5_COLOR: "rgba(255, 193, 37, 1)";
4
4
  export declare const MA10_COLOR: "rgba(190, 131, 12, 1)";
@@ -1,4 +1,4 @@
1
- import { KLineData } from '../../../types/price';
1
+ import { KLineData } from '../../types/price';
2
2
  export interface PriceAxisOptions {
3
3
  x: number;
4
4
  y: number;
@@ -90,6 +90,10 @@ export interface CrosshairPriceLabelOptions {
90
90
  textColor?: string;
91
91
  fontSize?: number;
92
92
  paddingX?: number;
93
+ /** 价格偏移量(用于价格轴平移时同步显示) */
94
+ priceOffset?: number;
95
+ /** 优先显示的价格(如十字线已按 active pane 算好) */
96
+ price?: number;
93
97
  }
94
98
  export interface CrosshairTimeLabelOptions {
95
99
  x: number;
@@ -1,4 +1,4 @@
1
- import { KLineData } from '../../../types/price';
1
+ import { KLineData } from '../../types/price';
2
2
  import { drawOption, PriceRange } from './kLine';
3
3
  export interface GridOption {
4
4
  /** 网格线颜色 */
@@ -1,4 +1,4 @@
1
- import { KLineData } from '../../../types/price';
1
+ import { KLineData } from '../../types/price';
2
2
  export interface drawOption {
3
3
  kWidth: number;
4
4
  kGap: number;
@@ -1,5 +1,5 @@
1
- import { KLineData } from '../../../types/price';
2
- export { formatShanghaiDate } from '../../../utils/dateFormat';
1
+ import { KLineData } from '../../types/price';
2
+ export { formatShanghaiDate } from '../dateFormat';
3
3
  export declare const UP_COLOR: "rgba(214, 10, 34, 1)";
4
4
  export declare const DOWN_COLOR: "rgba(3, 123, 102, 1)";
5
5
  export declare const NEUTRAL_COLOR: "rgba(0, 0, 0, 0.78)";
@@ -1,2 +1,2 @@
1
- import { KLineData } from '../../../types/price';
1
+ import { KLineData } from '../../types/price';
2
2
  export declare function calcMAAtIndex(data: KLineData[], index: number, period: number): number | undefined;
@@ -1,4 +1,4 @@
1
- import { KLineData } from '../../../types/price';
1
+ import { KLineData } from '../../types/price';
2
2
  export type PriceRange = {
3
3
  maxPrice: number;
4
4
  minPrice: number;
@@ -1,3 +1,3 @@
1
- import { KLineData } from '../../../types/price';
1
+ import { KLineData } from '../../types/price';
2
2
  export declare function genRandomPriceData(count: number): KLineData[];
3
3
  export declare function reversalExampleData(): KLineData[];
@@ -1,5 +1,5 @@
1
- import { KLineData } from '../../types/price';
2
- import { VolumePriceRelation, VolumePriceConfig, DEFAULT_VOLUME_PRICE_CONFIG } from '../../types/volumePrice';
1
+ import { KLineData } from '../types/price';
2
+ import { VolumePriceRelation, VolumePriceConfig, DEFAULT_VOLUME_PRICE_CONFIG } from '../types/volumePrice';
3
3
  export { DEFAULT_VOLUME_PRICE_CONFIG };
4
4
  /**
5
5
  * 成交量前缀和计算器
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@363045841yyt/klinechart",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": "^20.19.0 || >=22.12.0"