@tradecanvas/svelte 1.3.28 → 1.3.30
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 +1 -1
- package/dist/TradeCanvas.svelte +20 -27
- package/dist/TradeCanvas.svelte.d.ts +6 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ Streams live Binance data by default. Pass `data={bars}` for static OHLC, or `ad
|
|
|
35
35
|
|
|
36
36
|
## Props
|
|
37
37
|
|
|
38
|
-
`symbol`, `timeframe`, `theme`, `chartType`, `indicators` (ids, or `{ id, params, position }`), `data` (bars of your own; no stream), `adapter`, `stream` (`false`: no stream of its own), `historyLimit`, `features` (changes apply after mount too), `autoScale`, `signalMarkers`, `signalMarkerStyle`, `tradeZones`, `tradeZoneStyle`, `overrides` (style overrides by key, all of your app's), `watermarkText`, `onReady`, and `bind:chart`.
|
|
38
|
+
`symbol`, `timeframe`, `theme`, `chartType`, `indicators` (ids, or `{ id, params, position }`), `data` (bars of your own; no stream; bars that go on from the last, pushed or in a new array, go in as live ticks), `adapter`, `stream` (`false`: no stream of its own), `historyLimit`, `features` (changes apply after mount too), `autoScale`, `signalMarkers`, `signalMarkerStyle`, `tradeZones`, `tradeZoneStyle`, `overrides` (style overrides by key, all of your app's), `watermarkText`, `onReady`, and `bind:chart`.
|
|
39
39
|
|
|
40
40
|
Reach the underlying `Chart` (drawings, trading, execution adapters, plugins, resizable panes) via `bind:chart` or `onReady`. See the [main docs](https://github.com/bonguynvan/tradecanvas).
|
|
41
41
|
|
package/dist/TradeCanvas.svelte
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
DARK_THEME,
|
|
7
7
|
LIGHT_THEME,
|
|
8
8
|
syncIndicators,
|
|
9
|
+
feedBars,
|
|
9
10
|
} from '@tradecanvas/chart';
|
|
10
11
|
import type {
|
|
11
12
|
ChartType,
|
|
@@ -21,6 +22,7 @@
|
|
|
21
22
|
ChartStyleOverrides,
|
|
22
23
|
ChartOptions,
|
|
23
24
|
IndicatorSpec,
|
|
25
|
+
FedBars,
|
|
24
26
|
} from '@tradecanvas/chart';
|
|
25
27
|
|
|
26
28
|
interface Props {
|
|
@@ -32,9 +34,12 @@
|
|
|
32
34
|
indicators?: IndicatorSpec[];
|
|
33
35
|
/**
|
|
34
36
|
* Bars: the chart shows these, and opens no stream of its own when it has
|
|
35
|
-
* them at mount.
|
|
36
|
-
*
|
|
37
|
-
*
|
|
37
|
+
* them at mount. Bars that go on from those given before, the last one
|
|
38
|
+
* changed or bars added after it, go in as live ticks (the view isn't
|
|
39
|
+
* reset): pushed onto the same array, changed in place, or in a new array.
|
|
40
|
+
* Any other bars are a new series, as are yours after a stream gave the
|
|
41
|
+
* chart bars of its own. An older bar changed needs a new array with a new
|
|
42
|
+
* bar in its place.
|
|
38
43
|
*/
|
|
39
44
|
data?: OHLCBar[];
|
|
40
45
|
adapter?: DataAdapter;
|
|
@@ -96,8 +101,8 @@
|
|
|
96
101
|
const indicatorIds = new Map<string, string>();
|
|
97
102
|
/** The stream open now (`symbol|timeframe`), or null. */
|
|
98
103
|
let streamKey: string | null = null;
|
|
99
|
-
/** The bars last given to the chart
|
|
100
|
-
let fed:
|
|
104
|
+
/** The bars last given to the chart (`feedBars`). */
|
|
105
|
+
let fed: FedBars | null = null;
|
|
101
106
|
/** The features last applied, as text. */
|
|
102
107
|
let featuresKey: string | null = null;
|
|
103
108
|
|
|
@@ -183,38 +188,26 @@
|
|
|
183
188
|
$effect(() => { instance?.setTheme(resolveTheme(theme)); });
|
|
184
189
|
$effect(() => { instance?.setChartType(chartType); });
|
|
185
190
|
const barKey = (b: OHLCBar | undefined) => (b ? `${b.time},${b.open},${b.high},${b.low},${b.close},${b.volume}` : '');
|
|
186
|
-
const plain = (b: OHLCBar) => $state.snapshot(b) as OHLCBar;
|
|
187
191
|
|
|
188
192
|
/**
|
|
189
|
-
* Bars into the chart: on
|
|
190
|
-
* changed
|
|
191
|
-
* recalculated; anything else is a new
|
|
192
|
-
* not $state proxies, to read in its frames.
|
|
193
|
+
* Bars into the chart: bars that go on from those given before (a bar pushed
|
|
194
|
+
* or the last one changed, in place or in a new array) go in as ticks, so the
|
|
195
|
+
* view stays put and only the end is recalculated; anything else is a new
|
|
196
|
+
* series. The chart gets plain copies, not $state proxies, to read in its frames.
|
|
193
197
|
*/
|
|
194
198
|
function feed(target: Chart, bars: OHLCBar[]): void {
|
|
195
|
-
|
|
196
|
-
const last = barKey(bars[n - 1]);
|
|
197
|
-
const prev = fed;
|
|
198
|
-
fed = { bars, length: n, last };
|
|
199
|
-
if (prev && prev.bars === bars && prev.length > 0) {
|
|
200
|
-
if (n === prev.length) {
|
|
201
|
-
if (last !== prev.last) target.updateLastBar(plain(bars[n - 1]));
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
if (n === prev.length + 1) {
|
|
205
|
-
target.updateLastBar(plain(bars[n - 2]));
|
|
206
|
-
target.appendBar(plain(bars[n - 1]));
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
target.setData($state.snapshot(bars) as OHLCBar[]);
|
|
199
|
+
fed = feedBars(target, bars, fed);
|
|
211
200
|
}
|
|
212
201
|
|
|
213
202
|
// Follows the array, its length and the last bar's fields: a bar pushed onto
|
|
214
203
|
// $state data or the forming bar changed, without walking every bar.
|
|
215
204
|
$effect(() => {
|
|
216
205
|
const bars = data;
|
|
217
|
-
|
|
206
|
+
// Without data, the next bars are a new series: a stream may have come in between.
|
|
207
|
+
if (!bars) {
|
|
208
|
+
fed = null;
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
218
211
|
void barKey(bars[bars.length - 1]);
|
|
219
212
|
untrack(() => { if (instance) feed(instance, bars); });
|
|
220
213
|
});
|
|
@@ -9,9 +9,12 @@ interface Props {
|
|
|
9
9
|
indicators?: IndicatorSpec[];
|
|
10
10
|
/**
|
|
11
11
|
* Bars: the chart shows these, and opens no stream of its own when it has
|
|
12
|
-
* them at mount.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* them at mount. Bars that go on from those given before, the last one
|
|
13
|
+
* changed or bars added after it, go in as live ticks (the view isn't
|
|
14
|
+
* reset): pushed onto the same array, changed in place, or in a new array.
|
|
15
|
+
* Any other bars are a new series, as are yours after a stream gave the
|
|
16
|
+
* chart bars of its own. An older bar changed needs a new array with a new
|
|
17
|
+
* bar in its place.
|
|
15
18
|
*/
|
|
16
19
|
data?: OHLCBar[];
|
|
17
20
|
adapter?: DataAdapter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tradecanvas/svelte",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.30",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Svelte 5 component for @tradecanvas/chart — reactive props, runes, zero boilerplate.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"README.md"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@tradecanvas/chart": "1.
|
|
42
|
+
"@tradecanvas/chart": "1.48.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"svelte": ">=5.0.0"
|