Skip to content

Commit 884fd8d

Browse files
authored
fix: 图例通过 margin 配置来对齐 (#1132)
1 parent 4ca832a commit 884fd8d

File tree

6 files changed

+23
-11
lines changed

6 files changed

+23
-11
lines changed

src/base/controller/padding.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ export default class PaddingController {
125125
}
126126
});
127127
}
128-
this.plot.config.theme.legend.margin = bleeding;
129128
this.bleeding = clone(bleeding);
130129
// 参与auto padding的components: axis legend label annotation
131130
const components_bbox = [new BBox(viewRange.minX, viewRange.minY, viewRange.width, viewRange.height)];

src/base/view-layer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,12 @@ export default abstract class ViewLayer<T extends ViewLayerConfig = ViewLayerCon
803803

804804
protected isLimitInPlot() {
805805
const yAxisOptions = this.options.yAxis as IValueAxis;
806-
if (hasKey(yAxisOptions, 'max') || hasKey(yAxisOptions, 'min')) {
806+
if (
807+
hasKey(yAxisOptions, 'max') ||
808+
hasKey(yAxisOptions, 'min') ||
809+
hasKey(yAxisOptions, 'maxLimit') ||
810+
hasKey(yAxisOptions, 'minLimit')
811+
) {
807812
return true;
808813
}
809814
return false;

src/interaction/scrollbar.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,14 @@ export default class ScrollbarInteraction extends BaseInteraction {
8585
view.on('afterrender', () => {
8686
const padding = this.view.padding;
8787
// if we're not in `auto padding` process
88-
if (!isEqual([0, 0, 0, 0], padding)) {
89-
if (!this.trackLen) {
90-
this.measureScrollBar();
91-
this.changeViewData(this.getScrollRange(), true);
92-
} else {
93-
this.renderScrollbar();
94-
}
88+
if (padding === 'auto' || isEqual(padding, [0, 0, 0, 1])) {
89+
return;
90+
}
91+
if (!this.trackLen) {
92+
this.measureScrollBar();
93+
this.changeViewData(this.getScrollRange(), true);
94+
} else {
95+
this.renderScrollbar();
9596
}
9697
});
9798
}

src/interaction/slider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { IGroup, Slider, VIEW_LIFE_CIRCLE } from '../dependents';
22
import BBox from '../util/bbox';
33
import { Scale } from '@antv/scale';
4-
import { clamp, head, last, map, size, throttle, isEmpty } from '@antv/util';
4+
import { clamp, head, last, map, size, throttle, isEmpty, isEqual } from '@antv/util';
55
import { ISliderInteractionConfig } from '../interface/config';
66
import BaseInteraction from './base';
77
import { getDataByScaleRange } from './helper/data-range';
@@ -95,6 +95,10 @@ export default class SliderInteraction extends BaseInteraction {
9595
this.xScaleCfg = undefined;
9696
// 等待 view 每次 render 完成后更新 slider 组件
9797
const callback = () => {
98+
const padding = this.view.padding;
99+
if (padding === 'auto' || isEqual(padding, [0, 0, 0, 1])) {
100+
return;
101+
}
98102
if (isEmpty(layer.options.data)) {
99103
return;
100104
}

src/interface/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export type LegendPosition =
162162
| 'right-bottom'
163163
| 'top-left'
164164
| 'top-center'
165-
| 'top-bottom'
165+
| 'top-right'
166166
| 'bottom-left'
167167
| 'bottom-center'
168168
| 'bottom-right';

src/theme/default.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ export const DEFAULT_GLOBAL_THEME = {
268268

269269
// G2Plot 组件主题配置
270270
components: {
271+
legend: {
272+
margin: [0, 24, 24, 24],
273+
},
271274
tooltipIndicator: {
272275
title: {
273276
style: {

0 commit comments

Comments
 (0)