Skip to content

Commit

Permalink
fix app crash when bar chart data is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
mintdart committed Sep 14, 2023
1 parent 3b1dcc5 commit 160c240
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/components/ECharts/BarChart/Stacked.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ export interface IStackedBarChartProps extends Omit<IChartProps, 'title' | 'char
showLegend?: boolean
}

type series = Array<{
data: [Date, number][]
type: 'bar'
stack: 'value'
}>

export default function StackedBarChart({
chartData,
valueSymbol = '$',
Expand All @@ -69,7 +63,7 @@ export default function StackedBarChart({
const [isDark] = useDarkModeManager()
const series = useMemo(() => {
const chartColor = color || stringToColour()
const series: series = chartData.map((cd) => {
const series = chartData.map((cd) => {
return {
name: cd.name,
type: 'bar',
Expand All @@ -93,6 +87,12 @@ export default function StackedBarChart({
}
})

series.forEach((seriesItem) => {
if (seriesItem.data.length === 0) {
seriesItem.large = false
}
})

return series
}, [chartData, color, stackColors])

Expand Down
6 changes: 6 additions & 0 deletions src/components/ECharts/BarChart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ export default function BarChart({
})
})

series.forEach((seriesItem) => {
if (seriesItem.data.length === 0) {
seriesItem.large = false
}
})

return series
}
}, [barWidths, chartData, color, defaultStacks, seriesConfig, stackColors, stackKeys, selectedStacks, isMonthly])
Expand Down
6 changes: 6 additions & 0 deletions src/components/ECharts/ProtocolChart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ export default function AreaBarChart({
}
}

series.forEach((seriesItem) => {
if (seriesItem.data.length === 0) {
seriesItem.large = false
}
})

return { series, yAxisByIndex }
}, [
chartData,
Expand Down
6 changes: 6 additions & 0 deletions src/components/LiquidationsPage/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ export const getOption = (
}))
}

series.forEach((seriesItem) => {
if (seriesItem.data.length === 0) {
seriesItem.large = false
}
})

const option: ECBasicOption = {
graphic: {
type: 'image',
Expand Down

0 comments on commit 160c240

Please sign in to comment.