@antv/component 2.1.7 → 2.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/component.min.js +1 -1
- package/esm/animation/fadeIn.d.ts +1 -1
- package/esm/animation/fadeOut.d.ts +1 -1
- package/esm/animation/utils.d.ts +3 -3
- package/esm/ui/axis/axis.d.ts +1 -1
- package/esm/ui/axis/axis.js +18 -2
- package/esm/ui/axis/axis.js.map +1 -1
- package/esm/ui/axis/classname-map.d.ts +18 -0
- package/esm/ui/axis/classname-map.js +20 -0
- package/esm/ui/axis/classname-map.js.map +1 -0
- package/esm/ui/axis/constant.js +16 -15
- package/esm/ui/axis/constant.js.map +1 -1
- package/esm/ui/axis/guides/grid.d.ts +1 -1
- package/esm/ui/axis/guides/grid.js +8 -1
- package/esm/ui/axis/guides/grid.js.map +1 -1
- package/esm/ui/axis/guides/labels.d.ts +1 -1
- package/esm/ui/axis/guides/labels.js +11 -4
- package/esm/ui/axis/guides/labels.js.map +1 -1
- package/esm/ui/axis/guides/line.js +31 -8
- package/esm/ui/axis/guides/line.js.map +1 -1
- package/esm/ui/axis/guides/ticks.d.ts +1 -1
- package/esm/ui/axis/guides/ticks.js +10 -3
- package/esm/ui/axis/guides/ticks.js.map +1 -1
- package/esm/ui/axis/guides/title.d.ts +1 -1
- package/esm/ui/axis/guides/title.js +6 -2
- package/esm/ui/axis/guides/title.js.map +1 -1
- package/esm/ui/axis/types.d.ts +1 -0
- package/esm/ui/axis/utils/classname.d.ts +46 -0
- package/esm/ui/axis/utils/classname.js +53 -0
- package/esm/ui/axis/utils/classname.js.map +1 -0
- package/esm/ui/axis/utils/index.d.ts +1 -0
- package/esm/ui/axis/utils/index.js +1 -0
- package/esm/ui/axis/utils/index.js.map +1 -1
- package/esm/ui/grid/index.d.ts +1 -1
- package/esm/ui/legend/category/item.d.ts +3 -1
- package/esm/ui/legend/category/item.js +42 -14
- package/esm/ui/legend/category/item.js.map +1 -1
- package/esm/ui/legend/category/items.d.ts +3 -0
- package/esm/ui/legend/category/items.js +12 -9
- package/esm/ui/legend/category/items.js.map +1 -1
- package/esm/ui/legend/category.d.ts +2 -1
- package/esm/ui/legend/category.js +45 -6
- package/esm/ui/legend/category.js.map +1 -1
- package/esm/ui/legend/classname-map.d.ts +37 -0
- package/esm/ui/legend/classname-map.js +38 -0
- package/esm/ui/legend/classname-map.js.map +1 -0
- package/esm/ui/legend/constant.d.ts +6 -0
- package/esm/ui/legend/constant.js +2 -0
- package/esm/ui/legend/constant.js.map +1 -1
- package/esm/ui/legend/continuous/handle.d.ts +1 -0
- package/esm/ui/legend/continuous/handle.js +23 -3
- package/esm/ui/legend/continuous/handle.js.map +1 -1
- package/esm/ui/legend/continuous/ribbon.d.ts +1 -0
- package/esm/ui/legend/continuous/ribbon.js +11 -1
- package/esm/ui/legend/continuous/ribbon.js.map +1 -1
- package/esm/ui/legend/continuous.d.ts +6 -0
- package/esm/ui/legend/continuous.js +77 -10
- package/esm/ui/legend/continuous.js.map +1 -1
- package/esm/ui/legend/title/index.js +5 -1
- package/esm/ui/legend/title/index.js.map +1 -1
- package/esm/ui/legend/title/types.d.ts +1 -0
- package/esm/ui/legend/types.d.ts +1 -0
- package/esm/ui/legend/utils/classname.d.ts +31 -0
- package/esm/ui/legend/utils/classname.js +35 -0
- package/esm/ui/legend/utils/classname.js.map +1 -0
- package/esm/ui/legend/utils/index.d.ts +1 -0
- package/esm/ui/legend/utils/index.js +2 -0
- package/esm/ui/legend/utils/index.js.map +1 -0
- package/esm/ui/navigator/index.js +19 -4
- package/esm/ui/navigator/index.js.map +1 -1
- package/esm/ui/navigator/types.d.ts +1 -0
- package/esm/ui/slider/handle.d.ts +2 -0
- package/esm/ui/slider/handle.js +21 -6
- package/esm/ui/slider/handle.js.map +1 -1
- package/esm/util/keyframe-interpolate.d.ts +1 -1
- package/lib/animation/fadeIn.d.ts +1 -1
- package/lib/animation/fadeOut.d.ts +1 -1
- package/lib/animation/utils.d.ts +3 -3
- package/lib/ui/axis/axis.d.ts +1 -1
- package/lib/ui/axis/axis.js +18 -2
- package/lib/ui/axis/axis.js.map +1 -1
- package/lib/ui/axis/classname-map.d.ts +18 -0
- package/lib/ui/axis/classname-map.js +23 -0
- package/lib/ui/axis/classname-map.js.map +1 -0
- package/lib/ui/axis/constant.js +16 -15
- package/lib/ui/axis/constant.js.map +1 -1
- package/lib/ui/axis/guides/grid.d.ts +1 -1
- package/lib/ui/axis/guides/grid.js +8 -1
- package/lib/ui/axis/guides/grid.js.map +1 -1
- package/lib/ui/axis/guides/labels.d.ts +1 -1
- package/lib/ui/axis/guides/labels.js +11 -4
- package/lib/ui/axis/guides/labels.js.map +1 -1
- package/lib/ui/axis/guides/line.js +31 -8
- package/lib/ui/axis/guides/line.js.map +1 -1
- package/lib/ui/axis/guides/ticks.d.ts +1 -1
- package/lib/ui/axis/guides/ticks.js +10 -3
- package/lib/ui/axis/guides/ticks.js.map +1 -1
- package/lib/ui/axis/guides/title.d.ts +1 -1
- package/lib/ui/axis/guides/title.js +6 -2
- package/lib/ui/axis/guides/title.js.map +1 -1
- package/lib/ui/axis/types.d.ts +1 -0
- package/lib/ui/axis/utils/classname.d.ts +46 -0
- package/lib/ui/axis/utils/classname.js +58 -0
- package/lib/ui/axis/utils/classname.js.map +1 -0
- package/lib/ui/axis/utils/index.d.ts +1 -0
- package/lib/ui/axis/utils/index.js +1 -0
- package/lib/ui/axis/utils/index.js.map +1 -1
- package/lib/ui/grid/index.d.ts +1 -1
- package/lib/ui/legend/category/item.d.ts +3 -1
- package/lib/ui/legend/category/item.js +42 -14
- package/lib/ui/legend/category/item.js.map +1 -1
- package/lib/ui/legend/category/items.d.ts +3 -0
- package/lib/ui/legend/category/items.js +11 -8
- package/lib/ui/legend/category/items.js.map +1 -1
- package/lib/ui/legend/category.d.ts +2 -1
- package/lib/ui/legend/category.js +45 -6
- package/lib/ui/legend/category.js.map +1 -1
- package/lib/ui/legend/classname-map.d.ts +37 -0
- package/lib/ui/legend/classname-map.js +41 -0
- package/lib/ui/legend/classname-map.js.map +1 -0
- package/lib/ui/legend/constant.d.ts +6 -0
- package/lib/ui/legend/constant.js +4 -1
- package/lib/ui/legend/constant.js.map +1 -1
- package/lib/ui/legend/continuous/handle.d.ts +1 -0
- package/lib/ui/legend/continuous/handle.js +23 -3
- package/lib/ui/legend/continuous/handle.js.map +1 -1
- package/lib/ui/legend/continuous/ribbon.d.ts +1 -0
- package/lib/ui/legend/continuous/ribbon.js +11 -1
- package/lib/ui/legend/continuous/ribbon.js.map +1 -1
- package/lib/ui/legend/continuous.d.ts +6 -0
- package/lib/ui/legend/continuous.js +76 -9
- package/lib/ui/legend/continuous.js.map +1 -1
- package/lib/ui/legend/title/index.js +5 -1
- package/lib/ui/legend/title/index.js.map +1 -1
- package/lib/ui/legend/title/types.d.ts +1 -0
- package/lib/ui/legend/types.d.ts +1 -0
- package/lib/ui/legend/utils/classname.d.ts +31 -0
- package/lib/ui/legend/utils/classname.js +39 -0
- package/lib/ui/legend/utils/classname.js.map +1 -0
- package/lib/ui/legend/utils/index.d.ts +1 -0
- package/lib/ui/legend/utils/index.js +5 -0
- package/lib/ui/legend/utils/index.js.map +1 -0
- package/lib/ui/navigator/index.js +19 -4
- package/lib/ui/navigator/index.js.map +1 -1
- package/lib/ui/navigator/types.d.ts +1 -0
- package/lib/ui/slider/handle.d.ts +2 -0
- package/lib/ui/slider/handle.js +21 -6
- package/lib/ui/slider/handle.js.map +1 -1
- package/lib/util/keyframe-interpolate.d.ts +1 -1
- package/package.json +3 -2
- package/src/ui/axis/axis.ts +19 -2
- package/src/ui/axis/classname-map.ts +22 -0
- package/src/ui/axis/constant.ts +17 -15
- package/src/ui/axis/guides/grid.ts +8 -1
- package/src/ui/axis/guides/labels.ts +16 -6
- package/src/ui/axis/guides/line.ts +50 -12
- package/src/ui/axis/guides/ticks.ts +15 -5
- package/src/ui/axis/guides/title.ts +10 -4
- package/src/ui/axis/types.ts +1 -0
- package/src/ui/axis/utils/classname.ts +62 -0
- package/src/ui/axis/utils/index.ts +1 -0
- package/src/ui/legend/category/item.ts +59 -12
- package/src/ui/legend/category/items.ts +18 -7
- package/src/ui/legend/category.ts +46 -7
- package/src/ui/legend/classname-map.ts +45 -0
- package/src/ui/legend/constant.ts +3 -0
- package/src/ui/legend/continuous/handle.ts +41 -4
- package/src/ui/legend/continuous/ribbon.ts +17 -1
- package/src/ui/legend/continuous.ts +96 -10
- package/src/ui/legend/title/index.ts +5 -1
- package/src/ui/legend/title/types.ts +1 -0
- package/src/ui/legend/types.ts +1 -0
- package/src/ui/legend/utils/classname.ts +39 -0
- package/src/ui/legend/utils/index.ts +1 -0
- package/src/ui/navigator/index.ts +32 -2
- package/src/ui/navigator/types.ts +1 -0
- package/src/ui/slider/handle.ts +44 -6
package/src/ui/axis/axis.ts
CHANGED
|
@@ -11,6 +11,8 @@ import { renderAxisLine } from './guides/line';
|
|
|
11
11
|
import { renderTicks } from './guides/ticks';
|
|
12
12
|
import { renderTitle } from './guides/title';
|
|
13
13
|
import type { AxisDatum, AxisOptions, AxisStyleProps, RequiredAxisStyleProps } from './types';
|
|
14
|
+
import { applyClassName, getAxisClassName } from './utils/classname';
|
|
15
|
+
import { CLASSNAME_SUFFIX_MAP } from './classname-map';
|
|
14
16
|
|
|
15
17
|
export type {
|
|
16
18
|
ArcAxisOptions,
|
|
@@ -27,9 +29,10 @@ function renderAxisMain(
|
|
|
27
29
|
data: AxisDatum[],
|
|
28
30
|
animation: StandardAnimationOption
|
|
29
31
|
) {
|
|
30
|
-
const { showLine, showTick, showLabel } = attributes;
|
|
32
|
+
const { showLine, showTick, showLabel, classNamePrefix } = attributes;
|
|
31
33
|
/** line */
|
|
32
34
|
const lineGroup = container.maybeAppendByClassName(CLASS_NAMES.lineGroup, 'g');
|
|
35
|
+
applyClassName(lineGroup, CLASS_NAMES.lineGroup, CLASSNAME_SUFFIX_MAP.lineGroup, classNamePrefix);
|
|
33
36
|
const lineTransitions =
|
|
34
37
|
ifShow(showLine!, lineGroup, (group) => {
|
|
35
38
|
return renderAxisLine(group, attributes, animation);
|
|
@@ -37,6 +40,7 @@ function renderAxisMain(
|
|
|
37
40
|
|
|
38
41
|
/** tick */
|
|
39
42
|
const tickGroup = container.maybeAppendByClassName(CLASS_NAMES.tickGroup, 'g');
|
|
43
|
+
applyClassName(tickGroup, CLASS_NAMES.tickGroup, CLASSNAME_SUFFIX_MAP.tickGroup, classNamePrefix);
|
|
40
44
|
const tickTransitions =
|
|
41
45
|
ifShow(showTick!, tickGroup, (group) => {
|
|
42
46
|
return renderTicks(group, data, attributes, animation);
|
|
@@ -44,6 +48,7 @@ function renderAxisMain(
|
|
|
44
48
|
|
|
45
49
|
/** label */
|
|
46
50
|
const labelGroup = container.maybeAppendByClassName(CLASS_NAMES.labelGroup, 'g');
|
|
51
|
+
applyClassName(labelGroup, CLASS_NAMES.labelGroup, CLASSNAME_SUFFIX_MAP.labelGroup, classNamePrefix);
|
|
47
52
|
const labelTransitions =
|
|
48
53
|
ifShow(showLabel!, labelGroup, (group) => {
|
|
49
54
|
return renderLabels(group, data, attributes, animation, container.node());
|
|
@@ -58,7 +63,16 @@ export class Axis extends Component<AxisStyleProps> {
|
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
render(attributes: RequiredAxisStyleProps, container: Group, specificAnimation?: GenericAnimation) {
|
|
61
|
-
const { titleText, data, animate, showTitle, showGrid, dataThreshold, truncRange } = attributes;
|
|
66
|
+
const { titleText, data, animate, showTitle, showGrid, dataThreshold, truncRange, classNamePrefix } = attributes;
|
|
67
|
+
|
|
68
|
+
// Set root container className
|
|
69
|
+
const baseClassName = container.className || 'axis';
|
|
70
|
+
if (classNamePrefix) {
|
|
71
|
+
container.attr('className', `${baseClassName} ${classNamePrefix}axis`);
|
|
72
|
+
} else if (!container.className) {
|
|
73
|
+
container.attr('className', 'axis');
|
|
74
|
+
}
|
|
75
|
+
|
|
62
76
|
const sampledData = sampling(data, dataThreshold).filter(({ value }) => {
|
|
63
77
|
if (truncRange && value > truncRange[0] && value < truncRange[1]) return false;
|
|
64
78
|
return true;
|
|
@@ -68,11 +82,13 @@ export class Axis extends Component<AxisStyleProps> {
|
|
|
68
82
|
|
|
69
83
|
/** grid */
|
|
70
84
|
const gridGroup = select(container).maybeAppendByClassName(CLASS_NAMES.gridGroup, 'g');
|
|
85
|
+
applyClassName(gridGroup, CLASS_NAMES.gridGroup, CLASSNAME_SUFFIX_MAP.gridGroup, classNamePrefix);
|
|
71
86
|
const gridTransitions =
|
|
72
87
|
ifShow(showGrid!, gridGroup, (group) => renderGrid(group, sampledData, attributes, finalAnimation)) || [];
|
|
73
88
|
|
|
74
89
|
/** main group */
|
|
75
90
|
const mainGroup = select(container).maybeAppendByClassName(CLASS_NAMES.mainGroup, 'g');
|
|
91
|
+
applyClassName(mainGroup, CLASS_NAMES.mainGroup, CLASSNAME_SUFFIX_MAP.mainGroup, classNamePrefix);
|
|
76
92
|
|
|
77
93
|
if (titleText && ((!this.initialized && finalAnimation.enter) || (this.initialized && finalAnimation.update))) {
|
|
78
94
|
renderAxisMain(attributes, select(this.offscreenGroup), sampledData, parseAnimationOption(false));
|
|
@@ -81,6 +97,7 @@ export class Axis extends Component<AxisStyleProps> {
|
|
|
81
97
|
const mainTransitions = renderAxisMain(attributes, select(mainGroup.node()), sampledData, finalAnimation);
|
|
82
98
|
/** title */
|
|
83
99
|
const titleGroup = select(container).maybeAppendByClassName(CLASS_NAMES.titleGroup, 'g');
|
|
100
|
+
applyClassName(titleGroup, CLASS_NAMES.titleGroup, CLASSNAME_SUFFIX_MAP.titleGroup, classNamePrefix);
|
|
84
101
|
const titleTransitions =
|
|
85
102
|
ifShow(showTitle, titleGroup, (group) => {
|
|
86
103
|
return renderTitle(group, this, attributes, finalAnimation);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const CLASSNAME_SUFFIX_MAP = {
|
|
2
|
+
// group
|
|
3
|
+
gridGroup: 'grid-group',
|
|
4
|
+
mainGroup: 'main-group',
|
|
5
|
+
lineGroup: 'line-group',
|
|
6
|
+
tickGroup: 'tick-group',
|
|
7
|
+
labelGroup: 'label-group',
|
|
8
|
+
titleGroup: 'title-group',
|
|
9
|
+
|
|
10
|
+
// content
|
|
11
|
+
grid: 'grid',
|
|
12
|
+
line: 'line',
|
|
13
|
+
lineFirst: 'line-first',
|
|
14
|
+
lineSecond: 'line-second',
|
|
15
|
+
tick: 'tick',
|
|
16
|
+
tickItem: 'tick-item',
|
|
17
|
+
label: 'label',
|
|
18
|
+
labelItem: 'label-item',
|
|
19
|
+
title: 'title',
|
|
20
|
+
} as const;
|
|
21
|
+
|
|
22
|
+
export type ClassNameSuffix = keyof typeof CLASSNAME_SUFFIX_MAP;
|
package/src/ui/axis/constant.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { Path } from '../../shapes';
|
|
|
3
3
|
import { classNames } from '../../util';
|
|
4
4
|
import type { AxisBaseStyleProps } from './types';
|
|
5
5
|
|
|
6
|
+
import { CLASSNAME_SUFFIX_MAP } from './classname-map';
|
|
7
|
+
|
|
6
8
|
export const AXIS_BASE_DEFAULT_ATTR: Partial<AxisBaseStyleProps> = {
|
|
7
9
|
data: [],
|
|
8
10
|
animate: {
|
|
@@ -76,21 +78,21 @@ export const HELIX_DEFAULT_OPTIONS = deepMix({}, AXIS_BASE_DEFAULT_ATTR, {
|
|
|
76
78
|
|
|
77
79
|
export const CLASS_NAMES = classNames(
|
|
78
80
|
{
|
|
79
|
-
mainGroup:
|
|
80
|
-
gridGroup:
|
|
81
|
-
grid:
|
|
82
|
-
lineGroup:
|
|
83
|
-
line:
|
|
84
|
-
tickGroup:
|
|
85
|
-
tick:
|
|
86
|
-
tickItem:
|
|
87
|
-
labelGroup:
|
|
88
|
-
label:
|
|
89
|
-
labelItem:
|
|
90
|
-
titleGroup:
|
|
91
|
-
title:
|
|
92
|
-
lineFirst:
|
|
93
|
-
lineSecond:
|
|
81
|
+
mainGroup: CLASSNAME_SUFFIX_MAP.mainGroup,
|
|
82
|
+
gridGroup: CLASSNAME_SUFFIX_MAP.gridGroup,
|
|
83
|
+
grid: CLASSNAME_SUFFIX_MAP.grid,
|
|
84
|
+
lineGroup: CLASSNAME_SUFFIX_MAP.lineGroup,
|
|
85
|
+
line: CLASSNAME_SUFFIX_MAP.line,
|
|
86
|
+
tickGroup: CLASSNAME_SUFFIX_MAP.tickGroup,
|
|
87
|
+
tick: CLASSNAME_SUFFIX_MAP.tick,
|
|
88
|
+
tickItem: CLASSNAME_SUFFIX_MAP.tickItem,
|
|
89
|
+
labelGroup: CLASSNAME_SUFFIX_MAP.labelGroup,
|
|
90
|
+
label: CLASSNAME_SUFFIX_MAP.label,
|
|
91
|
+
labelItem: CLASSNAME_SUFFIX_MAP.labelItem,
|
|
92
|
+
titleGroup: CLASSNAME_SUFFIX_MAP.titleGroup,
|
|
93
|
+
title: CLASSNAME_SUFFIX_MAP.title,
|
|
94
|
+
lineFirst: CLASSNAME_SUFFIX_MAP.lineFirst,
|
|
95
|
+
lineSecond: CLASSNAME_SUFFIX_MAP.lineSecond,
|
|
94
96
|
},
|
|
95
97
|
'axis'
|
|
96
98
|
);
|
|
@@ -7,6 +7,8 @@ import { CLASS_NAMES } from '../constant';
|
|
|
7
7
|
import type { AxisDatum, AxisGridStyleProps, AxisStyleProps } from '../types';
|
|
8
8
|
import { getValuePos } from './line';
|
|
9
9
|
import { filterExec, getDirectionVector } from './utils';
|
|
10
|
+
import { applyClassName } from '../utils/classname';
|
|
11
|
+
import { CLASSNAME_SUFFIX_MAP } from '../classname-map';
|
|
10
12
|
|
|
11
13
|
function getGridVector(value: number, attr: Required<AxisStyleProps>) {
|
|
12
14
|
return getDirectionVector(value, attr.gridDirection, attr);
|
|
@@ -63,6 +65,7 @@ export function renderGrid(
|
|
|
63
65
|
attr: Required<AxisStyleProps>,
|
|
64
66
|
animate: StandardAnimationOption
|
|
65
67
|
) {
|
|
68
|
+
const { classNamePrefix } = attr;
|
|
66
69
|
const gridAttr = subStyleProps<Required<AxisGridStyleProps>>(attr, 'grid');
|
|
67
70
|
const { type, areaFill } = gridAttr;
|
|
68
71
|
const center = getGridCenter(attr);
|
|
@@ -83,7 +86,11 @@ export function renderGrid(
|
|
|
83
86
|
.selectAll(CLASS_NAMES.grid.class)
|
|
84
87
|
.data([1])
|
|
85
88
|
.join(
|
|
86
|
-
(enter) =>
|
|
89
|
+
(enter) => {
|
|
90
|
+
const grid = enter.append(() => new Grid({ style })).attr('className', CLASS_NAMES.grid.name);
|
|
91
|
+
applyClassName(grid, CLASS_NAMES.grid, CLASSNAME_SUFFIX_MAP.grid, classNamePrefix);
|
|
92
|
+
return grid;
|
|
93
|
+
},
|
|
87
94
|
(update) =>
|
|
88
95
|
update.transition(function () {
|
|
89
96
|
return this.update(style);
|
|
@@ -30,6 +30,8 @@ import type { AxisDatum, AxisLabelStyleProps, AxisStyleProps } from '../types';
|
|
|
30
30
|
import { getFactor } from '../utils';
|
|
31
31
|
import { getValuePos } from './line';
|
|
32
32
|
import { filterExec, getCallbackStyle, getLabelVector, getLineTangentVector } from './utils';
|
|
33
|
+
import { applyClassName } from '../utils/classname';
|
|
34
|
+
import { CLASSNAME_SUFFIX_MAP } from '../classname-map';
|
|
33
35
|
|
|
34
36
|
function angleNormalizer(angle: number) {
|
|
35
37
|
let normalizedAngle = angle;
|
|
@@ -198,7 +200,9 @@ function overlapHandler(attr: Required<AxisStyleProps>, main: DisplayObject) {
|
|
|
198
200
|
wrap: (label, width, lines) => {
|
|
199
201
|
label && wrapIt(label, width, lines);
|
|
200
202
|
},
|
|
201
|
-
getTextShape: (label) =>
|
|
203
|
+
getTextShape: (label) => {
|
|
204
|
+
return label.querySelector<DisplayObject>(CLASS_NAMES.labelItem.class) as Text;
|
|
205
|
+
},
|
|
202
206
|
});
|
|
203
207
|
}
|
|
204
208
|
|
|
@@ -210,11 +214,13 @@ function renderLabel(
|
|
|
210
214
|
attr: Required<AxisStyleProps>
|
|
211
215
|
): DisplayObject {
|
|
212
216
|
const index = data.indexOf(datum);
|
|
213
|
-
const { labelRender } = attr;
|
|
217
|
+
const { labelRender, classNamePrefix } = attr;
|
|
218
|
+
|
|
214
219
|
const label = select(container)
|
|
215
220
|
.append(labelRender ? renderHTMLLabel(datum, index, data, attr) : formatter(datum, index, data, attr))
|
|
216
221
|
.attr('className', CLASS_NAMES.labelItem.name)
|
|
217
222
|
.node();
|
|
223
|
+
applyClassName(select(label), CLASS_NAMES.labelItem, CLASSNAME_SUFFIX_MAP.labelItem, classNamePrefix);
|
|
218
224
|
const [labelStyle, { transform, ...groupStyle }] = splitStyle(getCallbackStyle(style, [datum, index, data]));
|
|
219
225
|
|
|
220
226
|
percentTransform(label, transform);
|
|
@@ -238,24 +244,28 @@ export function renderLabels(
|
|
|
238
244
|
animate: StandardAnimationOption,
|
|
239
245
|
main: DisplayObject
|
|
240
246
|
) {
|
|
247
|
+
const { classNamePrefix } = attr;
|
|
241
248
|
const finalData = filterExec(data, attr.labelFilter);
|
|
242
249
|
const style = subStyleProps<AxisLabelStyleProps>(attr, 'label');
|
|
250
|
+
|
|
243
251
|
let _exit!: Selection<AxisDatum>;
|
|
244
252
|
const transitions = container
|
|
245
253
|
.selectAll(CLASS_NAMES.label.class)
|
|
246
254
|
.data(finalData, (d, i) => i)
|
|
247
255
|
.join(
|
|
248
|
-
(enter) =>
|
|
249
|
-
enter
|
|
256
|
+
(enter) => {
|
|
257
|
+
const labels = enter
|
|
250
258
|
.append('g')
|
|
251
259
|
.attr('className', CLASS_NAMES.label.name)
|
|
252
260
|
.transition(function (datum) {
|
|
253
261
|
renderLabel(this, datum, data, style, attr);
|
|
254
262
|
const { x, y } = getLabelPos(datum, data, attr);
|
|
255
|
-
// .axis-label
|
|
256
263
|
this.style.transform = `translate(${x}, ${y})`;
|
|
257
264
|
return null;
|
|
258
|
-
})
|
|
265
|
+
});
|
|
266
|
+
applyClassName(labels, CLASS_NAMES.label, CLASSNAME_SUFFIX_MAP.label, classNamePrefix);
|
|
267
|
+
return labels;
|
|
268
|
+
},
|
|
259
269
|
(update) =>
|
|
260
270
|
update.transition(function (datum) {
|
|
261
271
|
const prevLabel = this.querySelector(CLASS_NAMES.labelItem.class);
|
|
@@ -15,6 +15,8 @@ import {
|
|
|
15
15
|
import { CLASS_NAMES } from '../constant';
|
|
16
16
|
import type { RequiredArcAxisStyleProps, RequiredAxisStyleProps, RequiredLinearAxisStyleProps } from '../types';
|
|
17
17
|
import { getLineAngle, getLineTangentVector } from './utils';
|
|
18
|
+
import { applyClassName, getAxisClassName } from '../utils/classname';
|
|
19
|
+
import { CLASSNAME_SUFFIX_MAP } from '../classname-map';
|
|
18
20
|
|
|
19
21
|
type LineDatum = {
|
|
20
22
|
line: [Vector2, Vector2];
|
|
@@ -97,18 +99,21 @@ function renderArc(
|
|
|
97
99
|
style: RequiredArcAxisStyleProps,
|
|
98
100
|
animate: StandardAnimationOption
|
|
99
101
|
) {
|
|
100
|
-
const { startAngle, endAngle, center, radius } = attr;
|
|
102
|
+
const { startAngle, endAngle, center, radius, classNamePrefix } = attr;
|
|
101
103
|
|
|
102
104
|
return container
|
|
103
105
|
.selectAll(CLASS_NAMES.line.class)
|
|
104
106
|
.data([{ d: getArcPath(startAngle, endAngle, ...center, radius) }], (d, i) => i)
|
|
105
107
|
.join(
|
|
106
|
-
(enter) =>
|
|
107
|
-
enter
|
|
108
|
+
(enter) => {
|
|
109
|
+
const line = enter
|
|
108
110
|
.append('path')
|
|
109
111
|
.attr('className', CLASS_NAMES.line.name)
|
|
110
112
|
.styles(attr)
|
|
111
|
-
.styles({ d: (d: any) => d.d })
|
|
113
|
+
.styles({ d: (d: any) => d.d });
|
|
114
|
+
applyClassName(line, CLASS_NAMES.line, CLASSNAME_SUFFIX_MAP.line, classNamePrefix);
|
|
115
|
+
return line;
|
|
116
|
+
},
|
|
112
117
|
(update) =>
|
|
113
118
|
update
|
|
114
119
|
.transition(function () {
|
|
@@ -158,7 +163,7 @@ function renderLinear(
|
|
|
158
163
|
style: RequiredLinearAxisStyleProps,
|
|
159
164
|
animate: StandardAnimationOption
|
|
160
165
|
) {
|
|
161
|
-
const { showTrunc, startPos, endPos, truncRange, lineExtension } = attr;
|
|
166
|
+
const { showTrunc, startPos, endPos, truncRange, lineExtension, classNamePrefix } = attr;
|
|
162
167
|
const [[x1, y1], [x2, y2]] = [startPos, endPos];
|
|
163
168
|
const [ox1, oy1, ox2, oy2] = lineExtension ? extendLine(startPos, endPos, lineExtension) : new Array(4).fill(0);
|
|
164
169
|
const renderLine = (data: LineDatum[]) => {
|
|
@@ -166,14 +171,43 @@ function renderLinear(
|
|
|
166
171
|
.selectAll(CLASS_NAMES.line.class)
|
|
167
172
|
.data(data, (d, i) => i)
|
|
168
173
|
.join(
|
|
169
|
-
(enter) =>
|
|
170
|
-
enter
|
|
174
|
+
(enter) => {
|
|
175
|
+
const lines = enter
|
|
171
176
|
.append('line')
|
|
172
|
-
.attr('className', (d: LineDatum) => `${CLASS_NAMES.line.name} ${d.className}`)
|
|
173
177
|
.styles(style)
|
|
174
178
|
.transition(function (d: LineDatum) {
|
|
175
179
|
return transition(this, getLinePath(d.line), false);
|
|
176
|
-
})
|
|
180
|
+
});
|
|
181
|
+
// Set className with appropriate logic for line elements
|
|
182
|
+
lines.attr('className', (d: LineDatum) => {
|
|
183
|
+
if (!classNamePrefix) {
|
|
184
|
+
return `${CLASS_NAMES.line.name} ${d.className}`;
|
|
185
|
+
}
|
|
186
|
+
const baseLineClassName = getAxisClassName(
|
|
187
|
+
CLASS_NAMES.line.name,
|
|
188
|
+
CLASSNAME_SUFFIX_MAP.line,
|
|
189
|
+
classNamePrefix
|
|
190
|
+
);
|
|
191
|
+
if (d.className === CLASS_NAMES.lineFirst.name) {
|
|
192
|
+
const specificClassName = getAxisClassName(
|
|
193
|
+
CLASS_NAMES.lineFirst.name,
|
|
194
|
+
CLASSNAME_SUFFIX_MAP.lineFirst,
|
|
195
|
+
classNamePrefix
|
|
196
|
+
);
|
|
197
|
+
return `${baseLineClassName} ${specificClassName}`;
|
|
198
|
+
}
|
|
199
|
+
if (d.className === CLASS_NAMES.lineSecond.name) {
|
|
200
|
+
const specificClassName = getAxisClassName(
|
|
201
|
+
CLASS_NAMES.lineSecond.name,
|
|
202
|
+
CLASSNAME_SUFFIX_MAP.lineSecond,
|
|
203
|
+
classNamePrefix
|
|
204
|
+
);
|
|
205
|
+
return `${baseLineClassName} ${specificClassName}`;
|
|
206
|
+
}
|
|
207
|
+
return baseLineClassName;
|
|
208
|
+
});
|
|
209
|
+
return lines;
|
|
210
|
+
},
|
|
177
211
|
(update) =>
|
|
178
212
|
update.styles(style).transition(function ({ line }: LineDatum) {
|
|
179
213
|
return transition(this, getLinePath(line), animate.update);
|
|
@@ -228,9 +262,13 @@ function renderAxisArrow(
|
|
|
228
262
|
const { showArrow, showTrunc, lineArrow, lineArrowOffset, lineArrowSize } = attr;
|
|
229
263
|
|
|
230
264
|
let shapeToAddArrow: Selection;
|
|
231
|
-
if (type === 'arc')
|
|
232
|
-
|
|
233
|
-
else
|
|
265
|
+
if (type === 'arc') {
|
|
266
|
+
shapeToAddArrow = container.select(CLASS_NAMES.line.class);
|
|
267
|
+
} else if (showTrunc) {
|
|
268
|
+
shapeToAddArrow = container.select(CLASS_NAMES.lineSecond.class);
|
|
269
|
+
} else {
|
|
270
|
+
shapeToAddArrow = container.select(CLASS_NAMES.line.class);
|
|
271
|
+
}
|
|
234
272
|
if (!showArrow || !lineArrow || (attr.type === 'arc' && isCircle(attr.startAngle, attr.endAngle))) {
|
|
235
273
|
const node = shapeToAddArrow.node<Line>();
|
|
236
274
|
if (node) node.style.markerEnd = undefined;
|
|
@@ -8,6 +8,8 @@ import { CLASS_NAMES } from '../constant';
|
|
|
8
8
|
import type { AxisDatum, AxisTickStyleProps, RequiredAxisStyleProps } from '../types';
|
|
9
9
|
import { getValuePos } from './line';
|
|
10
10
|
import { filterExec, getCallbackStyle, getDirectionVector } from './utils';
|
|
11
|
+
import { applyClassName } from '../utils/classname';
|
|
12
|
+
import { CLASSNAME_SUFFIX_MAP } from '../classname-map';
|
|
11
13
|
|
|
12
14
|
type RequiredAxisTickStyleProps = Required<AxisTickStyleProps>;
|
|
13
15
|
|
|
@@ -42,11 +44,14 @@ function createTickEl(
|
|
|
42
44
|
data: AxisDatum[],
|
|
43
45
|
attr: RequiredAxisStyleProps
|
|
44
46
|
) {
|
|
45
|
-
const { tickFormatter: formatter } = attr;
|
|
47
|
+
const { tickFormatter: formatter, classNamePrefix } = attr;
|
|
46
48
|
const tickVector = getTickVector(datum.value, attr);
|
|
47
49
|
let el: any = 'line';
|
|
48
50
|
if (isFunction(formatter)) el = () => getCallbackValue(formatter, [datum, index, data, tickVector]);
|
|
49
|
-
|
|
51
|
+
|
|
52
|
+
const tick = container.append(el).attr('className', CLASS_NAMES.tickItem.name);
|
|
53
|
+
applyClassName(tick, CLASS_NAMES.tickItem, CLASSNAME_SUFFIX_MAP.tickItem, classNamePrefix);
|
|
54
|
+
return tick;
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
function applyTickStyle(
|
|
@@ -86,19 +91,24 @@ export function renderTicks(
|
|
|
86
91
|
attr: RequiredAxisStyleProps,
|
|
87
92
|
animate: StandardAnimationOption
|
|
88
93
|
) {
|
|
94
|
+
const { classNamePrefix } = attr;
|
|
89
95
|
const finalData = filterExec(axisData, attr.tickFilter);
|
|
90
96
|
const tickAttr = subStyleProps<RequiredAxisTickStyleProps>(attr, 'tick');
|
|
97
|
+
|
|
91
98
|
return container
|
|
92
99
|
.selectAll(CLASS_NAMES.tick.class)
|
|
93
100
|
.data(finalData, (d) => d.id || d.label)
|
|
94
101
|
.join(
|
|
95
|
-
(enter) =>
|
|
96
|
-
enter
|
|
102
|
+
(enter) => {
|
|
103
|
+
const ticks = enter
|
|
97
104
|
.append('g')
|
|
98
105
|
.attr('className', CLASS_NAMES.tick.name)
|
|
99
106
|
.transition(function (datum: AxisDatum, index: number) {
|
|
100
107
|
return createTick.call(this, datum, index, finalData, attr, tickAttr, false);
|
|
101
|
-
})
|
|
108
|
+
});
|
|
109
|
+
applyClassName(ticks, CLASS_NAMES.tick, CLASSNAME_SUFFIX_MAP.tick, classNamePrefix);
|
|
110
|
+
return ticks;
|
|
111
|
+
},
|
|
102
112
|
(update) =>
|
|
103
113
|
update.transition(function (datum: AxisDatum, index: number) {
|
|
104
114
|
this.removeChildren();
|
|
@@ -15,6 +15,8 @@ import {
|
|
|
15
15
|
} from '../../../util';
|
|
16
16
|
import { CLASS_NAMES } from '../constant';
|
|
17
17
|
import type { RequiredAxisStyleProps } from '../types';
|
|
18
|
+
import { applyClassName } from '../utils/classname';
|
|
19
|
+
import { CLASSNAME_SUFFIX_MAP } from '../classname-map';
|
|
18
20
|
|
|
19
21
|
function getTitlePosition(
|
|
20
22
|
mainGroup: Selection,
|
|
@@ -101,7 +103,8 @@ export function renderTitle(
|
|
|
101
103
|
attr: RequiredAxisStyleProps,
|
|
102
104
|
animate: StandardAnimationOption
|
|
103
105
|
) {
|
|
104
|
-
const { titleText } = attr;
|
|
106
|
+
const { titleText, classNamePrefix } = attr;
|
|
107
|
+
|
|
105
108
|
return container
|
|
106
109
|
.selectAll(CLASS_NAMES.title.class)
|
|
107
110
|
.data(
|
|
@@ -109,13 +112,16 @@ export function renderTitle(
|
|
|
109
112
|
(d, i) => d.title
|
|
110
113
|
)
|
|
111
114
|
.join(
|
|
112
|
-
(enter) =>
|
|
113
|
-
enter
|
|
115
|
+
(enter) => {
|
|
116
|
+
const titles = enter
|
|
114
117
|
.append(() => renderExtDo(titleText))
|
|
115
118
|
.attr('className', CLASS_NAMES.title.name)
|
|
116
119
|
.transition(function () {
|
|
117
120
|
return applyTitleStyle(select(this), container, axis, attr, animate.enter);
|
|
118
|
-
})
|
|
121
|
+
});
|
|
122
|
+
applyClassName(titles, CLASS_NAMES.title, CLASSNAME_SUFFIX_MAP.title, classNamePrefix);
|
|
123
|
+
return titles;
|
|
124
|
+
},
|
|
119
125
|
(update) =>
|
|
120
126
|
update.transition(function () {
|
|
121
127
|
return applyTitleStyle(select(this), container, axis, attr, animate.update);
|
package/src/ui/axis/types.ts
CHANGED
|
@@ -183,6 +183,7 @@ export type AxisBaseStyleProps = PrefixStyleProps<Partial<AxisTitleStyleProps>,
|
|
|
183
183
|
showTick?: boolean;
|
|
184
184
|
showTitle?: boolean;
|
|
185
185
|
showTrunc?: boolean;
|
|
186
|
+
classNamePrefix?: string;
|
|
186
187
|
};
|
|
187
188
|
|
|
188
189
|
export type LinearAxisStyleProps = AxisBaseStyleProps & { type: 'linear'; startPos: Vector2; endPos: Vector2 };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate axis className with optional prefix
|
|
3
|
+
* @param baseClassName Base className (e.g., 'axis-line')
|
|
4
|
+
* @param suffix Suffix (e.g., 'line')
|
|
5
|
+
* @param classNamePrefix User-defined prefix (e.g., 'g2-')
|
|
6
|
+
* @returns Concatenated className
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* getAxisClassName('axis-line', 'line', 'g2-')
|
|
10
|
+
* // => 'axis-line g2-axis-line'
|
|
11
|
+
*
|
|
12
|
+
* getAxisClassName('axis-line', 'line', undefined)
|
|
13
|
+
* // => 'axis-line'
|
|
14
|
+
*/
|
|
15
|
+
export function getAxisClassName(baseClassName: string, suffix: string, classNamePrefix?: string): string {
|
|
16
|
+
if (!classNamePrefix) return baseClassName;
|
|
17
|
+
return `${baseClassName} ${classNamePrefix}axis-${suffix}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Extract className from component attributes
|
|
22
|
+
* @param attributes Component attributes
|
|
23
|
+
* @param baseClassName Base className object
|
|
24
|
+
* @param suffix Suffix string
|
|
25
|
+
* @returns Concatenated className
|
|
26
|
+
*/
|
|
27
|
+
export function getClassNameFromAttrs(
|
|
28
|
+
attributes: { classNamePrefix?: string },
|
|
29
|
+
baseClassName: { name: string },
|
|
30
|
+
suffix: string
|
|
31
|
+
): string {
|
|
32
|
+
const { classNamePrefix = '' } = attributes;
|
|
33
|
+
return getAxisClassName(baseClassName.name, suffix, classNamePrefix);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Apply full className (with prefix) to a selection element
|
|
38
|
+
* This is a helper to implement the two-step pattern:
|
|
39
|
+
* 1. Create element with base className
|
|
40
|
+
* 2. Apply full className with prefix
|
|
41
|
+
*
|
|
42
|
+
* @param selection The selection to apply className to
|
|
43
|
+
* @param baseClassName Base className object from CLASS_NAMES
|
|
44
|
+
* @param suffix Suffix from CLASSNAME_SUFFIX_MAP
|
|
45
|
+
* @param classNamePrefix Optional user-defined prefix
|
|
46
|
+
* @returns The selection for chaining
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const element = container.maybeAppendByClassName(CLASS_NAMES.grid, 'g');
|
|
50
|
+
* applyClassName(element, CLASS_NAMES.grid, CLASSNAME_SUFFIX_MAP.grid, classNamePrefix);
|
|
51
|
+
*/
|
|
52
|
+
export function applyClassName(
|
|
53
|
+
selection: any,
|
|
54
|
+
baseClassName: { name: string },
|
|
55
|
+
suffix: string,
|
|
56
|
+
classNamePrefix?: string
|
|
57
|
+
): any {
|
|
58
|
+
if (classNamePrefix) {
|
|
59
|
+
selection.attr('className', getAxisClassName(baseClassName.name, suffix, classNamePrefix));
|
|
60
|
+
}
|
|
61
|
+
return selection;
|
|
62
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { VerticalFactor, Direction } from '../types';
|
|
2
2
|
|
|
3
3
|
export * from './test';
|
|
4
|
+
export * from './classname';
|
|
4
5
|
|
|
5
6
|
export function getFactor(...args: Direction[]): VerticalFactor {
|
|
6
7
|
const fn = (str: (typeof args)[number]): VerticalFactor => (str === 'positive' ? -1 : 1);
|