-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optional parameters to interpolators.
Related d3/d3-scale#39.
- Loading branch information
Showing
9 changed files
with
91 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var slice = Array.prototype.slice; | ||
|
||
function bindN(type, args) { | ||
args = slice.call(args); | ||
args[0] = null; | ||
args.unshift(null); | ||
return function(a, b) { | ||
args[0] = a; | ||
args[1] = b; | ||
return type.apply(null, args); | ||
}; | ||
} | ||
|
||
export default function(type) { | ||
return arguments.length === 1 ? type : bindN(type, arguments); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {cubehelix} from "d3-color"; | ||
import deltaHue from "./deltaHue"; | ||
|
||
export default function(a, b, gamma) { | ||
if (arguments.length < 3) gamma = 1; | ||
a = cubehelix(a); | ||
b = cubehelix(b); | ||
var ah = isNaN(a.h) ? b.h : a.h, | ||
as = isNaN(a.s) ? b.s : a.s, | ||
al = a.l, | ||
bh = isNaN(b.h) ? 0 : deltaHue(b.h, ah), | ||
bs = isNaN(b.s) ? 0 : b.s - as, | ||
bl = b.l - al; | ||
return function(t) { | ||
a.h = ah + bh * t; | ||
a.s = as + bs * t; | ||
a.l = al + bl * Math.pow(t, gamma); | ||
return a + ""; | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {cubehelix} from "d3-color"; | ||
|
||
export default function(a, b, gamma) { | ||
if (arguments.length < 3) gamma = 1; | ||
a = cubehelix(a); | ||
b = cubehelix(b); | ||
var ah = isNaN(a.h) ? b.h : a.h, | ||
as = isNaN(a.s) ? b.s : a.s, | ||
al = a.l, | ||
bh = isNaN(b.h) ? 0 : b.h - ah, | ||
bs = isNaN(b.s) ? 0 : b.s - as, | ||
bl = b.l - al; | ||
return function(t) { | ||
a.h = ah + bh * t; | ||
a.s = as + bs * t; | ||
a.l = al + bl * Math.pow(t, gamma); | ||
return a + ""; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var tape = require("tape"), | ||
interpolate = require("../"); | ||
|
||
tape("bind(type) returns type", function(test) { | ||
test.equal(interpolate.bind(interpolate.cubehelix), interpolate.cubehelix); | ||
test.equal(interpolate.bind(interpolate.rgb), interpolate.rgb); | ||
test.end(); | ||
}); | ||
|
||
tape("bind(type, parameter) binds the specified parameter to the given type", function(test) { | ||
test.equal(interpolate.bind(interpolate.cubehelix, 3)("purple", "orange")(0.5), interpolate.cubehelix("purple", "orange", 3)(0.5)); | ||
test.equal(interpolate.bind(interpolate.cubehelixLong, 3)("purple", "orange")(0.5), interpolate.cubehelixLong("purple", "orange", 3)(0.5)); | ||
test.equal(interpolate.bind(interpolate.rgb, 3)("purple", "orange")(0.5), interpolate.rgb("purple", "orange", 3)(0.5)); // ignored | ||
test.end(); | ||
}); |