Skip to content

Commit 64cfbb6

Browse files
feat(scatter): enhance custom stroke and fill colors
1 parent 3742860 commit 64cfbb6

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

Diff for: packages/core/src/components/graphs/scatter.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class Scatter extends Component {
6262
.attr("r", options.points.radius)
6363
.attr("fill", d => {
6464
if (filled) {
65-
return this.model.getFillScale()[d.datasetLabel](d.label) as any;
65+
return this.model.getFillColor(d.datasetLabel, d.label, d.value);
6666
}
6767
})
6868
.attr("fill-opacity", filled ? 0.2 : 1)
@@ -95,6 +95,7 @@ export class Scatter extends Component {
9595
date: datum.date,
9696
label: labels[i],
9797
datasetLabel: d.label,
98+
class: datum.class,
9899
value: isNaN(datum) ? datum.value : datum
99100
}));
100101
}
@@ -106,7 +107,7 @@ export class Scatter extends Component {
106107
const hoveredElement = select(this);
107108
hoveredElement.classed("hovered", true);
108109

109-
hoveredElement.style("fill", (d: any) => self.model.getFillScale()[d.datasetLabel](d.label));
110+
hoveredElement.style("fill", (d: any) => self.model.getFillColor(d.datasetLabel, d.label, d.value));
110111

111112
// Show tooltip
112113
self.services.events.dispatchEvent("show-tooltip", {

Diff for: packages/core/src/interfaces/charts.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ export interface BaseChartOptions {
4141
/**
4242
* Optional function to generate the fill color based on datasetLabel, label, and/or value
4343
*/
44-
getFillColor?: (datasetLabel: any, label?: any, value?: any) => string;
44+
getFillColor?: (datasetLabel: any, label?: any, value?: any, defaultFillColor?: string) => string;
4545
/**
4646
* Optional function to generate the stroke color based on datasetLabel, label, and/or value
4747
*/
48-
getStrokeColor?: (datasetLabel: any, label?: any, value?: any) => string;
48+
getStrokeColor?: (datasetLabel: any, label?: any, value?: any, defaultStrokeColor?: string) => string;
4949
/**
5050
* stylesheet options
5151
*/

Diff for: packages/core/src/model.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,21 @@ export class ChartModel {
188188

189189
getFillColor(datasetLabel: any, label?: any, value?: any) {
190190
const options = this.getOptions();
191+
const defaultFillColor = this.getFillScale()[datasetLabel](label);
191192
if (options.getFillColor) {
192-
return options.getFillColor(datasetLabel, label, value);
193+
return options.getFillColor(datasetLabel, label, value, defaultFillColor);
193194
} else {
194-
return this.getFillScale()[datasetLabel](label);
195+
return defaultFillColor;
195196
}
196197
}
197198

198199
getStrokeColor(datasetLabel: any, label?: any, value?: any) {
199200
const options = this.getOptions();
201+
const defaultStrokeColor = this.colorScale[datasetLabel](label);
200202
if (options.getStrokeColor) {
201-
return options.getStrokeColor(datasetLabel, label, value);
203+
return options.getStrokeColor(datasetLabel, label, value, defaultStrokeColor);
202204
} else {
203-
return this.colorScale[datasetLabel](label);
205+
return defaultStrokeColor;
204206
}
205207
}
206208

0 commit comments

Comments
 (0)