@antv/g2 5.0.6 → 5.0.8
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 +4 -4
- package/dist/g2.min.js +4 -4
- package/esm/animation/morphing.js +4 -0
- package/esm/animation/morphing.js.map +1 -1
- package/esm/api/chart.d.ts +4 -7
- package/esm/api/chart.js +22 -90
- package/esm/api/chart.js.map +1 -1
- package/esm/api/mark/index.d.ts +3 -1
- package/esm/api/mark/index.js +2 -1
- package/esm/api/mark/index.js.map +1 -1
- package/esm/api/mark/mark.d.ts +7 -1
- package/esm/api/mark/mark.js +9 -0
- package/esm/api/mark/mark.js.map +1 -1
- package/esm/api/utils.d.ts +10 -0
- package/esm/api/utils.js +71 -0
- package/esm/api/utils.js.map +1 -0
- package/esm/component/axis.js +17 -19
- package/esm/component/axis.js.map +1 -1
- package/esm/component/axisX.js +3 -1
- package/esm/component/axisX.js.map +1 -1
- package/esm/component/axisY.js +1 -1
- package/esm/component/axisY.js.map +1 -1
- package/esm/component/constant.js +6 -0
- package/esm/component/constant.js.map +1 -1
- package/esm/component/legendCategory.js +8 -5
- package/esm/component/legendCategory.js.map +1 -1
- package/esm/component/legendContinuous.js +91 -33
- package/esm/component/legendContinuous.js.map +1 -1
- package/esm/component/utils.d.ts +9 -5
- package/esm/component/utils.js +14 -14
- package/esm/component/utils.js.map +1 -1
- package/esm/composition/mark.js +2 -1
- package/esm/composition/mark.js.map +1 -1
- package/esm/data/index.d.ts +2 -0
- package/esm/data/index.js +1 -0
- package/esm/data/index.js.map +1 -1
- package/esm/data/kde.d.ts +10 -0
- package/esm/data/kde.js +30 -0
- package/esm/data/kde.js.map +1 -0
- package/esm/interaction/brushFilter.js +2 -6
- package/esm/interaction/brushFilter.js.map +1 -1
- package/esm/interaction/brushHighlight.d.ts +3 -2
- package/esm/interaction/brushHighlight.js +202 -28
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/brushXHighlight.js +1 -1
- package/esm/interaction/brushXHighlight.js.map +1 -1
- package/esm/interaction/brushYHighlight.js +1 -1
- package/esm/interaction/brushYHighlight.js.map +1 -1
- package/esm/interaction/event.d.ts +1 -0
- package/esm/interaction/event.js +14 -12
- package/esm/interaction/event.js.map +1 -1
- package/esm/interaction/tooltip.d.ts +4 -4
- package/esm/interaction/tooltip.js +103 -31
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/mark/density.d.ts +4 -0
- package/esm/mark/density.js +61 -0
- package/esm/mark/density.js.map +1 -0
- package/esm/mark/gauge.d.ts +7 -0
- package/esm/mark/gauge.js +4 -6
- package/esm/mark/gauge.js.map +1 -1
- package/esm/mark/index.d.ts +2 -0
- package/esm/mark/index.js +1 -0
- package/esm/mark/index.js.map +1 -1
- package/esm/runtime/component.d.ts +4 -2
- package/esm/runtime/component.js +164 -12
- package/esm/runtime/component.js.map +1 -1
- package/esm/runtime/layout.d.ts +3 -3
- package/esm/runtime/layout.js +40 -21
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/plot.js +10 -7
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/scale.js +2 -2
- package/esm/runtime/scale.js.map +1 -1
- package/esm/runtime/transform.js +4 -1
- package/esm/runtime/transform.js.map +1 -1
- package/esm/runtime/types/component.d.ts +1 -0
- package/esm/shape/area/area.js +1 -1
- package/esm/shape/area/area.js.map +1 -1
- package/esm/shape/area/curve.js +1 -1
- package/esm/shape/area/curve.js.map +1 -1
- package/esm/shape/box/violin.d.ts +3 -0
- package/esm/shape/box/violin.js +85 -0
- package/esm/shape/box/violin.js.map +1 -0
- package/esm/shape/connector/connector.js +1 -1
- package/esm/shape/density/density.d.ts +8 -0
- package/esm/shape/density/density.js +50 -0
- package/esm/shape/density/density.js.map +1 -0
- package/esm/shape/index.d.ts +4 -0
- package/esm/shape/index.js +2 -0
- package/esm/shape/index.js.map +1 -1
- package/esm/shape/line/curve.js +1 -1
- package/esm/shape/line/curve.js.map +1 -1
- package/esm/shape/text/advance.d.ts +1 -1
- package/esm/shape/text/advance.js +1 -1
- package/esm/shape/text/advance.js.map +1 -1
- package/esm/shape/text/badge.js +1 -1
- package/esm/shape/utils.js +1 -1
- package/esm/shape/utils.js.map +1 -1
- package/esm/spec/composition.d.ts +22 -19
- package/esm/spec/dataTransform.d.ts +34 -2
- package/esm/spec/interaction.d.ts +3 -1
- package/esm/spec/mark.d.ts +9 -8
- package/esm/spec/transform.d.ts +1 -1
- package/esm/spec/utils.d.ts +1 -0
- package/esm/stdlib/index.js +5 -5
- package/esm/stdlib/index.js.map +1 -1
- package/esm/theme/classic.js +3 -0
- package/esm/theme/classic.js.map +1 -1
- package/esm/theme/classicDark.js +1 -0
- package/esm/theme/classicDark.js.map +1 -1
- package/esm/transform/filter.js +6 -2
- package/esm/transform/filter.js.map +1 -1
- package/esm/{shape → utils}/createElement.d.ts +1 -1
- package/esm/{shape → utils}/createElement.js.map +1 -1
- package/esm/utils/helper.d.ts +3 -0
- package/esm/utils/helper.js +3 -0
- package/esm/utils/helper.js.map +1 -1
- package/esm/utils/scale.js +5 -1
- package/esm/utils/scale.js.map +1 -1
- package/esm/utils/size.js +7 -4
- package/esm/utils/size.js.map +1 -1
- package/lib/animation/morphing.js +4 -0
- package/lib/animation/morphing.js.map +1 -1
- package/lib/api/chart.d.ts +4 -7
- package/lib/api/chart.js +27 -97
- package/lib/api/chart.js.map +1 -1
- package/lib/api/mark/index.d.ts +3 -1
- package/lib/api/mark/index.js +1 -0
- package/lib/api/mark/index.js.map +1 -1
- package/lib/api/mark/mark.d.ts +7 -1
- package/lib/api/mark/mark.js +10 -1
- package/lib/api/mark/mark.js.map +1 -1
- package/lib/api/utils.d.ts +10 -0
- package/lib/api/utils.js +80 -0
- package/lib/api/utils.js.map +1 -0
- package/lib/component/axis.js +17 -19
- package/lib/component/axis.js.map +1 -1
- package/lib/component/axisX.js +3 -1
- package/lib/component/axisX.js.map +1 -1
- package/lib/component/axisY.js +1 -1
- package/lib/component/axisY.js.map +1 -1
- package/lib/component/constant.js +6 -0
- package/lib/component/constant.js.map +1 -1
- package/lib/component/legendCategory.js +7 -4
- package/lib/component/legendCategory.js.map +1 -1
- package/lib/component/legendContinuous.js +90 -32
- package/lib/component/legendContinuous.js.map +1 -1
- package/lib/component/utils.d.ts +9 -5
- package/lib/component/utils.js +16 -15
- package/lib/component/utils.js.map +1 -1
- package/lib/composition/mark.js +2 -1
- package/lib/composition/mark.js.map +1 -1
- package/lib/data/index.d.ts +2 -0
- package/lib/data/index.js +3 -1
- package/lib/data/index.js.map +1 -1
- package/lib/data/kde.d.ts +10 -0
- package/lib/data/kde.js +38 -0
- package/lib/data/kde.js.map +1 -0
- package/lib/interaction/brushFilter.js +2 -6
- package/lib/interaction/brushFilter.js.map +1 -1
- package/lib/interaction/brushHighlight.d.ts +3 -2
- package/lib/interaction/brushHighlight.js +201 -27
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/brushXHighlight.js +1 -1
- package/lib/interaction/brushXHighlight.js.map +1 -1
- package/lib/interaction/brushYHighlight.js +1 -1
- package/lib/interaction/brushYHighlight.js.map +1 -1
- package/lib/interaction/event.d.ts +1 -0
- package/lib/interaction/event.js +15 -12
- package/lib/interaction/event.js.map +1 -1
- package/lib/interaction/tooltip.d.ts +4 -4
- package/lib/interaction/tooltip.js +102 -30
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/mark/density.d.ts +4 -0
- package/lib/mark/density.js +65 -0
- package/lib/mark/density.js.map +1 -0
- package/lib/mark/gauge.d.ts +7 -0
- package/lib/mark/gauge.js +4 -6
- package/lib/mark/gauge.js.map +1 -1
- package/lib/mark/index.d.ts +2 -0
- package/lib/mark/index.js +3 -1
- package/lib/mark/index.js.map +1 -1
- package/lib/runtime/component.d.ts +4 -2
- package/lib/runtime/component.js +163 -10
- package/lib/runtime/component.js.map +1 -1
- package/lib/runtime/layout.d.ts +3 -3
- package/lib/runtime/layout.js +40 -21
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/plot.js +10 -7
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/scale.js +2 -2
- package/lib/runtime/scale.js.map +1 -1
- package/lib/runtime/transform.js +4 -1
- package/lib/runtime/transform.js.map +1 -1
- package/lib/runtime/types/component.d.ts +1 -0
- package/lib/shape/area/area.js +1 -1
- package/lib/shape/area/area.js.map +1 -1
- package/lib/shape/area/curve.js +1 -1
- package/lib/shape/area/curve.js.map +1 -1
- package/lib/shape/box/violin.d.ts +3 -0
- package/lib/shape/box/violin.js +89 -0
- package/lib/shape/box/violin.js.map +1 -0
- package/lib/shape/connector/connector.js +1 -1
- package/lib/shape/density/density.d.ts +8 -0
- package/lib/shape/density/density.js +54 -0
- package/lib/shape/density/density.js.map +1 -0
- package/lib/shape/index.d.ts +4 -0
- package/lib/shape/index.js +6 -1
- package/lib/shape/index.js.map +1 -1
- package/lib/shape/line/curve.js +1 -1
- package/lib/shape/line/curve.js.map +1 -1
- package/lib/shape/text/advance.d.ts +1 -1
- package/lib/shape/text/advance.js +1 -1
- package/lib/shape/text/advance.js.map +1 -1
- package/lib/shape/text/badge.js +1 -1
- package/lib/shape/utils.js +1 -1
- package/lib/shape/utils.js.map +1 -1
- package/lib/spec/composition.d.ts +22 -19
- package/lib/spec/dataTransform.d.ts +34 -2
- package/lib/spec/interaction.d.ts +3 -1
- package/lib/spec/mark.d.ts +9 -8
- package/lib/spec/transform.d.ts +1 -1
- package/lib/spec/utils.d.ts +1 -0
- package/lib/stdlib/index.js +2 -2
- package/lib/stdlib/index.js.map +1 -1
- package/lib/theme/classic.js +3 -0
- package/lib/theme/classic.js.map +1 -1
- package/lib/theme/classicDark.js +1 -0
- package/lib/theme/classicDark.js.map +1 -1
- package/lib/transform/filter.js +6 -2
- package/lib/transform/filter.js.map +1 -1
- package/lib/{shape → utils}/createElement.d.ts +1 -1
- package/lib/{shape → utils}/createElement.js.map +1 -1
- package/lib/utils/helper.d.ts +3 -0
- package/lib/utils/helper.js +5 -1
- package/lib/utils/helper.js.map +1 -1
- package/lib/utils/scale.js +5 -1
- package/lib/utils/scale.js.map +1 -1
- package/lib/utils/size.js +7 -4
- package/lib/utils/size.js.map +1 -1
- package/package.json +5 -3
- package/src/animation/morphing.ts +5 -0
- package/src/api/chart.ts +30 -113
- package/src/api/mark/index.ts +3 -0
- package/src/api/mark/mark.ts +12 -0
- package/src/api/utils.ts +79 -0
- package/src/component/axis.ts +22 -18
- package/src/component/axisX.ts +3 -1
- package/src/component/axisY.ts +2 -1
- package/src/component/constant.ts +6 -0
- package/src/component/legendCategory.ts +19 -6
- package/src/component/legendContinuous.ts +185 -74
- package/src/component/utils.ts +14 -3
- package/src/composition/mark.ts +2 -0
- package/src/data/index.ts +2 -0
- package/src/data/kde.ts +53 -0
- package/src/interaction/brushFilter.ts +8 -6
- package/src/interaction/brushHighlight.ts +258 -20
- package/src/interaction/brushXHighlight.ts +1 -0
- package/src/interaction/brushYHighlight.ts +1 -0
- package/src/interaction/event.ts +19 -13
- package/src/interaction/tooltip.ts +154 -25
- package/src/mark/density.ts +81 -0
- package/src/mark/gauge.ts +13 -7
- package/src/mark/index.ts +2 -0
- package/src/runtime/component.ts +210 -12
- package/src/runtime/layout.ts +74 -19
- package/src/runtime/plot.ts +8 -6
- package/src/runtime/scale.ts +2 -2
- package/src/runtime/transform.ts +2 -1
- package/src/runtime/types/component.ts +1 -0
- package/src/shape/area/area.ts +1 -1
- package/src/shape/area/curve.ts +1 -1
- package/src/shape/box/violin.ts +119 -0
- package/src/shape/connector/connector.ts +1 -1
- package/src/shape/density/density.ts +52 -0
- package/src/shape/index.ts +4 -0
- package/src/shape/line/curve.ts +1 -1
- package/src/shape/text/advance.ts +1 -1
- package/src/shape/text/badge.ts +1 -1
- package/src/shape/utils.ts +1 -1
- package/src/spec/composition.ts +22 -19
- package/src/spec/dataTransform.ts +35 -0
- package/src/spec/interaction.ts +3 -2
- package/src/spec/mark.ts +10 -6
- package/src/spec/transform.ts +1 -0
- package/src/spec/utils.ts +2 -0
- package/src/stdlib/index.ts +8 -0
- package/src/theme/classic.ts +3 -0
- package/src/theme/classicDark.ts +1 -0
- package/src/transform/filter.ts +6 -2
- package/src/{shape → utils}/createElement.ts +1 -1
- package/src/utils/helper.ts +12 -1
- package/src/utils/scale.ts +5 -1
- package/src/utils/size.ts +10 -4
- /package/esm/{shape → utils}/createElement.js +0 -0
- /package/lib/{shape → utils}/createElement.js +0 -0
package/src/component/axis.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Coordinate } from '@antv/coord';
|
|
|
2
2
|
import type { DisplayObject } from '@antv/g';
|
|
3
3
|
import { Axis as AxisComponent } from '@antv/gui';
|
|
4
4
|
import { Linear as LinearScale } from '@antv/scale';
|
|
5
|
-
import { deepMix } from '@antv/util';
|
|
5
|
+
import { deepMix, has } from '@antv/util';
|
|
6
6
|
import { extent } from 'd3-array';
|
|
7
7
|
import { format } from 'd3-format';
|
|
8
8
|
import {
|
|
@@ -193,34 +193,31 @@ function inferGridLength(position: GCP, coordinate: Coordinate) {
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
function inferLabelOverlap(transform = [], style: Record<string, any>) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
labelAutoEllipsis = false,
|
|
200
|
-
} = style;
|
|
196
|
+
if (transform.length > 0) return transform;
|
|
197
|
+
const { labelAutoRotate, labelAutoHide, labelAutoEllipsis, labelAutoWrap } =
|
|
198
|
+
style;
|
|
201
199
|
|
|
202
|
-
const finalTransforms = [
|
|
200
|
+
const finalTransforms = [];
|
|
203
201
|
|
|
204
|
-
const
|
|
202
|
+
const addToTransforms = (overlap, state) => {
|
|
205
203
|
if (state) {
|
|
206
|
-
|
|
207
|
-
if (index !== -1) finalTransforms[index] = overlap;
|
|
208
|
-
else finalTransforms.push(overlap);
|
|
209
|
-
} else {
|
|
210
|
-
const index = finalTransforms.findIndex((t) => t.type === overlap.type);
|
|
211
|
-
if (index !== -1) finalTransforms.splice(index, 1);
|
|
204
|
+
finalTransforms.push(overlap);
|
|
212
205
|
}
|
|
213
206
|
};
|
|
214
207
|
|
|
215
|
-
|
|
208
|
+
addToTransforms(
|
|
216
209
|
{
|
|
217
210
|
type: 'rotate',
|
|
218
211
|
optionalAngles: [0, 15, 30, 45, 60, 90],
|
|
219
212
|
},
|
|
220
213
|
labelAutoRotate,
|
|
221
214
|
);
|
|
222
|
-
|
|
223
|
-
|
|
215
|
+
addToTransforms({ type: 'ellipsis', minLength: 20 }, labelAutoEllipsis);
|
|
216
|
+
addToTransforms({ type: 'hide' }, labelAutoHide);
|
|
217
|
+
addToTransforms(
|
|
218
|
+
{ type: 'wrap', wordWrapWidth: 100, maxLines: 3, recoveryWhenFail: true },
|
|
219
|
+
labelAutoWrap,
|
|
220
|
+
);
|
|
224
221
|
return finalTransforms;
|
|
225
222
|
}
|
|
226
223
|
|
|
@@ -480,6 +477,7 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
|
|
|
480
477
|
tickFilter,
|
|
481
478
|
tickMethod,
|
|
482
479
|
transform,
|
|
480
|
+
indexBBox,
|
|
483
481
|
...userDefinitions
|
|
484
482
|
} = options;
|
|
485
483
|
|
|
@@ -503,7 +501,6 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
|
|
|
503
501
|
};
|
|
504
502
|
|
|
505
503
|
const gridLength = inferGridLength(position, coordinate);
|
|
506
|
-
|
|
507
504
|
const overrideStyle = inferAxisLinearOverrideStyle(
|
|
508
505
|
position,
|
|
509
506
|
orientation,
|
|
@@ -523,16 +520,23 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
|
|
|
523
520
|
position,
|
|
524
521
|
coordinate,
|
|
525
522
|
),
|
|
523
|
+
crossSize: size,
|
|
526
524
|
titleText: titleContent(title),
|
|
527
525
|
labelOverlap: inferLabelOverlap(transform, internalAxisStyle),
|
|
528
526
|
grid: inferGrid(internalAxisStyle.grid, coordinate, scale),
|
|
529
527
|
gridLength,
|
|
530
528
|
// Always showLine, make title could align the end of axis.
|
|
531
529
|
line: true,
|
|
530
|
+
indexBBox,
|
|
532
531
|
...(!internalAxisStyle.line ? { lineOpacity: 0 } : null),
|
|
533
532
|
...overrideStyle,
|
|
534
533
|
...important,
|
|
535
534
|
};
|
|
535
|
+
|
|
536
|
+
// For hide overlap, do not set crossSize.
|
|
537
|
+
const hasHide = finalAxisStyle.labelOverlap.find((d) => d.type === 'hide');
|
|
538
|
+
if (hasHide) finalAxisStyle.crossSize = false;
|
|
539
|
+
|
|
536
540
|
return new AxisComponent({
|
|
537
541
|
className: 'axis',
|
|
538
542
|
style: adaptor(finalAxisStyle),
|
package/src/component/axisX.ts
CHANGED
|
@@ -7,7 +7,9 @@ export type AxisXOptions = AxisOptions;
|
|
|
7
7
|
* LinearAxis component bind to x scale.
|
|
8
8
|
*/
|
|
9
9
|
export const AxisX: GCC<AxisXOptions> = (options) => {
|
|
10
|
-
return
|
|
10
|
+
return (...args) =>
|
|
11
|
+
// empirical value for crossPadding
|
|
12
|
+
LinearAxis(Object.assign({}, { crossPadding: 50 }, options))(...args);
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
AxisX.props = {
|
package/src/component/axisY.ts
CHANGED
|
@@ -7,7 +7,8 @@ export type AxisYOptions = AxisOptions;
|
|
|
7
7
|
* LinearAxis component bind to y scale.
|
|
8
8
|
*/
|
|
9
9
|
export const AxisY: GCC<AxisYOptions> = (options) => {
|
|
10
|
-
return
|
|
10
|
+
return (...args) =>
|
|
11
|
+
LinearAxis(Object.assign({}, { crossPadding: 10 }, options))(...args);
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
AxisY.props = {
|
|
@@ -198,6 +198,11 @@ export const LEGEND_INFER_STRATEGIES: InferStrategy[] = [
|
|
|
198
198
|
['color', 'constant'],
|
|
199
199
|
['size', 'continuous'],
|
|
200
200
|
],
|
|
201
|
+
[
|
|
202
|
+
['size', 'continuous'],
|
|
203
|
+
['opacity', 'continuous'],
|
|
204
|
+
],
|
|
205
|
+
[['size', 'continuous']],
|
|
201
206
|
],
|
|
202
207
|
],
|
|
203
208
|
[
|
|
@@ -232,6 +237,7 @@ export const LEGEND_INFER_STRATEGIES: InferStrategy[] = [
|
|
|
232
237
|
['opacity', 'continuous'],
|
|
233
238
|
],
|
|
234
239
|
[['color', 'continuous']],
|
|
240
|
+
[['opacity', 'continuous']],
|
|
235
241
|
],
|
|
236
242
|
],
|
|
237
243
|
];
|
|
@@ -19,7 +19,7 @@ import { useMarker } from '../utils/marker';
|
|
|
19
19
|
import {
|
|
20
20
|
adaptor,
|
|
21
21
|
domainOf,
|
|
22
|
-
|
|
22
|
+
LegendCategoryLayout,
|
|
23
23
|
inferComponentLayout,
|
|
24
24
|
inferComponentShape,
|
|
25
25
|
scaleOf,
|
|
@@ -124,9 +124,15 @@ function inferItemMarker(
|
|
|
124
124
|
}
|
|
125
125
|
if (typeof itemMarker === 'function') return itemMarker;
|
|
126
126
|
return (d, i) =>
|
|
127
|
-
createShape(
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
createShape(
|
|
128
|
+
itemMarker || `${namespace}.${shapes[i]}`,
|
|
129
|
+
library,
|
|
130
|
+
coordinate,
|
|
131
|
+
theme,
|
|
132
|
+
{
|
|
133
|
+
color: d.color,
|
|
134
|
+
},
|
|
135
|
+
);
|
|
130
136
|
}
|
|
131
137
|
|
|
132
138
|
function inferItemMarkerOpacity(scales: Scale[]) {
|
|
@@ -238,20 +244,27 @@ export const LegendCategory: GCC<LegendCategoryOptions> = (options) => {
|
|
|
238
244
|
};
|
|
239
245
|
|
|
240
246
|
const { legend: legendTheme = {} } = theme;
|
|
241
|
-
|
|
247
|
+
|
|
248
|
+
const categoryStyle = adaptor(
|
|
249
|
+
Object.assign({}, legendTheme, legendStyle, style),
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
const layoutWrapper = new LegendCategoryLayout({
|
|
242
253
|
style: {
|
|
243
254
|
x: bbox.x,
|
|
244
255
|
y: bbox.y,
|
|
245
256
|
width: bbox.width,
|
|
246
257
|
height: bbox.height,
|
|
247
258
|
...finalLayout,
|
|
259
|
+
// @ts-ignore
|
|
260
|
+
subOptions: categoryStyle,
|
|
248
261
|
},
|
|
249
262
|
});
|
|
250
263
|
|
|
251
264
|
layoutWrapper.appendChild(
|
|
252
265
|
new Category({
|
|
253
266
|
className: 'legend-category',
|
|
254
|
-
style:
|
|
267
|
+
style: categoryStyle,
|
|
255
268
|
}),
|
|
256
269
|
);
|
|
257
270
|
return layoutWrapper;
|
|
@@ -1,17 +1,22 @@
|
|
|
1
|
+
import { parseColor } from '@antv/g';
|
|
1
2
|
import { Continuous } from '@antv/gui';
|
|
2
3
|
import { Quantile, Quantize, Threshold } from '@antv/scale';
|
|
3
4
|
import { format } from 'd3-format';
|
|
4
5
|
import type {
|
|
5
6
|
FlexLayout,
|
|
7
|
+
G2Theme,
|
|
6
8
|
GuideComponentComponent as GCC,
|
|
9
|
+
GuideComponentOrientation as GCO,
|
|
7
10
|
GuideComponentPosition as GCP,
|
|
8
11
|
Scale,
|
|
9
12
|
} from '../runtime';
|
|
13
|
+
import { lastOf } from '../utils/array';
|
|
10
14
|
import {
|
|
11
|
-
adaptor,
|
|
12
15
|
G2Layout,
|
|
16
|
+
adaptor,
|
|
13
17
|
inferComponentLayout,
|
|
14
18
|
inferComponentShape,
|
|
19
|
+
isHorizontal,
|
|
15
20
|
scaleOf,
|
|
16
21
|
titleContent,
|
|
17
22
|
} from './utils';
|
|
@@ -23,68 +28,171 @@ export type LegendContinuousOptions = {
|
|
|
23
28
|
[key: string]: any;
|
|
24
29
|
};
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
type Shape = {
|
|
32
|
+
orientation: string;
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
length: number;
|
|
36
|
+
size: number;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type Config = {
|
|
40
|
+
orientation: string;
|
|
41
|
+
width: number;
|
|
42
|
+
height: number;
|
|
43
|
+
color: string[];
|
|
44
|
+
data: any[];
|
|
45
|
+
labelFilter?: (datum: any, index: number) => boolean;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
function calculateFinalSize(size: number, defaultSize: number): number {
|
|
49
|
+
return Math.min(size, defaultSize);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function updateShapeDimensions(
|
|
53
|
+
shape: Shape,
|
|
54
|
+
finalSize: number,
|
|
55
|
+
orientation: Exclude<GCO, number>,
|
|
56
|
+
): Shape {
|
|
57
|
+
shape.size = finalSize;
|
|
58
|
+
if (isHorizontal(orientation)) {
|
|
59
|
+
shape.height = finalSize;
|
|
60
|
+
} else {
|
|
61
|
+
shape.width = finalSize;
|
|
62
|
+
}
|
|
63
|
+
return shape;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function inferContinuousShape(
|
|
28
67
|
value: Record<string, any>,
|
|
29
68
|
options: LegendContinuousOptions,
|
|
30
69
|
component: GCC,
|
|
31
|
-
) {
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
options,
|
|
38
|
-
component,
|
|
70
|
+
): Shape {
|
|
71
|
+
const { size } = options;
|
|
72
|
+
const shape = inferComponentShape(value, options, component);
|
|
73
|
+
const finalSize = calculateFinalSize(
|
|
74
|
+
size,
|
|
75
|
+
LegendContinuous.props.defaultLegendSize,
|
|
39
76
|
);
|
|
77
|
+
return updateShapeDimensions(shape, finalSize, shape.orientation);
|
|
78
|
+
}
|
|
40
79
|
|
|
41
|
-
|
|
80
|
+
function getFormatter(max: number) {
|
|
81
|
+
return (value: number) => ({
|
|
82
|
+
value: value / max,
|
|
83
|
+
label: String(value),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
42
86
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
value: index,
|
|
59
|
-
label: value,
|
|
60
|
-
}));
|
|
61
|
-
return {
|
|
62
|
-
data,
|
|
63
|
-
...shape,
|
|
64
|
-
color: range,
|
|
65
|
-
labelFilter: (datum, index) => {
|
|
66
|
-
return index > 0 && index < data.length - 1;
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
}
|
|
87
|
+
function getQuantizeOrQuantileConfig(
|
|
88
|
+
shape: Shape,
|
|
89
|
+
colorScale: Threshold,
|
|
90
|
+
min: number,
|
|
91
|
+
max: number,
|
|
92
|
+
range: string[],
|
|
93
|
+
): Config {
|
|
94
|
+
const thresholds = (colorScale as any).thresholds as number[];
|
|
95
|
+
const formatter = getFormatter(max);
|
|
96
|
+
return {
|
|
97
|
+
...shape,
|
|
98
|
+
color: range,
|
|
99
|
+
data: [min, ...thresholds, max].map(formatter),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
70
102
|
|
|
71
|
-
|
|
72
|
-
|
|
103
|
+
function getThresholdConfig(
|
|
104
|
+
shape: Shape,
|
|
105
|
+
colorScale: Threshold,
|
|
106
|
+
range: string[],
|
|
107
|
+
): Config {
|
|
108
|
+
const thresholds = (colorScale as any).thresholds as number[];
|
|
109
|
+
const data = [-Infinity, ...thresholds, Infinity].map((value, index) => ({
|
|
110
|
+
value: index,
|
|
111
|
+
label: value,
|
|
112
|
+
}));
|
|
73
113
|
return {
|
|
74
114
|
...shape,
|
|
75
|
-
data
|
|
115
|
+
data,
|
|
116
|
+
color: range,
|
|
117
|
+
labelFilter: (datum, index) => {
|
|
118
|
+
return index > 0 && index < data.length - 1;
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function rangeOf(scale: Scale) {
|
|
124
|
+
const { domain } = scale.getOptions();
|
|
125
|
+
const [min, max] = [domain[0], lastOf(domain)];
|
|
126
|
+
return [min, max];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* if color scale is not defined, create a constant color scale based on default color
|
|
131
|
+
* @param scale
|
|
132
|
+
* @param theme
|
|
133
|
+
*/
|
|
134
|
+
function createColorScale(scale: Scale, theme: G2Theme): Scale {
|
|
135
|
+
const { defaultColor } = theme;
|
|
136
|
+
const options = scale.getOptions();
|
|
137
|
+
const newScale = scale.clone();
|
|
138
|
+
newScale.update({ ...options, range: [parseColor(defaultColor).toString()] });
|
|
139
|
+
return newScale;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function getLinearConfig(
|
|
143
|
+
shape: Shape,
|
|
144
|
+
colorScale: Scale,
|
|
145
|
+
sizeScale: Scale,
|
|
146
|
+
opacityScale: Scale,
|
|
147
|
+
theme: G2Theme,
|
|
148
|
+
): Config {
|
|
149
|
+
const { length } = shape;
|
|
150
|
+
const scale =
|
|
151
|
+
colorScale || createColorScale(sizeScale || opacityScale, theme);
|
|
152
|
+
const [min, max] = rangeOf(scale);
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
...shape,
|
|
156
|
+
data: scale.getTicks().map((value) => ({ value })),
|
|
76
157
|
color: new Array(length).fill(0).map((d, i) => {
|
|
77
158
|
const value = ((max - min) / (length - 1)) * i + min;
|
|
78
|
-
const color =
|
|
159
|
+
const color = scale.map(value);
|
|
79
160
|
const opacity = opacityScale ? opacityScale.map(value) : 1;
|
|
80
161
|
return color.replace(
|
|
81
|
-
/rgb[a]*\(([\d]{1,3})
|
|
162
|
+
/rgb[a]*\(([\d]{1,3}) *, *([\d]{1,3}) *, *([\d]{1,3})[\S\s]*\)/,
|
|
82
163
|
(match, p1, p2, p3) => `rgba(${p1}, ${p2}, ${p3}, ${opacity})`,
|
|
83
164
|
);
|
|
84
165
|
}),
|
|
85
166
|
};
|
|
86
167
|
}
|
|
87
168
|
|
|
169
|
+
function inferContinuousConfig(
|
|
170
|
+
scales: Scale[],
|
|
171
|
+
value: Record<string, any>,
|
|
172
|
+
options: LegendContinuousOptions,
|
|
173
|
+
component: GCC,
|
|
174
|
+
theme: G2Theme,
|
|
175
|
+
): Config {
|
|
176
|
+
const colorScale = scaleOf(scales, 'color');
|
|
177
|
+
const shape = inferContinuousShape(value, options, component);
|
|
178
|
+
|
|
179
|
+
if (colorScale instanceof Threshold) {
|
|
180
|
+
const { range } = colorScale.getOptions();
|
|
181
|
+
const [min, max] = rangeOf(colorScale);
|
|
182
|
+
// for quantize, quantile scale
|
|
183
|
+
if (colorScale instanceof Quantize || colorScale instanceof Quantile) {
|
|
184
|
+
return getQuantizeOrQuantileConfig(shape, colorScale, min, max, range);
|
|
185
|
+
}
|
|
186
|
+
// for threshold
|
|
187
|
+
return getThresholdConfig(shape, colorScale, range);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// for linear, pow, sqrt, log, time, utc scale
|
|
191
|
+
const sizeScale = scaleOf(scales, 'size');
|
|
192
|
+
const opacityScale = scaleOf(scales, 'opacity');
|
|
193
|
+
return getLinearConfig(shape, colorScale, sizeScale, opacityScale, theme);
|
|
194
|
+
}
|
|
195
|
+
|
|
88
196
|
/**
|
|
89
197
|
* Guide Component for continuous color scale.
|
|
90
198
|
* @todo Custom style.
|
|
@@ -101,14 +209,40 @@ export const LegendContinuous: GCC<LegendContinuousOptions> = (options) => {
|
|
|
101
209
|
style,
|
|
102
210
|
...rest
|
|
103
211
|
} = options;
|
|
212
|
+
|
|
104
213
|
return ({ scales, value, theme }) => {
|
|
105
214
|
const { bbox } = value;
|
|
106
215
|
const { x, y, width, height } = bbox;
|
|
216
|
+
const finalLayout = inferComponentLayout(position, layout);
|
|
107
217
|
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
218
|
+
const { continuousLegend: legendTheme = {} } = theme;
|
|
219
|
+
const finalStyle = adaptor(
|
|
220
|
+
Object.assign(
|
|
221
|
+
{},
|
|
222
|
+
legendTheme,
|
|
223
|
+
{
|
|
224
|
+
titleText: titleContent(title),
|
|
225
|
+
titleFontSize: 12,
|
|
226
|
+
handle: false,
|
|
227
|
+
indicator: false,
|
|
228
|
+
labelAlign: 'value',
|
|
229
|
+
labelFormatter:
|
|
230
|
+
typeof labelFormatter === 'string'
|
|
231
|
+
? (d) => format(labelFormatter)(d.label)
|
|
232
|
+
: labelFormatter,
|
|
233
|
+
...inferContinuousConfig(
|
|
234
|
+
scales,
|
|
235
|
+
value,
|
|
236
|
+
options,
|
|
237
|
+
LegendContinuous,
|
|
238
|
+
theme,
|
|
239
|
+
),
|
|
240
|
+
...style,
|
|
241
|
+
},
|
|
242
|
+
rest,
|
|
243
|
+
),
|
|
111
244
|
);
|
|
245
|
+
|
|
112
246
|
const layoutWrapper = new G2Layout({
|
|
113
247
|
style: {
|
|
114
248
|
x,
|
|
@@ -116,38 +250,14 @@ export const LegendContinuous: GCC<LegendContinuousOptions> = (options) => {
|
|
|
116
250
|
width,
|
|
117
251
|
height,
|
|
118
252
|
...finalLayout,
|
|
253
|
+
// @ts-ignore
|
|
254
|
+
subOptions: finalStyle,
|
|
119
255
|
},
|
|
120
256
|
});
|
|
121
257
|
|
|
122
|
-
const { continuousLegend: legendTheme = {} } = theme;
|
|
123
|
-
|
|
124
258
|
layoutWrapper.appendChild(
|
|
125
259
|
new Continuous({
|
|
126
|
-
style:
|
|
127
|
-
Object.assign(
|
|
128
|
-
{},
|
|
129
|
-
legendTheme,
|
|
130
|
-
{
|
|
131
|
-
titleText: titleContent(title),
|
|
132
|
-
titleFontSize: 12,
|
|
133
|
-
handle: false,
|
|
134
|
-
indicator: false,
|
|
135
|
-
labelAlign: 'value',
|
|
136
|
-
labelFormatter:
|
|
137
|
-
typeof labelFormatter === 'string'
|
|
138
|
-
? (d) => format(labelFormatter)(d.label)
|
|
139
|
-
: labelFormatter,
|
|
140
|
-
...inferContinuousConfig(
|
|
141
|
-
scales,
|
|
142
|
-
value,
|
|
143
|
-
options,
|
|
144
|
-
LegendContinuous,
|
|
145
|
-
),
|
|
146
|
-
...style,
|
|
147
|
-
},
|
|
148
|
-
rest,
|
|
149
|
-
),
|
|
150
|
-
),
|
|
260
|
+
style: finalStyle,
|
|
151
261
|
}),
|
|
152
262
|
);
|
|
153
263
|
|
|
@@ -161,4 +271,5 @@ LegendContinuous.props = {
|
|
|
161
271
|
defaultOrder: 1,
|
|
162
272
|
defaultSize: 60,
|
|
163
273
|
defaultLength: 300,
|
|
274
|
+
defaultLegendSize: 60,
|
|
164
275
|
};
|
package/src/component/utils.ts
CHANGED
|
@@ -83,10 +83,21 @@ export function inferComponentLayout(
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
export class G2Layout extends Layout {
|
|
86
|
+
get child() {
|
|
87
|
+
return this.children?.[0] as any;
|
|
88
|
+
}
|
|
89
|
+
|
|
86
90
|
update(options: any) {
|
|
87
91
|
this.attr(options);
|
|
88
|
-
const {
|
|
89
|
-
|
|
92
|
+
const { subOptions } = options;
|
|
93
|
+
this.child?.update(subOptions);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export class LegendCategoryLayout extends G2Layout {
|
|
98
|
+
update(options: any) {
|
|
99
|
+
const { subOptions } = options;
|
|
100
|
+
this.child?.update(subOptions);
|
|
90
101
|
}
|
|
91
102
|
}
|
|
92
103
|
|
|
@@ -122,7 +133,7 @@ export function inferComponentShape(
|
|
|
122
133
|
const length = userDefinedLength || defaultLength || bboxLength;
|
|
123
134
|
const orientation = isHorizontal ? 'horizontal' : 'vertical';
|
|
124
135
|
const [width, height] = isHorizontal ? [length, size] : [size, length];
|
|
125
|
-
return { orientation, width, height, size, length };
|
|
136
|
+
return { orientation, width, height, size, length } as const;
|
|
126
137
|
}
|
|
127
138
|
|
|
128
139
|
export function domainOf(scales: Scale[]): any[] {
|
package/src/composition/mark.ts
CHANGED
|
@@ -37,6 +37,7 @@ export const Mark: CC<MarkOptions> = () => {
|
|
|
37
37
|
labelTransform,
|
|
38
38
|
parentKey,
|
|
39
39
|
clip,
|
|
40
|
+
viewStyle,
|
|
40
41
|
...mark
|
|
41
42
|
} = options;
|
|
42
43
|
|
|
@@ -72,6 +73,7 @@ export const Mark: CC<MarkOptions> = () => {
|
|
|
72
73
|
marginRight,
|
|
73
74
|
parentKey,
|
|
74
75
|
clip,
|
|
76
|
+
style: viewStyle,
|
|
75
77
|
marks: [{ ...mark, key: `${key}-0`, data }],
|
|
76
78
|
},
|
|
77
79
|
];
|
package/src/data/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ export { Arc } from './arc';
|
|
|
15
15
|
export { WordCloud } from './wordCloud';
|
|
16
16
|
export { Join } from './join';
|
|
17
17
|
export { Slice } from './slice';
|
|
18
|
+
export { KDE } from './kde';
|
|
18
19
|
|
|
19
20
|
export type { FetchOptions } from './fetch';
|
|
20
21
|
export type { FoldOptions } from './fold';
|
|
@@ -33,3 +34,4 @@ export type { ArcOptions } from './arc';
|
|
|
33
34
|
export type { WordCloudOptions } from './wordCloud';
|
|
34
35
|
export type { JoinOptions } from './join';
|
|
35
36
|
export type { SliceOptions } from './slice';
|
|
37
|
+
export type { KDEOptions } from './kde';
|
package/src/data/kde.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import pdf from 'pdfast';
|
|
2
|
+
import { group } from 'd3-array';
|
|
3
|
+
import { DataComponent as DC } from '../runtime';
|
|
4
|
+
import { KDEDataTransform } from '../spec';
|
|
5
|
+
|
|
6
|
+
export type KDEOptions = Omit<KDEDataTransform, 'type'>;
|
|
7
|
+
|
|
8
|
+
export function defined(d: any): boolean {
|
|
9
|
+
return d !== undefined && d !== null && !Number.isNaN(d);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Kernel Density Estimation base on [pdfast](https://www.npmjs.com/package/pdfast),
|
|
14
|
+
* generating probability density function (pdf) using triangular kernel,
|
|
15
|
+
* optimized to run in O(N + K).
|
|
16
|
+
*/
|
|
17
|
+
export const KDE: DC<KDEOptions> = (options) => {
|
|
18
|
+
const {
|
|
19
|
+
field,
|
|
20
|
+
groupBy,
|
|
21
|
+
as = ['y', 'size'],
|
|
22
|
+
min,
|
|
23
|
+
max,
|
|
24
|
+
size = 10,
|
|
25
|
+
width,
|
|
26
|
+
} = options;
|
|
27
|
+
const [yField, sizeField] = as;
|
|
28
|
+
return (data) => {
|
|
29
|
+
const gs = Array.from(
|
|
30
|
+
group(data, (d) => groupBy.map((gb) => d[gb]).join('-')).values(),
|
|
31
|
+
);
|
|
32
|
+
return gs.map((g) => {
|
|
33
|
+
const pdfResult = pdf.create(
|
|
34
|
+
g.map((i) => i[field]),
|
|
35
|
+
{
|
|
36
|
+
min,
|
|
37
|
+
max,
|
|
38
|
+
size,
|
|
39
|
+
width,
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
const _y = pdfResult.map((result) => result.x);
|
|
43
|
+
const _size = pdfResult.map((result) => result.y);
|
|
44
|
+
return {
|
|
45
|
+
...(g[0] as Record<string, unknown>),
|
|
46
|
+
[yField]: _y,
|
|
47
|
+
[sizeField]: _size,
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
KDE.props = {};
|
|
@@ -131,9 +131,10 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
|
|
|
131
131
|
);
|
|
132
132
|
|
|
133
133
|
// Emit event.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
emitter.emit('brush:filter', {
|
|
135
|
+
...event,
|
|
136
|
+
data: { selection: [domainX, domainY] },
|
|
137
|
+
});
|
|
137
138
|
|
|
138
139
|
// Rerender and update view.
|
|
139
140
|
const newOptions = {
|
|
@@ -154,9 +155,10 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
|
|
|
154
155
|
const { x: scaleX, y: scaleY } = scale;
|
|
155
156
|
const domainX = scaleX.getOptions().domain;
|
|
156
157
|
const domainY = scaleY.getOptions().domain;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
emitter.emit('brush:filter', {
|
|
159
|
+
...event,
|
|
160
|
+
data: { selection: [domainX, domainY] },
|
|
161
|
+
});
|
|
160
162
|
|
|
161
163
|
filtered = false;
|
|
162
164
|
newView = view;
|