Skip to content

Commit

Permalink
fix(data): fix break when whole dataseries are null (#3134)
Browse files Browse the repository at this point in the history
Fix convert data for step when has no value

Ref #3124

Co-authored-by: netil <netil@AL02015654.local>
  • Loading branch information
netil and netil authored Mar 14, 2023
1 parent 8026808 commit 5d12c45
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
31 changes: 17 additions & 14 deletions src/ChartInternal/data/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,32 +795,35 @@ export default {
const {axis, config} = $$;
const stepType = config.line_step_type;
const isCategorized = axis ? axis.isCategorized() : false;

const converted = isArray(values) ? values.concat() : [values];

if (!(isCategorized || /step\-(after|before)/.test(stepType))) {
return values;
}

// insert & append cloning first/last value to be fully rendered covering on each gap sides
const head = converted[0];
const tail = converted[converted.length - 1];
const {id} = head;
let {x} = head;

// insert head
converted.unshift({x: --x, value: head.value, id});
// when all datas are null, return empty array
// https://github.com/naver/billboard.js/issues/3124
if (converted.length) {
// insert & append cloning first/last value to be fully rendered covering on each gap sides
const head = converted[0];
const tail = converted[converted.length - 1];
const {id} = head;
let {x} = head;

isCategorized && stepType === "step-after" &&
// insert head
converted.unshift({x: --x, value: head.value, id});

// append tail
x = tail.x;
converted.push({x: ++x, value: tail.value, id});
isCategorized && stepType === "step-after" &&
converted.unshift({x: --x, value: head.value, id});

isCategorized && stepType === "step-before" &&
// append tail
x = tail.x;
converted.push({x: ++x, value: tail.value, id});

isCategorized && stepType === "step-before" &&
converted.push({x: ++x, value: tail.value, id});
}

return converted;
},

Expand Down
2 changes: 1 addition & 1 deletion src/ChartInternal/interactions/eventrect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default {
const xAxisTickValues = $$.getMaxDataCountTarget();

if (!config.data_xSort) {
xAxisTickValues.sort((a, b) => a.x - b.x);
xAxisTickValues.sort((a, b) => b.x - a.x);
}

// update data's index value to be alinged with the x Axis
Expand Down
26 changes: 26 additions & 0 deletions test/internals/data-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1348,4 +1348,30 @@ describe("DATA", () => {
expect(r > 0).to.be.true;
});
});

describe("null data", () => {
before(() => {
args = {
data: {
columns: [
["data1", null, null, null, null, null, null],
["data2", 1, 10, 100, 1000, 10000, 100000],
],
type: "area-step"
},
line: {
connectNull: true
},
axis: {
x: {
type: "category"
}
}
};
});

it("category x axis with whole dataseries contains null", () => {
expect(true).to.be.true;
});
});
});

0 comments on commit 5d12c45

Please sign in to comment.