Skip to content

Commit

Permalink
fix(gauge): fixed wrong bottom padding calculation
Browse files Browse the repository at this point in the history
from now 'isLegendRight' can be truthy only if legend is enabled

Fix #1441
Close #1471
  • Loading branch information
michkami authored and netil committed Jun 25, 2020
1 parent c871ba5 commit 0542586
Show file tree
Hide file tree
Showing 5 changed files with 594 additions and 544 deletions.
11 changes: 7 additions & 4 deletions src/ChartInternal/internals/size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,14 @@ export default {
}

// for arc
state.arcWidth = state.width - (state.isLegendRight ? currLegend.width + 10 : 0);
state.arcHeight = state.height - (state.isLegendRight ? 0 : 10);
const hasGauge = $$.hasType("gauge");
const isLegendRight = state.legend_show && state.isLegendRight;

if ($$.hasType("gauge") && !config.gauge_fullCircle) {
state.arcHeight += state.height - $$.getGaugeLabelHeight();
state.arcWidth = state.width - (isLegendRight ? currLegend.width + 10 : 0);
state.arcHeight = state.height - (isLegendRight && !hasGauge ? 0 : 10);

if (hasGauge && !config.gauge_fullCircle) {
state.arcHeight += state.height - $$.getPaddingBottomForGauge();
}

$$.updateRadius && $$.updateRadius();
Expand Down
3 changes: 1 addition & 2 deletions src/ChartInternal/internals/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default {
const $$ = this;
const {config, state} = $$;
const isRotated = config.axis_rotated;
const hasGauge = $$.hasType("gauge");
let padding = 0;
let x;
let y;
Expand All @@ -29,7 +28,7 @@ export default {
y = asHalfPixel(state.margin2.top);
} else if (target === "legend") {
x = state.margin3.left;
y = state.margin3.top + (hasGauge ? 10 : 0);
y = state.margin3.top;
} else if (target === "x") {
x = isRotated ? -padding : 0;
y = isRotated ? 0 : state.height + padding;
Expand Down
10 changes: 9 additions & 1 deletion src/ChartInternal/shape/gauge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ export default {
},

getGaugeLabelHeight(): 20 | 0 {
return this.config.gauge_label_show ? 20 : 0;
const {config} = this;

return this.config.gauge_label_show && !config.gauge_fullCircle ? 20 : 0;
},

getPaddingBottomForGauge() {
const $$ = this;

return $$.getGaugeLabelHeight() * ($$.config.gauge_label_show ? 2 : 2.5);
}
};
Loading

0 comments on commit 0542586

Please sign in to comment.