Skip to content

Commit

Permalink
feat(D3 plugin): add color property to scatter and bar data (#265)
Browse files Browse the repository at this point in the history
feat: add color property to scatter and bar data
  • Loading branch information
korvin89 authored Sep 5, 2023
1 parent 2170c73 commit 3bad0cf
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/plugins/d3/renderer/hooks/useShapes/bar-x.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function BarXSeriesShapes(args: Args) {
.attr('y', (d) => d.y)
.attr('height', (d) => d.height)
.attr('width', (d) => d.width)
.attr('fill', item.color)
.attr('fill', (d) => d.data.color || item.color)
.on('mousemove', (e, point) => {
const [x, y] = pointer(e, svgContainer);
onSeriesMouseMove?.({
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/d3/renderer/hooks/useShapes/scatter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function ScatterSeriesShape(props: ScatterSeriesShapeProps) {
.enter()
.append('circle')
.attr('class', b('point'))
.attr('fill', series.color || '')
.attr('fill', (d) => d.color || series.color || '')
.attr('r', (d) => d.radius || DEFAULT_SCATTER_POINT_RADIUS)
.attr('cx', (d) => getCxAttr({point: d, xAxis, xScale}))
.attr('cy', (d) => getCyAttr({point: d, yAxis, yScale}))
Expand Down
1 change: 0 additions & 1 deletion src/types/widget-data/bar-x.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export type BarXSeriesData<T = any> = BaseSeriesData<T> & {
y?: number;
/** Corresponding value of axis category */
category?: string;

/** Data label value of the bar-x column. If not specified, the y value is used. */
label?: string | number;
};
Expand Down
2 changes: 2 additions & 0 deletions src/types/widget-data/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export type BaseSeriesData<T = any> = {
* Here you can add additional data for your own event callbacks and formatter callbacks
*/
custom?: T;
/** Individual color for the data chunk (point in scatter, segment in pie, bar etc) */
color?: string;
};

export type BaseTextStyle = {
Expand Down
2 changes: 0 additions & 2 deletions src/types/widget-data/pie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ export type PieSeriesData<T = any> = BaseSeriesData<T> & {
value: number;
/** The name of the pie segment (used in legend, tooltip etc). */
name: string;
/** Individual color for the pie segment. */
color?: string;
/** Initial visibility of the pie segment. */
visible?: boolean;
/** Initial data label of the pie segment. If not specified, the value is used. */
Expand Down

0 comments on commit 3bad0cf

Please sign in to comment.