Skip to content

Commit

Permalink
fix: generate multiple charts in the same session
Browse files Browse the repository at this point in the history
  • Loading branch information
gabidobo committed Jan 12, 2023
1 parent 511a44e commit 552f446
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/charts/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ const {
getIssueLevel,
} = require('./utils');

const d3n = new D3Node();
const {d3} = d3n;

// Modified from the original source below
// Copyright 2021 Observable, Inc.
// Released under the ISC license.
// https://observablehq.com/@d3/tree
const buildTree = (
data,
{
tree = d3.tree, // layout algorithm (typically d3.tree or d3.cluster)
tree,
showVersions = false,
width = 1000,
vulnerabilities = {},
Expand All @@ -29,6 +26,8 @@ const buildTree = (
showLicenseInfo = false,
} = {},
) => {
const d3n = new D3Node();
const {d3} = d3n;
const root = d3.hierarchy(processGraph(data, {maxDepth, includeDev}));

// Construct an ordinal color scale
Expand Down Expand Up @@ -71,7 +70,7 @@ const buildTree = (
const padding = 1;
const dx = 10;
const dy = width / (root.height + padding);
tree().nodeSize([dx, dy])(root);
(tree || d3.tree)().nodeSize([dx, dy])(root);

// Center the tree.
let x0 = Infinity;
Expand Down
9 changes: 4 additions & 5 deletions src/charts/treemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,23 @@ const {
getIssueLevel,
} = require('./utils');

const d3n = new D3Node();
const {d3} = d3n;

// Modified from the original source below
// Copyright 2021 Observable, Inc.
// Released under the ISC license.
// https://observablehq.com/@d3/treemap
function buildTreemap(
data,
{
tile = d3.treemapBinary, // treemap strategy
tile,
width = 1000, // outer width, in pixels
vulnerabilities = {},
maxDepth = Infinity,
includeDev = false,
showLicenseInfo = false,
} = {},
) {
const d3n = new D3Node();
const {d3} = d3n;
const moduleCallCounts = [];
const getModuleCallCount = (d) => {
if (d.data.size === 0) {
Expand Down Expand Up @@ -95,7 +94,7 @@ function buildTreemap(

d3
.treemap()
.tile(tile)
.tile(tile || d3.treemapBinary)
.size([width, width])
.paddingInner(1)
.paddingTop(19)
Expand Down

0 comments on commit 552f446

Please sign in to comment.