Skip to content

Commit

Permalink
Merge branch 'master' into zoom-rho
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed Jun 4, 2020
2 parents 629b0dc + ec754d4 commit abfc0ae
Show file tree
Hide file tree
Showing 44 changed files with 1,610 additions and 169 deletions.
14 changes: 0 additions & 14 deletions .eslintrc

This file was deleted.

15 changes: 15 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,15 @@
{
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 8
},
"env": {
"es6": true,
"node": true,
"browser": true
},
"rules": {
"no-cond-assign": 0
}
}
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,5 +1,5 @@
*.sublime-workspace
.DS_Store
build/
dist/
node_modules
npm-debug.log
3 changes: 0 additions & 3 deletions .npmignore

This file was deleted.

113 changes: 69 additions & 44 deletions README.md

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions d3-interpolate.sublime-project
Expand Up @@ -2,12 +2,16 @@
"folders": [
{
"path": ".",
"file_exclude_patterns": [
"*.sublime-workspace"
],
"folder_exclude_patterns": [
"build"
]
"file_exclude_patterns": ["*.sublime-workspace"],
"folder_exclude_patterns": ["dist"]
}
],
"build_systems": [
{
"name": "yarn test",
"cmd": ["yarn", "test"],
"file_regex": "\\((...*?):([0-9]*):([0-9]*)\\)",
"working_dir": "$project_path"
}
]
}
17 changes: 0 additions & 17 deletions index.js

This file was deleted.

31 changes: 18 additions & 13 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "d3-interpolate",
"version": "1.1.1",
"version": "1.4.0",
"description": "Interpolate numbers, colors, strings, arrays, objects, whatever!",
"keywords": [
"d3",
Expand All @@ -15,27 +15,32 @@
"name": "Mike Bostock",
"url": "http://bost.ocks.org/mike"
},
"main": "build/d3-interpolate.js",
"module": "index",
"jsnext:main": "index",
"main": "dist/d3-interpolate.js",
"unpkg": "dist/d3-interpolate.min.js",
"jsdelivr": "dist/d3-interpolate.min.js",
"module": "src/index.js",
"repository": {
"type": "git",
"url": "https://github.com/d3/d3-interpolate.git"
},
"files": [
"dist/**/*.js",
"src/**/*.js"
],
"scripts": {
"pretest": "rm -rf build && mkdir build && rollup --banner \"$(preamble)\" -f umd -g d3-color:d3 -n d3 -o build/d3-interpolate.js -- index.js",
"test": "tape 'test/**/*-test.js' && eslint index.js src test",
"prepublish": "npm run test && uglifyjs --preamble \"$(preamble)\" build/d3-interpolate.js -c -m -o build/d3-interpolate.min.js",
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git push --tags && cd ../d3.github.com && git pull && cp ../d3-interpolate/build/d3-interpolate.js d3-interpolate.v1.js && cp ../d3-interpolate/build/d3-interpolate.min.js d3-interpolate.v1.min.js && git add d3-interpolate.v1.js d3-interpolate.v1.min.js && git commit -m \"d3-interpolate ${VERSION}\" && git push && cd - && zip -j build/d3-interpolate.zip -- LICENSE README.md build/d3-interpolate.js build/d3-interpolate.min.js"
"pretest": "rollup -c",
"test": "tape 'test/**/*-test.js' && eslint src",
"prepublishOnly": "rm -rf dist && yarn test",
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../${npm_package_name}/dist/${npm_package_name}.js ${npm_package_name}.v${npm_package_version%%.*}.js && cp ../${npm_package_name}/dist/${npm_package_name}.min.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git add ${npm_package_name}.v${npm_package_version%%.*}.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git commit -m \"${npm_package_name} ${npm_package_version}\" && git push && cd - && zip -j dist/${npm_package_name}.zip -- LICENSE README.md dist/${npm_package_name}.js dist/${npm_package_name}.min.js"
},
"dependencies": {
"d3-color": "1"
},
"sideEffects": false,
"devDependencies": {
"eslint": "2",
"package-preamble": "0.0",
"rollup": "0.34",
"tape": "4",
"uglify-js": "2"
"eslint": "6",
"rollup": "1",
"rollup-plugin-terser": "5",
"tape": "4"
}
}
36 changes: 36 additions & 0 deletions rollup.config.js
@@ -0,0 +1,36 @@
import {terser} from "rollup-plugin-terser";
import * as meta from "./package.json";

const config = {
input: "src/index.js",
external: Object.keys(meta.dependencies || {}).filter(key => /^d3-/.test(key)),
output: {
file: `dist/${meta.name}.js`,
name: "d3",
format: "umd",
indent: false,
extend: true,
banner: `// ${meta.homepage} v${meta.version} Copyright ${(new Date).getFullYear()} ${meta.author.name}`,
globals: Object.assign({}, ...Object.keys(meta.dependencies || {}).filter(key => /^d3-/.test(key)).map(key => ({[key]: "d3"})))
},
plugins: []
};

export default [
config,
{
...config,
output: {
...config.output,
file: `dist/${meta.name}.min.js`
},
plugins: [
...config.plugins,
terser({
output: {
preamble: config.output.banner
}
})
]
}
];
9 changes: 7 additions & 2 deletions src/array.js
@@ -1,9 +1,14 @@
import value from "./value";
import value from "./value.js";
import numberArray, {isNumberArray} from "./numberArray.js";

export default function(a, b) {
return (isNumberArray(b) ? numberArray : genericArray)(a, b);
}

export function genericArray(a, b) {
var nb = b ? b.length : 0,
na = a ? Math.min(nb, a.length) : 0,
x = new Array(nb),
x = new Array(na),
c = new Array(nb),
i;

Expand Down
2 changes: 1 addition & 1 deletion src/basisClosed.js
@@ -1,4 +1,4 @@
import {basis} from "./basis";
import {basis} from "./basis.js";

export default function(values) {
var n = values.length;
Expand Down
2 changes: 1 addition & 1 deletion src/color.js
@@ -1,4 +1,4 @@
import constant from "./constant";
import constant from "./constant.js";

function linear(a, d) {
return function(t) {
Expand Down
2 changes: 1 addition & 1 deletion src/cubehelix.js
@@ -1,5 +1,5 @@
import {cubehelix as colorCubehelix} from "d3-color";
import color, {hue} from "./color";
import color, {hue} from "./color.js";

function cubehelix(hue) {
return (function cubehelixGamma(y) {
Expand Down
4 changes: 2 additions & 2 deletions src/date.js
@@ -1,6 +1,6 @@
export default function(a, b) {
var d = new Date;
return a = +a, b -= a, function(t) {
return d.setTime(a + b * t), d;
return a = +a, b = +b, function(t) {
return d.setTime(a * (1 - t) + b * t), d;
};
}
6 changes: 6 additions & 0 deletions src/discrete.js
@@ -0,0 +1,6 @@
export default function(range) {
var n = range.length;
return function(t) {
return range[Math.max(0, Math.min(n - 1, Math.floor(t * n)))];
};
}
2 changes: 1 addition & 1 deletion src/hcl.js
@@ -1,5 +1,5 @@
import {hcl as colorHcl} from "d3-color";
import color, {hue} from "./color";
import color, {hue} from "./color.js";

function hcl(hue) {
return function(start, end) {
Expand Down
2 changes: 1 addition & 1 deletion src/hsl.js
@@ -1,5 +1,5 @@
import {hsl as colorHsl} from "d3-color";
import color, {hue} from "./color";
import color, {hue} from "./color.js";

function hsl(hue) {
return function(start, end) {
Expand Down
9 changes: 9 additions & 0 deletions src/hue.js
@@ -0,0 +1,9 @@
import {hue} from "./color.js";

export default function(a, b) {
var i = hue(+a, +b);
return function(t) {
var x = i(t);
return x - 360 * Math.floor(x / 360);
};
}
21 changes: 21 additions & 0 deletions src/index.js
@@ -0,0 +1,21 @@
export {default as interpolate} from "./value.js";
export {default as interpolateArray} from "./array.js";
export {default as interpolateBasis} from "./basis.js";
export {default as interpolateBasisClosed} from "./basisClosed.js";
export {default as interpolateDate} from "./date.js";
export {default as interpolateDiscrete} from "./discrete.js";
export {default as interpolateHue} from "./hue.js";
export {default as interpolateNumber} from "./number.js";
export {default as interpolateNumberArray} from "./numberArray.js";
export {default as interpolateObject} from "./object.js";
export {default as interpolateRound} from "./round.js";
export {default as interpolateString} from "./string.js";
export {interpolateTransformCss, interpolateTransformSvg} from "./transform/index.js";
export {default as interpolateZoom} from "./zoom.js";
export {default as interpolateRgb, rgbBasis as interpolateRgbBasis, rgbBasisClosed as interpolateRgbBasisClosed} from "./rgb.js";
export {default as interpolateHsl, hslLong as interpolateHslLong} from "./hsl.js";
export {default as interpolateLab} from "./lab.js";
export {default as interpolateHcl, hclLong as interpolateHclLong} from "./hcl.js";
export {default as interpolateCubehelix, cubehelixLong as interpolateCubehelixLong} from "./cubehelix.js";
export {default as piecewise} from "./piecewise.js";
export {default as quantize} from "./quantize.js";
2 changes: 1 addition & 1 deletion src/lab.js
@@ -1,5 +1,5 @@
import {lab as colorLab} from "d3-color";
import color from "./color";
import color from "./color.js";

export default function lab(start, end) {
var l = color((start = colorLab(start)).l, (end = colorLab(end)).l),
Expand Down
4 changes: 2 additions & 2 deletions src/number.js
@@ -1,5 +1,5 @@
export default function(a, b) {
return a = +a, b -= a, function(t) {
return a + b * t;
return a = +a, b = +b, function(t) {
return a * (1 - t) + b * t;
};
}
14 changes: 14 additions & 0 deletions src/numberArray.js
@@ -0,0 +1,14 @@
export default function(a, b) {
if (!b) b = [];
var n = a ? Math.min(b.length, a.length) : 0,
c = b.slice(),
i;
return function(t) {
for (i = 0; i < n; ++i) c[i] = a[i] * (1 - t) + b[i] * t;
return c;
};
}

export function isNumberArray(x) {
return ArrayBuffer.isView(x) && !(x instanceof DataView);
}
2 changes: 1 addition & 1 deletion src/object.js
@@ -1,4 +1,4 @@
import value from "./value";
import value from "./value.js";

export default function(a, b) {
var i = {},
Expand Down
8 changes: 8 additions & 0 deletions src/piecewise.js
@@ -0,0 +1,8 @@
export default function piecewise(interpolate, values) {
var i = 0, n = values.length - 1, v = values[0], I = new Array(n < 0 ? 0 : n);
while (i < n) I[i] = interpolate(v, v = values[++i]);
return function(t) {
var i = Math.max(0, Math.min(n - 1, Math.floor(t *= n)));
return I[i](t - i);
};
}
8 changes: 4 additions & 4 deletions src/rgb.js
@@ -1,7 +1,7 @@
import {rgb as colorRgb} from "d3-color";
import basis from "./basis";
import basisClosed from "./basisClosed";
import {gamma} from "./color";
import basis from "./basis.js";
import basisClosed from "./basisClosed.js";
import nogamma, {gamma} from "./color.js";

export default (function rgbGamma(y) {
var color = gamma(y);
Expand All @@ -10,7 +10,7 @@ export default (function rgbGamma(y) {
var r = color((start = colorRgb(start)).r, (end = colorRgb(end)).r),
g = color(start.g, end.g),
b = color(start.b, end.b),
opacity = color(start.opacity, end.opacity);
opacity = nogamma(start.opacity, end.opacity);
return function(t) {
start.r = r(t);
start.g = g(t);
Expand Down
4 changes: 2 additions & 2 deletions src/round.js
@@ -1,5 +1,5 @@
export default function(a, b) {
return a = +a, b -= a, function(t) {
return Math.round(a + b * t);
return a = +a, b = +b, function(t) {
return Math.round(a * (1 - t) + b * t);
};
}
2 changes: 1 addition & 1 deletion src/string.js
@@ -1,4 +1,4 @@
import number from "./number";
import number from "./number.js";

var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
reB = new RegExp(reA.source, "g");
Expand Down
4 changes: 2 additions & 2 deletions src/transform/index.js
@@ -1,5 +1,5 @@
import number from "../number";
import {parseCss, parseSvg} from "./parse";
import number from "../number.js";
import {parseCss, parseSvg} from "./parse.js";

function interpolateTransform(parse, pxComma, pxParen, degParen) {

Expand Down
2 changes: 1 addition & 1 deletion src/transform/parse.js
@@ -1,4 +1,4 @@
import decompose, {identity} from "./decompose";
import decompose, {identity} from "./decompose.js";

var cssNode,
cssRoot,
Expand Down
20 changes: 11 additions & 9 deletions src/value.js
@@ -1,11 +1,12 @@
import {color} from "d3-color";
import rgb from "./rgb";
import array from "./array";
import date from "./date";
import number from "./number";
import object from "./object";
import string from "./string";
import constant from "./constant";
import rgb from "./rgb.js";
import {genericArray} from "./array.js";
import date from "./date.js";
import number from "./number.js";
import object from "./object.js";
import string from "./string.js";
import constant from "./constant.js";
import numberArray, {isNumberArray} from "./numberArray.js";

export default function(a, b) {
var t = typeof b, c;
Expand All @@ -14,7 +15,8 @@ export default function(a, b) {
: t === "string" ? ((c = color(b)) ? (b = c, rgb) : string)
: b instanceof color ? rgb
: b instanceof Date ? date
: Array.isArray(b) ? array
: isNaN(b) ? object
: isNumberArray(b) ? numberArray
: Array.isArray(b) ? genericArray
: typeof b.valueOf !== "function" && typeof b.toString !== "function" || isNaN(b) ? object
: number)(a, b);
}

0 comments on commit abfc0ae

Please sign in to comment.