@antv/g2 5.0.0-beta.2 → 5.0.0-beta.4
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/g2-lite.min.js +2 -2
- package/dist/g2.min.js +2 -2
- package/esm/api/mark/mark.js +1 -0
- package/esm/api/mark/mark.js.map +1 -1
- package/esm/api/mark/types.d.ts +1 -0
- package/esm/component/axis.js +45 -24
- package/esm/component/axis.js.map +1 -1
- package/esm/component/index.d.ts +4 -0
- package/esm/component/index.js +2 -0
- package/esm/component/index.js.map +1 -1
- package/esm/component/legendCategory.js +1 -0
- package/esm/component/legendCategory.js.map +1 -1
- package/esm/component/slider.d.ts +9 -0
- package/esm/component/slider.js +59 -0
- package/esm/component/slider.js.map +1 -0
- package/esm/component/sliderX.d.ts +7 -0
- package/esm/component/sliderX.js +9 -0
- package/esm/component/sliderX.js.map +1 -0
- package/esm/component/sliderY.d.ts +7 -0
- package/esm/component/sliderY.js +9 -0
- package/esm/component/sliderY.js.map +1 -0
- package/esm/composition/facetRect.js +4 -4
- package/esm/composition/facetRect.js.map +1 -1
- package/esm/composition/mark.js +2 -1
- package/esm/composition/mark.js.map +1 -1
- package/esm/composition/repeatMatrix.js +2 -2
- package/esm/composition/repeatMatrix.js.map +1 -1
- package/esm/data/filter.d.ts +3 -3
- package/esm/data/filter.js.map +1 -1
- package/esm/data/index.d.ts +3 -1
- package/esm/data/index.js +1 -0
- package/esm/data/index.js.map +1 -1
- package/esm/data/sort.d.ts +8 -0
- package/esm/data/sort.js +12 -0
- package/esm/data/sort.js.map +1 -0
- package/esm/interaction/builtin/tooltip.d.ts +6 -4
- package/esm/interaction/index.d.ts +2 -0
- package/esm/interaction/index.js +2 -0
- package/esm/interaction/index.js.map +1 -1
- package/esm/interaction/native/legendFilter.d.ts +8 -0
- package/esm/interaction/native/legendFilter.js +189 -0
- package/esm/interaction/native/legendFilter.js.map +1 -0
- package/esm/interaction/native/tooltip.d.ts +2 -2
- package/esm/interaction/native/tooltip.js +39 -17
- package/esm/interaction/native/tooltip.js.map +1 -1
- package/esm/interaction/native/utils.d.ts +1 -1
- package/esm/interaction/native/utils.js +2 -2
- package/esm/interaction/native/utils.js.map +1 -1
- package/esm/mark/area.js +1 -1
- package/esm/mark/area.js.map +1 -1
- package/esm/mark/line.js +1 -1
- package/esm/mark/line.js.map +1 -1
- package/esm/runtime/component.js +29 -1
- package/esm/runtime/component.js.map +1 -1
- package/esm/runtime/plot.js +14 -7
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/types/mark.d.ts +1 -1
- package/esm/runtime/types/options.d.ts +1 -0
- package/esm/runtime/types/theme.d.ts +5 -0
- package/esm/spec/data.d.ts +10 -3
- package/esm/spec/geometry.d.ts +2 -1
- package/esm/spec/interaction.d.ts +9 -2
- package/esm/spec/transform.d.ts +7 -2
- package/esm/stdlib/index.js +6 -6
- package/esm/stdlib/index.js.map +1 -1
- package/esm/theme/dark.js +78 -28
- package/esm/theme/dark.js.map +1 -1
- package/esm/theme/light.js +68 -17
- package/esm/theme/light.js.map +1 -1
- package/esm/transform/filter.d.ts +7 -0
- package/esm/transform/filter.js +42 -0
- package/esm/transform/filter.js.map +1 -0
- package/esm/transform/index.d.ts +2 -0
- package/esm/transform/index.js +1 -0
- package/esm/transform/index.js.map +1 -1
- package/esm/transform/sample.js.map +1 -1
- package/esm/transform/selectX.js +1 -1
- package/esm/transform/selectY.js +1 -1
- package/esm/utils/selection.d.ts +1 -0
- package/esm/utils/selection.js.map +1 -1
- package/esm/utils/size.js +1 -1
- package/esm/utils/size.js.map +1 -1
- package/lib/api/mark/mark.js +1 -0
- package/lib/api/mark/mark.js.map +1 -1
- package/lib/api/mark/types.d.ts +1 -0
- package/lib/component/axis.js +45 -24
- package/lib/component/axis.js.map +1 -1
- package/lib/component/index.d.ts +4 -0
- package/lib/component/index.js +5 -1
- package/lib/component/index.js.map +1 -1
- package/lib/component/legendCategory.js +1 -0
- package/lib/component/legendCategory.js.map +1 -1
- package/lib/component/slider.d.ts +9 -0
- package/lib/component/slider.js +63 -0
- package/lib/component/slider.js.map +1 -0
- package/lib/component/sliderX.d.ts +7 -0
- package/lib/component/sliderX.js +13 -0
- package/lib/component/sliderX.js.map +1 -0
- package/lib/component/sliderY.d.ts +7 -0
- package/lib/component/sliderY.js +13 -0
- package/lib/component/sliderY.js.map +1 -0
- package/lib/composition/facetRect.js +4 -4
- package/lib/composition/facetRect.js.map +1 -1
- package/lib/composition/mark.js +2 -1
- package/lib/composition/mark.js.map +1 -1
- package/lib/composition/repeatMatrix.js +2 -2
- package/lib/composition/repeatMatrix.js.map +1 -1
- package/lib/data/filter.d.ts +3 -3
- package/lib/data/filter.js.map +1 -1
- package/lib/data/index.d.ts +3 -1
- package/lib/data/index.js +3 -1
- package/lib/data/index.js.map +1 -1
- package/lib/data/sort.d.ts +8 -0
- package/lib/data/sort.js +17 -0
- package/lib/data/sort.js.map +1 -0
- package/lib/interaction/builtin/tooltip.d.ts +6 -4
- package/lib/interaction/index.d.ts +2 -0
- package/lib/interaction/index.js +5 -1
- package/lib/interaction/index.js.map +1 -1
- package/lib/interaction/native/legendFilter.d.ts +8 -0
- package/lib/interaction/native/legendFilter.js +193 -0
- package/lib/interaction/native/legendFilter.js.map +1 -0
- package/lib/interaction/native/tooltip.d.ts +2 -2
- package/lib/interaction/native/tooltip.js +39 -17
- package/lib/interaction/native/tooltip.js.map +1 -1
- package/lib/interaction/native/utils.d.ts +1 -1
- package/lib/interaction/native/utils.js +2 -2
- package/lib/interaction/native/utils.js.map +1 -1
- package/lib/mark/area.js +1 -1
- package/lib/mark/area.js.map +1 -1
- package/lib/mark/line.js +1 -1
- package/lib/mark/line.js.map +1 -1
- package/lib/runtime/component.js +29 -1
- package/lib/runtime/component.js.map +1 -1
- package/lib/runtime/plot.js +14 -7
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/types/mark.d.ts +1 -1
- package/lib/runtime/types/options.d.ts +1 -0
- package/lib/runtime/types/theme.d.ts +5 -0
- package/lib/spec/data.d.ts +10 -3
- package/lib/spec/geometry.d.ts +2 -1
- package/lib/spec/interaction.d.ts +9 -2
- package/lib/spec/transform.d.ts +7 -2
- package/lib/stdlib/index.js +2 -2
- package/lib/stdlib/index.js.map +1 -1
- package/lib/theme/dark.js +78 -28
- package/lib/theme/dark.js.map +1 -1
- package/lib/theme/light.js +68 -17
- package/lib/theme/light.js.map +1 -1
- package/lib/transform/filter.d.ts +7 -0
- package/lib/transform/filter.js +46 -0
- package/lib/transform/filter.js.map +1 -0
- package/lib/transform/index.d.ts +2 -0
- package/lib/transform/index.js +3 -1
- package/lib/transform/index.js.map +1 -1
- package/lib/transform/sample.js.map +1 -1
- package/lib/transform/selectX.js +2 -2
- package/lib/transform/selectY.js +2 -2
- package/lib/utils/selection.d.ts +1 -0
- package/lib/utils/selection.js.map +1 -1
- package/lib/utils/size.js +1 -1
- package/lib/utils/size.js.map +1 -1
- package/package.json +5 -4
- package/src/api/mark/mark.ts +1 -0
- package/src/api/mark/types.ts +1 -0
- package/src/component/axis.ts +46 -91
- package/src/component/index.ts +4 -0
- package/src/component/legendCategory.ts +1 -0
- package/src/component/slider.ts +63 -0
- package/src/component/sliderX.ts +16 -0
- package/src/component/sliderY.ts +16 -0
- package/src/composition/facetRect.ts +4 -2
- package/src/composition/mark.ts +2 -0
- package/src/composition/repeatMatrix.ts +8 -1
- package/src/data/filter.ts +3 -3
- package/src/data/index.ts +3 -1
- package/src/data/sort.ts +18 -0
- package/src/interaction/index.ts +3 -0
- package/src/interaction/native/legendFilter.ts +206 -0
- package/src/interaction/native/tooltip.ts +57 -16
- package/src/interaction/native/utils.ts +2 -1
- package/src/mark/area.ts +1 -1
- package/src/mark/line.ts +1 -1
- package/src/runtime/component.ts +49 -2
- package/src/runtime/plot.ts +11 -5
- package/src/runtime/types/mark.ts +1 -1
- package/src/runtime/types/options.ts +1 -0
- package/src/runtime/types/theme.ts +5 -0
- package/src/spec/data.ts +12 -2
- package/src/spec/geometry.ts +2 -7
- package/src/spec/interaction.ts +11 -1
- package/src/spec/transform.ts +9 -1
- package/src/stdlib/index.ts +12 -2
- package/src/theme/dark.ts +79 -28
- package/src/theme/light.ts +68 -17
- package/src/transform/filter.ts +48 -0
- package/src/transform/index.ts +2 -0
- package/src/transform/sample.ts +1 -2
- package/src/transform/selectX.ts +1 -1
- package/src/transform/selectY.ts +1 -1
- package/src/utils/selection.ts +2 -0
- package/src/utils/size.ts +1 -1
- package/src/.DS_Store +0 -0
- package/src/data/.DS_Store +0 -0
- package/src/shape/.DS_Store +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g2",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.4",
|
|
4
4
|
"description": "the Grammar of Graphics in Javascript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"lint": "eslint ./src ./__tests__ && prettier ./src ./__tests__ --check ",
|
|
21
21
|
"fix": "eslint ./src ./__tests__ --fix && prettier ./src ./__tests__ --write ",
|
|
22
22
|
"test": "run-s test:integration test:unit",
|
|
23
|
-
"test:unit": "jest --config jest.config.js --coverage",
|
|
24
|
-
"test:integration": "jest --config jest.node.config.js --coverage",
|
|
23
|
+
"test:unit": "jest --config jest.config.js --coverage -i",
|
|
24
|
+
"test:integration": "jest --config jest.node.config.js --coverage -i",
|
|
25
25
|
"test-live": "cross-env DEBUG_MODE=1 jest --watch",
|
|
26
26
|
"build:umd": "rimraf ./dist && rollup -c && npm run size",
|
|
27
27
|
"build:cjs": "rimraf ./lib && tsc --module commonjs --outDir lib",
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"d3-random": "^3.0.1",
|
|
66
66
|
"eslint": "^7.22.0",
|
|
67
67
|
"eslint-plugin-import": "^2.22.1",
|
|
68
|
+
"fecha": "^4.2.3",
|
|
68
69
|
"husky": "^7.0.0",
|
|
69
70
|
"jest": "^26.0.1",
|
|
70
71
|
"jest-electron": "^0.1.12",
|
|
@@ -137,4 +138,4 @@
|
|
|
137
138
|
"d3-shape": "^3.1.0",
|
|
138
139
|
"d3-voronoi": "^1.1.4"
|
|
139
140
|
}
|
|
140
|
-
}
|
|
141
|
+
}
|
package/src/api/mark/mark.ts
CHANGED
|
@@ -145,6 +145,7 @@ export const props: NodePropertyDescriptor[] = [
|
|
|
145
145
|
{ name: 'label', type: 'array', key: 'labels' },
|
|
146
146
|
{ name: 'axis', type: 'object' },
|
|
147
147
|
{ name: 'legend', type: 'object' },
|
|
148
|
+
{ name: 'slider', type: 'object' },
|
|
148
149
|
];
|
|
149
150
|
|
|
150
151
|
@defineProps(props)
|
package/src/api/mark/types.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type API<Props extends Geometry, Mark> = {
|
|
|
10
10
|
label: ArrayAttribute<Props['labels'], Mark>;
|
|
11
11
|
style: ObjectAttribute<Props['style'], Mark>;
|
|
12
12
|
axis: ObjectAttribute<Props['axis'], Mark>;
|
|
13
|
+
slider: ObjectAttribute<Props['slider'], Mark>;
|
|
13
14
|
legend: ObjectAttribute<Props['legend'], Mark>;
|
|
14
15
|
coordinate: ArrayAttribute<Props['coordinates'], Mark>;
|
|
15
16
|
interaction: ArrayAttribute<Props['interactions'], Mark>;
|
package/src/component/axis.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Coordinate
|
|
2
|
-
import { Axis as AxisComponent
|
|
1
|
+
import { Coordinate } from '@antv/coord';
|
|
2
|
+
import { Axis as AxisComponent } from '@antv/gui';
|
|
3
3
|
import { Linear as LinearScale } from '@antv/scale';
|
|
4
4
|
import { deepMix } from '@antv/util';
|
|
5
5
|
import { format } from 'd3-format';
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
isRadial,
|
|
13
13
|
isFisheye,
|
|
14
14
|
} from '../utils/coordinate';
|
|
15
|
+
import { capitalizeFirst } from '../utils/helper';
|
|
15
16
|
import {
|
|
16
17
|
BBox,
|
|
17
18
|
GuideComponentComponent as GCC,
|
|
@@ -242,124 +243,46 @@ function inferGrid(value: boolean, coordinate: Coordinate, scale: Scale) {
|
|
|
242
243
|
return value === undefined ? !!scale.getTicks : value;
|
|
243
244
|
}
|
|
244
245
|
|
|
245
|
-
function
|
|
246
|
+
function inferOverrideStyle(
|
|
246
247
|
position: GuideComponentPosition,
|
|
247
|
-
direction: string,
|
|
248
248
|
bbox: BBox,
|
|
249
249
|
coordinate: Coordinate,
|
|
250
|
-
scale: Scale,
|
|
251
250
|
): {
|
|
252
|
-
type: 'linear';
|
|
253
251
|
startPos: [number, number];
|
|
254
252
|
endPos: [number, number];
|
|
255
|
-
labelSpacing: number;
|
|
256
|
-
titlePosition: AxisStyleProps['titlePosition'];
|
|
257
|
-
titleTextBaseline: 'top' | 'bottom' | 'middle';
|
|
258
|
-
titleSpacing?: number;
|
|
259
|
-
titleTransform: string;
|
|
260
|
-
titleTransformOrigin: string;
|
|
261
|
-
labelDirection: 'negative' | 'positive';
|
|
262
|
-
labelTransform?: string;
|
|
263
|
-
tickDirection: 'negative' | 'positive';
|
|
264
|
-
showLabel?: boolean;
|
|
265
|
-
showTick?: boolean;
|
|
266
253
|
showLine?: boolean;
|
|
267
|
-
|
|
268
|
-
gridDirection: 'negative' | 'positive';
|
|
269
|
-
gridConnect?: string;
|
|
270
|
-
gridType?: string;
|
|
271
|
-
gridCenter?: Vector2;
|
|
272
|
-
gridControlAngles?: number[];
|
|
273
|
-
girdClosed?: true;
|
|
254
|
+
[k: string]: any;
|
|
274
255
|
} {
|
|
275
|
-
const gridLength = getGridLength(position, coordinate);
|
|
276
256
|
const [, cy] = coordinate.getCenter();
|
|
277
257
|
const { x, y, width, height } = bbox;
|
|
278
258
|
|
|
279
|
-
const common = {
|
|
280
|
-
type: 'linear' as const,
|
|
281
|
-
lineArrow: null,
|
|
282
|
-
titleTransform: undefined,
|
|
283
|
-
titleTransformOrigin: 'center',
|
|
284
|
-
labelAlign: 'horizontal',
|
|
285
|
-
gridLength,
|
|
286
|
-
};
|
|
287
|
-
|
|
288
259
|
if (position === 'bottom') {
|
|
289
260
|
return {
|
|
290
|
-
...common,
|
|
291
261
|
startPos: [x, y],
|
|
292
262
|
endPos: [x + width, y],
|
|
293
|
-
titlePosition: scale.getTicks ? 'right-bottom' : 'bottom',
|
|
294
|
-
titleTransform: scale.getTicks ? 'translate(-100%, 0)' : undefined,
|
|
295
|
-
titleSpacing: 10,
|
|
296
|
-
titleTextBaseline: 'bottom',
|
|
297
|
-
labelSpacing: 12,
|
|
298
|
-
labelDirection: 'positive',
|
|
299
|
-
tickDirection: 'positive',
|
|
300
|
-
gridDirection: 'negative',
|
|
301
263
|
};
|
|
302
264
|
} else if (position === 'left' || position === 'centerHorizontal') {
|
|
303
265
|
return {
|
|
304
|
-
...common,
|
|
305
266
|
startPos: [x + width, y],
|
|
306
267
|
endPos: [x + width, y + height],
|
|
307
|
-
titleSpacing: 10,
|
|
308
|
-
titleTextBaseline: 'middle',
|
|
309
|
-
titlePosition: 'left',
|
|
310
|
-
titleTransform: `translate(50%, 0) rotate(-90)`,
|
|
311
|
-
labelSpacing: 4,
|
|
312
|
-
labelDirection: 'positive',
|
|
313
|
-
tickDirection: 'positive',
|
|
314
|
-
gridDirection: 'negative',
|
|
315
268
|
showLine: position === 'centerHorizontal' ? true : undefined,
|
|
316
269
|
};
|
|
317
270
|
} else if (position === 'right') {
|
|
318
271
|
return {
|
|
319
|
-
...common,
|
|
320
272
|
endPos: [x, y + height],
|
|
321
273
|
startPos: [x, y],
|
|
322
|
-
titlePosition: 'right',
|
|
323
|
-
titleSpacing: 0,
|
|
324
|
-
titleTextBaseline: 'top',
|
|
325
|
-
titleTransform: `translate(-50%, 0) rotate(-90)`,
|
|
326
|
-
labelSpacing: 4,
|
|
327
|
-
labelDirection: 'negative',
|
|
328
|
-
tickDirection: 'negative',
|
|
329
|
-
gridDirection: 'positive',
|
|
330
274
|
};
|
|
331
275
|
} else if (position === 'arcY') {
|
|
332
276
|
return {
|
|
333
|
-
...common,
|
|
334
277
|
startPos: [x, y],
|
|
335
278
|
endPos: [x + width, y + height],
|
|
336
|
-
titlePosition: 'top',
|
|
337
|
-
titleSpacing: 0,
|
|
338
|
-
titleTextBaseline: 'bottom',
|
|
339
|
-
labelDirection: direction === 'right' ? 'negative' : 'positive',
|
|
340
|
-
labelTransform: direction === 'center' ? 'translate(50%, 0)' : '',
|
|
341
|
-
tickDirection: direction === 'right' ? 'negative' : 'positive',
|
|
342
|
-
labelSpacing: direction === 'center' ? 0 : 4,
|
|
343
|
-
gridDirection: 'negative',
|
|
344
|
-
gridConnect: 'arc',
|
|
345
|
-
gridType: 'surround',
|
|
346
279
|
gridCenter: [bbox.x, cy + bbox.y],
|
|
347
|
-
gridControlAngles: [90, 180, 360],
|
|
348
|
-
girdClosed: true,
|
|
349
280
|
};
|
|
350
281
|
}
|
|
351
282
|
|
|
352
283
|
return {
|
|
353
|
-
...common,
|
|
354
284
|
startPos: [x, y + height],
|
|
355
285
|
endPos: [x + width, y + height],
|
|
356
|
-
titlePosition: 'top',
|
|
357
|
-
titleSpacing: 0,
|
|
358
|
-
titleTextBaseline: 'middle',
|
|
359
|
-
labelSpacing: 8,
|
|
360
|
-
labelDirection: 'negative',
|
|
361
|
-
tickDirection: 'negative',
|
|
362
|
-
gridDirection: 'positive',
|
|
363
286
|
showLine: position === 'centerVertical' ? true : undefined,
|
|
364
287
|
};
|
|
365
288
|
}
|
|
@@ -418,6 +341,35 @@ const ArcAxis = (options) => {
|
|
|
418
341
|
};
|
|
419
342
|
};
|
|
420
343
|
|
|
344
|
+
function inferDefaultStyle(scale, theme, position, direction) {
|
|
345
|
+
const p = position === 'centerHorizontal' ? 'left' : position;
|
|
346
|
+
|
|
347
|
+
const themeStyle = Object.assign(
|
|
348
|
+
{},
|
|
349
|
+
theme.axis,
|
|
350
|
+
theme[`axis${capitalizeFirst(p)}`] || theme.axisTop,
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
if (position === 'bottom') {
|
|
354
|
+
return {
|
|
355
|
+
...themeStyle,
|
|
356
|
+
titlePosition: scale.getTicks ? 'right-bottom' : 'bottom',
|
|
357
|
+
titleTransformOrigin: 'center',
|
|
358
|
+
titleTransform: scale.getTicks ? 'translate(-100%, 0)' : undefined,
|
|
359
|
+
};
|
|
360
|
+
} else if (position === 'arcY') {
|
|
361
|
+
return {
|
|
362
|
+
...themeStyle,
|
|
363
|
+
labelDirection: direction === 'right' ? 'negative' : 'positive',
|
|
364
|
+
labelTransform: direction === 'center' ? 'translate(50%, 0)' : '',
|
|
365
|
+
tickDirection: direction === 'right' ? 'negative' : 'positive',
|
|
366
|
+
labelSpacing: direction === 'center' ? 0 : 4,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return themeStyle;
|
|
371
|
+
}
|
|
372
|
+
|
|
421
373
|
const LinearAxis: GCC<AxisOptions> = (options) => {
|
|
422
374
|
const {
|
|
423
375
|
order,
|
|
@@ -433,13 +385,14 @@ const LinearAxis: GCC<AxisOptions> = (options) => {
|
|
|
433
385
|
labelAutoHide = false,
|
|
434
386
|
labelAutoRotate = true,
|
|
435
387
|
grid,
|
|
388
|
+
label: showLabel = true,
|
|
389
|
+
tick: showTick = true,
|
|
436
390
|
...userDefinitions
|
|
437
391
|
} = options;
|
|
438
392
|
|
|
439
393
|
return (scale, value, coordinate, theme) => {
|
|
440
394
|
const { domain, bbox } = value;
|
|
441
395
|
|
|
442
|
-
const { axis: axisTheme } = theme;
|
|
443
396
|
const ticks = getTicks(
|
|
444
397
|
scale,
|
|
445
398
|
domain,
|
|
@@ -452,31 +405,33 @@ const LinearAxis: GCC<AxisOptions> = (options) => {
|
|
|
452
405
|
);
|
|
453
406
|
|
|
454
407
|
const showGrid = inferGrid(grid, coordinate, scale);
|
|
408
|
+
const gridLength = getGridLength(position, coordinate);
|
|
455
409
|
|
|
456
410
|
const {
|
|
457
|
-
showLabel = options.label === undefined ? true : options.label,
|
|
458
|
-
showTick = options.tick === undefined ? true : options.tick,
|
|
459
411
|
showLine = options.line === undefined ? false : options.line,
|
|
460
|
-
...
|
|
461
|
-
} =
|
|
412
|
+
...overrideStyle
|
|
413
|
+
} = inferOverrideStyle(position, bbox, coordinate);
|
|
414
|
+
|
|
415
|
+
const defaultStyle = inferDefaultStyle(scale, theme, position, direction);
|
|
462
416
|
|
|
463
417
|
const axisStyle = {
|
|
464
418
|
...defaultStyle,
|
|
419
|
+
type: 'linear' as const,
|
|
465
420
|
data: ticks,
|
|
466
421
|
title: titleContent(title),
|
|
467
422
|
showLabel,
|
|
468
423
|
labelTransforms: labelTransforms(labelAutoHide, labelAutoRotate),
|
|
469
424
|
showGrid,
|
|
470
425
|
showTick,
|
|
426
|
+
gridLength,
|
|
471
427
|
...userDefinitions,
|
|
472
428
|
// Always showLine, make title could align the end of axis.
|
|
473
429
|
showLine: true,
|
|
474
430
|
...(!showLine ? { lineOpacity: 0 } : null),
|
|
475
|
-
|
|
431
|
+
...overrideStyle,
|
|
432
|
+
};
|
|
476
433
|
|
|
477
|
-
return new AxisComponent({
|
|
478
|
-
style: Object.assign({}, axisTheme, axisStyle),
|
|
479
|
-
});
|
|
434
|
+
return new AxisComponent({ style: axisStyle });
|
|
480
435
|
};
|
|
481
436
|
};
|
|
482
437
|
|
package/src/component/index.ts
CHANGED
|
@@ -3,9 +3,13 @@ export { AxisY } from './axisY';
|
|
|
3
3
|
export { LegendCategory } from './legendCategory';
|
|
4
4
|
export { LegendContinuous } from './legendContinuous';
|
|
5
5
|
export { TitleComponent } from './title';
|
|
6
|
+
export { SliderX } from './sliderX';
|
|
7
|
+
export { SliderY } from './sliderY';
|
|
6
8
|
|
|
7
9
|
export type { AxisXOptions } from './axisX';
|
|
8
10
|
export type { AxisYOptions } from './axisY';
|
|
9
11
|
export type { LegendCategoryOptions } from './legendCategory';
|
|
10
12
|
export type { LegendContinuousOptions } from './legendContinuous';
|
|
11
13
|
export type { TitleComponentOptions } from './title';
|
|
14
|
+
export type { SliderXOptions } from './sliderX';
|
|
15
|
+
export type { SliderYOptions } from './sliderY';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Slider as SliderComponent } from '@antv/gui';
|
|
2
|
+
import { format } from 'd3-format';
|
|
3
|
+
import { least } from 'd3-array';
|
|
4
|
+
import { GuideComponentComponent as GCC, Scale } from '../runtime';
|
|
5
|
+
|
|
6
|
+
export type SliderOptions = {
|
|
7
|
+
orient: 'horizontal' | 'vertical';
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Slider component.
|
|
13
|
+
*/
|
|
14
|
+
export const Slider: GCC<SliderOptions> = (options) => {
|
|
15
|
+
// do not pass size.
|
|
16
|
+
const { orient, labelFormatter, size, ...rest } = options;
|
|
17
|
+
|
|
18
|
+
return (scale, value, coordinate, theme) => {
|
|
19
|
+
const { bbox } = value;
|
|
20
|
+
const { x, y, width, height } = bbox;
|
|
21
|
+
const { slider: sliderTheme = {} } = theme;
|
|
22
|
+
const defaultFormatter = scale.getFormatter?.() || ((v) => v);
|
|
23
|
+
const formatter =
|
|
24
|
+
typeof labelFormatter === 'string'
|
|
25
|
+
? format(labelFormatter)
|
|
26
|
+
: labelFormatter;
|
|
27
|
+
|
|
28
|
+
return new SliderComponent({
|
|
29
|
+
className: 'slider',
|
|
30
|
+
style: Object.assign({}, sliderTheme, {
|
|
31
|
+
x,
|
|
32
|
+
y,
|
|
33
|
+
length: orient === 'horizontal' ? width : height,
|
|
34
|
+
orient,
|
|
35
|
+
formatter: (v) => {
|
|
36
|
+
const f = formatter || defaultFormatter;
|
|
37
|
+
const tick = invertTick(scale, v);
|
|
38
|
+
return f(tick);
|
|
39
|
+
},
|
|
40
|
+
// @todo GUI should rename size to railSize
|
|
41
|
+
size: sliderTheme.railSize,
|
|
42
|
+
...rest,
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Translate [0,1] value to origin value.
|
|
50
|
+
*/
|
|
51
|
+
function invertTick(scale: Scale, v: number) {
|
|
52
|
+
if (!scale.getBandWidth) return scale.invert(v);
|
|
53
|
+
// @ts-ignore @todo should support in scale
|
|
54
|
+
const range = scale.adjustedRange as number[];
|
|
55
|
+
const abs = (v) => Math.abs(v);
|
|
56
|
+
return scale.invert(least(range, (a, b) => abs(a - v) - abs(b - v)));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
Slider.props = {
|
|
60
|
+
defaultPosition: 'bottom',
|
|
61
|
+
defaultSize: 24,
|
|
62
|
+
defaultOrder: 1,
|
|
63
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GuideComponentComponent as GCC } from '../runtime';
|
|
2
|
+
import { Slider, SliderOptions } from './slider';
|
|
3
|
+
|
|
4
|
+
export type SliderXOptions = SliderOptions;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* SliderX component.
|
|
8
|
+
*/
|
|
9
|
+
export const SliderX: GCC<SliderXOptions> = (options) => {
|
|
10
|
+
return Slider({ ...options, orient: 'horizontal' });
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
SliderX.props = {
|
|
14
|
+
...Slider.props,
|
|
15
|
+
defaultPosition: 'bottom',
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GuideComponentComponent as GCC } from '../runtime';
|
|
2
|
+
import { Slider, SliderOptions } from './slider';
|
|
3
|
+
|
|
4
|
+
export type SliderYOptions = SliderOptions;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* SliderY component.
|
|
8
|
+
*/
|
|
9
|
+
export const SliderY: GCC<SliderYOptions> = (options) => {
|
|
10
|
+
return Slider({ ...options, orient: 'vertical' });
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
SliderY.props = {
|
|
14
|
+
...Slider.props,
|
|
15
|
+
defaultPosition: 'left',
|
|
16
|
+
};
|
|
@@ -174,6 +174,7 @@ export const setChildren = useOverrideAdaptor<G2ViewTree>(
|
|
|
174
174
|
x: originX = 0,
|
|
175
175
|
y: originY = 0,
|
|
176
176
|
shareData = false,
|
|
177
|
+
key: viewKey,
|
|
177
178
|
} = options;
|
|
178
179
|
const { value: data } = dataValue;
|
|
179
180
|
// Only support field encode now.
|
|
@@ -233,8 +234,8 @@ export const setChildren = useOverrideAdaptor<G2ViewTree>(
|
|
|
233
234
|
legend = {},
|
|
234
235
|
...rest
|
|
235
236
|
}) => {
|
|
236
|
-
const guideY = scale?.y?.guide;
|
|
237
|
-
const guideX = scale?.x?.guide;
|
|
237
|
+
const guideY = scale?.y?.guide || axis.y;
|
|
238
|
+
const guideX = scale?.x?.guide || axis.x;
|
|
238
239
|
const defaultScale = {
|
|
239
240
|
x: { tickCount: encodeX ? 5 : undefined },
|
|
240
241
|
y: { tickCount: encodeY ? 5 : undefined },
|
|
@@ -256,6 +257,7 @@ export const setChildren = useOverrideAdaptor<G2ViewTree>(
|
|
|
256
257
|
data: newData,
|
|
257
258
|
x: left + paddingLeft + originX,
|
|
258
259
|
y: top + paddingTop + originY,
|
|
260
|
+
parentKey: viewKey,
|
|
259
261
|
width,
|
|
260
262
|
height,
|
|
261
263
|
paddingLeft: 0,
|
package/src/composition/mark.ts
CHANGED
|
@@ -35,6 +35,7 @@ export const Mark: CC<MarkOptions> = () => {
|
|
|
35
35
|
frame,
|
|
36
36
|
title,
|
|
37
37
|
labelTransform,
|
|
38
|
+
parentKey,
|
|
38
39
|
...mark
|
|
39
40
|
} = options;
|
|
40
41
|
|
|
@@ -68,6 +69,7 @@ export const Mark: CC<MarkOptions> = () => {
|
|
|
68
69
|
marginBottom,
|
|
69
70
|
marginTop,
|
|
70
71
|
marginRight,
|
|
72
|
+
parentKey,
|
|
71
73
|
marks: [{ ...mark, key: `${key}-0`, data }],
|
|
72
74
|
},
|
|
73
75
|
];
|
|
@@ -25,7 +25,13 @@ const setScale = useDefaultAdaptor<G2ViewTree>((options) => {
|
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
const setChildren = useOverrideAdaptor<G2ViewTree>((options) => {
|
|
28
|
-
const {
|
|
28
|
+
const {
|
|
29
|
+
data,
|
|
30
|
+
children,
|
|
31
|
+
x: originX = 0,
|
|
32
|
+
y: originY = 0,
|
|
33
|
+
key: viewKey,
|
|
34
|
+
} = options;
|
|
29
35
|
const createChildren = (visualData, scale, layout) => {
|
|
30
36
|
const { x: scaleX, y: scaleY } = scale;
|
|
31
37
|
const { paddingLeft, paddingTop } = layout;
|
|
@@ -76,6 +82,7 @@ const setChildren = useOverrideAdaptor<G2ViewTree>((options) => {
|
|
|
76
82
|
};
|
|
77
83
|
return {
|
|
78
84
|
data,
|
|
85
|
+
parentKey: viewKey,
|
|
79
86
|
key: `${key}-${i}`,
|
|
80
87
|
x: left + paddingLeft + originX,
|
|
81
88
|
y: top + paddingTop + originY,
|
package/src/data/filter.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DataComponent as DC } from '../runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { FilterDataTransform } from '../spec';
|
|
3
3
|
|
|
4
|
-
export type
|
|
4
|
+
export type FilterDataOptions = Omit<FilterDataTransform, 'type'>;
|
|
5
5
|
|
|
6
6
|
export function defined(d: any): boolean {
|
|
7
7
|
return d !== undefined && d !== null && !Number.isNaN(d);
|
|
@@ -11,7 +11,7 @@ export function defined(d: any): boolean {
|
|
|
11
11
|
* Filter data by specified fields and filter callback for each fields.
|
|
12
12
|
* It saves datum with every fields defined by default.
|
|
13
13
|
*/
|
|
14
|
-
export const Filter: DC<
|
|
14
|
+
export const Filter: DC<FilterDataOptions> = (options) => {
|
|
15
15
|
const { callback = defined } = options;
|
|
16
16
|
return (data) => data.filter(callback);
|
|
17
17
|
};
|
package/src/data/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { Fetch } from './fetch';
|
|
2
2
|
export { Fold } from './fold';
|
|
3
3
|
export { Filter } from './filter';
|
|
4
|
+
export { Sort } from './sort';
|
|
4
5
|
export { Pick } from './pick';
|
|
5
6
|
export { Rename } from './rename';
|
|
6
7
|
export { Subset } from './subset';
|
|
@@ -17,7 +18,8 @@ export { Join } from './join';
|
|
|
17
18
|
|
|
18
19
|
export type { FetchOptions } from './fetch';
|
|
19
20
|
export type { FoldOptions } from './fold';
|
|
20
|
-
export type {
|
|
21
|
+
export type { FilterDataOptions } from './filter';
|
|
22
|
+
export type { SortOptions } from './sort';
|
|
21
23
|
export type { PickOptions } from './pick';
|
|
22
24
|
export type { RenameOptions } from './rename';
|
|
23
25
|
export type { SubsetOptions } from './subset';
|
package/src/data/sort.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DataComponent as DC } from '../runtime';
|
|
2
|
+
import { SortTransform } from '../spec';
|
|
3
|
+
|
|
4
|
+
export type SortOptions = Omit<SortTransform, 'type'>;
|
|
5
|
+
|
|
6
|
+
export function defined(d: any): boolean {
|
|
7
|
+
return d !== undefined && d !== null && !Number.isNaN(d);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Sort data similar with Array.prototypo.sort.
|
|
12
|
+
*/
|
|
13
|
+
export const Sort: DC<SortOptions> = (options) => {
|
|
14
|
+
const { callback } = options;
|
|
15
|
+
return (data) => (Array.isArray(data) ? [...data].sort(callback) : data);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
Sort.props = {};
|
package/src/interaction/index.ts
CHANGED
|
@@ -9,6 +9,9 @@ export { ElementSelectByColor } from './native/elementSelectByColor';
|
|
|
9
9
|
export { ChartIndex } from './native/chartIndex';
|
|
10
10
|
export { Fisheye } from './native/fisheye';
|
|
11
11
|
export { Tooltip } from './native/tooltip';
|
|
12
|
+
export { LegendFilter } from './native/legendFilter';
|
|
13
|
+
|
|
14
|
+
export { LEGEND_ITEMS_CLASS_NAME } from './native/legendFilter';
|
|
12
15
|
|
|
13
16
|
// export { ElementSelected } from './builtin/elementSelected';
|
|
14
17
|
// export { Tooltip } from './builtin/tooltip';
|