@363045841yyt/klinechart 0.3.1 → 0.4.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.
- package/README.md +21 -0
- package/dist/index.cjs +9 -9
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2297 -1733
- package/dist/klinechart.css +1 -1
- package/dist/src/api/data/baostock.d.ts +1 -1
- package/dist/src/api/data/kLine.d.ts +1 -1
- package/dist/src/api/data/types.d.ts +1 -1
- package/dist/src/api/data/unified.d.ts +1 -1
- package/dist/src/components/IndicatorSelector.vue.d.ts +2 -0
- package/dist/src/components/KLineChart.vue.d.ts +2 -2
- package/dist/src/components/KLineTooltip.vue.d.ts +1 -1
- package/dist/src/components/MarkerTooltip.vue.d.ts +1 -1
- package/dist/src/core/chart.d.ts +40 -13
- package/dist/src/core/controller/interaction.d.ts +12 -6
- package/dist/src/core/layout/pane.d.ts +4 -4
- package/dist/src/core/renderers/Indicator/boll.d.ts +2 -2
- package/dist/src/core/renderers/Indicator/cci.d.ts +7 -3
- package/dist/src/core/renderers/Indicator/ene.d.ts +2 -2
- package/dist/src/core/renderers/Indicator/expma.d.ts +2 -2
- package/dist/src/core/renderers/Indicator/fastk.d.ts +7 -3
- package/dist/src/core/renderers/Indicator/index.d.ts +1 -1
- package/dist/src/core/renderers/Indicator/kst.d.ts +7 -3
- package/dist/src/core/renderers/Indicator/ma.d.ts +1 -1
- package/dist/src/core/renderers/Indicator/macd.d.ts +13 -3
- package/dist/src/core/renderers/Indicator/macdLegend.d.ts +1 -1
- package/dist/src/core/renderers/Indicator/mainIndicatorLegend.d.ts +1 -1
- package/dist/src/core/renderers/Indicator/mom.d.ts +7 -3
- package/dist/src/core/renderers/Indicator/rsi.d.ts +7 -3
- package/dist/src/core/renderers/Indicator/scale/cci_scale.d.ts +5 -0
- package/dist/src/core/renderers/Indicator/scale/fastk_scale.d.ts +5 -0
- package/dist/src/core/renderers/Indicator/scale/indicator_scale.d.ts +23 -0
- package/dist/src/core/renderers/Indicator/scale/kst_scale.d.ts +5 -0
- package/dist/src/core/renderers/Indicator/scale/macd_scale.d.ts +8 -0
- package/dist/src/core/renderers/Indicator/scale/mom_scale.d.ts +5 -0
- package/dist/src/core/renderers/Indicator/scale/rsi_scale.d.ts +5 -0
- package/dist/src/core/renderers/Indicator/scale/stoch_scale.d.ts +5 -0
- package/dist/src/core/renderers/Indicator/scale/wmsr_scale.d.ts +5 -0
- package/dist/src/core/renderers/Indicator/stoch.d.ts +7 -3
- package/dist/src/core/renderers/Indicator/wmsr.d.ts +7 -3
- package/dist/src/core/renderers/candle.d.ts +3 -3
- package/dist/src/core/renderers/crosshair.d.ts +1 -1
- package/dist/src/core/renderers/customMarkers.d.ts +1 -1
- package/dist/src/core/renderers/extremaMarkers.d.ts +1 -1
- package/dist/src/core/renderers/gridLines.d.ts +1 -1
- package/dist/src/core/renderers/lastPrice.d.ts +1 -1
- package/dist/src/core/renderers/paneTitle.d.ts +1 -1
- package/dist/src/core/renderers/subVolume.d.ts +1 -1
- package/dist/src/core/renderers/timeAxis.d.ts +1 -1
- package/dist/src/core/renderers/yAxis.d.ts +2 -2
- package/dist/src/core/utils/tickCount.d.ts +3 -2
- package/dist/src/core/viewport/viewport.d.ts +2 -2
- package/dist/src/plugin/HookSystem.d.ts +3 -3
- package/dist/src/plugin/PluginHost.d.ts +12 -5
- package/dist/src/plugin/StateStore.d.ts +37 -0
- package/dist/src/plugin/rendererPluginManager.d.ts +4 -0
- package/dist/src/plugin/stateKeys.d.ts +6 -0
- package/dist/src/plugin/types.d.ts +38 -2
- package/dist/src/semantic/controller.d.ts +1 -1
- package/dist/src/utils/kLineDraw/MA.d.ts +1 -1
- package/dist/src/utils/kLineDraw/axis.d.ts +1 -1
- package/dist/src/utils/kLineDraw/grid.d.ts +1 -1
- package/dist/src/utils/kLineDraw/kLine.d.ts +1 -1
- package/dist/src/utils/kline/format.d.ts +2 -2
- package/dist/src/utils/kline/ma.d.ts +1 -1
- package/dist/src/utils/kline/viewport.d.ts +1 -1
- package/dist/src/utils/mock/genRandomPriceData.d.ts +1 -1
- package/dist/src/utils/volumePrice.d.ts +2 -2
- package/package.json +1 -1
- /package/dist/{semantic → src/semantic}/schema.json.d.ts +0 -0
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { KLineData } from '
|
|
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):
|
|
22
|
+
export declare function createWMSRRendererPlugin(options?: WMSRRendererOptions): RendererPluginWithHost;
|
|
19
23
|
/**
|
|
20
24
|
* 计算指定索引处的 WMSR 值
|
|
21
25
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { RendererPlugin } from '
|
|
2
|
-
import { VolumePriceRelation } from '
|
|
3
|
-
import { MarkerManager } from '
|
|
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,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 根据面板高度计算网格线/价格标签数量
|
|
3
|
+
* 刻度间距固定约 60px
|
|
3
4
|
* @param height 面板高度(逻辑像素)
|
|
4
|
-
* @param isMain
|
|
5
|
+
* @param isMain 是否为主图面板(暂未使用,保留参数兼容)
|
|
5
6
|
* @returns tick 数量
|
|
6
7
|
*/
|
|
7
|
-
export declare function calculateTickCount(height: number, isMain
|
|
8
|
+
export declare function calculateTickCount(height: number, isMain?: boolean): number;
|
|
@@ -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,11 +1,13 @@
|
|
|
1
|
-
import { Plugin, PluginConfig, PluginHost, PluginState } 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;
|
|
5
5
|
private hookSystem;
|
|
6
6
|
private configManager;
|
|
7
|
+
private stateStore;
|
|
7
8
|
private isDestroyed;
|
|
8
|
-
|
|
9
|
+
private logger;
|
|
10
|
+
constructor(logger?: PluginLogger);
|
|
9
11
|
readonly events: {
|
|
10
12
|
on: <T = unknown>(event: string, handler: (data: T) => void) => void;
|
|
11
13
|
off: <T = unknown>(event: string, handler: (data: T) => void) => void;
|
|
@@ -15,13 +17,18 @@ export declare class PluginHostImpl implements PluginHost {
|
|
|
15
17
|
readonly hooks: {
|
|
16
18
|
tap: <T = unknown, R = unknown>(hookName: string, fn: (context: T) => R | Promise<R>, priority?: number) => void;
|
|
17
19
|
untap: (hookName: string, fn: (context: unknown) => unknown) => void;
|
|
18
|
-
call: <T = unknown, R = unknown>(hookName: string, context: T) => Promise<R[]>;
|
|
19
|
-
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[];
|
|
20
22
|
};
|
|
21
23
|
getConfig<K = unknown>(pluginName: string, key: string, defaultValue?: K): K;
|
|
22
24
|
setConfig(pluginName: string, key: string, value: unknown): void;
|
|
23
25
|
getPlugin<T extends Plugin = Plugin>(name: string): T | undefined;
|
|
24
26
|
log(level: 'info' | 'warn' | 'error', message: string, ...args: unknown[]): void;
|
|
27
|
+
setSharedState<T extends BaseIndicatorState>(namespace: string, state: T, ownerId?: string): void;
|
|
28
|
+
getSharedState<T extends BaseIndicatorState>(namespace: string): T | undefined;
|
|
29
|
+
clearSharedState(namespace: string): void;
|
|
30
|
+
registerStateOwner(ownerId: string, namespaces: string[]): void;
|
|
31
|
+
clearByOwner(ownerId: string): void;
|
|
25
32
|
/**
|
|
26
33
|
* 安装插件
|
|
27
34
|
*/
|
|
@@ -44,4 +51,4 @@ export declare class PluginHostImpl implements PluginHost {
|
|
|
44
51
|
destroy(): Promise<void>;
|
|
45
52
|
private ensureNotDestroyed;
|
|
46
53
|
}
|
|
47
|
-
export declare function createPluginHost(): PluginHostImpl;
|
|
54
|
+
export declare function createPluginHost(logger?: PluginLogger): PluginHostImpl;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BaseIndicatorState } from './types';
|
|
2
|
+
export declare class StateStore {
|
|
3
|
+
private states;
|
|
4
|
+
private ownerNamespaces;
|
|
5
|
+
/**
|
|
6
|
+
* 设置状态
|
|
7
|
+
* @param namespace 状态命名空间
|
|
8
|
+
* @param state 状态值
|
|
9
|
+
* @param ownerId 可选的拥有者 ID(用于冲突检测)
|
|
10
|
+
*/
|
|
11
|
+
setState<T extends BaseIndicatorState>(namespace: string, state: T, ownerId?: string): void;
|
|
12
|
+
/**
|
|
13
|
+
* 获取状态
|
|
14
|
+
* @param namespace 状态命名空间
|
|
15
|
+
*/
|
|
16
|
+
getState<T extends BaseIndicatorState>(namespace: string): T | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* 清除指定命名空间的状态
|
|
19
|
+
* @param namespace 状态命名空间
|
|
20
|
+
*/
|
|
21
|
+
clearState(namespace: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* 注册状态拥有者
|
|
24
|
+
* @param ownerId 拥有者 ID(通常是渲染器名称)
|
|
25
|
+
* @param namespaces 声明的命名空间列表
|
|
26
|
+
*/
|
|
27
|
+
registerStateOwner(ownerId: string, namespaces: string[]): void;
|
|
28
|
+
/**
|
|
29
|
+
* 按拥有者清除所有状态
|
|
30
|
+
* @param ownerId 拥有者 ID
|
|
31
|
+
*/
|
|
32
|
+
clearByOwner(ownerId: string): void;
|
|
33
|
+
/**
|
|
34
|
+
* 清空所有状态
|
|
35
|
+
*/
|
|
36
|
+
clear(): void;
|
|
37
|
+
}
|
|
@@ -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;
|
|
@@ -68,6 +78,16 @@ export interface PluginHost {
|
|
|
68
78
|
getPlugin<T extends Plugin = Plugin>(name: string): T | undefined;
|
|
69
79
|
/** 日志工具 */
|
|
70
80
|
log(level: 'info' | 'warn' | 'error', message: string, ...args: unknown[]): void;
|
|
81
|
+
/** 设置共享状态 */
|
|
82
|
+
setSharedState<T extends BaseIndicatorState>(namespace: string, state: T, ownerId?: string): void;
|
|
83
|
+
/** 获取共享状态 */
|
|
84
|
+
getSharedState<T extends BaseIndicatorState>(namespace: string): T | undefined;
|
|
85
|
+
/** 清除共享状态 */
|
|
86
|
+
clearSharedState(namespace: string): void;
|
|
87
|
+
/** 注册状态拥有者 */
|
|
88
|
+
registerStateOwner(ownerId: string, namespaces: string[]): void;
|
|
89
|
+
/** 按拥有者清除状态 */
|
|
90
|
+
clearByOwner(ownerId: string): void;
|
|
71
91
|
}
|
|
72
92
|
/** Pane 信息接口 */
|
|
73
93
|
export interface PaneInfo {
|
|
@@ -134,7 +154,17 @@ export declare const RENDERER_PRIORITY: {
|
|
|
134
154
|
readonly SYSTEM_XAXIS: -20;
|
|
135
155
|
readonly BACKGROUND: 0;
|
|
136
156
|
readonly GRID: 10;
|
|
157
|
+
/**
|
|
158
|
+
* 指标渲染器(MACD, RSI 等)
|
|
159
|
+
* 所有指标渲染器必须使用此优先级或 ≤30 的值
|
|
160
|
+
*/
|
|
137
161
|
readonly INDICATOR: 30;
|
|
162
|
+
/**
|
|
163
|
+
* 指标刻度渲染器(依赖于前方 INDICATOR 的状态)
|
|
164
|
+
* 所有刻度渲染器必须使用此优先级或 ≥35 的值,
|
|
165
|
+
* 确保每次绘制时指标更新先于刻度。
|
|
166
|
+
*/
|
|
167
|
+
readonly INDICATOR_SCALE: 35;
|
|
138
168
|
readonly MAIN: 50;
|
|
139
169
|
readonly OVERLAY: 80;
|
|
140
170
|
readonly FOREGROUND: 100;
|
|
@@ -183,4 +213,10 @@ export interface RendererPlugin {
|
|
|
183
213
|
export interface RendererPluginWithHost extends RendererPlugin {
|
|
184
214
|
/** 安装时获取 PluginHost 访问权限 */
|
|
185
215
|
onInstall?(host: PluginHost): void;
|
|
216
|
+
/** 声明该渲染器所拥有的状态命名空间,卸载时框架会自动清理 */
|
|
217
|
+
getDeclaredNamespaces?(): string[];
|
|
218
|
+
}
|
|
219
|
+
/** 指标渲染器状态基类 */
|
|
220
|
+
export interface BaseIndicatorState {
|
|
221
|
+
timestamp: number;
|
|
186
222
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { KLineData } from '
|
|
2
|
-
export { formatShanghaiDate } from '
|
|
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 '
|
|
1
|
+
import { KLineData } from '../../types/price';
|
|
2
2
|
export declare function calcMAAtIndex(data: KLineData[], index: number, period: number): number | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { KLineData } from '
|
|
2
|
-
import { VolumePriceRelation, VolumePriceConfig, DEFAULT_VOLUME_PRICE_CONFIG } from '
|
|
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
|
File without changes
|