Skip to content

Commit

Permalink
fix(gauge): Fix size mismatch w/o gauge multi label text is hidden
Browse files Browse the repository at this point in the history
Fix gauge's size to be eqaul when label text is hidden

Ref naver#2799
  • Loading branch information
netil committed Aug 1, 2022
1 parent 1d378e0 commit e7747ce
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ChartInternal/shape/arc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default {

// determine radius
state.radiusExpanded = Math.min(state.arcWidth, state.arcHeight) / 2 * (
$$.hasMultiArcGauge() ? 0.85 : 1
$$.hasMultiArcGauge() && config.gauge_label_show ? 0.85 : 1
);

state.radius = state.radiusExpanded * 0.95;
Expand Down
32 changes: 31 additions & 1 deletion test/shape/gauge-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,17 @@ describe("SHAPE GAUGE", () => {
colors: {}
}
},
legend: {
show: true
},
gauge: {
background: "",
type: "multi",
label: {
format: function(value) {
return `${value}%`;
}
},
show: true
},
fullCircle: false,
arcLength: 360,
Expand Down Expand Up @@ -761,6 +765,32 @@ describe("SHAPE GAUGE", () => {
}, 100);
});

const gaugeSizeWithoutLabel = {
width: 0,
height: 0,
radius: 0
};

it("set options: legend.show & gauge.label.show", () => {
const rect = chart.$.arc.node().getBoundingClientRect();

// store values to compare with next test
gaugeSizeWithoutLabel.width = rect.width;
gaugeSizeWithoutLabel.height = rect.height;
gaugeSizeWithoutLabel.radius = chart.internal.state.radius;

args.legend.show = false;
args.gauge.label.show = false;
});

it("Arc size should expand w/o when gauge label text is hidden.", () => {
const rect = chart.$.arc.node().getBoundingClientRect();
const {radius} = chart.internal.state;

expect(rect.width).to.be.greaterThan(gaugeSizeWithoutLabel.width);
expect(rect.height).to.be.greaterThan(gaugeSizeWithoutLabel.height);
expect(radius).to.be.greaterThan(gaugeSizeWithoutLabel.radius);
});
});

describe("Positioning", () => {
Expand Down

0 comments on commit e7747ce

Please sign in to comment.