Skip to content

Commit

Permalink
fix: scale range should not be changed
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwalley committed Jul 10, 2020
1 parent c645d70 commit 17b9995
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3-simple-slider",
"version": "1.7.1",
"version": "1.7.2",
"description": "Renders an SVG slider",
"keywords": [
"d3",
Expand Down
20 changes: 12 additions & 8 deletions src/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
};

Expand Down

0 comments on commit 17b9995

Please sign in to comment.