Skip to content
Snippets Groups Projects
Commit 42f8e8f3 authored by Leander's avatar Leander
Browse files

fix: no duplicated selection color

parent 2deb92d6
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ export type RadarChartConfig = ChartConfig & { ...@@ -6,6 +6,7 @@ export type RadarChartConfig = ChartConfig & {
selectedData: RadarChartSelection[], selectedData: RadarChartSelection[],
renderTooltip?: (dataPoint: any, tooltip: d3.Selection<d3.BaseType, unknown, HTMLElement, any>) => void, renderTooltip?: (dataPoint: any, tooltip: d3.Selection<d3.BaseType, unknown, HTMLElement, any>) => void,
axisCircles: number, axisCircles: number,
idAccessor: (d: any) => any,
attributes: { key: string, label: string }[] | [], attributes: { key: string, label: string }[] | [],
} }
...@@ -50,6 +51,7 @@ export default class RadarChart extends Chart { ...@@ -50,6 +51,7 @@ export default class RadarChart extends Chart {
axisCircles: _config.axisCircles || 2, axisCircles: _config.axisCircles || 2,
selectedData: _config.selectedData || [], selectedData: _config.selectedData || [],
attributes: _config.attributes || [], attributes: _config.attributes || [],
idAccessor: _config.idAccessor || (() => null),
} }
} }
...@@ -155,7 +157,7 @@ export default class RadarChart extends Chart { ...@@ -155,7 +157,7 @@ export default class RadarChart extends Chart {
const preparedData = this.getPreparedData() const preparedData = this.getPreparedData()
dataWrapper.selectAll('.data') dataWrapper.selectAll('.data')
.data(preparedData) .data(preparedData, (d: any) => this.config.idAccessor(d.data))
.join( .join(
(enter: any) => { (enter: any) => {
const data = enter.append("g") const data = enter.append("g")
......
...@@ -131,9 +131,10 @@ function updateSelectedNodes(node: Player) { ...@@ -131,9 +131,10 @@ function updateSelectedNodes(node: Player) {
if (selectedNodes.some(n => n.player === node.player)) { if (selectedNodes.some(n => n.player === node.player)) {
selectedNodes.splice(selectedNodes.findIndex((n: Player) => n.player === node.player), 1) selectedNodes.splice(selectedNodes.findIndex((n: Player) => n.player === node.player), 1)
} else { } else {
const missingColor = schemeTableau10.find((color) => selectedNodes.findIndex(n => n._color === color) === -1)
selectedNodes.push({ selectedNodes.push({
...node, ...node,
_color: schemeTableau10[selectedNodes.length] _color: missingColor ?? schemeTableau10[selectedNodes.length],
}) })
} }
bubbleChart?.updateSelectedNodes(selectedNodes) bubbleChart?.updateSelectedNodes(selectedNodes)
...@@ -145,6 +146,7 @@ function updateSelectedNodes(node: Player) { ...@@ -145,6 +146,7 @@ function updateSelectedNodes(node: Player) {
containerHeight: 750, containerHeight: 750,
margin: {top: 20, right: 20, bottom: 20, left: 20}, margin: {top: 20, right: 20, bottom: 20, left: 20},
axisCircles: 2, axisCircles: 2,
idAccessor: (d: any) => d.player,
attributes: [ attributes: [
{ {
key: 'Performance _ G+A', key: 'Performance _ G+A',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment