Skip to content

Commit 100f435

Browse files
committed
ChartColorInputs line type dashed to use 6,6 and dotted to be 0.1,6 with linecap round
1 parent 1c5a212 commit 100f435

4 files changed

Lines changed: 31 additions & 19 deletions

File tree

packages/components/src/internal/components/chart/ChartColorInputs.test.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,27 +152,29 @@ describe('SeriesOptionRenderer', () => {
152152

153153
describe('LineTypeOptionRenderer', () => {
154154
test('isValueRenderer false', () => {
155-
render(<LineTypeOptionRenderer isValueRenderer={false} strokeValue="" />);
155+
render(<LineTypeOptionRenderer isValueRenderer={false} label="Solid" value="" />);
156156
expect(document.querySelectorAll('.chart-builder-type-option')).toHaveLength(1);
157157
expect(document.querySelectorAll('.chart-builder-type-option--value')).toHaveLength(0);
158-
expect(document.querySelector('svg path').getAttribute('stroke-dasharray')).toBe('');
158+
expect(document.querySelector('svg path').getAttribute('stroke-dasharray')).toBe(null);
159159
});
160160

161161
test('isValueRenderer true', () => {
162-
render(<LineTypeOptionRenderer isValueRenderer strokeValue="" />);
162+
render(<LineTypeOptionRenderer isValueRenderer label="Solid" value="" />);
163163
expect(document.querySelectorAll('.chart-builder-type-option')).toHaveLength(1);
164164
expect(document.querySelectorAll('.chart-builder-type-option--value')).toHaveLength(1);
165-
expect(document.querySelector('svg path').getAttribute('stroke-dasharray')).toBe('');
165+
expect(document.querySelector('svg path').getAttribute('stroke-dasharray')).toBe(null);
166166
});
167167

168168
test('dashed line type', () => {
169-
render(<LineTypeOptionRenderer isValueRenderer strokeValue="12, 3" />);
170-
expect(document.querySelector('svg path').getAttribute("stroke-dasharray")).toBe('12, 3');
169+
render(<LineTypeOptionRenderer isValueRenderer label="Dashed" value="dashed" />);
170+
expect(document.querySelector('svg path').getAttribute("stroke-dasharray")).toBe('6,6');
171+
expect(document.querySelector('svg path').getAttribute("stroke-linecap")).toBe(null);
171172
});
172173

173174
test('dotted line type', () => {
174-
render(<LineTypeOptionRenderer isValueRenderer strokeValue="1, 1" />);
175-
expect(document.querySelector('svg path').getAttribute("stroke-dasharray")).toBe('1, 1');
175+
render(<LineTypeOptionRenderer isValueRenderer label="Dotted" value="dotted" />);
176+
expect(document.querySelector('svg path').getAttribute("stroke-dasharray")).toBe('0.1,6');
177+
expect(document.querySelector('svg path').getAttribute("stroke-linecap")).toBe('round');
176178
});
177179
});
178180

packages/components/src/internal/components/chart/ChartColorInputs.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,28 +86,37 @@ function shapeValueRenderer(option) {
8686
interface LineTypeOptionRendererProps {
8787
isValueRenderer: boolean;
8888
label: string;
89-
strokeValue: string;
89+
value: string;
9090
}
9191

9292
// export for jest testing
93-
export const LineTypeOptionRenderer: FC<LineTypeOptionRendererProps> = memo(({ label, strokeValue, isValueRenderer }) => {
93+
export const LineTypeOptionRenderer: FC<LineTypeOptionRendererProps> = memo(({ label, value, isValueRenderer }) => {
9494
const className = classNames('chart-builder-type-option', { 'chart-builder-type-option--value': isValueRenderer });
95+
const strokeValue = value === 'dashed' ? '6,6' : value === 'dotted' ? '0.1,6' : undefined;
96+
const strokeLineCap = value === 'dotted' ? 'round' : undefined;
9597
return (
9698
<span className={className} data-series-linetype={label}>
97-
<svg height="10" width="30">
98-
<path d="M 0 5 H 30" fill="none" stroke="#000000" strokeDasharray={strokeValue} strokeWidth="3" />
99+
<svg height="10" width="25">
100+
<path
101+
d="M 5 5 H 25"
102+
fill="none"
103+
stroke="#000000"
104+
strokeDasharray={strokeValue}
105+
strokeLinecap={strokeLineCap}
106+
strokeWidth="3"
107+
/>
99108
</svg>
100109
</span>
101110
);
102111
});
103112
LineTypeOptionRenderer.displayName = 'LineTypeOptionRenderer';
104113

105114
function lineTypeOptionRenderer(option) {
106-
return <LineTypeOptionRenderer isValueRenderer={false} label={option.data.label} strokeValue={option.data.value} />;
115+
return <LineTypeOptionRenderer isValueRenderer={false} label={option.data.label} value={option.data.value} />;
107116
}
108117

109118
function lineTypeValueRenderer(option) {
110-
return <LineTypeOptionRenderer isValueRenderer label={option.data.label} strokeValue={option.data.value} />;
119+
return <LineTypeOptionRenderer isValueRenderer label={option.data.label} value={option.data.value} />;
111120
}
112121

113122
interface SeriesOptionRendererProps {

packages/components/src/internal/components/chart/constants.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@ export const SHAPE_OPTIONS = [
3535
{ label: 'Cross', value: 'x' },
3636
];
3737

38-
export const LINE_TYPE_STROKES = { dashed: '12, 3', dotted: '2, 2', solid: '' };
39-
4038
export const LINE_TYPE_OPTIONS = [
41-
{ label: 'Solid', value: LINE_TYPE_STROKES.solid },
42-
{ label: 'Dashed', value: LINE_TYPE_STROKES.dashed },
43-
{ label: 'Dotted', value: LINE_TYPE_STROKES.dotted },
39+
{ label: 'Solid', value: '' },
40+
{ label: 'Dashed', value: 'dashed' },
41+
{ label: 'Dotted', value: 'dotted' },
4442
];
4543

4644
export const COLOR_OPTIONS_PER_TYPE = {

packages/components/src/theme/charts.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@
225225
.chart-color-input {
226226
flex: 1;
227227
}
228+
.chart-color-input label {
229+
display: block;
230+
}
228231

229232
.chart-builder-modal__chart-preview h4,
230233
.chart-settings h4 {

0 commit comments

Comments
 (0)