From 552f446fd6c70217b8c53acffa0d99526727bd0e Mon Sep 17 00:00:00 2001 From: Gabi Dobocan Date: Thu, 12 Jan 2023 18:09:43 +0200 Subject: [PATCH] fix: generate multiple charts in the same session --- src/charts/tree.js | 9 ++++----- src/charts/treemap.js | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/charts/tree.js b/src/charts/tree.js index 22b0fb6..91ae496 100644 --- a/src/charts/tree.js +++ b/src/charts/tree.js @@ -10,9 +10,6 @@ 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. @@ -20,7 +17,7 @@ const {d3} = d3n; const buildTree = ( data, { - tree = d3.tree, // layout algorithm (typically d3.tree or d3.cluster) + tree, showVersions = false, width = 1000, vulnerabilities = {}, @@ -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 @@ -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; diff --git a/src/charts/treemap.js b/src/charts/treemap.js index 6bcb840..c2d1f69 100644 --- a/src/charts/treemap.js +++ b/src/charts/treemap.js @@ -13,9 +13,6 @@ 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. @@ -23,7 +20,7 @@ const {d3} = d3n; function buildTreemap( data, { - tile = d3.treemapBinary, // treemap strategy + tile, width = 1000, // outer width, in pixels vulnerabilities = {}, maxDepth = Infinity, @@ -31,6 +28,8 @@ function buildTreemap( showLicenseInfo = false, } = {}, ) { + const d3n = new D3Node(); + const {d3} = d3n; const moduleCallCounts = []; const getModuleCallCount = (d) => { if (d.data.size === 0) { @@ -95,7 +94,7 @@ function buildTreemap( d3 .treemap() - .tile(tile) + .tile(tile || d3.treemapBinary) .size([width, width]) .paddingInner(1) .paddingTop(19)