@363045841yyt/klinechart 0.6.3 → 0.6.6
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 +4 -3
- package/dist/index.cjs +7 -7
- package/dist/index.js +2686 -1672
- package/dist/klinechart.css +1 -1
- package/dist/src/config/chartSettings.d.ts +11 -1
- package/dist/src/core/indicators/calculators.d.ts +140 -0
- package/dist/src/core/indicators/indicator.worker.d.ts +5 -0
- package/dist/src/core/indicators/indicatorRuntime.d.ts +71 -0
- package/dist/src/core/indicators/macdState.d.ts +58 -0
- package/dist/src/core/indicators/scheduler.d.ts +62 -198
- package/dist/src/core/indicators/soa.d.ts +115 -0
- package/dist/src/core/indicators/stateComposer.d.ts +47 -0
- package/dist/src/core/indicators/workerProtocol.d.ts +189 -0
- package/dist/src/core/renderers/Indicator/macd.d.ts +3 -11
- package/dist/src/core/renderers/Indicator/macdLegend.d.ts +5 -3
- package/dist/src/core/renderers/Indicator/rsi.d.ts +10 -0
- package/dist/src/core/renderers/webgl/candleSurface.d.ts +4 -0
- package/dist/src/core/utils/zoom.d.ts +2 -2
- package/dist/src/utils/dateFormat.d.ts +10 -8
- package/package.json +11 -9
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RendererPluginWithHost
|
|
1
|
+
import { RendererPluginWithHost } from '../../../plugin';
|
|
2
2
|
import { KLineData } from '../../../types/price';
|
|
3
3
|
export interface MACDConfig {
|
|
4
4
|
/** 快线周期(默认 12) */
|
|
@@ -14,16 +14,6 @@ export interface MACDConfig {
|
|
|
14
14
|
/** 是否显示 MACD 柱 */
|
|
15
15
|
showBAR?: boolean;
|
|
16
16
|
}
|
|
17
|
-
/** MACD 渲染器状态(共享给刻度渲染器) */
|
|
18
|
-
export interface MACDRenderState extends BaseIndicatorState {
|
|
19
|
-
valueMin: number;
|
|
20
|
-
valueMax: number;
|
|
21
|
-
latestValues?: {
|
|
22
|
-
dif: number;
|
|
23
|
-
dea: number;
|
|
24
|
-
macd: number;
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
17
|
export interface MACDRendererOptions {
|
|
28
18
|
/** 目标 pane ID(默认 'sub') */
|
|
29
19
|
paneId?: string;
|
|
@@ -32,10 +22,12 @@ export interface MACDRendererOptions {
|
|
|
32
22
|
}
|
|
33
23
|
/**
|
|
34
24
|
* 创建 MACD 渲染器插件
|
|
25
|
+
* 从 StateStore 读取 MACD 状态,不再内联计算
|
|
35
26
|
*/
|
|
36
27
|
export declare function createMACDRendererPlugin(options?: MACDRendererOptions): RendererPluginWithHost;
|
|
37
28
|
/**
|
|
38
29
|
* 计算指定索引处的 MACD 值(供图例使用)
|
|
30
|
+
* 使用 calculators.ts 中的计算函数
|
|
39
31
|
*/
|
|
40
32
|
export declare function calcMACDAtIndex(data: KLineData[], index: number, fastPeriod?: number, slowPeriod?: number, signalPeriod?: number): {
|
|
41
33
|
dif: number;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RendererPluginWithHost } from '../../../plugin';
|
|
2
2
|
export interface MACDLegendOptions {
|
|
3
3
|
/** Y 轴内边距(与主图保持一致) */
|
|
4
4
|
yPaddingPx?: number;
|
|
5
|
+
/** 目标 pane ID(默认 'sub') */
|
|
6
|
+
paneId?: string;
|
|
5
7
|
}
|
|
6
8
|
/**
|
|
7
9
|
* 创建 MACD 图例渲染器插件
|
|
8
|
-
*
|
|
10
|
+
* 从 StateStore 读取 MACD 状态,不再在 draw 时计算
|
|
9
11
|
*/
|
|
10
|
-
export declare function createMACDLegendRendererPlugin(options?: MACDLegendOptions):
|
|
12
|
+
export declare function createMACDLegendRendererPlugin(options?: MACDLegendOptions): RendererPluginWithHost;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { RendererPluginWithHost, PluginHost } from '../../../plugin';
|
|
2
|
+
type LinePoint = {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
};
|
|
2
6
|
export interface RSIRendererOptions {
|
|
3
7
|
/** 目标 pane ID(默认 'sub') */
|
|
4
8
|
paneId?: string;
|
|
@@ -11,6 +15,11 @@ export declare function createRSIRendererPlugin(options?: RSIRendererOptions): R
|
|
|
11
15
|
* 获取 RSI 标题信息(供 paneTitle 使用)
|
|
12
16
|
* 从 StateStore 读取已计算的 RSI 数据
|
|
13
17
|
*/
|
|
18
|
+
export declare function drawRSILinesWithCanvas2D(ctx: CanvasRenderingContext2D, scrollLeft: number, rsi1Points: LinePoint[], rsi2Points: LinePoint[], rsi3Points: LinePoint[], params: {
|
|
19
|
+
showRSI1: boolean;
|
|
20
|
+
showRSI2: boolean;
|
|
21
|
+
showRSI3: boolean;
|
|
22
|
+
}): void;
|
|
14
23
|
export declare function getRSITitleInfo(index: number, period1: number, period2: number, period3: number, pluginHost: PluginHost, paneId?: string): {
|
|
15
24
|
name: string;
|
|
16
25
|
params: number[];
|
|
@@ -20,3 +29,4 @@ export declare function getRSITitleInfo(index: number, period1: number, period2:
|
|
|
20
29
|
color: string;
|
|
21
30
|
}>;
|
|
22
31
|
} | null;
|
|
32
|
+
export {};
|
|
@@ -17,6 +17,8 @@ export declare class CandleWebGLSurface {
|
|
|
17
17
|
private logicalWidth;
|
|
18
18
|
private logicalHeight;
|
|
19
19
|
private available;
|
|
20
|
+
private rectCapacity;
|
|
21
|
+
private rectScratch;
|
|
20
22
|
constructor(canvas?: HTMLCanvasElement);
|
|
21
23
|
isAvailable(): boolean;
|
|
22
24
|
getCanvas(): HTMLCanvasElement;
|
|
@@ -33,6 +35,8 @@ export declare class LineWebGLSurface {
|
|
|
33
35
|
private logicalHeight;
|
|
34
36
|
private dpr;
|
|
35
37
|
private available;
|
|
38
|
+
private vertexCapacity;
|
|
39
|
+
private geoCache;
|
|
36
40
|
constructor(canvas?: HTMLCanvasElement);
|
|
37
41
|
isAvailable(): boolean;
|
|
38
42
|
getCanvas(): HTMLCanvasElement;
|
|
@@ -16,8 +16,8 @@ export interface ZoomResult {
|
|
|
16
16
|
}
|
|
17
17
|
/** 将缩放级别转换为 K 线宽度(逻辑像素) */
|
|
18
18
|
export declare function zoomLevelToKWidth(level: number, config: ZoomConfig): number;
|
|
19
|
-
/**
|
|
20
|
-
export declare function
|
|
19
|
+
/** 根据K线宽度和DPR推导间隙(逻辑像素),K线越窄间距越小 */
|
|
20
|
+
export declare function kGapFromKWidth(kWidth: number, dpr: number): number;
|
|
21
21
|
/**
|
|
22
22
|
* 缩放一级(+1 放大 / -1 缩小)
|
|
23
23
|
* 返回新状态或 null(已达边界)
|
|
@@ -51,7 +51,15 @@ export declare function formatMonthOrYear(timestamp: number): {
|
|
|
51
51
|
* @example
|
|
52
52
|
* monthKey(1736793600000) // "2025-1"
|
|
53
53
|
*/
|
|
54
|
-
|
|
54
|
+
/**
|
|
55
|
+
* 生成月份键值用于比较
|
|
56
|
+
* 返回数字 year * 12 + month,比字符串比较更快且无分配
|
|
57
|
+
* 使用 new Date 保证本地时区正确(与显示一致)
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* monthKey(1736793600000) // 24301 (2025*12 + 0)
|
|
61
|
+
*/
|
|
62
|
+
export declare function monthKey(timestamp: number): number;
|
|
55
63
|
/**
|
|
56
64
|
* formatDateToYYYYMMDD 的别名,保持与历史代码的兼容性
|
|
57
65
|
* timestamp 是"上海时区当天 00:00:00"映射到 UTC 的值;显示时强制按上海时区格式化
|
|
@@ -68,13 +76,7 @@ export declare const formatShanghaiDate: typeof formatDateToYYYYMMDD;
|
|
|
68
76
|
export declare const formatYMDShanghai: typeof formatDateToYYYYMMDD;
|
|
69
77
|
/**
|
|
70
78
|
* 查找每个月份第一个K线的索引
|
|
71
|
-
*
|
|
72
|
-
* @returns 月边界索引数组,例如 [0, 30, 60] 表示第0、30、60个K线分别是每月的第一个交易日
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* // 假设数据:[1/2, 1/3, 2/1, 2/2, 3/1, 3/2]
|
|
76
|
-
* findMonthBoundaries(data) // [0, 2, 4]
|
|
77
|
-
* // 解释:第0个K线是1月第一个,第2个K线是2月第一个,第4个K线是3月第一个
|
|
79
|
+
* 结果按数据引用缓存,同一份数据多次调用直接返回缓存
|
|
78
80
|
*/
|
|
79
81
|
export declare function findMonthBoundaries(data: Array<{
|
|
80
82
|
timestamp: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@363045841yyt/klinechart",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "A lightweight financial K-line charting library with first-class AI Agent support, crisp ResizeObserver-driven rendering, and plugin-based architecture. Focused on quantitative trading scenarios with TradingView-level interaction experience.",
|
|
5
5
|
"author": "363045841 <slslswbsy@qq.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,6 +12,16 @@
|
|
|
12
12
|
"homepage": "https://363045841.github.io/KLineChartQuant/",
|
|
13
13
|
"keywords": [
|
|
14
14
|
"kline-chart",
|
|
15
|
+
"plugin-architecture",
|
|
16
|
+
"webgl",
|
|
17
|
+
"high-performance",
|
|
18
|
+
"ai",
|
|
19
|
+
"crisp-rendering",
|
|
20
|
+
"sharp-rendering",
|
|
21
|
+
"agent",
|
|
22
|
+
"ai-chart",
|
|
23
|
+
"modern-ui",
|
|
24
|
+
"device-pixel-ratio",
|
|
15
25
|
"candlestick-chart",
|
|
16
26
|
"financial-chart",
|
|
17
27
|
"tradingview",
|
|
@@ -23,19 +33,11 @@
|
|
|
23
33
|
"chart-drawing",
|
|
24
34
|
"trend-line",
|
|
25
35
|
"fibonacci",
|
|
26
|
-
"high-performance",
|
|
27
36
|
"pixel-perfect",
|
|
28
|
-
"crisp-rendering",
|
|
29
|
-
"sharp-rendering",
|
|
30
|
-
"device-pixel-ratio",
|
|
31
37
|
"responsive",
|
|
32
|
-
"modern-ui",
|
|
33
|
-
"agent",
|
|
34
|
-
"ai-chart",
|
|
35
38
|
"visualization",
|
|
36
39
|
"quantitative-trading",
|
|
37
40
|
"technical-analysis",
|
|
38
|
-
"plugin-architecture",
|
|
39
41
|
"typescript"
|
|
40
42
|
],
|
|
41
43
|
"type": "module",
|