Skip to content

Commit

Permalink
fix(layout): auto inset ignore null bbox
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Jun 25, 2023
1 parent 3eb6b61 commit e3f436c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 10 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions __tests__/plots/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,4 @@ export { weatherLineMultiAxesLegend } from './weather-line-multi-axes-legend';
export { population2015IntervalDonutTextAnnotationInset } from './population2015-interval-donut-text-annotation-inset';
export { stocksLineSeriesGradient } from './stocks-line-series-gradient';
export { aaplLineMissingDataTrial } from './aapl-line-missing-data-trial';
export { mockIntervalFacetRectPolar } from './mock-interval-facet-rect-polar';
30 changes: 30 additions & 0 deletions __tests__/plots/static/mock-interval-facet-rect-polar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { G2Spec } from '../../../src';

export function mockIntervalFacetRectPolar(): G2Spec {
return {
type: 'facetRect',
height: 320,
data: [
{ type: 'A', value: 1, n: 64 },
{ type: 'A', value: 2, n: 37 },
{ type: 'A', value: 3, n: 29 },
{ type: 'B', value: 1, n: 58 },
{ type: 'B', value: 2, n: 38 },
{ type: 'B', value: 3, n: 25 },
],
encode: { x: 'type' },
children: [
{
type: 'interval',
frame: false,
coordinate: { type: 'polar' },
encode: {
x: 'value',
y: 'n',
color: 'value',
},
axis: { y: { label: false, title: false }, x: { title: false } },
},
],
};
}
2 changes: 1 addition & 1 deletion src/composition/facetRect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ function createGuideYRect(guide) {

function createGuide(guide, factory) {
if (typeof guide === 'function') return guide;
if (guide === null) return () => null;
if (guide === null || guide === false) return () => null;
return factory(guide);
}

Expand Down
4 changes: 2 additions & 2 deletions src/runtime/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { Coordinate } from '@antv/coord';
import { deepMix, isEqual } from '@antv/util';
import { group, groups, max, sum } from 'd3-array';
import { groups, max, sum } from 'd3-array';
import { format } from 'd3-format';
import { DisplayObject, Text } from '@antv/g';
import {
Expand All @@ -28,7 +28,7 @@ import {
isTranspose,
} from './coordinate';
import { useLibrary } from './library';
import { isValidScale, useRelationScale } from './scale';
import { isValidScale } from './scale';
import {
G2MarkState,
G2Theme,
Expand Down
17 changes: 10 additions & 7 deletions src/runtime/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Coordinate } from '@antv/coord';
import { ascending, group, max, sum } from 'd3-array';
import { deepMix } from '@antv/util';
import { isParallel, isPolar, isRadar, radiusOf } from '../utils/coordinate';
import { capitalizeFirst } from '../utils/helper';
import { capitalizeFirst, defined } from '../utils/helper';
import { divide } from '../utils/array';
import { camelCase } from '../utils/string';
import {
Expand Down Expand Up @@ -199,12 +199,15 @@ function computeInset(
const maxLabelSpacing = max(styles, (d) => d.labelSpacing ?? 0);

// Compute labelBBoxes.
const labelBBoxes = axes.flatMap((component, i) => {
const style = styles[i];
const scale = createScale(component, library);
const labels = computeLabelsBBox(component, scale, false, style);
return labels;
});
const labelBBoxes = axes
.flatMap((component, i) => {
const style = styles[i];
const scale = createScale(component, library);
const labels = computeLabelsBBox(component, scale, false, style);
return labels;
})
.filter(defined);

const size = max(labelBBoxes, (d) => d.height) + maxLabelSpacing;

// Compute titles.
Expand Down

0 comments on commit e3f436c

Please sign in to comment.