From 17b9995f6bb2e5066f9fda563f34035575073b34 Mon Sep 17 00:00:00 2001 From: johnwalley Date: Fri, 10 Jul 2020 10:02:15 +0100 Subject: [PATCH] fix: scale range should not be changed --- package-lock.json | 2 +- package.json | 2 +- src/slider.js | 20 ++++++++++++-------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1636480..cf698e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "d3-simple-slider", - "version": "1.7.1", + "version": "1.7.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index fa4cf01..576d1b8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "d3-simple-slider", - "version": "1.7.1", + "version": "1.7.2", "description": "Renders an SVG slider", "keywords": [ "d3", diff --git a/src/slider.js b/src/slider.js index 2e5dbba..ce49b3d 100644 --- a/src/slider.js +++ b/src/slider.js @@ -25,7 +25,7 @@ function translateY(y) { } function slider(orientation, scale) { - scale = typeof scale !== 'undefined' ? scale : null; + scale = typeof scale !== 'undefined' ? scale.copy() : null; var value = [0]; var defaultValue = [0]; @@ -95,13 +95,7 @@ function slider(orientation, scale) { function slider(context) { selection = context.selection ? context.selection() : context; - if (scale) { - scale = scale.range([ - min(scale.range()), - min(scale.range()) + - (orientation === top || orientation === bottom ? width : height), - ]); - } else { + if (!scale) { scale = domain[0] instanceof Date ? scaleTime() : scaleLinear(); scale = scale @@ -629,12 +623,22 @@ function slider(orientation, scale) { slider.width = function (_) { if (!arguments.length) return width; width = _; + + if (scale) { + scale.range([scale.range()[0], scale.range()[0] + width]); + } + return slider; }; slider.height = function (_) { if (!arguments.length) return height; height = _; + + if (scale) { + scale.range([scale.range()[0], scale.range()[0] + height]); + } + return slider; };