@tradecanvas/vue 1.0.10 → 1.0.14
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 -21
- package/README.md +64 -64
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 TradeCanvas Contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TradeCanvas Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
# @tradecanvas/vue
|
|
2
|
-
|
|
3
|
-
Vue 3 component for [`@tradecanvas/chart`](https://www.npmjs.com/package/@tradecanvas/chart) — reactive props, template ref, zero boilerplate.
|
|
4
|
-
|
|
5
|
-
## Install
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @tradecanvas/vue @tradecanvas/chart
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
`vue` (>= 3.3) is a peer dependency.
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
```vue
|
|
16
|
-
<script setup lang="ts">
|
|
17
|
-
import { TradeCanvas } from '@tradecanvas/vue'
|
|
18
|
-
import type { Chart } from '@tradecanvas/chart'
|
|
19
|
-
|
|
20
|
-
function onReady(chart: Chart) {
|
|
21
|
-
// full charting API
|
|
22
|
-
}
|
|
23
|
-
</script>
|
|
24
|
-
|
|
25
|
-
<template>
|
|
26
|
-
<div style="height: 500px">
|
|
27
|
-
<TradeCanvas
|
|
28
|
-
symbol="BTCUSDT"
|
|
29
|
-
timeframe="5m"
|
|
30
|
-
theme="dark"
|
|
31
|
-
:indicators="['rsi', 'macd']"
|
|
32
|
-
@ready="onReady"
|
|
33
|
-
/>
|
|
34
|
-
</div>
|
|
35
|
-
</template>
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Streams live Binance data by default. Pass `:data="bars"` for static OHLC, or `:adapter="..."` for any feed.
|
|
39
|
-
|
|
40
|
-
## Props & events
|
|
41
|
-
|
|
42
|
-
Props: `symbol`, `timeframe`, `theme`, `chartType`, `indicators`, `data`, `adapter`, `historyLimit`, `features`, `autoScale`, `signalMarkers`, `signalMarkerStyle`, `tradeZones`, `tradeZoneStyle`, `watermarkText`.
|
|
43
|
-
|
|
44
|
-
Events: `@ready="(chart) => …"`, `@crosshairMove="(payload) => …"`.
|
|
45
|
-
|
|
46
|
-
## Imperative access
|
|
47
|
-
|
|
48
|
-
```vue
|
|
49
|
-
<script setup lang="ts">
|
|
50
|
-
import { ref } from 'vue'
|
|
51
|
-
const el = ref()
|
|
52
|
-
// el.value.getChart() · el.value.screenshot('chart.png')
|
|
53
|
-
</script>
|
|
54
|
-
|
|
55
|
-
<template>
|
|
56
|
-
<TradeCanvas ref="el" symbol="BTCUSDT" />
|
|
57
|
-
</template>
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
Reach the underlying `Chart` (drawings, trading, execution adapters, plugins, resizable panes) via `@ready` or the template ref's `getChart()`. See the [main docs](https://github.com/bonguynvan/tradecanvas).
|
|
61
|
-
|
|
62
|
-
## License
|
|
63
|
-
|
|
64
|
-
MIT
|
|
1
|
+
# @tradecanvas/vue
|
|
2
|
+
|
|
3
|
+
Vue 3 component for [`@tradecanvas/chart`](https://www.npmjs.com/package/@tradecanvas/chart) — reactive props, template ref, zero boilerplate.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @tradecanvas/vue @tradecanvas/chart
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`vue` (>= 3.3) is a peer dependency.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```vue
|
|
16
|
+
<script setup lang="ts">
|
|
17
|
+
import { TradeCanvas } from '@tradecanvas/vue'
|
|
18
|
+
import type { Chart } from '@tradecanvas/chart'
|
|
19
|
+
|
|
20
|
+
function onReady(chart: Chart) {
|
|
21
|
+
// full charting API
|
|
22
|
+
}
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<template>
|
|
26
|
+
<div style="height: 500px">
|
|
27
|
+
<TradeCanvas
|
|
28
|
+
symbol="BTCUSDT"
|
|
29
|
+
timeframe="5m"
|
|
30
|
+
theme="dark"
|
|
31
|
+
:indicators="['rsi', 'macd']"
|
|
32
|
+
@ready="onReady"
|
|
33
|
+
/>
|
|
34
|
+
</div>
|
|
35
|
+
</template>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Streams live Binance data by default. Pass `:data="bars"` for static OHLC, or `:adapter="..."` for any feed.
|
|
39
|
+
|
|
40
|
+
## Props & events
|
|
41
|
+
|
|
42
|
+
Props: `symbol`, `timeframe`, `theme`, `chartType`, `indicators`, `data`, `adapter`, `historyLimit`, `features`, `autoScale`, `signalMarkers`, `signalMarkerStyle`, `tradeZones`, `tradeZoneStyle`, `watermarkText`.
|
|
43
|
+
|
|
44
|
+
Events: `@ready="(chart) => …"`, `@crosshairMove="(payload) => …"`.
|
|
45
|
+
|
|
46
|
+
## Imperative access
|
|
47
|
+
|
|
48
|
+
```vue
|
|
49
|
+
<script setup lang="ts">
|
|
50
|
+
import { ref } from 'vue'
|
|
51
|
+
const el = ref()
|
|
52
|
+
// el.value.getChart() · el.value.screenshot('chart.png')
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<template>
|
|
56
|
+
<TradeCanvas ref="el" symbol="BTCUSDT" />
|
|
57
|
+
</template>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Reach the underlying `Chart` (drawings, trading, execution adapters, plugins, resizable panes) via `@ready` or the template ref's `getChart()`. See the [main docs](https://github.com/bonguynvan/tradecanvas).
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
MIT
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../src/TradeCanvas.vue","../src/TradeCanvas.vue"],"sourcesContent":["<template>\r\n <div ref=\"containerEl\" :style=\"{ width: '100%', height: '100%' }\" />\r\n</template>\r\n\r\n<script setup lang=\"ts\">\r\nimport { ref, onMounted, onUnmounted, watch } from 'vue';\r\nimport {\r\n Chart,\r\n BinanceAdapter,\r\n DARK_THEME,\r\n LIGHT_THEME,\r\n} from '@tradecanvas/chart';\r\nimport type {\r\n ChartType,\r\n TimeFrame,\r\n FeaturesConfig,\r\n Theme,\r\n OHLCBar,\r\n SignalMarker,\r\n TradeZone,\r\n SignalMarkerStyle,\r\n TradeZoneStyle,\r\n DataAdapter,\r\n} from '@tradecanvas/chart';\r\n\r\nconst props = withDefaults(\r\n defineProps<{\r\n symbol?: string;\r\n timeframe?: TimeFrame;\r\n theme?: 'dark' | 'light' | Theme;\r\n chartType?: ChartType;\r\n indicators?: string[];\r\n data?: OHLCBar[];\r\n adapter?: DataAdapter;\r\n historyLimit?: number;\r\n features?: FeaturesConfig;\r\n autoScale?: boolean;\r\n signalMarkers?: SignalMarker[];\r\n signalMarkerStyle?: SignalMarkerStyle;\r\n tradeZones?: TradeZone[];\r\n tradeZoneStyle?: TradeZoneStyle;\r\n watermarkText?: string;\r\n }>(),\r\n {\r\n symbol: 'BTCUSDT',\r\n timeframe: '5m' as TimeFrame,\r\n theme: 'dark',\r\n chartType: 'candlestick' as ChartType,\r\n indicators: () => [],\r\n historyLimit: 500,\r\n autoScale: true,\r\n },\r\n);\r\n\r\nconst emit = defineEmits<{\r\n ready: [chart: Chart];\r\n crosshairMove: [payload: unknown];\r\n}>();\r\n\r\nfunction resolveTheme(theme: 'dark' | 'light' | Theme): Theme {\r\n if (theme === 'dark') return DARK_THEME;\r\n if (theme === 'light') return LIGHT_THEME;\r\n return theme as Theme;\r\n}\r\n\r\nconst containerEl = ref<HTMLDivElement>();\r\nlet chart: Chart | null = null;\r\nconst indicatorIds = new Map<string, string>();\r\n\r\nfunction getChart(): Chart | null {\r\n return chart;\r\n}\r\n\r\nfunction screenshot(filename?: string): void {\r\n chart?.screenshot(filename);\r\n}\r\n\r\nfunction screenshotDataURL(): string | null {\r\n return chart?.screenshotDataURL() ?? null;\r\n}\r\n\r\ndefineExpose({ getChart, screenshot, screenshotDataURL });\r\n\r\nonMounted(() => {\r\n if (!containerEl.value) return;\r\n\r\n chart = new Chart(containerEl.value, {\r\n chartType: props.chartType,\r\n theme: resolveTheme(props.theme),\r\n autoScale: props.autoScale,\r\n rightMargin: 5,\r\n crosshair: { mode: 'magnet' },\r\n watermark: props.watermarkText\r\n ? { text: props.watermarkText, fontSize: 48, color: 'rgba(255,255,255,0.03)' }\r\n : undefined,\r\n features: {\r\n drawings: true,\r\n drawingMagnet: true,\r\n drawingUndoRedo: true,\r\n indicators: true,\r\n trading: true,\r\n volume: true,\r\n legend: true,\r\n crosshair: true,\r\n keyboard: true,\r\n screenshot: true,\r\n alerts: true,\r\n barCountdown: true,\r\n logScale: true,\r\n watermark: true,\r\n ...props.features,\r\n },\r\n });\r\n\r\n if (props.data) {\r\n chart.setData(props.data);\r\n } else {\r\n const adapter = props.adapter ?? new BinanceAdapter();\r\n chart.connect({ adapter, symbol: props.symbol, timeframe: props.timeframe, historyLimit: props.historyLimit });\r\n }\r\n\r\n // Apply initial reactive collections not covered by the constructor options.\r\n // Vue's watches aren't immediate, so without this the first render of\r\n // indicators / signal markers / trade zones would be dropped.\r\n for (const name of props.indicators) {\r\n const instanceId = chart.addIndicator(name);\r\n if (instanceId) indicatorIds.set(name, instanceId);\r\n }\r\n if (props.signalMarkers) chart.setSignalMarkers(props.signalMarkers);\r\n if (props.signalMarkerStyle) chart.setSignalMarkerStyle(props.signalMarkerStyle);\r\n if (props.tradeZones) chart.setTradeZones(props.tradeZones);\r\n if (props.tradeZoneStyle) chart.setTradeZoneStyle(props.tradeZoneStyle);\r\n\r\n emit('ready', chart);\r\n});\r\n\r\nonUnmounted(() => {\r\n if (chart) {\r\n chart.disconnectStream();\r\n chart.destroy();\r\n chart = null;\r\n }\r\n});\r\n\r\nwatch(\r\n () => [props.symbol, props.timeframe] as const,\r\n ([newSymbol, newTimeframe]) => {\r\n if (!chart || props.data) return;\r\n chart.disconnectStream();\r\n const adapter = props.adapter ?? new BinanceAdapter();\r\n chart.connect({ adapter, symbol: newSymbol, timeframe: newTimeframe, historyLimit: props.historyLimit });\r\n if (props.watermarkText) chart.setWatermark(props.watermarkText);\r\n },\r\n);\r\n\r\nwatch(() => props.theme, (t) => { chart?.setTheme(resolveTheme(t)); });\r\nwatch(() => props.chartType, (ct) => { chart?.setChartType(ct); });\r\nwatch(() => props.data, (d) => { if (d) chart?.setData(d); }, { deep: true });\r\n\r\nwatch(\r\n () => props.indicators,\r\n (newIndicators) => {\r\n if (!chart) return;\r\n const desired = new Set(newIndicators);\r\n for (const [name, instanceId] of indicatorIds) {\r\n if (!desired.has(name)) {\r\n chart.removeIndicator(instanceId);\r\n indicatorIds.delete(name);\r\n }\r\n }\r\n for (const name of newIndicators) {\r\n if (!indicatorIds.has(name)) {\r\n const instanceId = chart.addIndicator(name);\r\n if (instanceId) indicatorIds.set(name, instanceId);\r\n }\r\n }\r\n },\r\n { deep: true },\r\n);\r\n\r\nwatch(() => props.signalMarkers, (m) => { if (m) chart?.setSignalMarkers(m); }, { deep: true });\r\nwatch(() => props.signalMarkerStyle, (s) => { if (s) chart?.setSignalMarkerStyle(s); }, { deep: true });\r\nwatch(() => props.tradeZones, (z) => { if (z) chart?.setTradeZones(z); }, { deep: true });\r\nwatch(() => props.tradeZoneStyle, (s) => { if (s) chart?.setTradeZoneStyle(s); }, { deep: true });\r\n</script>\r\n","<template>\r\n <div ref=\"containerEl\" :style=\"{ width: '100%', height: '100%' }\" />\r\n</template>\r\n\r\n<script setup lang=\"ts\">\r\nimport { ref, onMounted, onUnmounted, watch } from 'vue';\r\nimport {\r\n Chart,\r\n BinanceAdapter,\r\n DARK_THEME,\r\n LIGHT_THEME,\r\n} from '@tradecanvas/chart';\r\nimport type {\r\n ChartType,\r\n TimeFrame,\r\n FeaturesConfig,\r\n Theme,\r\n OHLCBar,\r\n SignalMarker,\r\n TradeZone,\r\n SignalMarkerStyle,\r\n TradeZoneStyle,\r\n DataAdapter,\r\n} from '@tradecanvas/chart';\r\n\r\nconst props = withDefaults(\r\n defineProps<{\r\n symbol?: string;\r\n timeframe?: TimeFrame;\r\n theme?: 'dark' | 'light' | Theme;\r\n chartType?: ChartType;\r\n indicators?: string[];\r\n data?: OHLCBar[];\r\n adapter?: DataAdapter;\r\n historyLimit?: number;\r\n features?: FeaturesConfig;\r\n autoScale?: boolean;\r\n signalMarkers?: SignalMarker[];\r\n signalMarkerStyle?: SignalMarkerStyle;\r\n tradeZones?: TradeZone[];\r\n tradeZoneStyle?: TradeZoneStyle;\r\n watermarkText?: string;\r\n }>(),\r\n {\r\n symbol: 'BTCUSDT',\r\n timeframe: '5m' as TimeFrame,\r\n theme: 'dark',\r\n chartType: 'candlestick' as ChartType,\r\n indicators: () => [],\r\n historyLimit: 500,\r\n autoScale: true,\r\n },\r\n);\r\n\r\nconst emit = defineEmits<{\r\n ready: [chart: Chart];\r\n crosshairMove: [payload: unknown];\r\n}>();\r\n\r\nfunction resolveTheme(theme: 'dark' | 'light' | Theme): Theme {\r\n if (theme === 'dark') return DARK_THEME;\r\n if (theme === 'light') return LIGHT_THEME;\r\n return theme as Theme;\r\n}\r\n\r\nconst containerEl = ref<HTMLDivElement>();\r\nlet chart: Chart | null = null;\r\nconst indicatorIds = new Map<string, string>();\r\n\r\nfunction getChart(): Chart | null {\r\n return chart;\r\n}\r\n\r\nfunction screenshot(filename?: string): void {\r\n chart?.screenshot(filename);\r\n}\r\n\r\nfunction screenshotDataURL(): string | null {\r\n return chart?.screenshotDataURL() ?? null;\r\n}\r\n\r\ndefineExpose({ getChart, screenshot, screenshotDataURL });\r\n\r\nonMounted(() => {\r\n if (!containerEl.value) return;\r\n\r\n chart = new Chart(containerEl.value, {\r\n chartType: props.chartType,\r\n theme: resolveTheme(props.theme),\r\n autoScale: props.autoScale,\r\n rightMargin: 5,\r\n crosshair: { mode: 'magnet' },\r\n watermark: props.watermarkText\r\n ? { text: props.watermarkText, fontSize: 48, color: 'rgba(255,255,255,0.03)' }\r\n : undefined,\r\n features: {\r\n drawings: true,\r\n drawingMagnet: true,\r\n drawingUndoRedo: true,\r\n indicators: true,\r\n trading: true,\r\n volume: true,\r\n legend: true,\r\n crosshair: true,\r\n keyboard: true,\r\n screenshot: true,\r\n alerts: true,\r\n barCountdown: true,\r\n logScale: true,\r\n watermark: true,\r\n ...props.features,\r\n },\r\n });\r\n\r\n if (props.data) {\r\n chart.setData(props.data);\r\n } else {\r\n const adapter = props.adapter ?? new BinanceAdapter();\r\n chart.connect({ adapter, symbol: props.symbol, timeframe: props.timeframe, historyLimit: props.historyLimit });\r\n }\r\n\r\n // Apply initial reactive collections not covered by the constructor options.\r\n // Vue's watches aren't immediate, so without this the first render of\r\n // indicators / signal markers / trade zones would be dropped.\r\n for (const name of props.indicators) {\r\n const instanceId = chart.addIndicator(name);\r\n if (instanceId) indicatorIds.set(name, instanceId);\r\n }\r\n if (props.signalMarkers) chart.setSignalMarkers(props.signalMarkers);\r\n if (props.signalMarkerStyle) chart.setSignalMarkerStyle(props.signalMarkerStyle);\r\n if (props.tradeZones) chart.setTradeZones(props.tradeZones);\r\n if (props.tradeZoneStyle) chart.setTradeZoneStyle(props.tradeZoneStyle);\r\n\r\n emit('ready', chart);\r\n});\r\n\r\nonUnmounted(() => {\r\n if (chart) {\r\n chart.disconnectStream();\r\n chart.destroy();\r\n chart = null;\r\n }\r\n});\r\n\r\nwatch(\r\n () => [props.symbol, props.timeframe] as const,\r\n ([newSymbol, newTimeframe]) => {\r\n if (!chart || props.data) return;\r\n chart.disconnectStream();\r\n const adapter = props.adapter ?? new BinanceAdapter();\r\n chart.connect({ adapter, symbol: newSymbol, timeframe: newTimeframe, historyLimit: props.historyLimit });\r\n if (props.watermarkText) chart.setWatermark(props.watermarkText);\r\n },\r\n);\r\n\r\nwatch(() => props.theme, (t) => { chart?.setTheme(resolveTheme(t)); });\r\nwatch(() => props.chartType, (ct) => { chart?.setChartType(ct); });\r\nwatch(() => props.data, (d) => { if (d) chart?.setData(d); }, { deep: true });\r\n\r\nwatch(\r\n () => props.indicators,\r\n (newIndicators) => {\r\n if (!chart) return;\r\n const desired = new Set(newIndicators);\r\n for (const [name, instanceId] of indicatorIds) {\r\n if (!desired.has(name)) {\r\n chart.removeIndicator(instanceId);\r\n indicatorIds.delete(name);\r\n }\r\n }\r\n for (const name of newIndicators) {\r\n if (!indicatorIds.has(name)) {\r\n const instanceId = chart.addIndicator(name);\r\n if (instanceId) indicatorIds.set(name, instanceId);\r\n }\r\n }\r\n },\r\n { deep: true },\r\n);\r\n\r\nwatch(() => props.signalMarkers, (m) => { if (m) chart?.setSignalMarkers(m); }, { deep: true });\r\nwatch(() => props.signalMarkerStyle, (s) => { if (s) chart?.setSignalMarkerStyle(s); }, { deep: true });\r\nwatch(() => props.tradeZones, (z) => { if (z) chart?.setTradeZones(z); }, { deep: true });\r\nwatch(() => props.tradeZoneStyle, (s) => { if (s) chart?.setTradeZoneStyle(s); }, { deep: true });\r\n</script>\r\n"],"mappings":"2iBAyBA,IAAM,EAAQ,EA6BR,EAAO,EAKb,SAAS,EAAa,EAAw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CAAC,EAC/F,EAAA,EAAA,WAAY,EAAM,kBAAoB,GAAM,CAAM,GAAG,GAAO,qBAAqB,EAAE,EAAK,CAAE,KAAM,GAAM,CAAC,EACvG,EAAA,EAAA,WAAY,EAAM,WAAa,GAAM,CAAM,GAAG,GAAO,cAAc,EAAE,EAAK,CAAE,KAAM,GAAM,CAAC,EACzF,EAAA,EAAA,WAAY,EAAM,eAAiB,GAAM,CAAM,GAAG,GAAO,kBAAkB,EAAE,EAAK,CAAE,KAAM,GAAM,CAAC,oDAtL3B,MAAA,SAA3D,cAAJ,IAAI,EAAe,MAAO,CAAA,MAAA,OAAA,OAAA,OAAiC"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/TradeCanvas.vue","../src/TradeCanvas.vue"],"sourcesContent":["<template>\n <div ref=\"containerEl\" :style=\"{ width: '100%', height: '100%' }\" />\n</template>\n\n<script setup lang=\"ts\">\nimport { ref, onMounted, onUnmounted, watch } from 'vue';\nimport {\n Chart,\n BinanceAdapter,\n DARK_THEME,\n LIGHT_THEME,\n} from '@tradecanvas/chart';\nimport type {\n ChartType,\n TimeFrame,\n FeaturesConfig,\n Theme,\n OHLCBar,\n SignalMarker,\n TradeZone,\n SignalMarkerStyle,\n TradeZoneStyle,\n DataAdapter,\n} from '@tradecanvas/chart';\n\nconst props = withDefaults(\n defineProps<{\n symbol?: string;\n timeframe?: TimeFrame;\n theme?: 'dark' | 'light' | Theme;\n chartType?: ChartType;\n indicators?: string[];\n data?: OHLCBar[];\n adapter?: DataAdapter;\n historyLimit?: number;\n features?: FeaturesConfig;\n autoScale?: boolean;\n signalMarkers?: SignalMarker[];\n signalMarkerStyle?: SignalMarkerStyle;\n tradeZones?: TradeZone[];\n tradeZoneStyle?: TradeZoneStyle;\n watermarkText?: string;\n }>(),\n {\n symbol: 'BTCUSDT',\n timeframe: '5m' as TimeFrame,\n theme: 'dark',\n chartType: 'candlestick' as ChartType,\n indicators: () => [],\n historyLimit: 500,\n autoScale: true,\n },\n);\n\nconst emit = defineEmits<{\n ready: [chart: Chart];\n crosshairMove: [payload: unknown];\n}>();\n\nfunction resolveTheme(theme: 'dark' | 'light' | Theme): Theme {\n if (theme === 'dark') return DARK_THEME;\n if (theme === 'light') return LIGHT_THEME;\n return theme as Theme;\n}\n\nconst containerEl = ref<HTMLDivElement>();\nlet chart: Chart | null = null;\nconst indicatorIds = new Map<string, string>();\n\nfunction getChart(): Chart | null {\n return chart;\n}\n\nfunction screenshot(filename?: string): void {\n chart?.screenshot(filename);\n}\n\nfunction screenshotDataURL(): string | null {\n return chart?.screenshotDataURL() ?? null;\n}\n\ndefineExpose({ getChart, screenshot, screenshotDataURL });\n\nonMounted(() => {\n if (!containerEl.value) return;\n\n chart = new Chart(containerEl.value, {\n chartType: props.chartType,\n theme: resolveTheme(props.theme),\n autoScale: props.autoScale,\n rightMargin: 5,\n crosshair: { mode: 'magnet' },\n watermark: props.watermarkText\n ? { text: props.watermarkText, fontSize: 48, color: 'rgba(255,255,255,0.03)' }\n : undefined,\n features: {\n drawings: true,\n drawingMagnet: true,\n drawingUndoRedo: true,\n indicators: true,\n trading: true,\n volume: true,\n legend: true,\n crosshair: true,\n keyboard: true,\n screenshot: true,\n alerts: true,\n barCountdown: true,\n logScale: true,\n watermark: true,\n ...props.features,\n },\n });\n\n if (props.data) {\n chart.setData(props.data);\n } else {\n const adapter = props.adapter ?? new BinanceAdapter();\n chart.connect({ adapter, symbol: props.symbol, timeframe: props.timeframe, historyLimit: props.historyLimit });\n }\n\n // Apply initial reactive collections not covered by the constructor options.\n // Vue's watches aren't immediate, so without this the first render of\n // indicators / signal markers / trade zones would be dropped.\n for (const name of props.indicators) {\n const instanceId = chart.addIndicator(name);\n if (instanceId) indicatorIds.set(name, instanceId);\n }\n if (props.signalMarkers) chart.setSignalMarkers(props.signalMarkers);\n if (props.signalMarkerStyle) chart.setSignalMarkerStyle(props.signalMarkerStyle);\n if (props.tradeZones) chart.setTradeZones(props.tradeZones);\n if (props.tradeZoneStyle) chart.setTradeZoneStyle(props.tradeZoneStyle);\n\n emit('ready', chart);\n});\n\nonUnmounted(() => {\n if (chart) {\n chart.disconnectStream();\n chart.destroy();\n chart = null;\n }\n});\n\nwatch(\n () => [props.symbol, props.timeframe] as const,\n ([newSymbol, newTimeframe]) => {\n if (!chart || props.data) return;\n chart.disconnectStream();\n const adapter = props.adapter ?? new BinanceAdapter();\n chart.connect({ adapter, symbol: newSymbol, timeframe: newTimeframe, historyLimit: props.historyLimit });\n if (props.watermarkText) chart.setWatermark(props.watermarkText);\n },\n);\n\nwatch(() => props.theme, (t) => { chart?.setTheme(resolveTheme(t)); });\nwatch(() => props.chartType, (ct) => { chart?.setChartType(ct); });\nwatch(() => props.data, (d) => { if (d) chart?.setData(d); }, { deep: true });\n\nwatch(\n () => props.indicators,\n (newIndicators) => {\n if (!chart) return;\n const desired = new Set(newIndicators);\n for (const [name, instanceId] of indicatorIds) {\n if (!desired.has(name)) {\n chart.removeIndicator(instanceId);\n indicatorIds.delete(name);\n }\n }\n for (const name of newIndicators) {\n if (!indicatorIds.has(name)) {\n const instanceId = chart.addIndicator(name);\n if (instanceId) indicatorIds.set(name, instanceId);\n }\n }\n },\n { deep: true },\n);\n\nwatch(() => props.signalMarkers, (m) => { if (m) chart?.setSignalMarkers(m); }, { deep: true });\nwatch(() => props.signalMarkerStyle, (s) => { if (s) chart?.setSignalMarkerStyle(s); }, { deep: true });\nwatch(() => props.tradeZones, (z) => { if (z) chart?.setTradeZones(z); }, { deep: true });\nwatch(() => props.tradeZoneStyle, (s) => { if (s) chart?.setTradeZoneStyle(s); }, { deep: true });\n</script>\n","<template>\n <div ref=\"containerEl\" :style=\"{ width: '100%', height: '100%' }\" />\n</template>\n\n<script setup lang=\"ts\">\nimport { ref, onMounted, onUnmounted, watch } from 'vue';\nimport {\n Chart,\n BinanceAdapter,\n DARK_THEME,\n LIGHT_THEME,\n} from '@tradecanvas/chart';\nimport type {\n ChartType,\n TimeFrame,\n FeaturesConfig,\n Theme,\n OHLCBar,\n SignalMarker,\n TradeZone,\n SignalMarkerStyle,\n TradeZoneStyle,\n DataAdapter,\n} from '@tradecanvas/chart';\n\nconst props = withDefaults(\n defineProps<{\n symbol?: string;\n timeframe?: TimeFrame;\n theme?: 'dark' | 'light' | Theme;\n chartType?: ChartType;\n indicators?: string[];\n data?: OHLCBar[];\n adapter?: DataAdapter;\n historyLimit?: number;\n features?: FeaturesConfig;\n autoScale?: boolean;\n signalMarkers?: SignalMarker[];\n signalMarkerStyle?: SignalMarkerStyle;\n tradeZones?: TradeZone[];\n tradeZoneStyle?: TradeZoneStyle;\n watermarkText?: string;\n }>(),\n {\n symbol: 'BTCUSDT',\n timeframe: '5m' as TimeFrame,\n theme: 'dark',\n chartType: 'candlestick' as ChartType,\n indicators: () => [],\n historyLimit: 500,\n autoScale: true,\n },\n);\n\nconst emit = defineEmits<{\n ready: [chart: Chart];\n crosshairMove: [payload: unknown];\n}>();\n\nfunction resolveTheme(theme: 'dark' | 'light' | Theme): Theme {\n if (theme === 'dark') return DARK_THEME;\n if (theme === 'light') return LIGHT_THEME;\n return theme as Theme;\n}\n\nconst containerEl = ref<HTMLDivElement>();\nlet chart: Chart | null = null;\nconst indicatorIds = new Map<string, string>();\n\nfunction getChart(): Chart | null {\n return chart;\n}\n\nfunction screenshot(filename?: string): void {\n chart?.screenshot(filename);\n}\n\nfunction screenshotDataURL(): string | null {\n return chart?.screenshotDataURL() ?? null;\n}\n\ndefineExpose({ getChart, screenshot, screenshotDataURL });\n\nonMounted(() => {\n if (!containerEl.value) return;\n\n chart = new Chart(containerEl.value, {\n chartType: props.chartType,\n theme: resolveTheme(props.theme),\n autoScale: props.autoScale,\n rightMargin: 5,\n crosshair: { mode: 'magnet' },\n watermark: props.watermarkText\n ? { text: props.watermarkText, fontSize: 48, color: 'rgba(255,255,255,0.03)' }\n : undefined,\n features: {\n drawings: true,\n drawingMagnet: true,\n drawingUndoRedo: true,\n indicators: true,\n trading: true,\n volume: true,\n legend: true,\n crosshair: true,\n keyboard: true,\n screenshot: true,\n alerts: true,\n barCountdown: true,\n logScale: true,\n watermark: true,\n ...props.features,\n },\n });\n\n if (props.data) {\n chart.setData(props.data);\n } else {\n const adapter = props.adapter ?? new BinanceAdapter();\n chart.connect({ adapter, symbol: props.symbol, timeframe: props.timeframe, historyLimit: props.historyLimit });\n }\n\n // Apply initial reactive collections not covered by the constructor options.\n // Vue's watches aren't immediate, so without this the first render of\n // indicators / signal markers / trade zones would be dropped.\n for (const name of props.indicators) {\n const instanceId = chart.addIndicator(name);\n if (instanceId) indicatorIds.set(name, instanceId);\n }\n if (props.signalMarkers) chart.setSignalMarkers(props.signalMarkers);\n if (props.signalMarkerStyle) chart.setSignalMarkerStyle(props.signalMarkerStyle);\n if (props.tradeZones) chart.setTradeZones(props.tradeZones);\n if (props.tradeZoneStyle) chart.setTradeZoneStyle(props.tradeZoneStyle);\n\n emit('ready', chart);\n});\n\nonUnmounted(() => {\n if (chart) {\n chart.disconnectStream();\n chart.destroy();\n chart = null;\n }\n});\n\nwatch(\n () => [props.symbol, props.timeframe] as const,\n ([newSymbol, newTimeframe]) => {\n if (!chart || props.data) return;\n chart.disconnectStream();\n const adapter = props.adapter ?? new BinanceAdapter();\n chart.connect({ adapter, symbol: newSymbol, timeframe: newTimeframe, historyLimit: props.historyLimit });\n if (props.watermarkText) chart.setWatermark(props.watermarkText);\n },\n);\n\nwatch(() => props.theme, (t) => { chart?.setTheme(resolveTheme(t)); });\nwatch(() => props.chartType, (ct) => { chart?.setChartType(ct); });\nwatch(() => props.data, (d) => { if (d) chart?.setData(d); }, { deep: true });\n\nwatch(\n () => props.indicators,\n (newIndicators) => {\n if (!chart) return;\n const desired = new Set(newIndicators);\n for (const [name, instanceId] of indicatorIds) {\n if (!desired.has(name)) {\n chart.removeIndicator(instanceId);\n indicatorIds.delete(name);\n }\n }\n for (const name of newIndicators) {\n if (!indicatorIds.has(name)) {\n const instanceId = chart.addIndicator(name);\n if (instanceId) indicatorIds.set(name, instanceId);\n }\n }\n },\n { deep: true },\n);\n\nwatch(() => props.signalMarkers, (m) => { if (m) chart?.setSignalMarkers(m); }, { deep: true });\nwatch(() => props.signalMarkerStyle, (s) => { if (s) chart?.setSignalMarkerStyle(s); }, { deep: true });\nwatch(() => props.tradeZones, (z) => { if (z) chart?.setTradeZones(z); }, { deep: true });\nwatch(() => props.tradeZoneStyle, (s) => { if (s) chart?.setTradeZoneStyle(s); }, { deep: true });\n</script>\n"],"mappings":"2iBAyBA,IAAM,EAAQ,EA6BR,EAAO,EAKb,SAAS,EAAa,EAAwC,CAG5D,OAFI,IAAU,OAAe,EAAA,WACzB,IAAU,QAAgB,EAAA,YACvB,EAGT,IAAM,GAAA,EAAA,EAAA,MAAmC,CACrC,EAAsB,KACpB,EAAe,IAAI,IAEzB,SAAS,GAAyB,CAChC,OAAO,EAGT,SAAS,EAAW,EAAyB,CAC3C,GAAO,WAAW,EAAS,CAG7B,SAAS,GAAmC,CAC1C,OAAO,GAAO,mBAAmB,EAAI,YAGvC,EAAa,CAAE,WAAU,aAAY,oBAAmB,CAAC,EAEzD,EAAA,EAAA,eAAgB,CACT,KAAY,MA8BjB,IA5BA,EAAQ,IAAI,EAAA,MAAM,EAAY,MAAO,CACnC,UAAW,EAAM,UACjB,MAAO,EAAa,EAAM,MAAM,CAChC,UAAW,EAAM,UACjB,YAAa,EACb,UAAW,CAAE,KAAM,SAAU,CAC7B,UAAW,EAAM,cACb,CAAE,KAAM,EAAM,cAAe,SAAU,GAAI,MAAO,yBAAyB,CAC3E,IAAA,GACJ,SAAU,CACR,SAAU,GACV,cAAe,GACf,gBAAiB,GACjB,WAAY,GACZ,QAAS,GACT,OAAQ,GACR,OAAQ,GACR,UAAW,GACX,SAAU,GACV,WAAY,GACZ,OAAQ,GACR,aAAc,GACd,SAAU,GACV,UAAW,GACX,GAAG,EAAM,SACV,CACF,CAAC,CAEE,EAAM,KACR,EAAM,QAAQ,EAAM,KAAK,KACpB,CACL,IAAM,EAAU,EA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AM,KAAe,EAC1B,EAAQ,IAAI,EAAK,GACpB,EAAM,gBAAgB,EAAW,CACjC,EAAa,OAAO,EAAK,EAG7B,IAAK,IAAM,KAAQ,EACjB,GAAI,CAAC,EAAa,IAAI,EAAK,CAAE,CAC3B,IAAM,EAAa,EAAM,aAAa,EAAK,CACvC,GAAY,EAAa,IAAI,EAAM,EAAW,GAIxD,CAAE,KAAM,GAAM,CACf,EAED,EAAA,EAAA,WAAY,EAAM,cAAgB,GAAM,CAAM,GAAG,GAAO,iBAAiB,EAAE,EAAK,CAAE,KAAM,GAAM,CAAC,EAC/F,EAAA,EAAA,WAAY,EAAM,kBAAoB,GAAM,CAAM,GAAG,GAAO,qBAAqB,EAAE,EAAK,CAAE,KAAM,GAAM,CAAC,EACvG,EAAA,EAAA,WAAY,EAAM,WAAa,GAAM,CAAM,GAAG,GAAO,cAAc,EAAE,EAAK,CAAE,KAAM,GAAM,CAAC,EACzF,EAAA,EAAA,WAAY,EAAM,eAAiB,GAAM,CAAM,GAAG,GAAO,kBAAkB,EAAE,EAAK,CAAE,KAAM,GAAM,CAAC,oDAtL3B,MAAA,SAA3D,cAAJ,IAAI,EAAe,MAAO,CAAA,MAAA,OAAA,OAAA,OAAiC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/TradeCanvas.vue","../src/TradeCanvas.vue"],"sourcesContent":["<template>\r\n <div ref=\"containerEl\" :style=\"{ width: '100%', height: '100%' }\" />\r\n</template>\r\n\r\n<script setup lang=\"ts\">\r\nimport { ref, onMounted, onUnmounted, watch } from 'vue';\r\nimport {\r\n Chart,\r\n BinanceAdapter,\r\n DARK_THEME,\r\n LIGHT_THEME,\r\n} from '@tradecanvas/chart';\r\nimport type {\r\n ChartType,\r\n TimeFrame,\r\n FeaturesConfig,\r\n Theme,\r\n OHLCBar,\r\n SignalMarker,\r\n TradeZone,\r\n SignalMarkerStyle,\r\n TradeZoneStyle,\r\n DataAdapter,\r\n} from '@tradecanvas/chart';\r\n\r\nconst props = withDefaults(\r\n defineProps<{\r\n symbol?: string;\r\n timeframe?: TimeFrame;\r\n theme?: 'dark' | 'light' | Theme;\r\n chartType?: ChartType;\r\n indicators?: string[];\r\n data?: OHLCBar[];\r\n adapter?: DataAdapter;\r\n historyLimit?: number;\r\n features?: FeaturesConfig;\r\n autoScale?: boolean;\r\n signalMarkers?: SignalMarker[];\r\n signalMarkerStyle?: SignalMarkerStyle;\r\n tradeZones?: TradeZone[];\r\n tradeZoneStyle?: TradeZoneStyle;\r\n watermarkText?: string;\r\n }>(),\r\n {\r\n symbol: 'BTCUSDT',\r\n timeframe: '5m' as TimeFrame,\r\n theme: 'dark',\r\n chartType: 'candlestick' as ChartType,\r\n indicators: () => [],\r\n historyLimit: 500,\r\n autoScale: true,\r\n },\r\n);\r\n\r\nconst emit = defineEmits<{\r\n ready: [chart: Chart];\r\n crosshairMove: [payload: unknown];\r\n}>();\r\n\r\nfunction resolveTheme(theme: 'dark' | 'light' | Theme): Theme {\r\n if (theme === 'dark') return DARK_THEME;\r\n if (theme === 'light') return LIGHT_THEME;\r\n return theme as Theme;\r\n}\r\n\r\nconst containerEl = ref<HTMLDivElement>();\r\nlet chart: Chart | null = null;\r\nconst indicatorIds = new Map<string, string>();\r\n\r\nfunction getChart(): Chart | null {\r\n return chart;\r\n}\r\n\r\nfunction screenshot(filename?: string): void {\r\n chart?.screenshot(filename);\r\n}\r\n\r\nfunction screenshotDataURL(): string | null {\r\n return chart?.screenshotDataURL() ?? null;\r\n}\r\n\r\ndefineExpose({ getChart, screenshot, screenshotDataURL });\r\n\r\nonMounted(() => {\r\n if (!containerEl.value) return;\r\n\r\n chart = new Chart(containerEl.value, {\r\n chartType: props.chartType,\r\n theme: resolveTheme(props.theme),\r\n autoScale: props.autoScale,\r\n rightMargin: 5,\r\n crosshair: { mode: 'magnet' },\r\n watermark: props.watermarkText\r\n ? { text: props.watermarkText, fontSize: 48, color: 'rgba(255,255,255,0.03)' }\r\n : undefined,\r\n features: {\r\n drawings: true,\r\n drawingMagnet: true,\r\n drawingUndoRedo: true,\r\n indicators: true,\r\n trading: true,\r\n volume: true,\r\n legend: true,\r\n crosshair: true,\r\n keyboard: true,\r\n screenshot: true,\r\n alerts: true,\r\n barCountdown: true,\r\n logScale: true,\r\n watermark: true,\r\n ...props.features,\r\n },\r\n });\r\n\r\n if (props.data) {\r\n chart.setData(props.data);\r\n } else {\r\n const adapter = props.adapter ?? new BinanceAdapter();\r\n chart.connect({ adapter, symbol: props.symbol, timeframe: props.timeframe, historyLimit: props.historyLimit });\r\n }\r\n\r\n // Apply initial reactive collections not covered by the constructor options.\r\n // Vue's watches aren't immediate, so without this the first render of\r\n // indicators / signal markers / trade zones would be dropped.\r\n for (const name of props.indicators) {\r\n const instanceId = chart.addIndicator(name);\r\n if (instanceId) indicatorIds.set(name, instanceId);\r\n }\r\n if (props.signalMarkers) chart.setSignalMarkers(props.signalMarkers);\r\n if (props.signalMarkerStyle) chart.setSignalMarkerStyle(props.signalMarkerStyle);\r\n if (props.tradeZones) chart.setTradeZones(props.tradeZones);\r\n if (props.tradeZoneStyle) chart.setTradeZoneStyle(props.tradeZoneStyle);\r\n\r\n emit('ready', chart);\r\n});\r\n\r\nonUnmounted(() => {\r\n if (chart) {\r\n chart.disconnectStream();\r\n chart.destroy();\r\n chart = null;\r\n }\r\n});\r\n\r\nwatch(\r\n () => [props.symbol, props.timeframe] as const,\r\n ([newSymbol, newTimeframe]) => {\r\n if (!chart || props.data) return;\r\n chart.disconnectStream();\r\n const adapter = props.adapter ?? new BinanceAdapter();\r\n chart.connect({ adapter, symbol: newSymbol, timeframe: newTimeframe, historyLimit: props.historyLimit });\r\n if (props.watermarkText) chart.setWatermark(props.watermarkText);\r\n },\r\n);\r\n\r\nwatch(() => props.theme, (t) => { chart?.setTheme(resolveTheme(t)); });\r\nwatch(() => props.chartType, (ct) => { chart?.setChartType(ct); });\r\nwatch(() => props.data, (d) => { if (d) chart?.setData(d); }, { deep: true });\r\n\r\nwatch(\r\n () => props.indicators,\r\n (newIndicators) => {\r\n if (!chart) return;\r\n const desired = new Set(newIndicators);\r\n for (const [name, instanceId] of indicatorIds) {\r\n if (!desired.has(name)) {\r\n chart.removeIndicator(instanceId);\r\n indicatorIds.delete(name);\r\n }\r\n }\r\n for (const name of newIndicators) {\r\n if (!indicatorIds.has(name)) {\r\n const instanceId = chart.addIndicator(name);\r\n if (instanceId) indicatorIds.set(name, instanceId);\r\n }\r\n }\r\n },\r\n { deep: true },\r\n);\r\n\r\nwatch(() => props.signalMarkers, (m) => { if (m) chart?.setSignalMarkers(m); }, { deep: true });\r\nwatch(() => props.signalMarkerStyle, (s) => { if (s) chart?.setSignalMarkerStyle(s); }, { deep: true });\r\nwatch(() => props.tradeZones, (z) => { if (z) chart?.setTradeZones(z); }, { deep: true });\r\nwatch(() => props.tradeZoneStyle, (s) => { if (s) chart?.setTradeZoneStyle(s); }, { deep: true });\r\n</script>\r\n","<template>\r\n <div ref=\"containerEl\" :style=\"{ width: '100%', height: '100%' }\" />\r\n</template>\r\n\r\n<script setup lang=\"ts\">\r\nimport { ref, onMounted, onUnmounted, watch } from 'vue';\r\nimport {\r\n Chart,\r\n BinanceAdapter,\r\n DARK_THEME,\r\n LIGHT_THEME,\r\n} from '@tradecanvas/chart';\r\nimport type {\r\n ChartType,\r\n TimeFrame,\r\n FeaturesConfig,\r\n Theme,\r\n OHLCBar,\r\n SignalMarker,\r\n TradeZone,\r\n SignalMarkerStyle,\r\n TradeZoneStyle,\r\n DataAdapter,\r\n} from '@tradecanvas/chart';\r\n\r\nconst props = withDefaults(\r\n defineProps<{\r\n symbol?: string;\r\n timeframe?: TimeFrame;\r\n theme?: 'dark' | 'light' | Theme;\r\n chartType?: ChartType;\r\n indicators?: string[];\r\n data?: OHLCBar[];\r\n adapter?: DataAdapter;\r\n historyLimit?: number;\r\n features?: FeaturesConfig;\r\n autoScale?: boolean;\r\n signalMarkers?: SignalMarker[];\r\n signalMarkerStyle?: SignalMarkerStyle;\r\n tradeZones?: TradeZone[];\r\n tradeZoneStyle?: TradeZoneStyle;\r\n watermarkText?: string;\r\n }>(),\r\n {\r\n symbol: 'BTCUSDT',\r\n timeframe: '5m' as TimeFrame,\r\n theme: 'dark',\r\n chartType: 'candlestick' as ChartType,\r\n indicators: () => [],\r\n historyLimit: 500,\r\n autoScale: true,\r\n },\r\n);\r\n\r\nconst emit = defineEmits<{\r\n ready: [chart: Chart];\r\n crosshairMove: [payload: unknown];\r\n}>();\r\n\r\nfunction resolveTheme(theme: 'dark' | 'light' | Theme): Theme {\r\n if (theme === 'dark') return DARK_THEME;\r\n if (theme === 'light') return LIGHT_THEME;\r\n return theme as Theme;\r\n}\r\n\r\nconst containerEl = ref<HTMLDivElement>();\r\nlet chart: Chart | null = null;\r\nconst indicatorIds = new Map<string, string>();\r\n\r\nfunction getChart(): Chart | null {\r\n return chart;\r\n}\r\n\r\nfunction screenshot(filename?: string): void {\r\n chart?.screenshot(filename);\r\n}\r\n\r\nfunction screenshotDataURL(): string | null {\r\n return chart?.screenshotDataURL() ?? null;\r\n}\r\n\r\ndefineExpose({ getChart, screenshot, screenshotDataURL });\r\n\r\nonMounted(() => {\r\n if (!containerEl.value) return;\r\n\r\n chart = new Chart(containerEl.value, {\r\n chartType: props.chartType,\r\n theme: resolveTheme(props.theme),\r\n autoScale: props.autoScale,\r\n rightMargin: 5,\r\n crosshair: { mode: 'magnet' },\r\n watermark: props.watermarkText\r\n ? { text: props.watermarkText, fontSize: 48, color: 'rgba(255,255,255,0.03)' }\r\n : undefined,\r\n features: {\r\n drawings: true,\r\n drawingMagnet: true,\r\n drawingUndoRedo: true,\r\n indicators: true,\r\n trading: true,\r\n volume: true,\r\n legend: true,\r\n crosshair: true,\r\n keyboard: true,\r\n screenshot: true,\r\n alerts: true,\r\n barCountdown: true,\r\n logScale: true,\r\n watermark: true,\r\n ...props.features,\r\n },\r\n });\r\n\r\n if (props.data) {\r\n chart.setData(props.data);\r\n } else {\r\n const adapter = props.adapter ?? new BinanceAdapter();\r\n chart.connect({ adapter, symbol: props.symbol, timeframe: props.timeframe, historyLimit: props.historyLimit });\r\n }\r\n\r\n // Apply initial reactive collections not covered by the constructor options.\r\n // Vue's watches aren't immediate, so without this the first render of\r\n // indicators / signal markers / trade zones would be dropped.\r\n for (const name of props.indicators) {\r\n const instanceId = chart.addIndicator(name);\r\n if (instanceId) indicatorIds.set(name, instanceId);\r\n }\r\n if (props.signalMarkers) chart.setSignalMarkers(props.signalMarkers);\r\n if (props.signalMarkerStyle) chart.setSignalMarkerStyle(props.signalMarkerStyle);\r\n if (props.tradeZones) chart.setTradeZones(props.tradeZones);\r\n if (props.tradeZoneStyle) chart.setTradeZoneStyle(props.tradeZoneStyle);\r\n\r\n emit('ready', chart);\r\n});\r\n\r\nonUnmounted(() => {\r\n if (chart) {\r\n chart.disconnectStream();\r\n chart.destroy();\r\n chart = null;\r\n }\r\n});\r\n\r\nwatch(\r\n () => [props.symbol, props.timeframe] as const,\r\n ([newSymbol, newTimeframe]) => {\r\n if (!chart || props.data) return;\r\n chart.disconnectStream();\r\n const adapter = props.adapter ?? new BinanceAdapter();\r\n chart.connect({ adapter, symbol: newSymbol, timeframe: newTimeframe, historyLimit: props.historyLimit });\r\n if (props.watermarkText) chart.setWatermark(props.watermarkText);\r\n },\r\n);\r\n\r\nwatch(() => props.theme, (t) => { chart?.setTheme(resolveTheme(t)); });\r\nwatch(() => props.chartType, (ct) => { chart?.setChartType(ct); });\r\nwatch(() => props.data, (d) => { if (d) chart?.setData(d); }, { deep: true });\r\n\r\nwatch(\r\n () => props.indicators,\r\n (newIndicators) => {\r\n if (!chart) return;\r\n const desired = new Set(newIndicators);\r\n for (const [name, instanceId] of indicatorIds) {\r\n if (!desired.has(name)) {\r\n chart.removeIndicator(instanceId);\r\n indicatorIds.delete(name);\r\n }\r\n }\r\n for (const name of newIndicators) {\r\n if (!indicatorIds.has(name)) {\r\n const instanceId = chart.addIndicator(name);\r\n if (instanceId) indicatorIds.set(name, instanceId);\r\n }\r\n }\r\n },\r\n { deep: true },\r\n);\r\n\r\nwatch(() => props.signalMarkers, (m) => { if (m) chart?.setSignalMarkers(m); }, { deep: true });\r\nwatch(() => props.signalMarkerStyle, (s) => { if (s) chart?.setSignalMarkerStyle(s); }, { deep: true });\r\nwatch(() => props.tradeZones, (z) => { if (z) chart?.setTradeZones(z); }, { deep: true });\r\nwatch(() => props.tradeZoneStyle, (s) => { if (s) chart?.setTradeZoneStyle(s); }, { deep: true });\r\n</script>\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyBA,IAAM,IAAQ,GA6BR,IAAO;EAKb,SAAS,EAAa,GAAwC;AAG5D,UAFI,MAAU,SAAe,IACzB,MAAU,UAAgB,IACvB;;EAGT,IAAM,IAAc,GAAqB,EACrC,IAAsB,MACpB,oBAAe,IAAI,KAAqB;EAE9C,SAAS,IAAyB;AAChC,UAAO;;EAGT,SAAS,EAAW,GAAyB;AAC3C,MAAO,WAAW,EAAS;;EAG7B,SAAS,IAAmC;AAC1C,UAAO,GAAO,mBAAmB,IAAI;;SAGvC,EAAa;GAAE;GAAU;GAAY;GAAmB,CAAC,EAEzD,QAAgB;AACT,SAAY,OA8BjB;QA5BA,IAAQ,IAAI,EAAM,EAAY,OAAO;KACnC,WAAW,EAAM;KACjB,OAAO,EAAa,EAAM,MAAM;KAChC,WAAW,EAAM;KACjB,aAAa;KACb,WAAW,EAAE,MAAM,UAAU;KAC7B,WAAW,EAAM,gBACb;MAAE,MAAM,EAAM;MAAe,UAAU;MAAI,OAAO;MAA0B,GAC5E,KAAA;KACJ,UAAU;MACR,UAAU;MACV,eAAe;MACf,iBAAiB;MACjB,YAAY;MACZ,SAAS;MACT,QAAQ;MACR,QAAQ;MACR,WAAW;MACX,UAAU;MACV,YAAY;MACZ,QAAQ;MACR,cAAc;MACd,UAAU;MACV,WAAW;MACX,GAAG,EAAM;MACV;KACF,CAAC,EAEE,EAAM,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AAM,CAAC,GAAM,MAAe,EAC/B,CAAK,EAAQ,IAAI,EAAK,KACpB,EAAM,gBAAgB,EAAW,EACjC,EAAa,OAAO,EAAK;AAG7B,QAAK,IAAM,KAAQ,EACjB,KAAI,CAAC,EAAa,IAAI,EAAK,EAAE;IAC3B,IAAM,IAAa,EAAM,aAAa,EAAK;AAC3C,IAAI,KAAY,EAAa,IAAI,GAAM,EAAW;;KAIxD,EAAE,MAAM,IAAM,CACf,EAED,QAAY,EAAM,gBAAgB,MAAM;AAAE,GAAI,KAAG,GAAO,iBAAiB,EAAE;KAAK,EAAE,MAAM,IAAM,CAAC,EAC/F,QAAY,EAAM,oBAAoB,MAAM;AAAE,GAAI,KAAG,GAAO,qBAAqB,EAAE;KAAK,EAAE,MAAM,IAAM,CAAC,EACvG,QAAY,EAAM,aAAa,MAAM;AAAE,GAAI,KAAG,GAAO,cAAc,EAAE;KAAK,EAAE,MAAM,IAAM,CAAC,EACzF,QAAY,EAAM,iBAAiB,MAAM;AAAE,GAAI,KAAG,GAAO,kBAAkB,EAAE;KAAK,EAAE,MAAM,IAAM,CAAC,kBAtL/F,EAAoE,OAAA;YAA3D;GAAJ,KAAI;GAAe,OAAO;IAAA,OAAA;IAAA,QAAA;IAAiC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/TradeCanvas.vue","../src/TradeCanvas.vue"],"sourcesContent":["<template>\n <div ref=\"containerEl\" :style=\"{ width: '100%', height: '100%' }\" />\n</template>\n\n<script setup lang=\"ts\">\nimport { ref, onMounted, onUnmounted, watch } from 'vue';\nimport {\n Chart,\n BinanceAdapter,\n DARK_THEME,\n LIGHT_THEME,\n} from '@tradecanvas/chart';\nimport type {\n ChartType,\n TimeFrame,\n FeaturesConfig,\n Theme,\n OHLCBar,\n SignalMarker,\n TradeZone,\n SignalMarkerStyle,\n TradeZoneStyle,\n DataAdapter,\n} from '@tradecanvas/chart';\n\nconst props = withDefaults(\n defineProps<{\n symbol?: string;\n timeframe?: TimeFrame;\n theme?: 'dark' | 'light' | Theme;\n chartType?: ChartType;\n indicators?: string[];\n data?: OHLCBar[];\n adapter?: DataAdapter;\n historyLimit?: number;\n features?: FeaturesConfig;\n autoScale?: boolean;\n signalMarkers?: SignalMarker[];\n signalMarkerStyle?: SignalMarkerStyle;\n tradeZones?: TradeZone[];\n tradeZoneStyle?: TradeZoneStyle;\n watermarkText?: string;\n }>(),\n {\n symbol: 'BTCUSDT',\n timeframe: '5m' as TimeFrame,\n theme: 'dark',\n chartType: 'candlestick' as ChartType,\n indicators: () => [],\n historyLimit: 500,\n autoScale: true,\n },\n);\n\nconst emit = defineEmits<{\n ready: [chart: Chart];\n crosshairMove: [payload: unknown];\n}>();\n\nfunction resolveTheme(theme: 'dark' | 'light' | Theme): Theme {\n if (theme === 'dark') return DARK_THEME;\n if (theme === 'light') return LIGHT_THEME;\n return theme as Theme;\n}\n\nconst containerEl = ref<HTMLDivElement>();\nlet chart: Chart | null = null;\nconst indicatorIds = new Map<string, string>();\n\nfunction getChart(): Chart | null {\n return chart;\n}\n\nfunction screenshot(filename?: string): void {\n chart?.screenshot(filename);\n}\n\nfunction screenshotDataURL(): string | null {\n return chart?.screenshotDataURL() ?? null;\n}\n\ndefineExpose({ getChart, screenshot, screenshotDataURL });\n\nonMounted(() => {\n if (!containerEl.value) return;\n\n chart = new Chart(containerEl.value, {\n chartType: props.chartType,\n theme: resolveTheme(props.theme),\n autoScale: props.autoScale,\n rightMargin: 5,\n crosshair: { mode: 'magnet' },\n watermark: props.watermarkText\n ? { text: props.watermarkText, fontSize: 48, color: 'rgba(255,255,255,0.03)' }\n : undefined,\n features: {\n drawings: true,\n drawingMagnet: true,\n drawingUndoRedo: true,\n indicators: true,\n trading: true,\n volume: true,\n legend: true,\n crosshair: true,\n keyboard: true,\n screenshot: true,\n alerts: true,\n barCountdown: true,\n logScale: true,\n watermark: true,\n ...props.features,\n },\n });\n\n if (props.data) {\n chart.setData(props.data);\n } else {\n const adapter = props.adapter ?? new BinanceAdapter();\n chart.connect({ adapter, symbol: props.symbol, timeframe: props.timeframe, historyLimit: props.historyLimit });\n }\n\n // Apply initial reactive collections not covered by the constructor options.\n // Vue's watches aren't immediate, so without this the first render of\n // indicators / signal markers / trade zones would be dropped.\n for (const name of props.indicators) {\n const instanceId = chart.addIndicator(name);\n if (instanceId) indicatorIds.set(name, instanceId);\n }\n if (props.signalMarkers) chart.setSignalMarkers(props.signalMarkers);\n if (props.signalMarkerStyle) chart.setSignalMarkerStyle(props.signalMarkerStyle);\n if (props.tradeZones) chart.setTradeZones(props.tradeZones);\n if (props.tradeZoneStyle) chart.setTradeZoneStyle(props.tradeZoneStyle);\n\n emit('ready', chart);\n});\n\nonUnmounted(() => {\n if (chart) {\n chart.disconnectStream();\n chart.destroy();\n chart = null;\n }\n});\n\nwatch(\n () => [props.symbol, props.timeframe] as const,\n ([newSymbol, newTimeframe]) => {\n if (!chart || props.data) return;\n chart.disconnectStream();\n const adapter = props.adapter ?? new BinanceAdapter();\n chart.connect({ adapter, symbol: newSymbol, timeframe: newTimeframe, historyLimit: props.historyLimit });\n if (props.watermarkText) chart.setWatermark(props.watermarkText);\n },\n);\n\nwatch(() => props.theme, (t) => { chart?.setTheme(resolveTheme(t)); });\nwatch(() => props.chartType, (ct) => { chart?.setChartType(ct); });\nwatch(() => props.data, (d) => { if (d) chart?.setData(d); }, { deep: true });\n\nwatch(\n () => props.indicators,\n (newIndicators) => {\n if (!chart) return;\n const desired = new Set(newIndicators);\n for (const [name, instanceId] of indicatorIds) {\n if (!desired.has(name)) {\n chart.removeIndicator(instanceId);\n indicatorIds.delete(name);\n }\n }\n for (const name of newIndicators) {\n if (!indicatorIds.has(name)) {\n const instanceId = chart.addIndicator(name);\n if (instanceId) indicatorIds.set(name, instanceId);\n }\n }\n },\n { deep: true },\n);\n\nwatch(() => props.signalMarkers, (m) => { if (m) chart?.setSignalMarkers(m); }, { deep: true });\nwatch(() => props.signalMarkerStyle, (s) => { if (s) chart?.setSignalMarkerStyle(s); }, { deep: true });\nwatch(() => props.tradeZones, (z) => { if (z) chart?.setTradeZones(z); }, { deep: true });\nwatch(() => props.tradeZoneStyle, (s) => { if (s) chart?.setTradeZoneStyle(s); }, { deep: true });\n</script>\n","<template>\n <div ref=\"containerEl\" :style=\"{ width: '100%', height: '100%' }\" />\n</template>\n\n<script setup lang=\"ts\">\nimport { ref, onMounted, onUnmounted, watch } from 'vue';\nimport {\n Chart,\n BinanceAdapter,\n DARK_THEME,\n LIGHT_THEME,\n} from '@tradecanvas/chart';\nimport type {\n ChartType,\n TimeFrame,\n FeaturesConfig,\n Theme,\n OHLCBar,\n SignalMarker,\n TradeZone,\n SignalMarkerStyle,\n TradeZoneStyle,\n DataAdapter,\n} from '@tradecanvas/chart';\n\nconst props = withDefaults(\n defineProps<{\n symbol?: string;\n timeframe?: TimeFrame;\n theme?: 'dark' | 'light' | Theme;\n chartType?: ChartType;\n indicators?: string[];\n data?: OHLCBar[];\n adapter?: DataAdapter;\n historyLimit?: number;\n features?: FeaturesConfig;\n autoScale?: boolean;\n signalMarkers?: SignalMarker[];\n signalMarkerStyle?: SignalMarkerStyle;\n tradeZones?: TradeZone[];\n tradeZoneStyle?: TradeZoneStyle;\n watermarkText?: string;\n }>(),\n {\n symbol: 'BTCUSDT',\n timeframe: '5m' as TimeFrame,\n theme: 'dark',\n chartType: 'candlestick' as ChartType,\n indicators: () => [],\n historyLimit: 500,\n autoScale: true,\n },\n);\n\nconst emit = defineEmits<{\n ready: [chart: Chart];\n crosshairMove: [payload: unknown];\n}>();\n\nfunction resolveTheme(theme: 'dark' | 'light' | Theme): Theme {\n if (theme === 'dark') return DARK_THEME;\n if (theme === 'light') return LIGHT_THEME;\n return theme as Theme;\n}\n\nconst containerEl = ref<HTMLDivElement>();\nlet chart: Chart | null = null;\nconst indicatorIds = new Map<string, string>();\n\nfunction getChart(): Chart | null {\n return chart;\n}\n\nfunction screenshot(filename?: string): void {\n chart?.screenshot(filename);\n}\n\nfunction screenshotDataURL(): string | null {\n return chart?.screenshotDataURL() ?? null;\n}\n\ndefineExpose({ getChart, screenshot, screenshotDataURL });\n\nonMounted(() => {\n if (!containerEl.value) return;\n\n chart = new Chart(containerEl.value, {\n chartType: props.chartType,\n theme: resolveTheme(props.theme),\n autoScale: props.autoScale,\n rightMargin: 5,\n crosshair: { mode: 'magnet' },\n watermark: props.watermarkText\n ? { text: props.watermarkText, fontSize: 48, color: 'rgba(255,255,255,0.03)' }\n : undefined,\n features: {\n drawings: true,\n drawingMagnet: true,\n drawingUndoRedo: true,\n indicators: true,\n trading: true,\n volume: true,\n legend: true,\n crosshair: true,\n keyboard: true,\n screenshot: true,\n alerts: true,\n barCountdown: true,\n logScale: true,\n watermark: true,\n ...props.features,\n },\n });\n\n if (props.data) {\n chart.setData(props.data);\n } else {\n const adapter = props.adapter ?? new BinanceAdapter();\n chart.connect({ adapter, symbol: props.symbol, timeframe: props.timeframe, historyLimit: props.historyLimit });\n }\n\n // Apply initial reactive collections not covered by the constructor options.\n // Vue's watches aren't immediate, so without this the first render of\n // indicators / signal markers / trade zones would be dropped.\n for (const name of props.indicators) {\n const instanceId = chart.addIndicator(name);\n if (instanceId) indicatorIds.set(name, instanceId);\n }\n if (props.signalMarkers) chart.setSignalMarkers(props.signalMarkers);\n if (props.signalMarkerStyle) chart.setSignalMarkerStyle(props.signalMarkerStyle);\n if (props.tradeZones) chart.setTradeZones(props.tradeZones);\n if (props.tradeZoneStyle) chart.setTradeZoneStyle(props.tradeZoneStyle);\n\n emit('ready', chart);\n});\n\nonUnmounted(() => {\n if (chart) {\n chart.disconnectStream();\n chart.destroy();\n chart = null;\n }\n});\n\nwatch(\n () => [props.symbol, props.timeframe] as const,\n ([newSymbol, newTimeframe]) => {\n if (!chart || props.data) return;\n chart.disconnectStream();\n const adapter = props.adapter ?? new BinanceAdapter();\n chart.connect({ adapter, symbol: newSymbol, timeframe: newTimeframe, historyLimit: props.historyLimit });\n if (props.watermarkText) chart.setWatermark(props.watermarkText);\n },\n);\n\nwatch(() => props.theme, (t) => { chart?.setTheme(resolveTheme(t)); });\nwatch(() => props.chartType, (ct) => { chart?.setChartType(ct); });\nwatch(() => props.data, (d) => { if (d) chart?.setData(d); }, { deep: true });\n\nwatch(\n () => props.indicators,\n (newIndicators) => {\n if (!chart) return;\n const desired = new Set(newIndicators);\n for (const [name, instanceId] of indicatorIds) {\n if (!desired.has(name)) {\n chart.removeIndicator(instanceId);\n indicatorIds.delete(name);\n }\n }\n for (const name of newIndicators) {\n if (!indicatorIds.has(name)) {\n const instanceId = chart.addIndicator(name);\n if (instanceId) indicatorIds.set(name, instanceId);\n }\n }\n },\n { deep: true },\n);\n\nwatch(() => props.signalMarkers, (m) => { if (m) chart?.setSignalMarkers(m); }, { deep: true });\nwatch(() => props.signalMarkerStyle, (s) => { if (s) chart?.setSignalMarkerStyle(s); }, { deep: true });\nwatch(() => props.tradeZones, (z) => { if (z) chart?.setTradeZones(z); }, { deep: true });\nwatch(() => props.tradeZoneStyle, (s) => { if (s) chart?.setTradeZoneStyle(s); }, { deep: true });\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyBA,IAAM,IAAQ,GA6BR,IAAO;EAKb,SAAS,EAAa,GAAwC;AAG5D,UAFI,MAAU,SAAe,IACzB,MAAU,UAAgB,IACvB;;EAGT,IAAM,IAAc,GAAqB,EACrC,IAAsB,MACpB,oBAAe,IAAI,KAAqB;EAE9C,SAAS,IAAyB;AAChC,UAAO;;EAGT,SAAS,EAAW,GAAyB;AAC3C,MAAO,WAAW,EAAS;;EAG7B,SAAS,IAAmC;AAC1C,UAAO,GAAO,mBAAmB,IAAI;;SAGvC,EAAa;GAAE;GAAU;GAAY;GAAmB,CAAC,EAEzD,QAAgB;AACT,SAAY,OA8BjB;QA5BA,IAAQ,IAAI,EAAM,EAAY,OAAO;KACnC,WAAW,EAAM;KACjB,OAAO,EAAa,EAAM,MAAM;KAChC,WAAW,EAAM;KACjB,aAAa;KACb,WAAW,EAAE,MAAM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|
"type": "module",
|
|
5
5
|
"description": "Vue 3 component for @tradecanvas/chart — reactive props, template ref, zero boilerplate.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"README.md"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@tradecanvas/chart": "1.
|
|
37
|
+
"@tradecanvas/chart": "1.11.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"vue": ">=3.3.0"
|