diff --git a/__tests__/integration/snapshots/static/flareTreemapCustom.svg b/__tests__/integration/snapshots/static/flareTreemapCustom.svg index cb0432c159..5bd29ffd4c 100644 --- a/__tests__/integration/snapshots/static/flareTreemapCustom.svg +++ b/__tests__/integration/snapshots/static/flareTreemapCustom.svg @@ -10353,10 +10353,10 @@ @@ -10374,7 +10374,7 @@ font-weight="normal" text-anchor="left" > - w + wh @@ -10505,10 +10505,10 @@ @@ -10526,7 +10526,7 @@ font-weight="normal" text-anchor="left" > - m + ma @@ -10999,10 +10999,10 @@ @@ -11020,7 +11020,7 @@ font-weight="normal" text-anchor="left" > - M + Me diff --git a/__tests__/integration/snapshots/static/salesIntervalLabelOverlapHide.svg b/__tests__/integration/snapshots/static/salesIntervalLabelOverlapHide.svg new file mode 100644 index 0000000000..cd37a5c91f --- /dev/null +++ b/__tests__/integration/snapshots/static/salesIntervalLabelOverlapHide.svg @@ -0,0 +1,1554 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1951 年 + + + + + + + 1952 年 + + + + + + + 1956 年 + + + + + + + 1957 年 + + + + + + + 1958 年 + + + + + + + 1959 年 + + + + + + + 1960 年 + + + + + + + 1962 年 + + + + + + + + + year + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + 20000 + + + + + + + 40000 + + + + + + + 60000 + + + + + + + 80000 + + + + + + + 100000 + + + + + + + 120000 + + + + + + + 140000 + + + + + + + + + sales + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1233 + + + + + + + + + + + + + 53332 + + + + + + + + + + + + + 63331 + + + + + + + + + + + + + 143335 + + + + + + + + + + + + + 43338 + + + + + + + + + + + + + 33338 + + + + + + + + + + + + + 33338 + + + + + + + + + + + + + 33338 + + + + + + + + + + + + \ No newline at end of file diff --git a/__tests__/integration/spec-animation.spec.ts b/__tests__/integration/spec-animation.spec.ts index 3fafa5f4b9..2f4fcb4081 100644 --- a/__tests__/integration/spec-animation.spec.ts +++ b/__tests__/integration/spec-animation.spec.ts @@ -1,6 +1,5 @@ import EventEmitter from '@antv/event-emitter'; import { Canvas } from '@antv/g'; -// import { deepMix } from '@antv/util'; import { G2Context } from '../../src'; import * as chartTests from '../plots/animation'; import { filterTests } from './utils/filterTests'; diff --git a/__tests__/plots/api/chart-3d.ts b/__tests__/plots/api/chart-3d.ts index 6477becc2f..df29d4c367 100644 --- a/__tests__/plots/api/chart-3d.ts +++ b/__tests__/plots/api/chart-3d.ts @@ -56,6 +56,7 @@ export function chart3d(context) { direction: [-1, 0, 1], }, }); + // @ts-ignore canvas!.appendChild(light); }); diff --git a/__tests__/plots/static/index.ts b/__tests__/plots/static/index.ts index 4389c40295..d3824a6384 100644 --- a/__tests__/plots/static/index.ts +++ b/__tests__/plots/static/index.ts @@ -116,6 +116,7 @@ export { salaryHeatmapScaleLinear } from './salary-heatmap-scale-linear'; export { salaryHeatmapScaleThreshold } from './salary-heatmap-scale-threshold'; export { salaryHeatmapScaleQuantize } from './salary-heatmap-scale-quantize'; export { salaryHeatmapScaleQuantile } from './salary-heatmap-scale-quantile'; +export { salesIntervalLabelOverlapHide } from './sales-interval-label-overlap-hide'; export { monthIntervalFacetCircle } from './month-interval-facet-circle'; export { titanicPointPack } from './titanic-point-pack'; export { titanicPointPackSharedData } from './titanic-point-pack-shared-data'; diff --git a/__tests__/plots/static/sales-interval-label-overlap-hide.ts b/__tests__/plots/static/sales-interval-label-overlap-hide.ts new file mode 100644 index 0000000000..dd2709d564 --- /dev/null +++ b/__tests__/plots/static/sales-interval-label-overlap-hide.ts @@ -0,0 +1,27 @@ +import { G2Spec } from '../../../src'; + +export function salesIntervalLabelOverlapHide(): G2Spec { + return { + type: 'interval', + data: [ + { year: '1951 年', sales: 1233 }, + { year: '1952 年', sales: 53332 }, + { year: '1956 年', sales: 63331 }, + { year: '1957 年', sales: 143335 }, + { year: '1958 年', sales: 43338 }, + { year: '1959 年', sales: 33338 }, + { year: '1960 年', sales: 33338 }, + { year: '1962 年', sales: 33338 }, + ], + encode: { + x: 'year', + y: 'sales', + }, + labels: [ + { + text: 'sales', + transform: [{ type: 'overflowHide' }], + }, + ], + }; +} diff --git a/package.json b/package.json index 030cfb9e72..b769ab7fe4 100644 --- a/package.json +++ b/package.json @@ -140,17 +140,17 @@ "limit-size": [ { "path": "dist/g2.min.js", - "limit": "290 Kb", + "limit": "300 Kb", "gzip": true }, { "path": "dist/g2.min.js", - "limit": "970 Kb", + "limit": "1000 Kb", "gzip": false }, { "path": "dist/g2.lite.min.js", - "limit": "260 Kb", + "limit": "270 Kb", "gzip": true } ], diff --git a/src/utils/bounds.ts b/src/utils/bounds.ts index 54de72d4d2..8d5e1ba399 100644 --- a/src/utils/bounds.ts +++ b/src/utils/bounds.ts @@ -5,6 +5,9 @@ type Min = Vector2; type Max = Vector2; export type Bounds = [Min, Max]; +// There is a certain error in the calculation of text bounds. +const EPSILON = 1e-2; + export function parseAABB(min2: AABB): Bounds { const { min, max } = min2; return [ @@ -17,21 +20,36 @@ export function parseAABB(min2: AABB): Bounds { * Whether the `point` in `bounds`. * @param point * @param bounds + * @param threshold */ -export function isInBounds(point: Vector2, bounds: Bounds): boolean { +export function isInBounds( + point: Vector2, + bounds: Bounds, + threshold = EPSILON, +): boolean { const [x, y] = point; const [min, max] = bounds; - return x >= min[0] && x <= max[0] && y >= min[1] && y <= max[1]; + return ( + x >= min[0] - threshold && + x <= max[0] + threshold && + y >= min[1] - threshold && + y <= max[1] + threshold + ); } /** * Whether `b1` is overflow from `b2`. * @param b1 * @param b2 + * @param threshold The threshold to determine whether the bounds is overflowed, default is 0. */ -export function isOverflow(b1: Bounds, b2: Bounds): boolean { +export function isOverflow( + b1: Bounds, + b2: Bounds, + threshold = EPSILON, +): boolean { const [min, max] = b1; - return !(isInBounds(min, b2) && isInBounds(max, b2)); + return !(isInBounds(min, b2, threshold) && isInBounds(max, b2, threshold)); } /**