Skip to content

Commit

Permalink
fix(treemap): Fix generation w/non-exist node
Browse files Browse the repository at this point in the history
when given bindto element doesn't exist, will append node
internally, but generating treemap data will throw parent.ownerDocument error.
Fix waraping treemap data in array.

Fix #3777
  • Loading branch information
netil authored May 23, 2024
1 parent 7f5d5b0 commit 02987ab
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/ChartInternal/shape/treemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export default {
const treemapData = $$.treemapFn($$.getTreemapData(targets ?? $$.data.targets));

// using $el.treemap reference can alter data, so select treemap <g> again
treemap.data(treemapData);
treemap.data([treemapData]);
},

/**
Expand Down
23 changes: 13 additions & 10 deletions test/assets/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,28 @@ function initDom(idValue) {
/**
* Generate chart
* @param {Object} args chart options
* @param {boolean} raw Generate with only given options
* @return {bb} billboard.js instance
*/
function generate(args) {
function generate(args, raw = false) {
let chart;
let inputType = "mouse";

if (args) {
if (!args.bindto) {
args.bindto = "#chart";
}
if (!raw) {
if (!args.bindto) {
args.bindto = "#chart";
}

initDom(args.bindto);
initDom(args.bindto);

// when touch param is set, make to be 'touch' input mode
if (args.interaction?.inputType?.touch) {
inputType = "touch";
}
// when touch param is set, make to be 'touch' input mode
if (args.interaction?.inputType?.touch) {
inputType = "touch";
}

window.$$TEST$$.convertInputType = inputType;
window.$$TEST$$.convertInputType = inputType;
}

chart = bb.generate(args);
}
Expand Down
19 changes: 19 additions & 0 deletions test/shape/treemap-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,25 @@ describe("TREEMAP", () => {

treemap.destroy();
});

it("should generate w/o error", () => {
const param = {
data: {
columns: [
["data1", 1300],
],
type: "treemap"
},
bindto: "#chart25"
};

// generate with only given argument
const treemap = util.generate(param, true)

treemap.destroy();

expect(true).to.be.ok;
});
});

describe("label options", () => {
Expand Down

0 comments on commit 02987ab

Please sign in to comment.