Skip to content

Commit

Permalink
fix: reading from undefined (#25418)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
pauldambra and github-actions[bot] authored Oct 7, 2024
1 parent cbc5afd commit 391065c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions frontend/src/scenes/insights/views/LineGraph/LineGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -455,21 +455,28 @@ export function LineGraph_({
datalabels: {
color: 'white',
anchor: (context) => {
const datum = context.dataset.data[context.dataIndex]
// the type here doesn't allow for undefined, but we see errors where things are undefined
const datum = context.dataset?.data[context.dataIndex]
return typeof datum !== 'number' ? 'end' : datum > 0 ? 'end' : 'start'
},
backgroundColor: (context) => {
return (context.dataset.borderColor as string) || 'black'
// the type here doesn't allow for undefined, but we see errors where things are undefined
return (context.dataset?.borderColor as string) || 'black'
},
display: (context) => {
const datum = context.dataset.data[context.dataIndex]
// the type here doesn't allow for undefined, but we see errors where things are undefined
const datum = context.dataset?.data[context.dataIndex]
if (showValuesOnSeries && inSurveyView) {
return true
}
return showValuesOnSeries === true && typeof datum === 'number' && datum !== 0 ? 'auto' : false
},
formatter: (value: number, context) => {
const data = context.chart.data as ExtendedChartData
// the type here doesn't allow for undefined, but we see errors where things are undefined
const data = context.chart?.data as ExtendedChartData
if (!data) {
return ''
}
const { datasetIndex, dataIndex } = context
const percentageValue = data.calculatedData?.[datasetIndex][dataIndex]
return formatPercentStackAxisValue(trendsFilter, percentageValue || value, isPercentStackView)
Expand Down

0 comments on commit 391065c

Please sign in to comment.