kline-charts-react 0.0.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/LICENSE +21 -0
- package/README.md +388 -0
- package/dist/KLineChart.d.ts +5 -0
- package/dist/components/IndicatorDisplay/IndicatorDisplay.d.ts +12 -0
- package/dist/components/IndicatorDisplay/index.d.ts +1 -0
- package/dist/components/IndicatorSelector/IndicatorSelector.d.ts +12 -0
- package/dist/components/IndicatorSelector/index.d.ts +1 -0
- package/dist/components/Loading/Loading.d.ts +8 -0
- package/dist/components/Loading/index.d.ts +1 -0
- package/dist/components/MADisplay/MADisplay.d.ts +10 -0
- package/dist/components/MADisplay/index.d.ts +1 -0
- package/dist/components/PeriodSelector/PeriodSelector.d.ts +10 -0
- package/dist/components/PeriodSelector/index.d.ts +1 -0
- package/dist/components/SubPaneTitle/SubPaneTitle.d.ts +13 -0
- package/dist/components/SubPaneTitle/index.d.ts +1 -0
- package/dist/components/Toolbar/Toolbar.d.ts +20 -0
- package/dist/components/Toolbar/index.d.ts +1 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/useEcharts.d.ts +26 -0
- package/dist/hooks/useKlineData.d.ts +24 -0
- package/dist/hooks/useZoomHistory.d.ts +18 -0
- package/dist/index.cjs +51 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +26563 -0
- package/dist/index.umd.js +51 -0
- package/dist/kline-charts-react.css +1 -0
- package/dist/types/data.d.ts +207 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/props.d.ts +279 -0
- package/dist/types/theme.d.ts +47 -0
- package/dist/utils/cache.d.ts +56 -0
- package/dist/utils/formatters.d.ts +115 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/indicators.d.ts +109 -0
- package/dist/utils/optionBuilder.d.ts +32 -0
- package/dist/utils/timelineBuilder.d.ts +11 -0
- package/package.json +95 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 格式化数字(千分位)
|
|
3
|
+
*/
|
|
4
|
+
export declare function formatNumber(value: number | null | undefined, decimals?: number): string;
|
|
5
|
+
/**
|
|
6
|
+
* 格式化价格
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatPrice(value: number | null | undefined): string;
|
|
9
|
+
/**
|
|
10
|
+
* 格式化涨跌幅(带百分号和正负号)
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatPercent(value: number | null | undefined): string;
|
|
13
|
+
/**
|
|
14
|
+
* 格式化涨跌额(带正负号)
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatChange(value: number | null | undefined): string;
|
|
17
|
+
/**
|
|
18
|
+
* 格式化成交量(万/亿)
|
|
19
|
+
* 整数不显示 .00
|
|
20
|
+
*/
|
|
21
|
+
export declare function formatVolume(value: number | null | undefined): string;
|
|
22
|
+
/**
|
|
23
|
+
* 格式化成交额(万/亿)
|
|
24
|
+
* 整数不显示 .00
|
|
25
|
+
*/
|
|
26
|
+
export declare function formatAmount(value: number | null | undefined): string;
|
|
27
|
+
/**
|
|
28
|
+
* 格式化日期
|
|
29
|
+
*/
|
|
30
|
+
export declare function formatDate(date: string | Date, format?: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Tooltip 数据类型
|
|
33
|
+
*/
|
|
34
|
+
export interface TooltipData {
|
|
35
|
+
date: string;
|
|
36
|
+
open: number | null;
|
|
37
|
+
high: number | null;
|
|
38
|
+
low: number | null;
|
|
39
|
+
close: number | null;
|
|
40
|
+
volume?: number | null;
|
|
41
|
+
amount?: number | null;
|
|
42
|
+
change?: number | null;
|
|
43
|
+
changePercent?: number | null;
|
|
44
|
+
turnoverRate?: number | null;
|
|
45
|
+
amplitude?: number | null;
|
|
46
|
+
indicators?: string[];
|
|
47
|
+
ma?: {
|
|
48
|
+
ma5?: number | null;
|
|
49
|
+
ma10?: number | null;
|
|
50
|
+
ma20?: number | null;
|
|
51
|
+
ma30?: number | null;
|
|
52
|
+
ma60?: number | null;
|
|
53
|
+
};
|
|
54
|
+
boll?: {
|
|
55
|
+
upper: number | null;
|
|
56
|
+
mid: number | null;
|
|
57
|
+
lower: number | null;
|
|
58
|
+
};
|
|
59
|
+
sar?: {
|
|
60
|
+
sar: number | null;
|
|
61
|
+
trend: number | null;
|
|
62
|
+
};
|
|
63
|
+
kc?: {
|
|
64
|
+
upper: number | null;
|
|
65
|
+
mid: number | null;
|
|
66
|
+
lower: number | null;
|
|
67
|
+
};
|
|
68
|
+
macd?: {
|
|
69
|
+
dif: number | null;
|
|
70
|
+
dea: number | null;
|
|
71
|
+
macd: number | null;
|
|
72
|
+
};
|
|
73
|
+
kdj?: {
|
|
74
|
+
k: number | null;
|
|
75
|
+
d: number | null;
|
|
76
|
+
j: number | null;
|
|
77
|
+
};
|
|
78
|
+
rsi?: {
|
|
79
|
+
rsi6?: number | null;
|
|
80
|
+
rsi12?: number | null;
|
|
81
|
+
rsi24?: number | null;
|
|
82
|
+
};
|
|
83
|
+
wr?: {
|
|
84
|
+
wr6?: number | null;
|
|
85
|
+
wr10?: number | null;
|
|
86
|
+
};
|
|
87
|
+
bias?: {
|
|
88
|
+
bias6?: number | null;
|
|
89
|
+
bias12?: number | null;
|
|
90
|
+
bias24?: number | null;
|
|
91
|
+
};
|
|
92
|
+
cci?: {
|
|
93
|
+
cci: number | null;
|
|
94
|
+
};
|
|
95
|
+
atr?: {
|
|
96
|
+
atr: number | null;
|
|
97
|
+
};
|
|
98
|
+
obv?: {
|
|
99
|
+
obv: number | null;
|
|
100
|
+
obvMa: number | null;
|
|
101
|
+
};
|
|
102
|
+
roc?: {
|
|
103
|
+
roc: number | null;
|
|
104
|
+
signal: number | null;
|
|
105
|
+
};
|
|
106
|
+
dmi?: {
|
|
107
|
+
pdi: number | null;
|
|
108
|
+
mdi: number | null;
|
|
109
|
+
adx: number | null;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 格式化 K 线 Tooltip
|
|
114
|
+
*/
|
|
115
|
+
export declare function formatKlineTooltip(data: TooltipData): string;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { OHLCV, MAResult, MACDResult, BOLLResult, KDJResult, RSIResult, WRResult, BIASResult, CCIResult, ATRResult, OBVResult, ROCResult, DMIResult, SARResult, KCResult } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 计算 SMA(简单移动平均)
|
|
4
|
+
*/
|
|
5
|
+
export declare function calcSMA(data: (number | null)[], period: number): (number | null)[];
|
|
6
|
+
/**
|
|
7
|
+
* 计算 EMA(指数移动平均)
|
|
8
|
+
*/
|
|
9
|
+
export declare function calcEMA(data: (number | null)[], period: number): (number | null)[];
|
|
10
|
+
/**
|
|
11
|
+
* 计算 WMA(加权移动平均)
|
|
12
|
+
*/
|
|
13
|
+
export declare function calcWMA(data: (number | null)[], period: number): (number | null)[];
|
|
14
|
+
/**
|
|
15
|
+
* 计算 MA(移动平均线)
|
|
16
|
+
*/
|
|
17
|
+
export declare function calcMA(closes: (number | null)[], options?: {
|
|
18
|
+
periods?: number[];
|
|
19
|
+
type?: 'sma' | 'ema' | 'wma';
|
|
20
|
+
}): MAResult[];
|
|
21
|
+
/**
|
|
22
|
+
* 计算 MACD
|
|
23
|
+
*/
|
|
24
|
+
export declare function calcMACD(closes: (number | null)[], options?: {
|
|
25
|
+
short?: number;
|
|
26
|
+
long?: number;
|
|
27
|
+
signal?: number;
|
|
28
|
+
}): MACDResult[];
|
|
29
|
+
/**
|
|
30
|
+
* 计算 BOLL(布林带)
|
|
31
|
+
*/
|
|
32
|
+
export declare function calcBOLL(closes: (number | null)[], options?: {
|
|
33
|
+
period?: number;
|
|
34
|
+
stdDev?: number;
|
|
35
|
+
}): BOLLResult[];
|
|
36
|
+
/**
|
|
37
|
+
* 计算 KDJ
|
|
38
|
+
*/
|
|
39
|
+
export declare function calcKDJ(data: OHLCV[], options?: {
|
|
40
|
+
period?: number;
|
|
41
|
+
kPeriod?: number;
|
|
42
|
+
dPeriod?: number;
|
|
43
|
+
}): KDJResult[];
|
|
44
|
+
/**
|
|
45
|
+
* 计算 RSI
|
|
46
|
+
*/
|
|
47
|
+
export declare function calcRSI(closes: (number | null)[], options?: {
|
|
48
|
+
periods?: number[];
|
|
49
|
+
}): RSIResult[];
|
|
50
|
+
/**
|
|
51
|
+
* 计算 WR(威廉指标)
|
|
52
|
+
*/
|
|
53
|
+
export declare function calcWR(data: OHLCV[], options?: {
|
|
54
|
+
periods?: number[];
|
|
55
|
+
}): WRResult[];
|
|
56
|
+
/**
|
|
57
|
+
* 计算 BIAS(乖离率)
|
|
58
|
+
*/
|
|
59
|
+
export declare function calcBIAS(closes: (number | null)[], options?: {
|
|
60
|
+
periods?: number[];
|
|
61
|
+
}): BIASResult[];
|
|
62
|
+
/**
|
|
63
|
+
* 计算 CCI(顺势指标)
|
|
64
|
+
*/
|
|
65
|
+
export declare function calcCCI(data: OHLCV[], options?: {
|
|
66
|
+
period?: number;
|
|
67
|
+
}): CCIResult[];
|
|
68
|
+
/**
|
|
69
|
+
* 计算 ATR(平均真实波幅)
|
|
70
|
+
*/
|
|
71
|
+
export declare function calcATR(data: OHLCV[], options?: {
|
|
72
|
+
period?: number;
|
|
73
|
+
}): ATRResult[];
|
|
74
|
+
/**
|
|
75
|
+
* 计算 OBV(能量潮)
|
|
76
|
+
*/
|
|
77
|
+
export declare function calcOBV(data: OHLCV[], options?: {
|
|
78
|
+
maPeriod?: number;
|
|
79
|
+
}): OBVResult[];
|
|
80
|
+
/**
|
|
81
|
+
* 计算 ROC(变动率)
|
|
82
|
+
*/
|
|
83
|
+
export declare function calcROC(closes: (number | null)[], options?: {
|
|
84
|
+
period?: number;
|
|
85
|
+
signalPeriod?: number;
|
|
86
|
+
}): ROCResult[];
|
|
87
|
+
/**
|
|
88
|
+
* 计算 DMI(趋向指标)
|
|
89
|
+
*/
|
|
90
|
+
export declare function calcDMI(data: OHLCV[], options?: {
|
|
91
|
+
period?: number;
|
|
92
|
+
adxPeriod?: number;
|
|
93
|
+
}): DMIResult[];
|
|
94
|
+
/**
|
|
95
|
+
* 计算 SAR(抛物线转向指标)
|
|
96
|
+
*/
|
|
97
|
+
export declare function calcSAR(data: OHLCV[], options?: {
|
|
98
|
+
afStart?: number;
|
|
99
|
+
afIncrement?: number;
|
|
100
|
+
afMax?: number;
|
|
101
|
+
}): SARResult[];
|
|
102
|
+
/**
|
|
103
|
+
* 计算 KC(肯特纳通道)
|
|
104
|
+
*/
|
|
105
|
+
export declare function calcKC(data: OHLCV[], options?: {
|
|
106
|
+
emaPeriod?: number;
|
|
107
|
+
atrPeriod?: number;
|
|
108
|
+
multiplier?: number;
|
|
109
|
+
}): KCResult[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { EChartsOption } from 'echarts';
|
|
2
|
+
import { KlineWithIndicators, ThemeConfig, IndicatorType, PaneConfig } from '../types';
|
|
3
|
+
export declare const DATA_ZOOM_INSIDE_ID = "kline-zoom-inside";
|
|
4
|
+
export declare const DATA_ZOOM_SLIDER_ID = "kline-zoom-slider";
|
|
5
|
+
/**
|
|
6
|
+
* 生成默认面板配置参数
|
|
7
|
+
*/
|
|
8
|
+
interface GetDefaultPanesOptions {
|
|
9
|
+
/** 最多显示几个副图,默认 3,最大 3,传入 0 表示不显示副图 */
|
|
10
|
+
maxSubPanes?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 生成默认面板配置
|
|
14
|
+
* 每个副图指标独立一个面板
|
|
15
|
+
*/
|
|
16
|
+
export declare function getDefaultPanes(indicators: IndicatorType[], options?: GetDefaultPanesOptions): PaneConfig[];
|
|
17
|
+
/**
|
|
18
|
+
* 构建 ECharts Option
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildOption(params: {
|
|
21
|
+
data: KlineWithIndicators[];
|
|
22
|
+
theme: ThemeConfig;
|
|
23
|
+
indicators: IndicatorType[];
|
|
24
|
+
panes?: PaneConfig[];
|
|
25
|
+
visibleCount?: number;
|
|
26
|
+
containerHeight?: number;
|
|
27
|
+
}): EChartsOption;
|
|
28
|
+
/**
|
|
29
|
+
* 合并 ECharts Option
|
|
30
|
+
*/
|
|
31
|
+
export declare function mergeOption(baseOption: EChartsOption, customOption: EChartsOption | undefined, mode?: 'safeMerge' | 'replace'): EChartsOption;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EChartsOption } from 'echarts';
|
|
2
|
+
import { TimelineData, ThemeConfig } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* 构建分时图 Option
|
|
5
|
+
*/
|
|
6
|
+
export declare function buildTimelineOption(params: {
|
|
7
|
+
data: TimelineData[];
|
|
8
|
+
theme: ThemeConfig;
|
|
9
|
+
prevClose?: number;
|
|
10
|
+
containerHeight?: number;
|
|
11
|
+
}): EChartsOption;
|
package/package.json
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kline-charts-react",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Professional stock K-line chart React component with built-in data source, powered by ECharts and stock-sdk",
|
|
5
|
+
"author": "chengzuopeng",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.cjs",
|
|
9
|
+
"module": "dist/index.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"./style.css": "./dist/kline-charts-react.css"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"sideEffects": [
|
|
24
|
+
"*.css"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"dev": "yarn --cwd playground dev",
|
|
28
|
+
"build": "tsc -b && vite build",
|
|
29
|
+
"build:lib": "tsc -b && vite build",
|
|
30
|
+
"build:playground": "yarn --cwd playground build",
|
|
31
|
+
"lint": "eslint .",
|
|
32
|
+
"preview": "yarn --cwd playground preview",
|
|
33
|
+
"prepublishOnly": "yarn build"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"react": ">=17.0.0",
|
|
37
|
+
"react-dom": ">=17.0.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"react": {
|
|
41
|
+
"optional": false
|
|
42
|
+
},
|
|
43
|
+
"react-dom": {
|
|
44
|
+
"optional": false
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"echarts": "^5.5.0",
|
|
49
|
+
"stock-sdk": "^1.6.1"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/node": "^22.0.0",
|
|
53
|
+
"@types/react": "^18.3.18",
|
|
54
|
+
"@types/react-dom": "^18.3.5",
|
|
55
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
56
|
+
"eslint": "^9.17.0",
|
|
57
|
+
"react": "^18.3.1",
|
|
58
|
+
"react-dom": "^18.3.1",
|
|
59
|
+
"typescript": "~5.6.2",
|
|
60
|
+
"vite": "^6.0.5",
|
|
61
|
+
"vite-plugin-dts": "^4.4.0"
|
|
62
|
+
},
|
|
63
|
+
"keywords": [
|
|
64
|
+
"kline",
|
|
65
|
+
"k-line",
|
|
66
|
+
"stock",
|
|
67
|
+
"chart",
|
|
68
|
+
"echarts",
|
|
69
|
+
"react",
|
|
70
|
+
"candlestick",
|
|
71
|
+
"trading",
|
|
72
|
+
"finance",
|
|
73
|
+
"stock-chart",
|
|
74
|
+
"technical-analysis",
|
|
75
|
+
"macd",
|
|
76
|
+
"bollinger",
|
|
77
|
+
"kdj",
|
|
78
|
+
"rsi",
|
|
79
|
+
"a-share",
|
|
80
|
+
"hk-stock",
|
|
81
|
+
"us-stock"
|
|
82
|
+
],
|
|
83
|
+
"repository": {
|
|
84
|
+
"type": "git",
|
|
85
|
+
"url": "https://github.com/chengzuopeng/kline-charts.git"
|
|
86
|
+
},
|
|
87
|
+
"bugs": {
|
|
88
|
+
"url": "https://github.com/chengzuopeng/kline-charts/issues"
|
|
89
|
+
},
|
|
90
|
+
"homepage": "https://github.com/chengzuopeng/kline-charts#readme",
|
|
91
|
+
"engines": {
|
|
92
|
+
"node": ">=18.0.0"
|
|
93
|
+
},
|
|
94
|
+
"packageManager": "yarn@1.22.22"
|
|
95
|
+
}
|