@antv/g2 5.1.6-beta.1 → 5.1.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/g2",
3
- "version": "5.1.6-beta.1",
3
+ "version": "5.1.6",
4
4
  "description": "the Grammar of Graphics in Javascript",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -44,7 +44,7 @@
44
44
  "prepare": "husky install",
45
45
  "upload": "node scripts/upload/snapshot.js",
46
46
  "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
47
- "translate": "translate -d site/docs/api"
47
+ "translate": "translate -d"
48
48
  },
49
49
  "keywords": [
50
50
  "antv",
package/src/api/utils.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { isNumber } from '@antv/util';
1
2
  import { G2ViewTree } from '../runtime';
2
3
  import { getContainerSize } from '../utils/size';
3
4
  import { deepAssign } from '../utils/helper';
@@ -33,6 +34,11 @@ export const REMOVE_FLAG = '__remove__';
33
34
 
34
35
  export const CALLBACK_NODE = '__callback__';
35
36
 
37
+ /** Minimum chart width */
38
+ export const MIN_CHART_WIDTH = 1;
39
+ /** Minimum chart height */
40
+ export const MIN_CHART_HEIGHT = 1;
41
+
36
42
  export function normalizeContainer(
37
43
  container: string | HTMLElement,
38
44
  ): HTMLElement {
@@ -70,12 +76,28 @@ export function valueOf(node: Node): Record<string, any> {
70
76
  }
71
77
 
72
78
  export function sizeOf(options, container) {
73
- const { autoFit } = options;
74
- const { width = 640, height = 480 } = autoFit
75
- ? getContainerSize(container)
76
- : options;
77
- const { depth = 0 } = options;
78
- return { width, height, depth };
79
+ const { width = 640, height = 480, autoFit, depth = 0 } = options;
80
+ let effectiveWidth = width;
81
+ let effectiveHeight = height;
82
+
83
+ if (autoFit) {
84
+ const { width: containerWidth, height: containerHeight } =
85
+ getContainerSize(container);
86
+ effectiveWidth = containerWidth || effectiveWidth;
87
+ effectiveHeight = containerHeight || effectiveHeight;
88
+ }
89
+
90
+ return {
91
+ width: Math.max(
92
+ isNumber(effectiveWidth) ? effectiveWidth : MIN_CHART_WIDTH,
93
+ MIN_CHART_WIDTH,
94
+ ),
95
+ height: Math.max(
96
+ isNumber(effectiveHeight) ? effectiveHeight : MIN_CHART_HEIGHT,
97
+ MIN_CHART_HEIGHT,
98
+ ),
99
+ depth,
100
+ };
79
101
  }
80
102
 
81
103
  export function optionsOf(node: Node): Record<string, any> {
@@ -82,11 +82,7 @@ export function createColorKey(view) {
82
82
  }
83
83
 
84
84
  export function createXKey(view) {
85
- const { x: scaleX } = view.scale;
86
- return (element) => {
87
- const { x } = element.__data__;
88
- return scaleX.invert(x);
89
- };
85
+ return (element) => element.__data__.x;
90
86
  }
91
87
 
92
88
  export function createDatumof(view: G2ViewDescriptor | G2ViewDescriptor[]) {
@@ -710,7 +710,13 @@ function computeAxisSize(
710
710
 
711
711
  // Get styles to be applied.
712
712
  const style = styleOf(component, position, theme);
713
- const { tickLength = 0, labelSpacing = 0, titleSpacing = 0, ...rest } = style;
713
+ const {
714
+ tickLength = 0,
715
+ labelSpacing = 0,
716
+ titleSpacing = 0,
717
+ labelAutoRotate,
718
+ ...rest
719
+ } = style;
714
720
 
715
721
  // Compute Labels.
716
722
  const scale = createScale(component, library);
@@ -727,7 +733,9 @@ function computeAxisSize(
727
733
  // rotate 90 deg to display them.
728
734
  if (
729
735
  overflowX(scale, labelBBoxes, crossSize, crossPadding, tickFilter) &&
730
- !labelTransform
736
+ !labelTransform &&
737
+ labelAutoRotate !== false &&
738
+ labelAutoRotate !== null
731
739
  ) {
732
740
  component.labelTransform = 'rotate(90)';
733
741
  component.size = maxLabelWidth + paddingTick;
@@ -311,7 +311,6 @@ function computePadding(
311
311
 
312
312
  for (const position of positions) {
313
313
  const key = `padding${capitalizeFirst(camelCase(position))}`;
314
- const insetKey = `inset${capitalizeFirst(camelCase(position))}`;
315
314
  const components = positionComponents.get(position) || [];
316
315
  const value = layout[key];
317
316
  const defaultSizeOf = (d) => {
@@ -342,6 +341,11 @@ function computePadding(
342
341
  }
343
342
  };
344
343
 
344
+ const maybeHide = (d) => {
345
+ if (!d.type.startsWith('axis')) return;
346
+ if (d.labelAutoHide === undefined) d.labelAutoHide = true;
347
+ };
348
+
345
349
  const isHorizontal = position === 'bottom' || position === 'top';
346
350
 
347
351
  // !!!Note
@@ -356,6 +360,7 @@ function computePadding(
356
360
  // Specified padding.
357
361
  if (typeof value === 'number') {
358
362
  components.forEach(defaultSizeOf);
363
+ components.forEach(maybeHide);
359
364
  } else {
360
365
  // Compute padding dynamically.
361
366
  if (components.length === 0) {
@@ -236,7 +236,6 @@ export function create({
236
236
  labelDirection: 'negative',
237
237
  tickDirection: 'negative',
238
238
  titlePosition: 'top',
239
- labelAutoRotate: false,
240
239
  titleSpacing: 12,
241
240
  labelSpacing: 4,
242
241
  titleTextBaseline: 'middle',
@@ -244,7 +243,6 @@ export function create({
244
243
  axisBottom: {
245
244
  gridDirection: 'negative',
246
245
  labelDirection: 'positive',
247
- labelAutoRotate: false,
248
246
  tickDirection: 'positive',
249
247
  titlePosition: 'bottom',
250
248
  titleSpacing: 12,
@@ -253,7 +251,6 @@ export function create({
253
251
  },
254
252
  axisLeft: {
255
253
  gridDirection: 'positive',
256
- labelAutoRotate: false,
257
254
  labelDirection: 'negative',
258
255
  labelSpacing: 4,
259
256
  tickDirection: 'negative',
@@ -269,7 +266,6 @@ export function create({
269
266
  labelSpacing: 4,
270
267
  tickDirection: 'positive',
271
268
  titlePosition: 'right',
272
- labelAutoRotate: false,
273
269
  titleSpacing: 12,
274
270
  titleTextBaseline: 'top',
275
271
  titleDirection: 'vertical',