Skip to content

Commit

Permalink
🔨 (tooltip) get rid of mobx warning
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Nov 14, 2024
1 parent 1a76b25 commit 452dd61
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 37 deletions.
4 changes: 2 additions & 2 deletions packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -724,10 +724,10 @@ export class LineChart
)
: series.color

const values = [
const values = excludeUndefined([
point?.y,
point?.colorValue as undefined | number,
]
])

return {
name,
Expand Down
40 changes: 17 additions & 23 deletions packages/@ourworldindata/grapher/src/tooltip/TooltipContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
sortBy,
formatInlineList,
GrapherTooltipAnchor,
ensureEqualLength,
} from "@ourworldindata/utils"
import {
TooltipTableProps,
Expand Down Expand Up @@ -270,29 +269,24 @@ export class TooltipTable extends React.Component<TooltipTableProps> {
</span>
)}
</td>
{/* ensure arrays of equal length are zipped to
avoid a mobx warning about accessing elements
that are out of bounds */}
{zip(...ensureEqualLength(columns, values)).map(
([column, value]) => {
const missing = value === undefined
return column ? (
<td
key={column.slug}
className={classnames(
"series-value",
{ missing }
{zip(columns, values).map(([column, value]) => {
const missing = value === undefined
return column ? (
<td
key={column.slug}
className={classnames(
"series-value",
{ missing }
)}
>
{!missing &&
column.formatValueShort(
value,
format
)}
>
{!missing &&
column.formatValueShort(
value,
format
)}
</td>
) : null
}
)}
</td>
) : null
})}
{notice && (
<td className="time-notice">
<FontAwesomeIcon icon={faInfoCircle} />{" "}
Expand Down
11 changes: 0 additions & 11 deletions packages/@ourworldindata/utils/src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2000,14 +2000,3 @@ export function getPaginationPageNumbers(

return pageNumbers
}

export function ensureEqualLength<T, U>(
arr1: T[],
arr2: U[]
): [(T | undefined)[], (U | undefined)[]] {
const length = Math.max(arr1.length, arr2.length)
return [
[...arr1, ...new Array(length - arr1.length).fill(undefined)],
[...arr2, ...new Array(length - arr2.length).fill(undefined)],
]
}
1 change: 0 additions & 1 deletion packages/@ourworldindata/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ export {
formatInlineList,
lazy,
getParentVariableIdFromChartConfig,
ensureEqualLength,
} from "./Util.js"

export {
Expand Down

0 comments on commit 452dd61

Please sign in to comment.