|
1 | 1 | import React from 'react'; |
2 | 2 |
|
3 | | -import {color, path, select} from 'd3'; |
| 3 | +import {color, select} from 'd3'; |
4 | 4 | import type {Dispatch} from 'd3'; |
5 | 5 | import get from 'lodash/get'; |
6 | 6 |
|
7 | 7 | import type {LabelData} from '../../../types'; |
8 | 8 | import {block, filterOverlappingLabels} from '../../../utils'; |
9 | 9 | import type {PreparedSeriesOptions} from '../../useSeries/types'; |
10 | 10 | import {HtmlLayer} from '../HtmlLayer'; |
| 11 | +import {getRectPath} from '../utils'; |
11 | 12 |
|
12 | 13 | import type {PreparedBarXData} from './types'; |
13 | 14 |
|
14 | 15 | export {prepareBarXData} from './prepare-data'; |
15 | 16 | export * from './types'; |
16 | 17 |
|
17 | | -const b = block('d3-bar-x'); |
| 18 | +const b = block('bar-x'); |
18 | 19 |
|
19 | 20 | type Args = { |
20 | 21 | dispatcher: Dispatch<object>; |
@@ -42,26 +43,18 @@ export const BarXSeriesShapes = (args: Args) => { |
42 | 43 | .data(preparedData) |
43 | 44 | .join('path') |
44 | 45 | .attr('d', (d) => { |
45 | | - const borderRadius = d.isTopItem |
| 46 | + const borderRadius = d.isLastStackItem |
46 | 47 | ? Math.min(d.height, d.width / 2, d.series.borderRadius) |
47 | 48 | : 0; |
48 | | - const p = path(); |
49 | | - p.moveTo(d.x + borderRadius, d.y); |
50 | | - p.lineTo(d.x + d.width - borderRadius, d.y); |
51 | | - p.arc( |
52 | | - d.x + d.width - borderRadius, |
53 | | - d.y + borderRadius, |
54 | | - borderRadius, |
55 | | - -Math.PI / 2, |
56 | | - 0, |
57 | | - false, |
58 | | - ); |
59 | | - p.lineTo(d.x + d.width, d.y + d.height); |
60 | | - p.lineTo(d.x, d.y + d.height); |
61 | | - p.lineTo(d.x, d.y + borderRadius); |
62 | | - p.arc(d.x + borderRadius, d.y + borderRadius, borderRadius, Math.PI, -Math.PI / 2); |
63 | | - p.moveTo(d.x + borderRadius, d.y); |
64 | | - p.closePath(); |
| 49 | + |
| 50 | + const p = getRectPath({ |
| 51 | + x: d.x, |
| 52 | + y: d.y, |
| 53 | + width: d.width, |
| 54 | + height: d.height, |
| 55 | + borderRadius: [borderRadius, borderRadius, 0, 0], |
| 56 | + }); |
| 57 | + |
65 | 58 | return p.toString(); |
66 | 59 | }) |
67 | 60 | .attr('class', b('segment')) |
|
0 commit comments