This commit is contained in:
2026-06-14 19:11:37 +03:30
parent 3254a6dadb
commit b3113bc398
9 changed files with 185 additions and 40 deletions
@@ -1,6 +1,13 @@
import { ref } from 'vue'
import { getAllPrices } from '@/api/home'
const MIN_SCALED_CHART_VALUE = 30_000
const MIN_FULL_CHART_VALUE = 30_000_000
function isValidChartValue(value: number): boolean {
return value > MIN_SCALED_CHART_VALUE || value > MIN_FULL_CHART_VALUE
}
export function usePriceChart() {
const priceChartSeries = ref([{ name: 'قیمت', data: [] }])
const selection = ref('DAILY')
@@ -16,7 +23,18 @@ export function usePriceChart() {
const response = await getAllPrices()
const data = response.data?.prices
const selectedData = data[selection.value] || []
priceChartSeries.value[0].data = selectedData.map((item: any) => [item.timestamp, item.value - 1])
let lastValid = 0
priceChartSeries.value[0].data = selectedData
.map((item: { timestamp: number; value: number }) => {
let value = Number(item.value)
if (!isValidChartValue(value)) {
value = lastValid
} else {
lastValid = value
}
return [item.timestamp, value] as [number, number]
})
.filter((point: [number, number]) => point[1] > 0)
} catch (error) {
console.error('Error fetching prices:', error)
} finally {