Skip to content

Commit

Permalink
Make the last category color gray (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMStraub committed Jan 14, 2024
1 parent 4ea9fd2 commit 69643c4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/charts/FanChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,24 @@ function getLegendCategories(categories) {
return sortedCounter.map(([cat]) => cat)
}

// change the order of category10 so the last one is gray
const schemeCategorical = [
...schemeCategory10.slice(0, 7),
schemeCategory10[9],
schemeCategory10[8],
schemeCategory10[7],
]

function colorFunctionCategory(d, callback, categories) {
const category = callback(d?.data?.person)
if (category === undefined) {
return 'rgb(220, 220, 220)'
}
const index = categories.findIndex(cat => cat === category)
if (index === -1 || index >= 9) {
return schemeCategory10[9]
return schemeCategorical[9]
}
return schemeCategory10[index]
return schemeCategorical[index]
}

// Finds the bounding rectangle of a list of rectangles
Expand Down Expand Up @@ -239,12 +247,12 @@ export function FanChart(
colorOpacity = 0.3
const legendData = categories.slice(0, 9).map((cat, i) => ({
label: cat,
color: schemeCategory10[i],
color: schemeCategorical[i],
}))
if (categories.length > 9) {
legendData.push({
label: strings.Other ?? 'Other',
color: schemeCategory10[9],
color: schemeCategorical[9],
})
}
legendFunction = le => LegendCategorical(le, legendData, {opacity: 0.4})
Expand Down

0 comments on commit 69643c4

Please sign in to comment.