Skip to content

Commit

Permalink
fix(legend): legend.inset.anchor is working again
Browse files Browse the repository at this point in the history
Refactored 'getCurrentPaddingRight(withoutTickTextOverflow = false)' to
'getCurrentPaddingRight(withXAxisTickTextOverflow = false)'.

From now on, if 'getCurrentPaddingRight()' is called without passing parameters
'xAxisTickOverflow' will be 0 and 'getXAxisTickTextY2Overflow()' will only be called
when autorotate x axis ticks is enabled.

Fix #1935
Close #1936
  • Loading branch information
michkami authored and netil committed Feb 10, 2021
1 parent c63dedb commit b5ba930
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ChartInternal/internals/size.axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default {
const $$ = this;
const {state: {axis, current}} = $$;
const xAxisLength = current.width -
$$.getCurrentPaddingLeft(false) - $$.getCurrentPaddingRight(true);
$$.getCurrentPaddingLeft(false) - $$.getCurrentPaddingRight();
const tickCountWithPadding = axis.x.tickCount +
axis.x.padding.left + axis.x.padding.right;

Expand Down
10 changes: 5 additions & 5 deletions src/ChartInternal/internals/size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ export default {
return padding + (axisWidth * axesLen);
},

getCurrentPaddingRight(withoutTickTextOverflow = false): number {
getCurrentPaddingRight(withXAxisTickTextOverflow = false): number {
const $$ = this;
const {config, state: {hasAxis}} = $$;
const defaultPadding = 10;
const legendWidthOnRight = $$.state.isLegendRight ? $$.getLegendWidth() + 20 : 0;
const axesLen = hasAxis ? config.axis_y2_axes.length : 0;
const axisWidth = hasAxis ? $$.getAxisWidthByAxisId("y2") : 0;
const xAxisTickTextOverflow = withoutTickTextOverflow ?
0 : $$.axis.getXAxisTickTextY2Overflow(defaultPadding);
const xAxisTickTextOverflow = withXAxisTickTextOverflow ?
$$.axis.getXAxisTickTextY2Overflow(defaultPadding) : 0;
let padding;

if (isValue(config.padding_right)) {
Expand Down Expand Up @@ -266,12 +266,12 @@ export default {
// for main
state.margin = !hasArc && isRotated ? {
top: $$.getHorizontalAxisHeight("y2") + $$.getCurrentPaddingTop(),
right: hasArc ? 0 : $$.getCurrentPaddingRight(),
right: hasArc ? 0 : $$.getCurrentPaddingRight(true),
bottom: $$.getHorizontalAxisHeight("y") + legendHeightForBottom + $$.getCurrentPaddingBottom(),
left: subchartHeight + (hasArc ? 0 : $$.getCurrentPaddingLeft())
} : {
top: 4 + $$.getCurrentPaddingTop(), // for top tick text
right: hasArc ? 0 : $$.getCurrentPaddingRight(),
right: hasArc ? 0 : $$.getCurrentPaddingRight(true),
bottom: xAxisHeight + subchartHeight + legendHeightForBottom + $$.getCurrentPaddingBottom(),
left: hasArc ? 0 : $$.getCurrentPaddingLeft()
};
Expand Down
2 changes: 1 addition & 1 deletion src/ChartInternal/internals/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export default {
const hasGauge = $$.hasType("gauge") && !config.gauge_fullCircle;
const svgLeft = $$.getSvgLeft(true);
let [x, y] = d3Mouse(element);
let chartRight = svgLeft + current.width - $$.getCurrentPaddingRight(true);
let chartRight = svgLeft + current.width - $$.getCurrentPaddingRight();
const chartLeft = $$.getCurrentPaddingLeft(true);
const size = 20;

Expand Down
25 changes: 25 additions & 0 deletions test/internals/legend-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,31 @@ describe("LEGEND", () => {

expect(box.height).to.be.equal(48);
});

it("set options", () => {
args = {
data: {
x: "x",
columns: [
["x", "A", "B", "C", "D", "E", "F"],
["col1", 7, 8, 5, 4, 8, 9],
["col2", 10, 6, 9, 1, 6, 8]
],
type: "radar", // for ESM specify as: radar()
labels: true,
},
legend: {
position: "inset",
inset: {
anchor: "bottom-right"
}
}
}
});

it("shouldn't throw error for radar type", () => {
expect(chart.$.legend.selectAll("g").empty()).to.be.false;
});
});

describe("should update args to have only one series", () => {
Expand Down

0 comments on commit b5ba930

Please sign in to comment.