data fixes; indicator=>workspace sync

This commit is contained in:
2026-03-31 20:29:12 -04:00
parent 998f69fa1a
commit cd28e18e52
45 changed files with 1324 additions and 1239 deletions

View File

@@ -6,6 +6,14 @@ import { useTradingViewShapes } from '../composables/useTradingViewShapes'
import { useTradingViewIndicators } from '../composables/useTradingViewIndicators'
import { useChartStore } from '../stores/chart'
import type { IChartingLibraryWidget } from '../types/tradingview'
import { intervalToSeconds } from '../utils'
// Convert seconds to TradingView interval string
function secondsToInterval(seconds: number): string {
if (seconds % 86400 === 0) return `${seconds / 86400}D`
if (seconds % 3600 === 0) return `${seconds / 3600}H`
return `${seconds / 60}` // plain number = minutes
}
const chartContainer = ref<HTMLDivElement | null>(null)
const chartStore = useChartStore()
@@ -31,7 +39,7 @@ onMounted(() => {
tvWidget = new window.TradingView.widget({
symbol: chartStore.symbol, // Use symbol from store
datafeed: datafeed,
interval: chartStore.period as any,
interval: secondsToInterval(chartStore.period) as any,
container: chartContainer.value!,
library_path: '/charting_library/',
locale: 'en',
@@ -190,9 +198,10 @@ function setupChartListeners() {
// Listen for period changes
chart.onIntervalChanged().subscribe(null, (interval: string) => {
console.log('[ChartView] Period changed to:', interval)
const seconds = intervalToSeconds(interval)
console.log('[ChartView] Period changed to:', interval, `(${seconds}s)`)
isUpdatingFromChart = true
chartStore.period = interval
chartStore.period = seconds
isUpdatingFromChart = false
})
@@ -244,10 +253,11 @@ function setupStoreWatchers() {
(newPeriod) => {
if (isUpdatingFromChart) return
console.log('[ChartView] Store period changed externally to:', newPeriod)
if (chart.resolution() !== newPeriod) {
chart.setResolution(newPeriod, () => {
console.log('[ChartView] Chart period updated to:', newPeriod)
const tvInterval = secondsToInterval(newPeriod)
console.log('[ChartView] Store period changed externally to:', newPeriod, `-> ${tvInterval}`)
if (chart.resolution() !== tvInterval) {
chart.setResolution(tvInterval, () => {
console.log('[ChartView] Chart period updated to:', tvInterval)
})
}
}