Comparing version 0.0.4 to 0.1.0
399
index.js
@@ -1,397 +0,2 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-transition')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'd3-transition'], factory) : | ||
(factory(global.d3_brush = {}, global.d3_transition)); | ||
}(this, function (exports, d3Transition) { 'use strict'; | ||
var d3Brush = exports; | ||
var transition = d3Transition.transition; | ||
function d3_identity(d) { | ||
return d; | ||
} | ||
function d3_scaleRange(scale) { | ||
return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range()); | ||
} | ||
function d3_Map() { | ||
this._ = Object.create(null); | ||
} | ||
d3Brush.rebind = function(target, source) { | ||
var i = 1, n = arguments.length, method; | ||
while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]); | ||
return target; | ||
}; | ||
function d3_rebind(target, source, method) { | ||
return function() { | ||
var value = method.apply(source, arguments); | ||
return value === source ? target : value; | ||
}; | ||
} | ||
d3Brush.dispatch = function() { | ||
var dispatch = new d3_dispatch(), i = -1, n = arguments.length; | ||
while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch); | ||
return dispatch; | ||
}; | ||
function d3_dispatch() {} | ||
d3_dispatch.prototype.on = function(type, listener) { | ||
var i = type.indexOf("."), name = ""; | ||
if (i >= 0) { | ||
name = type.slice(i + 1); | ||
type = type.slice(0, i); | ||
} | ||
if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener); | ||
if (arguments.length === 2) { | ||
if (listener == null) for (type in this) { | ||
if (this.hasOwnProperty(type)) this[type].on(name, null); | ||
} | ||
return this; | ||
} | ||
}; | ||
function d3_dispatch_event(dispatch) { | ||
var listeners = [], listenerByName = new d3_Map(); | ||
function event() { | ||
var z = listeners, i = -1, n = z.length, l; | ||
while (++i < n) if (l = z[i].on) l.apply(this, arguments); | ||
return dispatch; | ||
} | ||
event.on = function(name, listener) { | ||
var l = listenerByName.get(name), i; | ||
if (arguments.length < 2) return l && l.on; | ||
if (l) { | ||
l.on = null; | ||
listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1)); | ||
listenerByName.remove(name); | ||
} | ||
if (listener) listeners.push(listenerByName.set(name, { | ||
on: listener | ||
})); | ||
return dispatch; | ||
}; | ||
return event; | ||
} | ||
d3Brush.event = null; | ||
function d3_eventPreventDefault() { | ||
d3Brush.event.preventDefault(); | ||
} | ||
function d3_eventSource() { | ||
var e = d3Brush.event, s; | ||
while (s = e.sourceEvent) e = s; | ||
return e; | ||
} | ||
function d3_eventDispatch(target) { | ||
var dispatch = new d3_dispatch(), i = 0, n = arguments.length; | ||
while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch); | ||
dispatch.of = function(thiz, argumentz) { | ||
return function(e1) { | ||
try { | ||
var e0 = e1.sourceEvent = d3Brush.event; | ||
e1.target = target; | ||
d3Brush.event = e1; | ||
dispatch[e1.type].apply(thiz, argumentz); | ||
} finally { | ||
d3Brush.event = e0; | ||
} | ||
}; | ||
}; | ||
return dispatch; | ||
} | ||
d3Brush.requote = function(s) { | ||
return s.replace(d3_requote_re, "\\$&"); | ||
}; | ||
var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g; | ||
d3Brush.brush = function() { | ||
var event = d3_eventDispatch(brush, "brushstart", "brush", "brushend"), x = null, y = null, xExtent = [ 0, 0 ], yExtent = [ 0, 0 ], xExtentDomain, yExtentDomain, xClamp = true, yClamp = true, resizes = d3_svg_brushResizes[0]; | ||
function brush(g) { | ||
g.each(function() { | ||
var g = d3Selection.select(this).style("pointer-events", "all").style("-webkit-tap-highlight-color", "rgba(0,0,0,0)").on("mousedown.brush", brushstart).on("touchstart.brush", brushstart); | ||
var background = g.selectAll(".background").data([ 0 ]); | ||
background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair"); | ||
g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move"); | ||
var resize = g.selectAll(".resize").data(resizes, d3_identity); | ||
resize.exit().remove(); | ||
resize.enter().append("g").attr("class", function(d) { | ||
return "resize " + d; | ||
}).style("cursor", function(d) { | ||
return d3_svg_brushCursor[d]; | ||
}).append("rect").attr("x", function(d) { | ||
return /[ew]$/.test(d) ? -3 : null; | ||
}).attr("y", function(d) { | ||
return /^[ns]/.test(d) ? -3 : null; | ||
}).attr("width", 6).attr("height", 6).style("visibility", "hidden"); | ||
resize.style("display", brush.empty() ? "none" : null); | ||
var gUpdate = transition(g), backgroundUpdate = transition(background), range; | ||
if (x) { | ||
range = d3_scaleRange(x); | ||
backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]); | ||
redrawX(gUpdate); | ||
} | ||
if (y) { | ||
range = d3_scaleRange(y); | ||
backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]); | ||
redrawY(gUpdate); | ||
} | ||
redraw(gUpdate); | ||
}); | ||
} | ||
brush.event = function(g) { | ||
g.each(function() { | ||
var event_ = event.of(this, arguments), extent1 = { | ||
x: xExtent, | ||
y: yExtent, | ||
i: xExtentDomain, | ||
j: yExtentDomain | ||
}, extent0 = this.__chart__ || extent1; | ||
this.__chart__ = extent1; | ||
if (d3_transitionInheritId) { | ||
d3Selection.select(this).transition().each("start.brush", function() { | ||
xExtentDomain = extent0.i; | ||
yExtentDomain = extent0.j; | ||
xExtent = extent0.x; | ||
yExtent = extent0.y; | ||
event_({ | ||
type: "brushstart" | ||
}); | ||
}).tween("brush:brush", function() { | ||
var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y); | ||
xExtentDomain = yExtentDomain = null; | ||
return function(t) { | ||
xExtent = extent1.x = xi(t); | ||
yExtent = extent1.y = yi(t); | ||
event_({ | ||
type: "brush", | ||
mode: "resize" | ||
}); | ||
}; | ||
}).each("end.brush", function() { | ||
xExtentDomain = extent1.i; | ||
yExtentDomain = extent1.j; | ||
event_({ | ||
type: "brush", | ||
mode: "resize" | ||
}); | ||
event_({ | ||
type: "brushend" | ||
}); | ||
}); | ||
} else { | ||
event_({ | ||
type: "brushstart" | ||
}); | ||
event_({ | ||
type: "brush", | ||
mode: "resize" | ||
}); | ||
event_({ | ||
type: "brushend" | ||
}); | ||
} | ||
}); | ||
}; | ||
function redraw(g) { | ||
g.selectAll(".resize").attr("transform", function(d) { | ||
return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")"; | ||
}); | ||
} | ||
function redrawX(g) { | ||
g.select(".extent").attr("x", xExtent[0]); | ||
g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]); | ||
} | ||
function redrawY(g) { | ||
g.select(".extent").attr("y", yExtent[0]); | ||
g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]); | ||
} | ||
function brushstart() { | ||
var target = this, eventTarget = d3Selection.select(d3.event.target), event_ = event.of(target, arguments), g = d3.select(target), resizing = eventTarget.datum(), resizingX = !/^(n|s)$/.test(resizing) && x, resizingY = !/^(e|w)$/.test(resizing) && y, dragging = eventTarget.classed("extent"), dragRestore = d3_event_dragSuppress(target), center, origin = d3.mouse(target), offset; | ||
var w = d3Selection.select(d3_window(target)).on("keydown.brush", keydown).on("keyup.brush", keyup); | ||
if (d3Brush.event.changedTouches) { | ||
w.on("touchmove.brush", brushmove).on("touchend.brush", brushend); | ||
} else { | ||
w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend); | ||
} | ||
g.interrupt().selectAll("*").interrupt(); | ||
if (dragging) { | ||
origin[0] = xExtent[0] - origin[0]; | ||
origin[1] = yExtent[0] - origin[1]; | ||
} else if (resizing) { | ||
var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing); | ||
offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ]; | ||
origin[0] = xExtent[ex]; | ||
origin[1] = yExtent[ey]; | ||
} else if (d3Brush.event.altKey) center = origin.slice(); | ||
g.style("pointer-events", "none").selectAll(".resize").style("display", null); | ||
d3Selection.select("body").style("cursor", eventTarget.style("cursor")); | ||
event_({ | ||
type: "brushstart" | ||
}); | ||
brushmove(); | ||
function keydown() { | ||
if (d3Brush.event.keyCode == 32) { | ||
if (!dragging) { | ||
center = null; | ||
origin[0] -= xExtent[1]; | ||
origin[1] -= yExtent[1]; | ||
dragging = 2; | ||
} | ||
d3_eventPreventDefault(); | ||
} | ||
} | ||
function keyup() { | ||
if (d3Brush.event.keyCode == 32 && dragging == 2) { | ||
origin[0] += xExtent[1]; | ||
origin[1] += yExtent[1]; | ||
dragging = 0; | ||
d3_eventPreventDefault(); | ||
} | ||
} | ||
function brushmove() { | ||
var point = d3Selection.mouse(target), moved = false; | ||
if (offset) { | ||
point[0] += offset[0]; | ||
point[1] += offset[1]; | ||
} | ||
if (!dragging) { | ||
if (d3Brush.event.altKey) { | ||
if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ]; | ||
origin[0] = xExtent[+(point[0] < center[0])]; | ||
origin[1] = yExtent[+(point[1] < center[1])]; | ||
} else center = null; | ||
} | ||
if (resizingX && move1(point, x, 0)) { | ||
redrawX(g); | ||
moved = true; | ||
} | ||
if (resizingY && move1(point, y, 1)) { | ||
redrawY(g); | ||
moved = true; | ||
} | ||
if (moved) { | ||
redraw(g); | ||
event_({ | ||
type: "brush", | ||
mode: dragging ? "move" : "resize" | ||
}); | ||
} | ||
} | ||
function move1(point, scale, i) { | ||
var range = d3_scaleRange(scale), r0 = range[0], r1 = range[1], position = origin[i], extent = i ? yExtent : xExtent, size = extent[1] - extent[0], min, max; | ||
if (dragging) { | ||
r0 -= position; | ||
r1 -= size + position; | ||
} | ||
min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i]; | ||
if (dragging) { | ||
max = (min += position) + size; | ||
} else { | ||
if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min)); | ||
if (position < min) { | ||
max = min; | ||
min = position; | ||
} else { | ||
max = position; | ||
} | ||
} | ||
if (extent[0] != min || extent[1] != max) { | ||
if (i) yExtentDomain = null; else xExtentDomain = null; | ||
extent[0] = min; | ||
extent[1] = max; | ||
return true; | ||
} | ||
} | ||
function brushend() { | ||
brushmove(); | ||
g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null); | ||
d3Selection.select("body").style("cursor", null); | ||
w.on("mousemove.brush", null).on("mouseup.brush", null).on("touchmove.brush", null).on("touchend.brush", null).on("keydown.brush", null).on("keyup.brush", null); | ||
dragRestore(); | ||
event_({ | ||
type: "brushend" | ||
}); | ||
} | ||
} | ||
brush.x = function(z) { | ||
if (!arguments.length) return x; | ||
x = z; | ||
resizes = d3_svg_brushResizes[!x << 1 | !y]; | ||
return brush; | ||
}; | ||
brush.y = function(z) { | ||
if (!arguments.length) return y; | ||
y = z; | ||
resizes = d3_svg_brushResizes[!x << 1 | !y]; | ||
return brush; | ||
}; | ||
brush.clamp = function(z) { | ||
if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null; | ||
if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z; | ||
return brush; | ||
}; | ||
brush.extent = function(z) { | ||
var x0, x1, y0, y1, t; | ||
if (!arguments.length) { | ||
if (x) { | ||
if (xExtentDomain) { | ||
x0 = xExtentDomain[0], x1 = xExtentDomain[1]; | ||
} else { | ||
x0 = xExtent[0], x1 = xExtent[1]; | ||
if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1); | ||
if (x1 < x0) t = x0, x0 = x1, x1 = t; | ||
} | ||
} | ||
if (y) { | ||
if (yExtentDomain) { | ||
y0 = yExtentDomain[0], y1 = yExtentDomain[1]; | ||
} else { | ||
y0 = yExtent[0], y1 = yExtent[1]; | ||
if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1); | ||
if (y1 < y0) t = y0, y0 = y1, y1 = t; | ||
} | ||
} | ||
return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ]; | ||
} | ||
if (x) { | ||
x0 = z[0], x1 = z[1]; | ||
if (y) x0 = x0[0], x1 = x1[0]; | ||
xExtentDomain = [ x0, x1 ]; | ||
if (x.invert) x0 = x(x0), x1 = x(x1); | ||
if (x1 < x0) t = x0, x0 = x1, x1 = t; | ||
if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ]; | ||
} | ||
if (y) { | ||
y0 = z[0], y1 = z[1]; | ||
if (x) y0 = y0[1], y1 = y1[1]; | ||
yExtentDomain = [ y0, y1 ]; | ||
if (y.invert) y0 = y(y0), y1 = y(y1); | ||
if (y1 < y0) t = y0, y0 = y1, y1 = t; | ||
if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ]; | ||
} | ||
return brush; | ||
}; | ||
brush.clear = function() { | ||
if (!brush.empty()) { | ||
xExtent = [ 0, 0 ], yExtent = [ 0, 0 ]; | ||
xExtentDomain = yExtentDomain = null; | ||
} | ||
return brush; | ||
}; | ||
brush.empty = function() { | ||
return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1]; | ||
}; | ||
return d3Brush.rebind(brush, event, "on"); | ||
}; | ||
var d3_svg_brushCursor = { | ||
n: "ns-resize", | ||
e: "ew-resize", | ||
s: "ns-resize", | ||
w: "ew-resize", | ||
nw: "nwse-resize", | ||
ne: "nesw-resize", | ||
se: "nwse-resize", | ||
sw: "nesw-resize" | ||
}; | ||
var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ]; | ||
})); | ||
export {version} from "./build/package"; | ||
export {default as brush, brushX, brushY} from "./src/brush"; |
{ | ||
"name": "d3-brush", | ||
"version": "0.0.4", | ||
"description": "Brush from d3.", | ||
"main": "index.js", | ||
"version": "0.1.0", | ||
"description": "", | ||
"keywords": [ | ||
"d3", | ||
"brush", | ||
"interaction" | ||
], | ||
"homepage": "https://github.com/d3/d3-brush", | ||
"license": "BSD-3-Clause", | ||
"author": { | ||
@@ -10,23 +16,28 @@ "name": "Mike Bostock", | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"main": "build/d3-brush.js", | ||
"jsnext:main": "index", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/yavorsky/d3-brush.git" | ||
"url": "https://github.com/d3/d3-brush.git" | ||
}, | ||
"keywords": [ | ||
"d3", | ||
"brush" | ||
], | ||
"license": "BSD-3-Clause", | ||
"contributors": [ | ||
"Artem Yavorsky <info@yavorsky.org>" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/yavorsky/d3-brush/issues" | ||
"scripts": { | ||
"pretest": "rm -rf build && mkdir build && json2module package.json > build/package.js && rollup -g d3-dispatch:d3_dispatch,d3-drag:d3_drag,d3-interpolate:d3_interpolate,d3-selection:d3_selection,d3-transition:d3_transition -f umd -n d3_brush -o build/d3-brush.js -- index.js", | ||
"test": "tape 'test/**/*-test.js' && eslint index.js src", | ||
"prepublish": "npm run test && uglifyjs build/d3-brush.js -c -m -o build/d3-brush.min.js", | ||
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git push --tags && cp build/d3-brush.js ../d3.github.com/d3-brush.v0.1.js && cp build/d3-brush.min.js ../d3.github.com/d3-brush.v0.1.min.js && cd ../d3.github.com && git add d3-brush.v0.1.js d3-brush.v0.1.min.js && git commit -m \"d3-brush ${VERSION}\" && git push && cd - && zip -j build/d3-brush.zip -- LICENSE README.md build/d3-brush.js build/d3-brush.min.js" | ||
}, | ||
"dependencies": { | ||
"d3-transition": "~0.2.5" | ||
"d3-dispatch": "~0.4.3", | ||
"d3-drag": "~0.2.0", | ||
"d3-interpolate": "~0.8.0", | ||
"d3-selection": "~0.7.2", | ||
"d3-transition": "~0.2.8" | ||
}, | ||
"devDependencies": { | ||
"eslint": "2", | ||
"json2module": "0.0", | ||
"rollup": "0.26", | ||
"tape": "4", | ||
"uglify-js": "2" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
42618
12
888
2
33
5
5
1
2
+ Addedd3-dispatch@~0.4.3
+ Addedd3-drag@~0.2.0
+ Addedd3-interpolate@~0.8.0
+ Addedd3-selection@~0.7.2
+ Addedd3-drag@0.2.2(transitive)
Updatedd3-transition@~0.2.8