Skip to content

Commit

Permalink
feat: support line strokeWidth (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristw authored and zhaoyongjie committed Nov 24, 2021
1 parent b0036ef commit 96f15dd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ export default [
},
legend: false,
},
strokeWidth: {
field: 'snapshot',
type: 'nominal',
scale: {
type: 'ordinal',
domain: ['Current', 'Last year'],
range: [3, 1.5],
},
legend: false,
},
},
},
height: 400,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function DefaultTooltipRenderer({
.filter(({ key }) => series[key])
.concat()
.sort((a, b) => series[b.key].y - series[a.key].y)
.map(({ key, stroke, strokeDasharray }) => ({
.map(({ key, stroke, strokeDasharray, strokeWidth }) => ({
key,
keyColumn: (
<>
Expand All @@ -37,7 +37,7 @@ export default function DefaultTooltipRenderer({
y1="3"
y2="3"
stroke={stroke}
strokeWidth="2"
strokeWidth={strokeWidth}
strokeDasharray={strokeDasharray}
/>
</svg>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const channelTypes = {
fill: 'Category',
stroke: 'Color',
strokeDasharray: 'Category',
strokeWidth: 'Numeric',
x: 'X',
y: 'Y',
} as const;
Expand All @@ -21,9 +22,10 @@ export type ChannelTypes = typeof channelTypes;
export interface Outputs {
x: number | null;
y: number | null;
stroke: string;
fill: boolean;
stroke: string;
strokeDasharray: string;
strokeWidth: number;
}

/**
Expand All @@ -36,6 +38,7 @@ export default class Encoder extends AbstractEncoder<ChannelTypes, Outputs> {
fill: { value: false },
stroke: { value: '#222' },
strokeDasharray: { value: '' },
strokeWidth: { value: 1 },
x: { field: 'x', type: 'quantitative' },
y: { field: 'y', type: 'quantitative' },
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface Series {
stroke: Outputs['stroke'];
fill: Outputs['fill'];
strokeDasharray: Outputs['strokeDasharray'];
strokeWidth: Outputs['strokeWidth'];
values: SeriesValue[];
}

Expand Down Expand Up @@ -120,6 +121,7 @@ export default class LineChart extends PureComponent<Props> {
fill: channels.fill.encode(firstDatum, false),
stroke: channels.stroke.encode(firstDatum, '#222'),
strokeDasharray: channels.strokeDasharray.encode(firstDatum, ''),
strokeWidth: channels.strokeWidth.encode(firstDatum, 1),
values: [],
};

Expand Down Expand Up @@ -160,7 +162,7 @@ export default class LineChart extends PureComponent<Props> {
interpolation="linear"
fill={`url(#${gradientId})`}
stroke={series.stroke}
strokeWidth={1.5}
strokeWidth={series.strokeWidth}
/>,
];
}),
Expand All @@ -176,7 +178,7 @@ export default class LineChart extends PureComponent<Props> {
data={series.values}
stroke={series.stroke}
strokeDasharray={series.strokeDasharray}
strokeWidth={1.5}
strokeWidth={series.strokeWidth}
/>
));

Expand Down

0 comments on commit 96f15dd

Please sign in to comment.