@keneth80/k-chart 1.9.0 → 1.11.0
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/CHANGELOG.md +39 -0
- package/README.md +208 -1
- package/docs/assets/kchart-hero.svg +110 -0
- package/docs/assets/kchart-icon.svg +40 -0
- package/docs/configuration-reference.md +395 -0
- package/docs/functional-api.md +164 -3
- package/examples/stackblitz-candlestick-basic/index.html +23 -0
- package/examples/stackblitz-candlestick-basic/package-lock.json +1435 -0
- package/examples/stackblitz-candlestick-basic/package.json +18 -0
- package/examples/stackblitz-candlestick-basic/src/main.ts +107 -0
- package/examples/stackblitz-candlestick-basic/src/style.css +16 -0
- package/examples/stackblitz-canvas-line-basic/index.html +23 -0
- package/examples/stackblitz-canvas-line-basic/package-lock.json +1435 -0
- package/examples/stackblitz-canvas-line-basic/package.json +18 -0
- package/examples/stackblitz-canvas-line-basic/src/main.ts +73 -0
- package/examples/stackblitz-canvas-line-basic/src/style.css +46 -0
- package/examples/stackblitz-column-basic/index.html +23 -0
- package/examples/stackblitz-column-basic/package-lock.json +1435 -0
- package/examples/stackblitz-column-basic/package.json +18 -0
- package/examples/stackblitz-column-basic/src/main.ts +128 -0
- package/examples/stackblitz-column-basic/src/style.css +41 -0
- package/examples/stackblitz-doughnut-basic/index.html +21 -0
- package/examples/stackblitz-doughnut-basic/package-lock.json +1435 -0
- package/examples/stackblitz-doughnut-basic/package.json +18 -0
- package/examples/stackblitz-doughnut-basic/src/main.ts +177 -0
- package/examples/stackblitz-doughnut-basic/src/style.css +43 -0
- package/examples/stackblitz-korea-region-map-basic/index.html +20 -0
- package/examples/stackblitz-korea-region-map-basic/package-lock.json +1434 -0
- package/examples/stackblitz-korea-region-map-basic/package.json +17 -0
- package/examples/stackblitz-korea-region-map-basic/src/main.ts +90 -0
- package/examples/stackblitz-korea-region-map-basic/src/style.css +57 -0
- package/examples/stackblitz-line-basic/index.html +23 -0
- package/examples/stackblitz-line-basic/package-lock.json +1435 -0
- package/examples/stackblitz-line-basic/package.json +18 -0
- package/examples/stackblitz-line-basic/src/main.ts +112 -0
- package/examples/stackblitz-line-basic/src/style.css +108 -0
- package/examples/stackblitz-multi-series-basic/index.html +1 -0
- package/examples/stackblitz-multi-series-basic/package-lock.json +1435 -0
- package/examples/stackblitz-multi-series-basic/package.json +9 -0
- package/examples/stackblitz-multi-series-basic/src/main.ts +29 -0
- package/examples/stackblitz-multi-series-basic/src/style.css +1 -0
- package/examples/stackblitz-options-basic/index.html +1 -0
- package/examples/stackblitz-options-basic/package-lock.json +1435 -0
- package/examples/stackblitz-options-basic/package.json +9 -0
- package/examples/stackblitz-options-basic/src/main.ts +32 -0
- package/examples/stackblitz-options-basic/src/style.css +1 -0
- package/examples/stackblitz-pie-basic/index.html +21 -0
- package/examples/stackblitz-pie-basic/package-lock.json +1435 -0
- package/examples/stackblitz-pie-basic/package.json +18 -0
- package/examples/stackblitz-pie-basic/src/main.ts +156 -0
- package/examples/stackblitz-pie-basic/src/style.css +43 -0
- package/examples/stackblitz-plot-basic/index.html +1 -0
- package/examples/stackblitz-plot-basic/package-lock.json +1435 -0
- package/examples/stackblitz-plot-basic/package.json +9 -0
- package/examples/stackblitz-plot-basic/src/main.ts +32 -0
- package/examples/stackblitz-plot-basic/src/style.css +1 -0
- package/examples/stackblitz-radial-basic/index.html +21 -0
- package/examples/stackblitz-radial-basic/package-lock.json +1435 -0
- package/examples/stackblitz-radial-basic/package.json +18 -0
- package/examples/stackblitz-radial-basic/src/main.ts +223 -0
- package/examples/stackblitz-radial-basic/src/style.css +87 -0
- package/examples/stackblitz-simple-api-basic/index.html +30 -0
- package/examples/stackblitz-simple-api-basic/package-lock.json +1435 -0
- package/examples/stackblitz-simple-api-basic/package.json +18 -0
- package/examples/stackblitz-simple-api-basic/src/main.ts +69 -0
- package/examples/stackblitz-simple-api-basic/src/style.css +127 -0
- package/examples/stackblitz-stacked-column-basic/index.html +23 -0
- package/examples/stackblitz-stacked-column-basic/package-lock.json +1435 -0
- package/examples/stackblitz-stacked-column-basic/package.json +18 -0
- package/examples/stackblitz-stacked-column-basic/src/main.ts +136 -0
- package/examples/stackblitz-stacked-column-basic/src/style.css +16 -0
- package/examples/stackblitz-three-wafer-basic/index.html +1 -0
- package/examples/stackblitz-three-wafer-basic/package-lock.json +1453 -0
- package/examples/stackblitz-three-wafer-basic/package.json +9 -0
- package/examples/stackblitz-three-wafer-basic/src/main.ts +29 -0
- package/examples/stackblitz-three-wafer-basic/src/style.css +1 -0
- package/examples/stackblitz-topology-basic/index.html +1 -0
- package/examples/stackblitz-topology-basic/package-lock.json +1435 -0
- package/examples/stackblitz-topology-basic/package.json +9 -0
- package/examples/stackblitz-topology-basic/src/main.ts +89 -0
- package/examples/stackblitz-topology-basic/src/style.css +1 -0
- package/examples/stackblitz-webgl-line-basic/index.html +23 -0
- package/examples/stackblitz-webgl-line-basic/package-lock.json +1435 -0
- package/examples/stackblitz-webgl-line-basic/package.json +18 -0
- package/examples/stackblitz-webgl-line-basic/src/main.ts +86 -0
- package/examples/stackblitz-webgl-line-basic/src/style.css +46 -0
- package/examples/stackblitz-worker-json-line/index.html +41 -0
- package/examples/stackblitz-worker-json-line/package-lock.json +1435 -0
- package/examples/stackblitz-worker-json-line/package.json +19 -0
- package/examples/stackblitz-worker-json-line/public/data/large-line.json +4322 -0
- package/examples/stackblitz-worker-json-line/src/kchart-render.worker.ts +4 -0
- package/examples/stackblitz-worker-json-line/src/main.ts +185 -0
- package/examples/stackblitz-worker-json-line/src/style.css +101 -0
- package/examples/stackblitz-world-country-map-basic/index.html +20 -0
- package/examples/stackblitz-world-country-map-basic/package-lock.json +1434 -0
- package/examples/stackblitz-world-country-map-basic/package.json +17 -0
- package/examples/stackblitz-world-country-map-basic/src/main.ts +64 -0
- package/examples/stackblitz-world-country-map-basic/src/style.css +57 -0
- package/lib/core/contracts.d.ts +72 -0
- package/lib/core/contracts.d.ts.map +1 -1
- package/lib/core/create-kchart.d.ts.map +1 -1
- package/lib/core/create-kchart.js +93 -4
- package/lib/core/create-kchart.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/kchart.d.ts +1 -0
- package/lib/kchart.d.ts.map +1 -1
- package/lib/kchart.js +1 -0
- package/lib/kchart.js.map +1 -1
- package/lib/presets/index.d.ts +97 -0
- package/lib/presets/index.d.ts.map +1 -0
- package/lib/presets/index.js +481 -0
- package/lib/presets/index.js.map +1 -0
- package/lib/series/canvas-line.d.ts.map +1 -1
- package/lib/series/canvas-line.js +16 -11
- package/lib/series/canvas-line.js.map +1 -1
- package/lib/series/index.d.ts +1 -0
- package/lib/series/index.d.ts.map +1 -1
- package/lib/series/index.js +1 -0
- package/lib/series/index.js.map +1 -1
- package/lib/series/svg-line.d.ts.map +1 -1
- package/lib/series/svg-line.js +19 -3
- package/lib/series/svg-line.js.map +1 -1
- package/lib/series/svg-region-map.d.ts +4 -0
- package/lib/series/svg-region-map.d.ts.map +1 -0
- package/lib/series/svg-region-map.js +324 -0
- package/lib/series/svg-region-map.js.map +1 -0
- package/lib/series/webgl-line.d.ts.map +1 -1
- package/lib/series/webgl-line.js +10 -3
- package/lib/series/webgl-line.js.map +1 -1
- package/package.json +13 -2
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kchart-stackblitz-candlestick-basic",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite --host 0.0.0.0",
|
|
8
|
+
"build": "tsc && vite build",
|
|
9
|
+
"preview": "vite preview --host 0.0.0.0"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@keneth80/k-chart": "^1.9.0"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"typescript": "^6.0.3",
|
|
16
|
+
"vite": "^7.2.7"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { createCanvasCandlestickSeries, createKChart } from '@keneth80/k-chart';
|
|
2
|
+
import './style.css';
|
|
3
|
+
|
|
4
|
+
interface StockPoint {
|
|
5
|
+
label: Date;
|
|
6
|
+
open: number;
|
|
7
|
+
high: number;
|
|
8
|
+
low: number;
|
|
9
|
+
close: number;
|
|
10
|
+
previousClose: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const addDays = (date: Date, days: number) => {
|
|
14
|
+
const next = new Date(date);
|
|
15
|
+
next.setDate(next.getDate() + days);
|
|
16
|
+
return next;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const createStockData = (length: number): StockPoint[] => {
|
|
20
|
+
const result: StockPoint[] = [];
|
|
21
|
+
let currentDate = new Date('2024-01-02T00:00:00');
|
|
22
|
+
let previousClose = 104;
|
|
23
|
+
let previousAdjustedClose = 104;
|
|
24
|
+
|
|
25
|
+
while (result.length < length) {
|
|
26
|
+
const day = currentDate.getDay();
|
|
27
|
+
if (day !== 0 && day !== 6) {
|
|
28
|
+
const index = result.length;
|
|
29
|
+
const trend = Math.sin(index / 24) * 8 + index * 0.045;
|
|
30
|
+
const swing = Math.sin(index / 3.4) * 2.8 + Math.cos(index / 5.7) * 1.7;
|
|
31
|
+
const open = previousClose + Math.sin(index / 4.8) * 1.4;
|
|
32
|
+
const close = open + swing * 0.72 + Math.sin(index / 2.3) * 0.9;
|
|
33
|
+
const high = Math.max(open, close) + 1.6 + Math.abs(Math.sin(index / 2.8)) * 2.4;
|
|
34
|
+
const low = Math.min(open, close) - 1.5 - Math.abs(Math.cos(index / 3.1)) * 2.1;
|
|
35
|
+
|
|
36
|
+
result.push({
|
|
37
|
+
label: new Date(currentDate),
|
|
38
|
+
open: Number((open + trend).toFixed(2)),
|
|
39
|
+
high: Number((high + trend).toFixed(2)),
|
|
40
|
+
low: Number((low + trend).toFixed(2)),
|
|
41
|
+
close: Number((close + trend).toFixed(2)),
|
|
42
|
+
previousClose: Number(previousAdjustedClose.toFixed(2))
|
|
43
|
+
});
|
|
44
|
+
previousClose = close;
|
|
45
|
+
previousAdjustedClose = close + trend;
|
|
46
|
+
}
|
|
47
|
+
currentDate = addDays(currentDate, 1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const data = createStockData(260);
|
|
54
|
+
const domain = [addDays(data[0].label, -8), addDays(data[data.length - 1].label, 8)];
|
|
55
|
+
|
|
56
|
+
const chart = createKChart<StockPoint>({
|
|
57
|
+
selector: '#chart',
|
|
58
|
+
data,
|
|
59
|
+
width: 920,
|
|
60
|
+
height: 460,
|
|
61
|
+
margin: { top: 88, right: 36, bottom: 58, left: 64 },
|
|
62
|
+
title: { text: 'Canvas Candlestick Renderer', align: 'left', fontSize: 18 },
|
|
63
|
+
grid: { visible: true, x: false, y: true, color: 'rgba(148, 163, 184, 0.22)', dasharray: '3 8' },
|
|
64
|
+
legend: { visible: true, placement: 'top', selectable: true },
|
|
65
|
+
tooltip: {
|
|
66
|
+
visible: true,
|
|
67
|
+
formatter: ({ data: point }) => `
|
|
68
|
+
<strong>${point.label.toISOString().slice(0, 10)}</strong>
|
|
69
|
+
<div>O ${point.open} / H ${point.high}</div>
|
|
70
|
+
<div>L ${point.low} / C ${point.close}</div>
|
|
71
|
+
`
|
|
72
|
+
},
|
|
73
|
+
zoom: {
|
|
74
|
+
enabled: true,
|
|
75
|
+
mode: 'wheel',
|
|
76
|
+
direction: 'x',
|
|
77
|
+
scaleExtent: [1, 80],
|
|
78
|
+
wheelZoom: { enabled: true, devices: 'pc', sensitivity: 0.85 },
|
|
79
|
+
gestureZoom: { enabled: true, devices: 'mobile', minTouches: 1 },
|
|
80
|
+
resetOnDoubleClick: true
|
|
81
|
+
},
|
|
82
|
+
axes: [
|
|
83
|
+
{ field: 'label', type: 'time', placement: 'bottom', title: 'Trading Day', tickCount: 8, domain },
|
|
84
|
+
{ field: 'close', type: 'number', placement: 'left', title: 'Price', domainFields: ['low', 'high'] }
|
|
85
|
+
],
|
|
86
|
+
series: [
|
|
87
|
+
createCanvasCandlestickSeries({
|
|
88
|
+
selector: 'stock-ohlc',
|
|
89
|
+
displayName: 'OHLC',
|
|
90
|
+
xField: 'label',
|
|
91
|
+
openField: 'open',
|
|
92
|
+
highField: 'high',
|
|
93
|
+
lowField: 'low',
|
|
94
|
+
closeField: 'close',
|
|
95
|
+
colorMode: 'previous-close',
|
|
96
|
+
previousCloseField: 'previousClose',
|
|
97
|
+
upColor: '#56d08f',
|
|
98
|
+
downColor: '#ff6b8a',
|
|
99
|
+
neutralColor: '#f3b45b',
|
|
100
|
+
wickColor: 'rgba(237, 243, 248, 0.78)',
|
|
101
|
+
minCandleWidth: 2,
|
|
102
|
+
maxCandleWidth: 10
|
|
103
|
+
})
|
|
104
|
+
]
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
chart.render();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
:root { color-scheme: dark; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: #0b1120; color: #e5edf7; }
|
|
2
|
+
* { box-sizing: border-box; }
|
|
3
|
+
body { margin: 0; min-width: 320px; min-height: 100vh; background: radial-gradient(circle at 20% 10%, rgba(86, 208, 143, 0.18), transparent 32rem), radial-gradient(circle at 80% 0%, rgba(255, 107, 138, 0.12), transparent 28rem), #0b1120; }
|
|
4
|
+
.page-shell { width: min(1120px, calc(100vw - 32px)); margin: 0 auto; padding: 40px 0; }
|
|
5
|
+
.intro { margin-bottom: 18px; }
|
|
6
|
+
.eyebrow { margin: 0 0 8px; color: #7dd3fc; font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
|
|
7
|
+
h1 { margin: 0; font-size: clamp(28px, 5vw, 52px); line-height: 1.05; }
|
|
8
|
+
.intro p:last-child { margin: 12px 0 0; color: #b8c5d6; }
|
|
9
|
+
code { color: #fbbf24; }
|
|
10
|
+
.chart-panel { min-height: 520px; padding: 24px; border: 1px solid rgba(148, 163, 184, 0.24); border-radius: 12px; background: linear-gradient(145deg, rgba(15, 23, 42, 0.92), rgba(17, 24, 39, 0.82)); box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28); }
|
|
11
|
+
#chart { width: 100%; height: 460px; }
|
|
12
|
+
#chart .kchart-svg text { font-family: inherit; }
|
|
13
|
+
#chart .domain, #chart .tick line { stroke: rgba(203, 213, 225, 0.54); }
|
|
14
|
+
#chart .tick text, #chart .kchart-axis-title { fill: #cbd5e1; }
|
|
15
|
+
#chart .kchart-title { fill: #f8fafc; }
|
|
16
|
+
#chart .kchart-legend text { fill: #dbeafe; }
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>KChart Canvas Line Basic</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<main class="page-shell">
|
|
10
|
+
<section class="intro">
|
|
11
|
+
<p class="eyebrow">StackBlitz starter</p>
|
|
12
|
+
<h1>KChart Canvas Line</h1>
|
|
13
|
+
<p>Edit <code>src/main.ts</code> and the Canvas renderer updates instantly.</p>
|
|
14
|
+
</section>
|
|
15
|
+
|
|
16
|
+
<section class="chart-panel">
|
|
17
|
+
<div id="chart"></div>
|
|
18
|
+
</section>
|
|
19
|
+
</main>
|
|
20
|
+
|
|
21
|
+
<script type="module" src="/src/main.ts"></script>
|
|
22
|
+
</body>
|
|
23
|
+
</html>
|