From 41569a29d7d9af40899984e7b5646e0f437bb289 Mon Sep 17 00:00:00 2001 From: Lucas Cimon Date: Tue, 24 Apr 2018 13:35:52 +0200 Subject: [PATCH] Changing default dependency wheel width to be the parent DOM element width --- js/d3.dependencyWheel.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/js/d3.dependencyWheel.js b/js/d3.dependencyWheel.js index e43d67c..b997e2a 100644 --- a/js/d3.dependencyWheel.js +++ b/js/d3.dependencyWheel.js @@ -32,16 +32,21 @@ d3.chart = d3.chart || {}; * @see https://github.com/fzaninotto/DependencyWheel for complete source and license */ d3.chart.dependencyWheel = function(options) { - - var width = 700; - var margin = 150; - var padding = 0.02; + options = options || {}; function chart(selection) { + + if (selection.length > 1) { + throw new Error('dependencyWheel.js chart does not support rendering on several elements'); + } + selection.each(function(data) { var matrix = data.matrix; var packageNames = data.packageNames; + var width = options.width || this.offsetWidth; + var margin = options.margin || width * 3 / 14; + var padding = options.padding || 0.02; var radius = width / 2 - margin; // create the layout @@ -152,20 +157,20 @@ d3.chart.dependencyWheel = function(options) { } chart.width = function(value) { - if (!arguments.length) return width; - width = value; + if (!arguments.length) return options.width; + options.width = value; return chart; }; chart.margin = function(value) { - if (!arguments.length) return margin; - margin = value; + if (!arguments.length) return options.margin; + options.margin = value; return chart; }; chart.padding = function(value) { - if (!arguments.length) return padding; - padding = value; + if (!arguments.length) return options.padding; + options.padding = value; return chart; };