Skip to content

Instantly share code, notes, and snippets.

@micahstubbs micahstubbs/.block
Last active Aug 14, 2018

Embed
What would you like to do?
us-budget-sankey
license: Apache-2.0
border: no
height: 780

US Federal Budget Balance, 1968-2017

Remaining goals for this piece:

  1. animated transitions between years
  2. line or bar chart below which will show a time series of the budget item selected by the user by clicking on the sankey
  3. adjust discretionary/mandatory arrangement so the net interest link doesnt overlap

a visualization by MasonChinkin, posted together as a #d3js learning exercise on night after a d3 meetup

see the example in webpage form as well at
https://masonchinkin.github.io/us-budget-sankey.html#portfolio

! function(t, e) { "object" == typeof exports && "undefined" != typeof module ? e(exports, require("d3-selection"), require("d3-drag"), require("d3-shape"), require("d3-dispatch")) : "function" == typeof define && define.amd ? define(["exports", "d3-selection", "d3-drag", "d3-shape", "d3-dispatch"], e) : e(t.d3 = t.d3 || {}, t.d3, t.d3, t.d3, t.d3) }(this, function(t, e, n, o, a) { "use strict";
function i() { var t = [],
n = void 0,
o = void 0,
i = [],
s = {},
r = {},
c = !1,
d = void 0,
u = z,
h = void 0,
l = void 0,
p = a.dispatch("subjectover", "subjectout", "subjectclick", "connectorover", "connectorout", "connectorclick", "noteover", "noteout", "noteclick", "dragend", "dragstart"),
v = void 0,
g = function(o) { v = o, c || o.selectAll("circle.handle").remove(); var a = t.map(function(t) { return t.type || (t.type = u), t.disable || (t.disable = i), new y(t) });
n = n || new f({ annotations: a, accessors: s, accessorsInverse: r, ids: d }), o.selectAll("g").data([n]).enter().append("g").attr("class", "annotations"); var g = o.select("g.annotations");
U(g, n.annotations, "g", "annotation"), g.selectAll("g.annotation").each(function(t) { var n = e.select(this);
n.attr("class", "annotation"), U(n, [t], "g", "annotation-connector"), U(n, [t], "g", "annotation-subject"), U(n, [t], "g", "annotation-note"), U(n.select("g.annotation-note"), [t], "g", "annotation-note-content"), t.type = "[object Object]" === t.type.toString() ? t.type : new t.type({ a: n, annotation: t, textWrap: h, notePadding: l, editMode: c, dispatcher: p, accessors: s }), t.type.draw(), t.type.drawText && t.type.drawText() }) }; return g.json = function() { return console.log("Annotations JSON was copied to your clipboard. Please note the annotation type is not JSON compatible. It appears in the objects array in the console, but not in the copied JSON.", n.json), window.copy(JSON.stringify(n.json.map(function(t) { return delete t.type, t }))), g }, g.update = function() { return t && n && (t = n.annotations.map(function(t) { return t.type.draw(), t })), g }, g.updateText = function() { return n && (n.updateText(h), t = n.annotations), g }, g.updatedAccessors = function() { return n.setPositionWithAccessors(), t = n.annotations, g }, g.disable = function(e) { return arguments.length ? (i = e, n && (n.updateDisable(i), t = n.annotations), g) : i }, g.textWrap = function(e) { return arguments.length ? (h = e, n && (n.updateTextWrap(h), t = n.annotations), g) : h }, g.notePadding = function(e) { return arguments.length ? (l = e, n && (n.updateNotePadding(l), t = n.annotations), g) : l }, g.type = function(e, o) { return arguments.length ? (u = e, n && (n.annotations.map(function(t) { t.type.note && t.type.note.selectAll("*:not(.annotation-note-content)").remove(), t.type.noteContent && t.type.noteContent.selectAll("*").remove(), t.type.subject && t.type.subject.selectAll("*").remove(), t.type.connector && t.type.connector.selectAll("*").remove(), t.type.typeSettings = {}, t.type = u, t.subject = o && o.subject || t.subject, t.connector = o && o.connector || t.connector, t.note = o && o.note || t.note }), t = n.annotations), g) : u }, g.annotations = function(e) { if (!arguments.length) return n && n.annotations || t; if (t = e, n && n.annotations) { t.some(function(t) { return !t.type || "[object Object]" !== t.type.toString() }) ? (n = null, g(v)) : n.annotations = t } return g }, g.context = function(t) { return arguments.length ? (o = t, g) : o }, g.accessors = function(t) { return arguments.length ? (s = t, g) : s }, g.accessorsInverse = function(t) { return arguments.length ? (r = t, g) : r }, g.ids = function(t) { return arguments.length ? (d = t, g) : d }, g.editMode = function(e) { return arguments.length ? (c = e, v && v.selectAll("g.annotation").classed("editable", c), n && (n.editMode(c), t = n.annotations), g) : c }, g.collection = function(t) { return arguments.length ? (n = t, g) : n }, g.on = function() { var t = p.on.apply(p, arguments); return t === p ? g : t }, g } var s = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) { return typeof t } : function(t) { return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t },
r = function(t, e) { if (!(t instanceof e)) throw new TypeError("Cannot call a class as a function") },
c = function() {
function t(t, e) { for (var n = 0; n < e.length; n++) { var o = e[n];
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(t, o.key, o) } } return function(e, n, o) { return n && t(e.prototype, n), o && t(e, o), e } }(),
d = Object.assign || function(t) { for (var e = 1; e < arguments.length; e++) { var n = arguments[e]; for (var o in n) Object.prototype.hasOwnProperty.call(n, o) && (t[o] = n[o]) } return t },
u = function t(e, n, o) { null === e && (e = Function.prototype); var a = Object.getOwnPropertyDescriptor(e, n); if (void 0 === a) { var i = Object.getPrototypeOf(e); return null === i ? void 0 : t(i, n, o) } if ("value" in a) return a.value; var s = a.get; if (void 0 !== s) return s.call(o) },
h = function(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function, not " + typeof e);
t.prototype = Object.create(e && e.prototype, { constructor: { value: t, enumerable: !1, writable: !0, configurable: !0 } }), e && (Object.setPrototypeOf ? Object.setPrototypeOf(t, e) : t.__proto__ = e) },
l = function(t, e) { if (!t) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return !e || "object" != typeof e && "function" != typeof e ? t : e },
p = function(t) { if (Array.isArray(t)) { for (var e = 0, n = Array(t.length); e < t.length; e++) n[e] = t[e]; return n } return Array.from(t) },
y = function() {
function t(e) { var n = e.x,
o = void 0 === n ? 0 : n,
a = e.y,
i = void 0 === a ? 0 : a,
s = e.nx,
c = e.ny,
d = e.dy,
u = void 0 === d ? 0 : d,
h = e.dx,
l = void 0 === h ? 0 : h,
p = e.color,
y = void 0 === p ? "grey" : p,
f = e.data,
v = e.type,
g = e.subject,
b = e.connector,
x = e.note,
m = e.disable,
j = e.id,
w = e.className;
r(this, t), this._dx = void 0 !== s ? s - o : l, this._dy = void 0 !== c ? c - i : u, this._x = o, this._y = i, this._color = y, this.id = j, this._className = w || "", this.type = v || "", this.data = f, this.note = x || {}, this.connector = b || {}, this.subject = g || {}, this.disable = m || [] } return c(t, [{ key: "updatePosition", value: function() { this.type.setPosition && (this.type.setPosition(), this.type.subject && 0 !== this.type.subject.selectAll(":not(.handle)").nodes().length && this.type.redrawSubject()) } }, { key: "updateOffset", value: function() { this.type.setOffset && (this.type.setOffset(), 0 !== this.type.connector.selectAll(":not(.handle)").nodes().length && this.type.redrawConnector(), this.type.redrawNote()) } }, { key: "className", get: function() { return this._className }, set: function(t) { this._className = t, this.type.setClassName && this.type.setClassName() } }, { key: "x", get: function() { return this._x }, set: function(t) { this._x = t, this.updatePosition() } }, { key: "y", get: function() { return this._y }, set: function(t) { this._y = t, this.updatePosition() } }, { key: "color", get: function() { return this._color }, set: function(t) { this._color = t, this.updatePosition() } }, { key: "dx", get: function() { return this._dx }, set: function(t) { this._dx = t, this.updateOffset() } }, { key: "dy", get: function() { return this._dy }, set: function(t) { this._dy = t, this.updateOffset() } }, { key: "nx", set: function(t) { this._dx = t - this._x, this.updateOffset() } }, { key: "ny", set: function(t) { this._dy = t - this._y, this.updateOffset() } }, { key: "offset", get: function() { return { x: this._dx, y: this._dy } }, set: function(t) { var e = t.x,
n = t.y;
this._dx = e, this._dy = n, this.updateOffset() } }, { key: "position", get: function() { return { x: this._x, y: this._y } }, set: function(t) { var e = t.x,
n = t.y;
this._x = e, this._y = n, this.updatePosition() } }, { key: "translation", get: function() { return { x: this._x + this._dx, y: this._y + this._dy } } }, { key: "json", get: function() { var t = { x: this._x, y: this._y, dx: this._dx, dy: this._dy }; return this.data && Object.keys(this.data).length > 0 && (t.data = this.data), this.type && (t.type = this.type), this._className && (t.className = this._className), Object.keys(this.connector).length > 0 && (t.connector = this.connector), Object.keys(this.subject).length > 0 && (t.subject = this.subject), Object.keys(this.note).length > 0 && (t.note = this.note), t } }]), t }(),
f = function() {
function t(e) { var n = e.annotations,
o = e.accessors,
a = e.accessorsInverse;
r(this, t), this.accessors = o, this.accessorsInverse = a, this.annotations = n } return c(t, [{ key: "clearTypes", value: function(t) { this.annotations.forEach(function(e) { e.type = void 0, e.subject = t && t.subject || e.subject, e.connector = t && t.connector || e.connector, e.note = t && t.note || e.note }) } }, { key: "setPositionWithAccessors", value: function() { var t = this;
this.annotations.forEach(function(e) { e.type.setPositionWithAccessors(t.accessors) }) } }, { key: "editMode", value: function(t) { this.annotations.forEach(function(e) { e.type && (e.type.editMode = t, e.type.updateEditMode()) }) } }, { key: "updateDisable", value: function(t) { this.annotations.forEach(function(e) { e.disable = t, e.type && t.forEach(function(t) { e.type[t] && (e.type[t].remove && e.type[t].remove(), e.type[t] = void 0) }) }) } }, { key: "updateTextWrap", value: function(t) { this.annotations.forEach(function(e) { e.type && e.type.updateTextWrap && e.type.updateTextWrap(t) }) } }, { key: "updateText", value: function() { this.annotations.forEach(function(t) { t.type && t.type.drawText && t.type.drawText() }) } }, { key: "updateNotePadding", value: function(t) { this.annotations.forEach(function(e) { e.type && (e.type.notePadding = t) }) } }, { key: "json", get: function() { var t = this; return this.annotations.map(function(e) { var n = e.json; return t.accessorsInverse && e.data && (n.data = {}, Object.keys(t.accessorsInverse).forEach(function(o) { n.data[o] = t.accessorsInverse[o]({ x: e.x, y: e.y }) })), n }) } }, { key: "noteNodes", get: function() { return this.annotations.map(function(t) { return d({}, t.type.getNoteBBoxOffset(), { positionX: t.x, positionY: t.y }) }) } }]), t }(),
v = function(t) { var e = t.cx,
n = void 0 === e ? 0 : e,
o = t.cy; return { move: { x: n, y: void 0 === o ? 0 : o } } },
g = function(t) { var e = t.cx,
n = void 0 === e ? 0 : e,
o = t.cy,
a = void 0 === o ? 0 : o,
i = t.r1,
s = t.r2,
r = t.padding,
c = { move: { x: n, y: a } }; return void 0 !== i && (c.r1 = { x: n + i / Math.sqrt(2), y: a + i / Math.sqrt(2) }), void 0 !== s && (c.r2 = { x: n + s / Math.sqrt(2), y: a + s / Math.sqrt(2) }), void 0 !== r && (c.padding = { x: n + i + r, y: a }), c },
b = function(t) { var o = t.group,
a = t.handles,
i = t.r,
s = void 0 === i ? 10 : i,
r = o.selectAll("circle.handle").data(a);
r.enter().append("circle").attr("class", "handle").attr("fill", "grey").attr("fill-opacity", .1).attr("cursor", "move").attr("stroke-dasharray", 5).attr("stroke", "grey").call(n.drag().container(e.select("g.annotations").node()).on("start", function(t) { return t.start && t.start(t) }).on("drag", function(t) { return t.drag && t.drag(t) }).on("end", function(t) { return t.end && t.end(t) })), o.selectAll("circle.handle").attr("cx", function(t) { return t.x }).attr("cy", function(t) { return t.y }).attr("r", function(t) { return t.r || s }).attr("class", function(t) { return "handle " + (t.className || "") }), r.exit().remove() },
x = function(t, e) { return "dynamic" !== t && "left" !== t && "right" !== t || (t = e < 0 ? "top" : "bottom"), t },
m = function(t, e) { return "dynamic" !== t && "top" !== t && "bottom" !== t || (t = e < 0 ? "right" : "left"), t },
j = ["topBottom", "top", "bottom"],
w = ["leftRight", "left", "right"],
_ = function(t) { var e = t.padding,
n = void 0 === e ? 0 : e,
o = t.bbox,
a = void 0 === o ? { x: 0, y: 0, width: 0, height: 0 } : o,
i = t.align,
s = t.orientation,
r = t.offset,
c = void 0 === r ? { x: 0, y: 0 } : r,
d = -a.x,
u = 0; return j.indexOf(s) !== -1 ? (i = m(i, c.x), c.y < 0 && "topBottom" === s || "top" === s ? u -= a.height + n : u += n, "middle" === i ? d -= a.width / 2 : "right" === i && (d -= a.width)) : w.indexOf(s) !== -1 && (i = x(i, c.y), c.x < 0 && "leftRight" === s || "left" === s ? d -= a.width + n : d += n, "middle" === i ? u -= a.height / 2 : "top" === i && (u -= a.height)), { x: d, y: u } },
k = function(t) { var e = t.data,
n = t.curve,
a = void 0 === n ? o.curveLinear : n,
i = t.canvasContext,
s = t.className,
r = t.classID,
c = o.line().curve(a),
d = { type: "path", className: s, classID: r, data: e }; return i ? (c.context(i), d.pathMethods = c) : d.attrs = { d: c(e) }, d },
O = function(t) { var e = t.data,
n = t.canvasContext,
a = t.className,
i = t.classID,
s = { type: "path", className: a, classID: i, data: e },
r = o.arc().innerRadius(e.innerRadius || 0).outerRadius(e.outerRadius || e.radius || 2).startAngle(e.startAngle || 0).endAngle(e.endAngle || 2 * Math.PI); return n ? (r.context(n), s.pathMethods = lineGen) : s.attrs = { d: r() }, s },
N = function(t) { var e = t.align,
n = t.x,
o = void 0 === n ? 0 : n,
a = t.y,
i = void 0 === a ? 0 : a,
s = t.bbox; return e = x(e, t.offset.y), "top" === e ? i -= s.height : "middle" === e && (i -= s.height / 2), { components: [k({ data: [
[o, i],
[o, i + s.height]
], className: "note-line" })] } },
M = function(t) { var e = t.align,
n = t.x,
o = void 0 === n ? 0 : n,
a = t.y,
i = void 0 === a ? 0 : a,
s = t.offset,
r = t.bbox; return e = m(e, s.x), "right" === e ? o -= r.width : "middle" === e && (o -= r.width / 2), { components: [k({ data: [
[o, i],
[o + r.width, i]
], className: "note-line" })] } },
S = function(t) { var e = t.type,
n = t.subjectType,
o = e.annotation,
a = o.position,
i = o.x - a.x,
s = i + o.dx,
r = o.y - a.y,
c = r + o.dy,
d = o.subject; if ("circle" === n && (d.outerRadius || d.radius)) { var u = Math.sqrt((i - s) * (i - s) + (r - c) * (r - c)),
h = Math.asin(-c / u),
l = d.outerRadius || d.radius + (d.radiusPadding || 0);
i = Math.abs(Math.cos(h) * l) * (s < 0 ? -1 : 1), r = Math.abs(Math.sin(h) * l) * (c < 0 ? -1 : 1) } if ("rect" === n) { var p = d.width,
y = d.height;
(p > 0 && o.dx > 0 || p < 0 && o.dx < 0) && (i = Math.abs(p) > Math.abs(o.dx) ? p / 2 : p), (y > 0 && o.dy > 0 || y < 0 && o.dy < 0) && (r = Math.abs(y) > Math.abs(o.dy) ? y / 2 : y), i === p / 2 && r === y / 2 && (i = s, r = c) } return [
[i, r],
[s, c]
] },
C = function(t) { return { components: [k({ data: S(t), className: "connector" })] } },
P = function(t) { var e = t.type,
n = t.subjectType,
o = e.annotation,
a = o.position,
i = o.x - a.x,
s = i + o.dx,
r = o.y - a.y,
c = r + o.dy,
d = o.subject; if ("rect" === n) { var u = d.width,
h = d.height;
(u > 0 && o.dx > 0 || u < 0 && o.dx < 0) && (i = Math.abs(u) > Math.abs(o.dx) ? u / 2 : u), (h > 0 && o.dy > 0 || h < 0 && o.dy < 0) && (r = Math.abs(h) > Math.abs(o.dy) ? h / 2 : h), i === u / 2 && r === h / 2 && (i = s, r = c) } var l = [
[i, r],
[s, c]
],
p = c - r,
y = s - i,
f = s,
v = c,
g = c < r && s > i || s < i && c > r ? -1 : 1; if (Math.abs(y) < Math.abs(p) ? (f = s, v = r + y * g) : (v = c, f = i + p * g), "circle" === n && (d.outerRadius || d.radius)) { var b = (d.outerRadius || d.radius) + (d.radiusPadding || 0),
x = b / Math.sqrt(2); if (Math.abs(y) > x && Math.abs(p) > x) i = x * (s < 0 ? -1 : 1), r = x * (c < 0 ? -1 : 1), l = [
[i, r],
[f, v],
[s, c]
];
else if (Math.abs(y) > Math.abs(p)) { var m = Math.asin(-c / b);
i = Math.abs(Math.cos(m) * b) * (s < 0 ? -1 : 1), l = [
[i, c],
[s, c]
] } else { var j = Math.acos(s / b);
r = Math.abs(Math.sin(j) * b) * (c < 0 ? -1 : 1), l = [
[s, r],
[s, c]
] } } else l = [
[i, r],
[f, v],
[s, c]
]; return { components: [k({ data: l, className: "connector" })] } },
T = function(t) { var n = t.type,
a = t.connectorData,
i = t.subjectType;
a || (a = {}), a.points && "number" != typeof a.points || (a.points = A(n.annotation.offset, a.points)), a.curve || (a.curve = o.curveCatmullRom); var s = []; if (n.editMode) { var r = a.points.map(function(t, e) { return d({}, v({ cx: t[0], cy: t[1] }), { index: e }) }),
c = function(t) { a.points[t][0] += e.event.dx, a.points[t][1] += e.event.dy, n.redrawConnector() };
s = n.mapHandles(r.map(function(t) { return d({}, t.move, { drag: c.bind(n, t.index) }) })) } var u = S({ type: n, subjectType: i }); return u = [u[0]].concat(p(a.points), [u[1]]), { components: [k({ data: u, curve: a.curve, className: "connector" })], handles: s } },
A = function(t) { for (var e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 2, n = { x: t.x / (e + 1), y: t.y / (e + 1) }, o = [], a = 1; a <= e; a++) o.push([n.x * a + a % 2 * 20, n.y * a - a % 2 * 20]); return o },
E = function(t) { var e = t.annotation,
n = t.start,
o = t.end,
a = t.scale,
i = void 0 === a ? 1 : a,
s = e.position;
n = n ? [-o[0] + n[0], -o[1] + n[1]] : [e.dx, e.dy], o || (o = [e.x - s.x, e.y - s.y]); var r = o[0],
c = o[1],
d = n[0],
u = n[1],
h = 10 * i,
l = 16 / 180 * Math.PI,
p = Math.atan(u / d); return d < 0 && (p += Math.PI), { components: [k({ data: [
[r, c],
[Math.cos(p + l) * h + r, Math.sin(p + l) * h + c],
[Math.cos(p - l) * h + r, Math.sin(p - l) * h + c],
[r, c]
], className: "connector-end connector-arrow", classID: "connector-end" })] } },
R = function(t) { var e = t.line,
n = t.scale,
o = void 0 === n ? 1 : n,
a = O({ className: "connector-end connector-dot", classID: "connector-end", data: { radius: 3 * Math.sqrt(o) } }); return a.attrs.transform = "translate(" + e.data[0][0] + ", " + e.data[0][1] + ")", { components: [a] } },
B = function(t) { var n = t.subjectData,
o = t.type;
n.radius || n.outerRadius || (n.radius = 20); var a = [],
i = O({ data: n, className: "subject" }); if (o.editMode) { var s = g({ r1: i.data.outerRadius || i.data.radius, r2: i.data.innerRadius, padding: n.radiusPadding }),
r = function(t) { var a = n[t] + e.event.dx * Math.sqrt(2);
n[t] = a, o.redrawSubject(), o.redrawConnector() },
c = [d({}, s.r1, { drag: r.bind(o, void 0 !== n.outerRadius ? "outerRadius" : "radius") })];
n.innerRadius && c.push(d({}, s.r2, { drag: r.bind(o, "innerRadius") })), a = o.mapHandles(c) } return i.attrs["fill-opacity"] = 0, { components: [i], handles: a } },
I = function(t) { var n = t.subjectData,
o = t.type;
n.width || (n.width = 100), n.height || (n.height = 100); var a = [],
i = n.width,
s = n.height,
r = [
[0, 0],
[i, 0],
[i, s],
[0, s],
[0, 0]
],
c = k({ data: r, className: "subject" }); if (o.editMode) { var d = function() { n.width = e.event.x, o.redrawSubject(), o.redrawConnector() },
u = function() { n.height = e.event.y, o.redrawSubject(), o.redrawConnector() },
h = [{ x: i, y: s / 2, drag: d.bind(o) }, { x: i / 2, y: s, drag: u.bind(o) }];
a = o.mapHandles(h) } return c.attrs["fill-opacity"] = .1, { components: [c], handles: a } },
q = function(t) { var e = t.subjectData,
n = t.type,
o = n.annotation.position,
a = (void 0 !== e.x1 ? e.x1 : o.x) - o.x,
i = (void 0 !== e.x2 ? e.x2 : o.x) - o.x; return { components: [k({ data: [
[a, (void 0 !== e.y1 ? e.y1 : o.y) - o.y],
[i, (void 0 !== e.y2 ? e.y2 : o.y) - o.y]
], className: "subject" })] } },
D = function(t) { var n = t.subjectData,
o = void 0 === n ? {} : n,
a = t.type,
i = void 0 === a ? {} : a,
s = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {},
r = i.typeSettings && i.typeSettings.subject;
o.radius || (r && r.radius ? o.radius = r.radius : o.radius = 14), o.x || r && r.x && (o.x = r.x), o.y || r && r.y && (o.y = r.y); var c = [],
d = [],
u = o.radius,
h = .7 * u,
l = 0,
p = 0,
y = Math.sqrt(2) * u,
f = { xleftcorner: -u, xrightcorner: u, ytopcorner: -u, ybottomcorner: u, xleft: -y, xright: y, ytop: -y, ybottom: y };
o.x && !o.y ? l = f["x" + o.x] : o.y && !o.x ? p = f["y" + o.y] : o.x && o.y && (l = f["x" + o.x + "corner"], p = f["y" + o.y + "corner"]); var v = "translate(" + l + ", " + p + ")",
g = O({ className: "subject", data: { radius: u } });
g.attrs.transform = v, g.attrs.fill = s.color, g.attrs["stroke-linecap"] = "round", g.attrs["stroke-width"] = "3px"; var b = O({ className: "subject-ring", data: { outerRadius: u, innerRadius: h } });
b.attrs.transform = v, b.attrs["stroke-width"] = "3px", b.attrs.fill = "white"; var x = void 0; if (l && p || !l && !p) x = k({ className: "subject-pointer", data: [
[0, 0],
[l || 0, 0],
[0, p || 0],
[0, 0]
] });
else if (l || p) { var m = function(t) { var e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 1; return t && t / Math.sqrt(2) / Math.sqrt(2) || e * u / Math.sqrt(2) };
x = k({ className: "subject-pointer", data: [
[0, 0],
[m(l), m(p)],
[m(l, -1), m(p, -1)],
[0, 0]
] }) } if (x && (x.attrs.fill = s.color, x.attrs["stroke-linecap"] = "round", x.attrs["stroke-width"] = "3px", d.push(x)), i.editMode) { var j = function() { o.x = e.event.x < 2 * -u ? "left" : e.event.x > 2 * u ? "right" : void 0, o.y = e.event.y < 2 * -u ? "top" : e.event.y > 2 * u ? "bottom" : void 0, i.redrawSubject() },
w = { x: 2 * l, y: 2 * p, drag: j.bind(i) };
w.x || w.y || (w.y = -u), c = i.mapHandles([w]) } var _ = void 0; return o.text && (_ = { type: "text", className: "badge-text", attrs: { fill: "white", stroke: "none", "font-size": ".7em", text: o.text, "text-anchor": "middle", dy: ".25em", x: l, y: p } }), d.push(g), d.push(b), d.push(_), { components: d, handles: c } },
W = function() {
function t(e) { var n = e.a,
o = e.annotation,
a = e.editMode,
i = e.dispatcher,
s = e.notePadding,
c = e.accessors; if (r(this, t), this.a = n, this.note = o.disable.indexOf("note") === -1 && n.select("g.annotation-note"), this.noteContent = this.note && n.select("g.annotation-note-content"), this.connector = o.disable.indexOf("connector") === -1 && n.select("g.annotation-connector"), this.subject = o.disable.indexOf("subject") === -1 && n.select("g.annotation-subject"), this.dispatcher = i, i) { var d = Z.bind(null, i, o);
d({ component: this.note, name: "note" }), d({ component: this.connector, name: "connector" }), d({ component: this.subject, name: "subject" }) } this.annotation = o, this.editMode = o.editMode || a, this.notePadding = void 0 !== s ? s : 3, this.offsetCornerX = 0, this.offsetCornerY = 0, c && o.data && this.init(c) } return c(t, [{ key: "init", value: function(t) { this.annotation.x || this.mapX(t), this.annotation.y || this.mapY(t) } }, { key: "mapY", value: function(t) { t.y && (this.annotation.y = t.y(this.annotation.data)) } }, { key: "mapX", value: function(t) { t.x && (this.annotation.x = t.x(this.annotation.data)) } }, { key: "updateEditMode", value: function() { this.a.selectAll("circle.handle").remove() } }, { key: "drawOnSVG", value: function(t, e) { var n = this;
Array.isArray(e) || (e = [e]), e.filter(function(t) { return t }).forEach(function(e) { var o = e.type,
a = e.className,
i = e.attrs,
s = e.handles,
r = e.classID; if ("handle" === o) b({ group: t, r: i && i.r, handles: s });
else { U(t, [n.annotation], o, a, r); for (var c = t.select(o + "." + (r || a)), d = Object.keys(i), u = [], h = c.node().attributes, l = h.length - 1; l >= 0; l--) { var p = h[l].name;
d.indexOf(p) === -1 && "class" !== p && u.push(p) } d.forEach(function(t) { "text" === t ? c.text(i[t]) : c.attr(t, i[t]) }), u.forEach(function(t) { return c.attr(t, null) }) } }) } }, { key: "getNoteBBox", value: function() { return tt(this.note, ".annotation-note-content text") } }, { key: "getNoteBBoxOffset", value: function() { var t = tt(this.note, ".annotation-note-content"),
e = this.noteContent.attr("transform").split(/\(|\,|\)/g); return t.offsetCornerX = parseFloat(e[1]) + this.annotation.dx, t.offsetCornerY = parseFloat(e[2]) + this.annotation.dy, t.offsetX = this.annotation.dx, t.offsetY = this.annotation.dy, t } }, { key: "drawSubject", value: function() { var t = this,
e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},
n = this.annotation.subject,
o = e.type,
a = { type: this, subjectData: n },
i = {}; "circle" === o ? i = B(a) : "rect" === o ? i = I(a) : "threshold" === o ? i = q(a) : "badge" === o && (i = D(a, this.annotation)); var s = i,
r = s.components,
c = void 0 === r ? [] : r,
d = s.handles,
u = void 0 === d ? [] : d; return c.forEach(function(e) { e && e.attrs && !e.attrs.stroke && (e.attrs.stroke = t.annotation.color) }), this.editMode && (u = u.concat(this.mapHandles([{ drag: this.dragSubject.bind(this) }])), c.push({ type: "handle", handles: u })), c } }, { key: "drawConnector", value: function() { var t = this,
e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},
n = this.annotation.connector,
o = n.type || e.type,
a = { type: this, connectorData: n };
a.subjectType = this.typeSettings && this.typeSettings.subject && this.typeSettings.subject.type; var i = {};
i = "curve" === o ? T(a) : "elbow" === o ? P(a) : C(a); var s = i,
r = s.components,
c = void 0 === r ? [] : r,
d = s.handles,
u = void 0 === d ? [] : d,
h = c[0];
h && (h.attrs.stroke = this.annotation.color, h.attrs.fill = "none"); var l = n.end || e.end,
p = {}; if ("arrow" === l) { var y = h.data[1],
f = h.data[0];
Math.sqrt(Math.pow(y[0] - f[0], 2) + Math.pow(y[1] - f[1], 2)) < 5 && h.data[2] && (y = h.data[2]), p = E({ annotation: this.annotation, start: y, end: f, scale: n.endScale }) } else "dot" === l ? p = R({ line: h, scale: n.endScale }) : l && "none" !== l || this.connector && this.connector.select(".connector-end").remove(); return p.components && (p.components.forEach(function(e) { e.attrs.fill = t.annotation.color, e.attrs.stroke = t.annotation.color }), c = c.concat(p.components)), this.editMode && 0 !== u.length && c.push({ type: "handle", handles: u }), c } }, { key: "drawNote", value: function() { var t = this,
o = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},
a = this.annotation.note,
i = a.align || o.align || "dynamic",
s = { bbox: o.bbox, align: i, offset: this.annotation.offset },
r = a.lineType || o.lineType,
c = {}; "vertical" === r ? c = N(s) : "horizontal" === r && (c = M(s)); var d = c,
u = d.components,
h = void 0 === u ? [] : u,
l = d.handles,
p = void 0 === l ? [] : l; if (h.forEach(function(e) { e.attrs.stroke = t.annotation.color }), this.editMode) { p = this.mapHandles([{ x: 0, y: 0, drag: this.dragNote.bind(this) }]), h.push({ type: "handle", handles: p }); var y = this.dragNote.bind(this),
f = this.dragstarted.bind(this),
v = this.dragended.bind(this);
this.note.call(n.drag().container(e.select("g.annotations").node()).on("start", function(t) { return f(t) }).on("drag", function(t) { return y(t) }).on("end", function(t) { return v(t) })) } else this.note.on("mousedown.drag", null); return h } }, { key: "drawNoteContent", value: function(t) { var e = this.annotation.note,
n = void 0 !== e.padding ? e.padding : this.notePadding,
o = e.orientation || t.orientation || "topBottom",
a = e.lineType || t.lineType,
i = e.align || t.align || "dynamic"; "vertical" === a ? o = "leftRight" : "horizontal" === a && (o = "topBottom"); var s = { padding: n, bbox: t.bbox, offset: this.annotation.offset, orientation: o, align: i },
r = _(s),
c = r.x,
d = r.y; return this.offsetCornerX = c + this.annotation.dx, this.offsetCornerY = d + this.annotation.dy, this.note && this.noteContent.attr("transform", "translate(" + c + ", " + d + ")"), [] } }, { key: "drawOnScreen", value: function(t, e) { return this.drawOnSVG(t, e) } }, { key: "redrawSubject", value: function() { this.subject && this.drawOnScreen(this.subject, this.drawSubject()) } }, { key: "redrawConnector", value: function() { this.connector && this.drawOnScreen(this.connector, this.drawConnector()) } }, { key: "redrawNote", value: function() { var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : this.getNoteBBox();
this.noteContent && this.drawOnScreen(this.noteContent, this.drawNoteContent({ bbox: t })), this.note && this.drawOnScreen(this.note, this.drawNote({ bbox: t })) } }, { key: "setPosition", value: function() { var t = this.annotation.position;
this.a.attr("transform", "translate(" + t.x + ", " + t.y + ")") } }, { key: "setOffset", value: function() { if (this.note) { var t = this.annotation.offset;
this.note.attr("transform", "translate(" + t.x + ", " + t.y + ")") } } }, { key: "setPositionWithAccessors", value: function(t) { t && this.annotation.data && (this.mapX(t), this.mapY(t)), this.setPosition() } }, { key: "setClassName", value: function() { this.a.attr("class", "annotation " + (this.className && this.className()) + " " + (this.editMode ? "editable" : "") + " " + (this.annotation.className || "")) } }, { key: "draw", value: function() { this.setClassName(), this.setPosition(), this.setOffset(), this.redrawSubject(), this.redrawConnector(), this.redrawNote() } }, { key: "dragstarted", value: function() { e.event.sourceEvent.stopPropagation(), this.dispatcher && this.dispatcher.call("dragstart", this.a, this.annotation), this.a.classed("dragging", !0), this.a.selectAll("circle.handle").style("pointer-events", "none") } }, { key: "dragended", value: function() { this.dispatcher && this.dispatcher.call("dragend", this.a, this.annotation), this.a.classed("dragging", !1), this.a.selectAll("circle.handle").style("pointer-events", "all") } }, { key: "dragSubject", value: function() { var t = this.annotation.position;
t.x += e.event.dx, t.y += e.event.dy, this.annotation.position = t } }, { key: "dragNote", value: function() { var t = this.annotation.offset;
t.x += e.event.dx, t.y += e.event.dy, this.annotation.offset = t } }, { key: "mapHandles", value: function(t) { var e = this; return t.map(function(t) { return d({}, t, { start: e.dragstarted.bind(e), end: e.dragended.bind(e) }) }) } }]), t }(),
X = function(t, e, n) { return function(t) {
function o(t) { r(this, o); var n = l(this, (o.__proto__ || Object.getPrototypeOf(o)).call(this, t)); return n.typeSettings = e, e.disable && e.disable.forEach(function(t) { n[t] && n[t].remove(), n[t] = void 0, "note" === t && (n.noteContent = void 0) }), n } return h(o, t), c(o, [{ key: "className", value: function() { return "" + (e.className || u(o.prototype.__proto__ || Object.getPrototypeOf(o.prototype), "className", this) && u(o.prototype.__proto__ || Object.getPrototypeOf(o.prototype), "className", this).call(this) || "") } }, { key: "drawSubject", value: function(t) { return this.typeSettings.subject = d({}, e.subject, this.typeSettings.subject), u(o.prototype.__proto__ || Object.getPrototypeOf(o.prototype), "drawSubject", this).call(this, d({}, t, this.typeSettings.subject)) } }, { key: "drawConnector", value: function(t) { return this.typeSettings.connector = d({}, e.connector, this.typeSettings.connector), u(o.prototype.__proto__ || Object.getPrototypeOf(o.prototype), "drawConnector", this).call(this, d({}, t, e.connector, this.typeSettings.connector)) } }, { key: "drawNote", value: function(t) { return this.typeSettings.note = d({}, e.note, this.typeSettings.note), u(o.prototype.__proto__ || Object.getPrototypeOf(o.prototype), "drawNote", this).call(this, d({}, t, e.note, this.typeSettings.note)) } }, { key: "drawNoteContent", value: function(t) { return u(o.prototype.__proto__ || Object.getPrototypeOf(o.prototype), "drawNoteContent", this).call(this, d({}, t, e.note, this.typeSettings.note)) } }], [{ key: "init", value: function(t, e) { return u(o.__proto__ || Object.getPrototypeOf(o), "init", this).call(this, t, e), n && (t = n(t, e)), t } }]), o }(t) },
Y = function(t) {
function e(t) { r(this, e); var n = l(this, (e.__proto__ || Object.getPrototypeOf(e)).call(this, t)); return n.textWrap = t.textWrap || 120, n.drawText(), n } return h(e, t), c(e, [{ key: "updateTextWrap", value: function(t) { this.textWrap = t, this.drawText() } }, { key: "drawText", value: function() { if (this.note) { U(this.note, [this.annotation], "g", "annotation-note-content"); var t = this.note.select("g.annotation-note-content");
U(t, [this.annotation], "rect", "annotation-note-bg"), U(t, [this.annotation], "text", "annotation-note-label"), U(t, [this.annotation], "text", "annotation-note-title"); var e = { height: 0 },
n = this.a.select("text.annotation-note-label"),
o = this.annotation.note && this.annotation.note.wrap || this.typeSettings && this.typeSettings.note && this.typeSettings.note.wrap || this.textWrap,
a = this.annotation.note && this.annotation.note.wrapSplitter || this.typeSettings && this.typeSettings.note && this.typeSettings.note.wrapSplitter,
i = this.annotation.note && this.annotation.note.bgPadding || this.typeSettings && this.typeSettings.note && this.typeSettings.note.bgPadding,
r = { top: 0, bottom: 0, left: 0, right: 0 }; if ("number" == typeof i ? r = { top: i, bottom: i, left: i, right: i } : i && "object" === (void 0 === i ? "undefined" : s(i)) && (r = d(r, i)), this.annotation.note.title) { var c = this.a.select("text.annotation-note-title");
c.text(this.annotation.note.title), c.attr("fill", this.annotation.color), c.attr("font-weight", "bold"), c.call($, o, a), e = c.node().getBBox() } n.text(this.annotation.note.label).attr("dx", "0"), n.call($, o, a), n.attr("y", 1.1 * e.height || 0), n.attr("fill", this.annotation.color); var u = this.getNoteBBox();
this.a.select("rect.annotation-note-bg").attr("width", u.width + r.left + r.right).attr("height", u.height + r.top + r.bottom).attr("x", u.x - r.left).attr("y", -r.top).attr("fill", "white").attr("fill-opacity", 0) } } }]), e }(W),
H = X(Y, { className: "label", note: { align: "middle" }, disable: ["subject"] }),
z = X(Y, { className: "callout", note: { lineType: "horizontal" }, disable: ["subject"] }),
F = X(z, { className: "callout elbow", connector: { type: "elbow" }, disable: ["subject"] }),
J = X(z, { className: "callout curve", connector: { type: "curve" }, disable: ["subject"] }),
L = X(W, { className: "badge", subject: { type: "badge" }, disable: ["connector", "note"] }),
G = X(Y, { className: "callout circle", subject: { type: "circle" }, note: { lineType: "horizontal" }, connector: { type: "elbow" } }),
V = X(Y, { className: "callout rect", subject: { type: "rect" }, note: { lineType: "horizontal" }, connector: { type: "elbow" } }),
K = function(t) {
function e() { return r(this, e), l(this, (e.__proto__ || Object.getPrototypeOf(e)).apply(this, arguments)) } return h(e, t), c(e, [{ key: "mapY", value: function(t) { u(e.prototype.__proto__ || Object.getPrototypeOf(e.prototype), "mapY", this).call(this, t); var n = this.annotation;
(n.subject.x1 || n.subject.x2) && n.data && t.y && (n.y = t.y(n.data)), !n.subject.x1 && !n.subject.x2 || n.x || (n.x = n.subject.x1 || n.subject.x2) } }, { key: "mapX", value: function(t) { u(e.prototype.__proto__ || Object.getPrototypeOf(e.prototype), "mapX", this).call(this, t); var n = this.annotation;
(n.subject.y1 || n.subject.y2) && n.data && t.x && (n.x = t.x(n.data)), !n.subject.y1 && !n.subject.y2 || n.y || (n.y = n.subject.y1 || n.subject.y2) } }]), e }(z),
Q = X(K, { className: "callout xythreshold", subject: { type: "threshold" } }),
U = function(t, e, n, o, a) { var i = t.selectAll(n + "." + (a || o)).data(e); return i.enter().append(n).merge(i).attr("class", o), i.exit().remove(), t },
Z = function(t, e, n) { var o = n.component,
a = n.name;
o && o.on("mouseover.annotations", function() { t.call(a + "over", o, e) }).on("mouseout.annotations", function() { return t.call(a + "out", o, e) }).on("click.annotations", function() { return t.call(a + "click", o, e) }) },
$ = function(t, n, o) { var a = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : 1.2;
t.each(function() { for (var t = e.select(this), i = t.text().split(o || /[ \t\r\n]+/).reverse().filter(function(t) { return "" !== t }), s = void 0, r = [], c = t.text(null).append("tspan").attr("x", 0).attr("dy", "0.8em"); s = i.pop();) r.push(s), c.text(r.join(" ")), c.node().getComputedTextLength() > n && r.length > 1 && (r.pop(), c.text(r.join(" ")), r = [s], c = t.append("tspan").attr("x", 0).attr("dy", a + "em").text(s)) }) },
tt = function(t) { var e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : ":not(.handle)"; return t ? t.selectAll(e).nodes().reduce(function(t, e) { var n = e.getBBox();
t.x = Math.min(t.x, n.x), t.y = Math.min(t.y, n.y), t.width = Math.max(t.width, n.width); var o = e && e.attributes && e.attributes.y; return t.height = Math.max(t.height, (o && parseFloat(o.value) || 0) + n.height), t }, { x: 0, y: 0, width: 0, height: 0 }) : { x: 0, y: 0, width: 0, height: 0 } },
et = { annotation: i, annotationTypeBase: W, annotationLabel: H, annotationCallout: z, annotationCalloutCurve: J, annotationCalloutElbow: F, annotationCalloutCircle: G, annotationCalloutRect: V, annotationXYThreshold: Q, annotationBadge: L, annotationCustomType: X };
t.annotation = i, t.annotationTypeBase = W, t.annotationLabel = H, t.annotationCallout = z, t.annotationCalloutCurve = J, t.annotationCalloutElbow = F, t.annotationCalloutCircle = G, t.annotationCalloutRect = V, t.annotationXYThreshold = Q, t.annotationBadge = L, t.annotationCustomType = X, t.default = et, Object.defineProperty(t, "__esModule", { value: !0 }) });
// https://github.com/d3/d3-selection-multi Version 1.0.1. Copyright 2017 Mike Bostock.
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('d3-selection'), require('d3-transition')) :
typeof define === 'function' && define.amd ? define(['d3-selection', 'd3-transition'], factory) :
(factory(global.d3,global.d3));
}(this, (function (d3Selection,d3Transition) { 'use strict';
function attrsFunction(selection$$1, map) {
return selection$$1.each(function() {
var x = map.apply(this, arguments), s = d3Selection.select(this);
for (var name in x) s.attr(name, x[name]);
});
}
function attrsObject(selection$$1, map) {
for (var name in map) selection$$1.attr(name, map[name]);
return selection$$1;
}
var selection_attrs = function(map) {
return (typeof map === "function" ? attrsFunction : attrsObject)(this, map);
};
function stylesFunction(selection$$1, map, priority) {
return selection$$1.each(function() {
var x = map.apply(this, arguments), s = d3Selection.select(this);
for (var name in x) s.style(name, x[name], priority);
});
}
function stylesObject(selection$$1, map, priority) {
for (var name in map) selection$$1.style(name, map[name], priority);
return selection$$1;
}
var selection_styles = function(map, priority) {
return (typeof map === "function" ? stylesFunction : stylesObject)(this, map, priority == null ? "" : priority);
};
function propertiesFunction(selection$$1, map) {
return selection$$1.each(function() {
var x = map.apply(this, arguments), s = d3Selection.select(this);
for (var name in x) s.property(name, x[name]);
});
}
function propertiesObject(selection$$1, map) {
for (var name in map) selection$$1.property(name, map[name]);
return selection$$1;
}
var selection_properties = function(map) {
return (typeof map === "function" ? propertiesFunction : propertiesObject)(this, map);
};
function attrsFunction$1(transition$$1, map) {
return transition$$1.each(function() {
var x = map.apply(this, arguments), t = d3Selection.select(this).transition(transition$$1);
for (var name in x) t.attr(name, x[name]);
});
}
function attrsObject$1(transition$$1, map) {
for (var name in map) transition$$1.attr(name, map[name]);
return transition$$1;
}
var transition_attrs = function(map) {
return (typeof map === "function" ? attrsFunction$1 : attrsObject$1)(this, map);
};
function stylesFunction$1(transition$$1, map, priority) {
return transition$$1.each(function() {
var x = map.apply(this, arguments), t = d3Selection.select(this).transition(transition$$1);
for (var name in x) t.style(name, x[name], priority);
});
}
function stylesObject$1(transition$$1, map, priority) {
for (var name in map) transition$$1.style(name, map[name], priority);
return transition$$1;
}
var transition_styles = function(map, priority) {
return (typeof map === "function" ? stylesFunction$1 : stylesObject$1)(this, map, priority == null ? "" : priority);
};
d3Selection.selection.prototype.attrs = selection_attrs;
d3Selection.selection.prototype.styles = selection_styles;
d3Selection.selection.prototype.properties = selection_properties;
d3Transition.transition.prototype.attrs = transition_attrs;
d3Transition.transition.prototype.styles = transition_styles;
})));
// https://github.com/d3/d3-selection-multi Version 1.0.1. Copyright 2017 Mike Bostock.
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(require("d3-selection"),require("d3-transition")):"function"==typeof define&&define.amd?define(["d3-selection","d3-transition"],n):n(t.d3,t.d3)}(this,function(t,n){"use strict";function r(n,r){return n.each(function(){var n=r.apply(this,arguments),e=t.select(this);for(var i in n)e.attr(i,n[i])})}function e(t,n){for(var r in n)t.attr(r,n[r]);return t}function i(n,r,e){return n.each(function(){var n=r.apply(this,arguments),i=t.select(this);for(var o in n)i.style(o,n[o],e)})}function o(t,n,r){for(var e in n)t.style(e,n[e],r);return t}function f(n,r){return n.each(function(){var n=r.apply(this,arguments),e=t.select(this);for(var i in n)e.property(i,n[i])})}function u(t,n){for(var r in n)t.property(r,n[r]);return t}function s(n,r){return n.each(function(){var e=r.apply(this,arguments),i=t.select(this).transition(n);for(var o in e)i.attr(o,e[o])})}function c(t,n){for(var r in n)t.attr(r,n[r]);return t}function a(n,r,e){return n.each(function(){var i=r.apply(this,arguments),o=t.select(this).transition(n);for(var f in i)o.style(f,i[f],e)})}function p(t,n,r){for(var e in n)t.style(e,n[e],r);return t}var l=function(t){return("function"==typeof t?r:e)(this,t)},y=function(t,n){return("function"==typeof t?i:o)(this,t,null==n?"":n)},h=function(t){return("function"==typeof t?f:u)(this,t)},v=function(t){return("function"==typeof t?s:c)(this,t)},d=function(t,n){return("function"==typeof t?a:p)(this,t,null==n?"":n)};t.selection.prototype.attrs=l,t.selection.prototype.styles=y,t.selection.prototype.properties=h,n.transition.prototype.attrs=v,n.transition.prototype.styles=d});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("d3-array"),require("d3-axis"),require("d3-dispatch"),require("d3-drag"),require("d3-ease"),require("d3-scale"),require("d3-selection")):"function"==typeof define&&define.amd?define(["exports","d3-array","d3-axis","d3-dispatch","d3-drag","d3-ease","d3-scale","d3-selection"],e):e(t.d3=t.d3||{},t.d3,t.d3,t.d3,t.d3,t.d3,t.d3,t.d3)}(this,function(t,e,a,r,n,l,i,s){"use strict";function c(){function t(t){z=t.selection?t.selection():t,M=v[0]instanceof Date?i.scaleTime():i.scaleLinear(),M=M.domain(v).range([0,h]).clamp(!0),D=i.scaleLinear().range(M.range()).domain(M.range()).clamp(!0),p=i.scaleLinear().range(v).domain(v).clamp(!0)(p),q=q||M.tickFormat(),z.selectAll(".axis").data([null]).enter().append("g").attr("transform","translate(0,7)").attr("class","axis");var e=z.selectAll(".slider").data([null]),r=e.enter().append("g").attr("class","slider").attr("cursor","ew-resize").attr("transform","translate(0,0)").call(n.drag().on("start",function(){s.select(this).classed("active",!0);var t=D(s.event.x),a=u(M.invert(t));f(a),A.call("start",e,a),d(a)}).on("drag",function(){var t=D(s.event.x),a=u(M.invert(t));f(a),A.call("drag",e,a),d(a)}).on("end",function(){s.select(this).classed("active",!1);var t=D(s.event.x),a=u(M.invert(t));f(a),A.call("end",e,a),d(a)}));r.append("line").attr("class","track").attr("x1",0).attr("y1",0).attr("y2",0).attr("stroke","#bbb").attr("stroke-width",6).attr("stroke-linecap","round"),r.append("line").attr("class","track-inset").attr("x1",0).attr("y1",0).attr("y2",0).attr("stroke","#eee").attr("stroke-width",4).attr("stroke-linecap","round"),r.append("line").attr("class","track-overlay").attr("x1",0).attr("y1",0).attr("y2",0).attr("stroke","transparent").attr("stroke-width",40).attr("stroke-linecap","round").merge(e.select(".track-overlay"));var l=r.append("g").attr("class","parameter-value").attr("transform","translate("+M(p)+",0)").attr("font-family","sans-serif").attr("text-anchor","middle");l.append("path").attr("d",x).attr("fill","white").attr("stroke","#777"),g&&l.append("text").attr("font-size",30).attr("y",27).attr("dy",".71em").text(q(p)),t.select(".track").attr("x2",M.range()[1]),t.select(".track-inset").attr("x2",M.range()[1]),t.select(".track-overlay").attr("x2",M.range()[1]),t.select(".axis").call(a.axisBottom(M).tickFormat(q).ticks(w).tickValues(y)),z.select(".axis").select(".domain").remove(),t.select(".axis").attr("transform","translate(0,7)"),t.selectAll(".axis text").attr("fill","#aaa").attr("y",20).attr("dy",".71em").attr("text-anchor","middle"),t.selectAll(".axis line").attr("stroke","#aaa"),t.select(".parameter-value").attr("transform","translate("+M(p)+",0)"),c()}function c(){if(g){var t=[];z.selectAll(".axis .tick").each(function(e){t.push(Math.abs(e-p))});var a=e.scan(t);z.selectAll(".axis .tick text").attr("opacity",function(t,e){return e===a?0:1})}}function u(t){if(k){var a=(t-v[0])%k,r=t-a;return 2*a>k&&(r+=k),t instanceof Date?new Date(r):r}if(b){var n=e.scan(b.map(function(e){return Math.abs(t-e)}));return b[n]}return t}function d(e){p!==e&&(p=e,A.call("onchange",t,e),c())}function f(t,e){e=void 0!==e&&e;var a=z.select(".parameter-value");e&&(a=a.transition().ease(l.easeQuadOut).duration(o)),a.attr("transform","translate("+M(t)+",0)"),g&&z.select(".parameter-value text").text(q(t))}var p=0,m=0,v=[0,10],h=100,g=!0,x="M-5.5,-5.5v10l6,5.5l6,-5.5v-10z",k=null,y=null,b=null,q=null,w=null,A=r.dispatch("onchange","start","end","drag"),z=null,M=null,D=null;return t.min=function(e){return arguments.length?(v[0]=e,t):v[0]},t.max=function(e){return arguments.length?(v[1]=e,t):v[1]},t.domain=function(e){return arguments.length?(v=e,t):v},t.width=function(e){return arguments.length?(h=e,t):h},t.tickFormat=function(e){return arguments.length?(q=e,t):q},t.ticks=function(e){return arguments.length?(w=e,t):w},t.value=function(e){if(!arguments.length)return p;var a=D(M(e)),r=u(M.invert(a));return f(r,!0),d(r),t},t.default=function(e){return arguments.length?(m=e,p=e,t):m},t.step=function(e){return arguments.length?(k=e,t):k},t.tickValues=function(e){return arguments.length?(y=e,t):y},t.marks=function(e){return arguments.length?(b=e,t):b},t.handle=function(e){return arguments.length?(x=e,t):x},t.displayValue=function(e){return arguments.length?(g=e,t):g},t.on=function(){var e=A.on.apply(A,arguments);return e===A?t:e},t}var o=200;t.sliderHorizontal=function(){return c()},Object.defineProperty(t,"__esModule",{value:!0})});
// https://d3js.org Version 4.11.0. Copyright 2017 Mike Bostock.
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.d3 = global.d3 || {})));
}(this, (function (exports) { 'use strict';
var version = "4.11.0";
var ascending = function(a, b) {
return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
};
var bisector = function(compare) {
if (compare.length === 1) compare = ascendingComparator(compare);
return {
left: function(a, x, lo, hi) {
if (lo == null) lo = 0;
if (hi == null) hi = a.length;
while (lo < hi) {
var mid = lo + hi >>> 1;
if (compare(a[mid], x) < 0) lo = mid + 1;
else hi = mid;
}
return lo;
},
right: function(a, x, lo, hi) {
if (lo == null) lo = 0;
if (hi == null) hi = a.length;
while (lo < hi) {
var mid = lo + hi >>> 1;
if (compare(a[mid], x) > 0) hi = mid;
else lo = mid + 1;
}
return lo;
}
};
};
function ascendingComparator(f) {
return function(d, x) {
return ascending(f(d), x);
};
}
var ascendingBisect = bisector(ascending);
var bisectRight = ascendingBisect.right;
var bisectLeft = ascendingBisect.left;
var pairs = function(array, f) {
if (f == null) f = pair;
var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
while (i < n) pairs[i] = f(p, p = array[++i]);
return pairs;
};
function pair(a, b) {
return [a, b];
}
var cross = function(values0, values1, reduce) {
var n0 = values0.length,
n1 = values1.length,
values = new Array(n0 * n1),
i0,
i1,
i,
value0;
if (reduce == null) reduce = pair;
for (i0 = i = 0; i0 < n0; ++i0) {
for (value0 = values0[i0], i1 = 0; i1 < n1; ++i1, ++i) {
values[i] = reduce(value0, values1[i1]);
}
}
return values;
};
var descending = function(a, b) {
return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
};
var number = function(x) {
return x === null ? NaN : +x;
};
var variance = function(values, valueof) {
var n = values.length,
m = 0,
i = -1,
mean = 0,
value,
delta,
sum = 0;
if (valueof == null) {
while (++i < n) {
if (!isNaN(value = number(values[i]))) {
delta = value - mean;
mean += delta / ++m;
sum += delta * (value - mean);
}
}
}
else {
while (++i < n) {
if (!isNaN(value = number(valueof(values[i], i, values)))) {
delta = value - mean;
mean += delta / ++m;
sum += delta * (value - mean);
}
}
}
if (m > 1) return sum / (m - 1);
};
var deviation = function(array, f) {
var v = variance(array, f);
return v ? Math.sqrt(v) : v;
};
var extent = function(values, valueof) {
var n = values.length,
i = -1,
value,
min,
max;
if (valueof == null) {
while (++i < n) { // Find the first comparable value.
if ((value = values[i]) != null && value >= value) {
min = max = value;
while (++i < n) { // Compare the remaining values.
if ((value = values[i]) != null) {
if (min > value) min = value;
if (max < value) max = value;
}
}
}
}
}
else {
while (++i < n) { // Find the first comparable value.
if ((value = valueof(values[i], i, values)) != null && value >= value) {
min = max = value;
while (++i < n) { // Compare the remaining values.
if ((value = valueof(values[i], i, values)) != null) {
if (min > value) min = value;
if (max < value) max = value;
}
}
}
}
}
return [min, max];
};
var array = Array.prototype;
var slice = array.slice;
var map = array.map;
var constant = function(x) {
return function() {
return x;
};
};
var identity = function(x) {
return x;
};
var sequence = function(start, stop, step) {
start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
var i = -1,
n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
range = new Array(n);
while (++i < n) {
range[i] = start + i * step;
}
return range;
};
var e10 = Math.sqrt(50);
var e5 = Math.sqrt(10);
var e2 = Math.sqrt(2);
var ticks = function(start, stop, count) {
var reverse,
i = -1,
n,
ticks,
step;
stop = +stop, start = +start, count = +count;
if (start === stop && count > 0) return [start];
if (reverse = stop < start) n = start, start = stop, stop = n;
if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) return [];
if (step > 0) {
start = Math.ceil(start / step);
stop = Math.floor(stop / step);
ticks = new Array(n = Math.ceil(stop - start + 1));
while (++i < n) ticks[i] = (start + i) * step;
} else {
start = Math.floor(start * step);
stop = Math.ceil(stop * step);
ticks = new Array(n = Math.ceil(start - stop + 1));
while (++i < n) ticks[i] = (start - i) / step;
}
if (reverse) ticks.reverse();
return ticks;
};
function tickIncrement(start, stop, count) {
var step = (stop - start) / Math.max(0, count),
power = Math.floor(Math.log(step) / Math.LN10),
error = step / Math.pow(10, power);
return power >= 0
? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
: -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
}
function tickStep(start, stop, count) {
var step0 = Math.abs(stop - start) / Math.max(0, count),
step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
error = step0 / step1;
if (error >= e10) step1 *= 10;
else if (error >= e5) step1 *= 5;
else if (error >= e2) step1 *= 2;
return stop < start ? -step1 : step1;
}
var sturges = function(values) {
return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
};
var histogram = function() {
var value = identity,
domain = extent,
threshold = sturges;
function histogram(data) {
var i,
n = data.length,
x,
values = new Array(n);
for (i = 0; i < n; ++i) {
values[i] = value(data[i], i, data);
}
var xz = domain(values),
x0 = xz[0],
x1 = xz[1],
tz = threshold(values, x0, x1);
// Convert number of thresholds into uniform thresholds.
if (!Array.isArray(tz)) {
tz = tickStep(x0, x1, tz);
tz = sequence(Math.ceil(x0 / tz) * tz, Math.floor(x1 / tz) * tz, tz); // exclusive
}
// Remove any thresholds outside the domain.
var m = tz.length;
while (tz[0] <= x0) tz.shift(), --m;
while (tz[m - 1] > x1) tz.pop(), --m;
var bins = new Array(m + 1),
bin;
// Initialize bins.
for (i = 0; i <= m; ++i) {
bin = bins[i] = [];
bin.x0 = i > 0 ? tz[i - 1] : x0;
bin.x1 = i < m ? tz[i] : x1;
}
// Assign data to bins by value, ignoring any outside the domain.
for (i = 0; i < n; ++i) {
x = values[i];
if (x0 <= x && x <= x1) {
bins[bisectRight(tz, x, 0, m)].push(data[i]);
}
}
return bins;
}
histogram.value = function(_) {
return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
};
histogram.domain = function(_) {
return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
};
histogram.thresholds = function(_) {
return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
};
return histogram;
};
var threshold = function(values, p, valueof) {
if (valueof == null) valueof = number;
if (!(n = values.length)) return;
if ((p = +p) <= 0 || n < 2) return +valueof(values[0], 0, values);
if (p >= 1) return +valueof(values[n - 1], n - 1, values);
var n,
i = (n - 1) * p,
i0 = Math.floor(i),
value0 = +valueof(values[i0], i0, values),
value1 = +valueof(values[i0 + 1], i0 + 1, values);
return value0 + (value1 - value0) * (i - i0);
};
var freedmanDiaconis = function(values, min, max) {
values = map.call(values, number).sort(ascending);
return Math.ceil((max - min) / (2 * (threshold(values, 0.75) - threshold(values, 0.25)) * Math.pow(values.length, -1 / 3)));
};
var scott = function(values, min, max) {
return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
};
var max = function(values, valueof) {
var n = values.length,
i = -1,
value,
max;
if (valueof == null) {
while (++i < n) { // Find the first comparable value.
if ((value = values[i]) != null && value >= value) {
max = value;
while (++i < n) { // Compare the remaining values.
if ((value = values[i]) != null && value > max) {
max = value;
}
}
}
}
}
else {
while (++i < n) { // Find the first comparable value.
if ((value = valueof(values[i], i, values)) != null && value >= value) {
max = value;
while (++i < n) { // Compare the remaining values.
if ((value = valueof(values[i], i, values)) != null && value > max) {
max = value;
}
}
}
}
}
return max;
};
var mean = function(values, valueof) {
var n = values.length,
m = n,
i = -1,
value,
sum = 0;
if (valueof == null) {
while (++i < n) {
if (!isNaN(value = number(values[i]))) sum += value;
else --m;
}
}
else {
while (++i < n) {
if (!isNaN(value = number(valueof(values[i], i, values)))) sum += value;
else --m;
}
}
if (m) return sum / m;
};
var median = function(values, valueof) {
var n = values.length,
i = -1,
value,
numbers = [];
if (valueof == null) {
while (++i < n) {
if (!isNaN(value = number(values[i]))) {
numbers.push(value);
}
}
}
else {
while (++i < n) {
if (!isNaN(value = number(valueof(values[i], i, values)))) {
numbers.push(value);
}
}
}
return threshold(numbers.sort(ascending), 0.5);
};
var merge = function(arrays) {
var n = arrays.length,
m,
i = -1,
j = 0,
merged,
array;
while (++i < n) j += arrays[i].length;
merged = new Array(j);
while (--n >= 0) {
array = arrays[n];
m = array.length;
while (--m >= 0) {
merged[--j] = array[m];
}
}
return merged;
};
var min = function(values, valueof) {
var n = values.length,
i = -1,
value,
min;
if (valueof == null) {
while (++i < n) { // Find the first comparable value.
if ((value = values[i]) != null && value >= value) {
min = value;
while (++i < n) { // Compare the remaining values.
if ((value = values[i]) != null && min > value) {
min = value;
}
}
}
}
}
else {
while (++i < n) { // Find the first comparable value.
if ((value = valueof(values[i], i, values)) != null && value >= value) {
min = value;
while (++i < n) { // Compare the remaining values.
if ((value = valueof(values[i], i, values)) != null && min > value) {
min = value;
}
}
}
}
}
return min;
};
var permute = function(array, indexes) {
var i = indexes.length, permutes = new Array(i);
while (i--) permutes[i] = array[indexes[i]];
return permutes;
};
var scan = function(values, compare) {
if (!(n = values.length)) return;
var n,
i = 0,
j = 0,
xi,
xj = values[j];
if (compare == null) compare = ascending;
while (++i < n) {
if (compare(xi = values[i], xj) < 0 || compare(xj, xj) !== 0) {
xj = xi, j = i;
}
}
if (compare(xj, xj) === 0) return j;
};
var shuffle = function(array, i0, i1) {
var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
t,
i;
while (m) {
i = Math.random() * m-- | 0;
t = array[m + i0];
array[m + i0] = array[i + i0];
array[i + i0] = t;
}
return array;
};
var sum = function(values, valueof) {
var n = values.length,
i = -1,
value,
sum = 0;
if (valueof == null) {
while (++i < n) {
if (value = +values[i]) sum += value; // Note: zero and null are equivalent.
}
}
else {
while (++i < n) {
if (value = +valueof(values[i], i, values)) sum += value;
}
}
return sum;
};
var transpose = function(matrix) {
if (!(n = matrix.length)) return [];
for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
row[j] = matrix[j][i];
}
}
return transpose;
};
function length(d) {
return d.length;
}
var zip = function() {
return transpose(arguments);
};
var slice$1 = Array.prototype.slice;
var identity$1 = function(x) {
return x;
};
var top = 1;
var right = 2;
var bottom = 3;
var left = 4;
var epsilon = 1e-6;
function translateX(x) {
return "translate(" + (x + 0.5) + ",0)";
}
function translateY(y) {
return "translate(0," + (y + 0.5) + ")";
}
function number$1(scale) {
return function(d) {
return +scale(d);
};
}
function center(scale) {
var offset = Math.max(0, scale.bandwidth() - 1) / 2; // Adjust for 0.5px offset.
if (scale.round()) offset = Math.round(offset);
return function(d) {
return +scale(d) + offset;
};
}
function entering() {
return !this.__axis;
}
function axis(orient, scale) {
var tickArguments = [],
tickValues = null,
tickFormat = null,
tickSizeInner = 6,
tickSizeOuter = 6,
tickPadding = 3,
k = orient === top || orient === left ? -1 : 1,
x = orient === left || orient === right ? "x" : "y",
transform = orient === top || orient === bottom ? translateX : translateY;
function axis(context) {
var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,
format = tickFormat == null ? (scale.tickFormat ? scale.tickFormat.apply(scale, tickArguments) : identity$1) : tickFormat,
spacing = Math.max(tickSizeInner, 0) + tickPadding,
range = scale.range(),
range0 = +range[0] + 0.5,
range1 = +range[range.length - 1] + 0.5,
position = (scale.bandwidth ? center : number$1)(scale.copy()),
selection = context.selection ? context.selection() : context,
path = selection.selectAll(".domain").data([null]),
tick = selection.selectAll(".tick").data(values, scale).order(),
tickExit = tick.exit(),
tickEnter = tick.enter().append("g").attr("class", "tick"),
line = tick.select("line"),
text = tick.select("text");
path = path.merge(path.enter().insert("path", ".tick")
.attr("class", "domain")
.attr("stroke", "#000"));
tick = tick.merge(tickEnter);
line = line.merge(tickEnter.append("line")
.attr("stroke", "#000")
.attr(x + "2", k * tickSizeInner));
text = text.merge(tickEnter.append("text")
.attr("fill", "#000")
.attr(x, k * spacing)
.attr("dy", orient === top ? "0em" : orient === bottom ? "0.71em" : "0.32em"));
if (context !== selection) {
path = path.transition(context);
tick = tick.transition(context);
line = line.transition(context);
text = text.transition(context);
tickExit = tickExit.transition(context)
.attr("opacity", epsilon)
.attr("transform", function(d) { return isFinite(d = position(d)) ? transform(d) : this.getAttribute("transform"); });
tickEnter
.attr("opacity", epsilon)
.attr("transform", function(d) { var p = this.parentNode.__axis; return transform(p && isFinite(p = p(d)) ? p : position(d)); });
}
tickExit.remove();
path
.attr("d", orient === left || orient == right
? "M" + k * tickSizeOuter + "," + range0 + "H0.5V" + range1 + "H" + k * tickSizeOuter
: "M" + range0 + "," + k * tickSizeOuter + "V0.5H" + range1 + "V" + k * tickSizeOuter);
tick
.attr("opacity", 1)
.attr("transform", function(d) { return transform(position(d)); });
line
.attr(x + "2", k * tickSizeInner);
text
.attr(x, k * spacing)
.text(format);
selection.filter(entering)
.attr("fill", "none")
.attr("font-size", 10)
.attr("font-family", "sans-serif")
.attr("text-anchor", orient === right ? "start" : orient === left ? "end" : "middle");
selection
.each(function() { this.__axis = position; });
}
axis.scale = function(_) {
return arguments.length ? (scale = _, axis) : scale;
};
axis.ticks = function() {
return tickArguments = slice$1.call(arguments), axis;
};
axis.tickArguments = function(_) {
return arguments.length ? (tickArguments = _ == null ? [] : slice$1.call(_), axis) : tickArguments.slice();
};
axis.tickValues = function(_) {
return arguments.length ? (tickValues = _ == null ? null : slice$1.call(_), axis) : tickValues && tickValues.slice();
};
axis.tickFormat = function(_) {
return arguments.length ? (tickFormat = _, axis) : tickFormat;
};
axis.tickSize = function(_) {
return arguments.length ? (tickSizeInner = tickSizeOuter = +_, axis) : tickSizeInner;
};
axis.tickSizeInner = function(_) {
return arguments.length ? (tickSizeInner = +_, axis) : tickSizeInner;
};
axis.tickSizeOuter = function(_) {
return arguments.length ? (tickSizeOuter = +_, axis) : tickSizeOuter;
};
axis.tickPadding = function(_) {
return arguments.length ? (tickPadding = +_, axis) : tickPadding;
};
return axis;
}
function axisTop(scale) {
return axis(top, scale);
}
function axisRight(scale) {
return axis(right, scale);
}
function axisBottom(scale) {
return axis(bottom, scale);
}
function axisLeft(scale) {
return axis(left, scale);
}
var noop = {value: function() {}};
function dispatch() {
for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
_[t] = [];
}
return new Dispatch(_);
}
function Dispatch(_) {
this._ = _;
}
function parseTypenames(typenames, types) {
return typenames.trim().split(/^|\s+/).map(function(t) {
var name = "", i = t.indexOf(".");
if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
return {type: t, name: name};
});
}
Dispatch.prototype = dispatch.prototype = {
constructor: Dispatch,
on: function(typename, callback) {
var _ = this._,
T = parseTypenames(typename + "", _),
t,
i = -1,
n = T.length;
// If no callback was specified, return the callback of the given type and name.
if (arguments.length < 2) {
while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
return;
}
// If a type was specified, set the callback for the given type and name.
// Otherwise, if a null callback was specified, remove callbacks of the given name.
if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
while (++i < n) {
if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
}
return this;
},
copy: function() {
var copy = {}, _ = this._;
for (var t in _) copy[t] = _[t].slice();
return new Dispatch(copy);
},
call: function(type, that) {
if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
},
apply: function(type, that, args) {
if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
}
};
function get(type, name) {
for (var i = 0, n = type.length, c; i < n; ++i) {
if ((c = type[i]).name === name) {
return c.value;
}
}
}
function set(type, name, callback) {
for (var i = 0, n = type.length; i < n; ++i) {
if (type[i].name === name) {
type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
break;
}
}
if (callback != null) type.push({name: name, value: callback});
return type;
}
var xhtml = "http://www.w3.org/1999/xhtml";
var namespaces = {
svg: "http://www.w3.org/2000/svg",
xhtml: xhtml,
xlink: "http://www.w3.org/1999/xlink",
xml: "http://www.w3.org/XML/1998/namespace",
xmlns: "http://www.w3.org/2000/xmlns/"
};
var namespace = function(name) {
var prefix = name += "", i = prefix.indexOf(":");
if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
return namespaces.hasOwnProperty(prefix) ? {space: namespaces[prefix], local: name} : name;
};
function creatorInherit(name) {
return function() {
var document = this.ownerDocument,
uri = this.namespaceURI;
return uri === xhtml && document.documentElement.namespaceURI === xhtml
? document.createElement(name)
: document.createElementNS(uri, name);
};
}
function creatorFixed(fullname) {
return function() {
return this.ownerDocument.createElementNS(fullname.space, fullname.local);
};
}
var creator = function(name) {
var fullname = namespace(name);
return (fullname.local
? creatorFixed
: creatorInherit)(fullname);
};
var nextId = 0;
function local$1() {
return new Local;
}
function Local() {
this._ = "@" + (++nextId).toString(36);
}
Local.prototype = local$1.prototype = {
constructor: Local,
get: function(node) {
var id = this._;
while (!(id in node)) if (!(node = node.parentNode)) return;
return node[id];
},
set: function(node, value) {
return node[this._] = value;
},
remove: function(node) {
return this._ in node && delete node[this._];
},
toString: function() {
return this._;
}
};
var matcher = function(selector) {
return function() {
return this.matches(selector);
};
};
if (typeof document !== "undefined") {
var element = document.documentElement;
if (!element.matches) {
var vendorMatches = element.webkitMatchesSelector
|| element.msMatchesSelector
|| element.mozMatchesSelector
|| element.oMatchesSelector;
matcher = function(selector) {
return function() {
return vendorMatches.call(this, selector);
};
};
}
}
var matcher$1 = matcher;
var filterEvents = {};
exports.event = null;
if (typeof document !== "undefined") {
var element$1 = document.documentElement;
if (!("onmouseenter" in element$1)) {
filterEvents = {mouseenter: "mouseover", mouseleave: "mouseout"};
}
}
function filterContextListener(listener, index, group) {
listener = contextListener(listener, index, group);
return function(event) {
var related = event.relatedTarget;
if (!related || (related !== this && !(related.compareDocumentPosition(this) & 8))) {
listener.call(this, event);
}
};
}
function contextListener(listener, index, group) {
return function(event1) {
var event0 = exports.event; // Events can be reentrant (e.g., focus).
exports.event = event1;
try {
listener.call(this, this.__data__, index, group);
} finally {
exports.event = event0;
}
};
}
function parseTypenames$1(typenames) {
return typenames.trim().split(/^|\s+/).map(function(t) {
var name = "", i = t.indexOf(".");
if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
return {type: t, name: name};
});
}
function onRemove(typename) {
return function() {
var on = this.__on;
if (!on) return;
for (var j = 0, i = -1, m = on.length, o; j < m; ++j) {
if (o = on[j], (!typename.type || o.type === typename.type) && o.name === typename.name) {
this.removeEventListener(o.type, o.listener, o.capture);
} else {
on[++i] = o;
}
}
if (++i) on.length = i;
else delete this.__on;
};
}
function onAdd(typename, value, capture) {
var wrap = filterEvents.hasOwnProperty(typename.type) ? filterContextListener : contextListener;
return function(d, i, group) {
var on = this.__on, o, listener = wrap(value, i, group);
if (on) for (var j = 0, m = on.length; j < m; ++j) {
if ((o = on[j]).type === typename.type && o.name === typename.name) {
this.removeEventListener(o.type, o.listener, o.capture);
this.addEventListener(o.type, o.listener = listener, o.capture = capture);
o.value = value;
return;
}
}
this.addEventListener(typename.type, listener, capture);
o = {type: typename.type, name: typename.name, value: value, listener: listener, capture: capture};
if (!on) this.__on = [o];
else on.push(o);
};
}
var selection_on = function(typename, value, capture) {
var typenames = parseTypenames$1(typename + ""), i, n = typenames.length, t;
if (arguments.length < 2) {
var on = this.node().__on;
if (on) for (var j = 0, m = on.length, o; j < m; ++j) {
for (i = 0, o = on[j]; i < n; ++i) {
if ((t = typenames[i]).type === o.type && t.name === o.name) {
return o.value;
}
}
}
return;
}
on = value ? onAdd : onRemove;
if (capture == null) capture = false;
for (i = 0; i < n; ++i) this.each(on(typenames[i], value, capture));
return this;
};
function customEvent(event1, listener, that, args) {
var event0 = exports.event;
event1.sourceEvent = exports.event;
exports.event = event1;
try {
return listener.apply(that, args);
} finally {
exports.event = event0;
}
}
var sourceEvent = function() {
var current = exports.event, source;
while (source = current.sourceEvent) current = source;
return current;
};
var point = function(node, event) {
var svg = node.ownerSVGElement || node;
if (svg.createSVGPoint) {
var point = svg.createSVGPoint();
point.x = event.clientX, point.y = event.clientY;
point = point.matrixTransform(node.getScreenCTM().inverse());
return [point.x, point.y];
}
var rect = node.getBoundingClientRect();
return [event.clientX - rect.left - node.clientLeft, event.clientY - rect.top - node.clientTop];
};
var mouse = function(node) {
var event = sourceEvent();
if (event.changedTouches) event = event.changedTouches[0];
return point(node, event);
};
function none() {}
var selector = function(selector) {
return selector == null ? none : function() {
return this.querySelector(selector);
};
};
var selection_select = function(select) {
if (typeof select !== "function") select = selector(select);
for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
if ("__data__" in node) subnode.__data__ = node.__data__;
subgroup[i] = subnode;
}
}
}
return new Selection(subgroups, this._parents);
};
function empty$1() {
return [];
}
var selectorAll = function(selector) {
return selector == null ? empty$1 : function() {
return this.querySelectorAll(selector);
};
};
var selection_selectAll = function(select) {
if (typeof select !== "function") select = selectorAll(select);
for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
if (node = group[i]) {
subgroups.push(select.call(node, node.__data__, i, group));
parents.push(node);
}
}
}
return new Selection(subgroups, parents);
};
var selection_filter = function(match) {
if (typeof match !== "function") match = matcher$1(match);
for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
subgroup.push(node);
}
}
}
return new Selection(subgroups, this._parents);
};
var sparse = function(update) {
return new Array(update.length);
};
var selection_enter = function() {
return new Selection(this._enter || this._groups.map(sparse), this._parents);
};
function EnterNode(parent, datum) {
this.ownerDocument = parent.ownerDocument;
this.namespaceURI = parent.namespaceURI;
this._next = null;
this._parent = parent;
this.__data__ = datum;
}
EnterNode.prototype = {
constructor: EnterNode,
appendChild: function(child) { return this._parent.insertBefore(child, this._next); },
insertBefore: function(child, next) { return this._parent.insertBefore(child, next); },
querySelector: function(selector) { return this._parent.querySelector(selector); },
querySelectorAll: function(selector) { return this._parent.querySelectorAll(selector); }
};
var constant$1 = function(x) {
return function() {
return x;
};
};
var keyPrefix = "$"; // Protect against keys like “__proto__”.
function bindIndex(parent, group, enter, update, exit, data) {
var i = 0,
node,
groupLength = group.length,
dataLength = data.length;
// Put any non-null nodes that fit into update.
// Put any null nodes into enter.
// Put any remaining data into enter.
for (; i < dataLength; ++i) {
if (node = group[i]) {
node.__data__ = data[i];
update[i] = node;
} else {
enter[i] = new EnterNode(parent, data[i]);
}
}
// Put any non-null nodes that don’t fit into exit.
for (; i < groupLength; ++i) {
if (node = group[i]) {
exit[i] = node;
}
}
}
function bindKey(parent, group, enter, update, exit, data, key) {
var i,
node,
nodeByKeyValue = {},
groupLength = group.length,
dataLength = data.length,
keyValues = new Array(groupLength),
keyValue;
// Compute the key for each node.
// If multiple nodes have the same key, the duplicates are added to exit.
for (i = 0; i < groupLength; ++i) {
if (node = group[i]) {
keyValues[i] = keyValue = keyPrefix + key.call(node, node.__data__, i, group);
if (keyValue in nodeByKeyValue) {
exit[i] = node;
} else {
nodeByKeyValue[keyValue] = node;
}
}
}
// Compute the key for each datum.
// If there a node associated with this key, join and add it to update.
// If there is not (or the key is a duplicate), add it to enter.
for (i = 0; i < dataLength; ++i) {
keyValue = keyPrefix + key.call(parent, data[i], i, data);
if (node = nodeByKeyValue[keyValue]) {
update[i] = node;
node.__data__ = data[i];
nodeByKeyValue[keyValue] = null;
} else {
enter[i] = new EnterNode(parent, data[i]);
}
}
// Add any remaining nodes that were not bound to data to exit.
for (i = 0; i < groupLength; ++i) {
if ((node = group[i]) && (nodeByKeyValue[keyValues[i]] === node)) {
exit[i] = node;
}
}
}
var selection_data = function(value, key) {
if (!value) {
data = new Array(this.size()), j = -1;
this.each(function(d) { data[++j] = d; });
return data;
}
var bind = key ? bindKey : bindIndex,
parents = this._parents,
groups = this._groups;
if (typeof value !== "function") value = constant$1(value);
for (var m = groups.length, update = new Array(m), enter = new Array(m), exit = new Array(m), j = 0; j < m; ++j) {
var parent = parents[j],
group = groups[j],
groupLength = group.length,
data = value.call(parent, parent && parent.__data__, j, parents),
dataLength = data.length,
enterGroup = enter[j] = new Array(dataLength),
updateGroup = update[j] = new Array(dataLength),
exitGroup = exit[j] = new Array(groupLength);
bind(parent, group, enterGroup, updateGroup, exitGroup, data, key);
// Now connect the enter nodes to their following update node, such that
// appendChild can insert the materialized enter node before this node,
// rather than at the end of the parent node.
for (var i0 = 0, i1 = 0, previous, next; i0 < dataLength; ++i0) {
if (previous = enterGroup[i0]) {
if (i0 >= i1) i1 = i0 + 1;
while (!(next = updateGroup[i1]) && ++i1 < dataLength);
previous._next = next || null;
}
}
}
update = new Selection(update, parents);
update._enter = enter;
update._exit = exit;
return update;
};
var selection_exit = function() {
return new Selection(this._exit || this._groups.map(sparse), this._parents);
};
var selection_merge = function(selection$$1) {
for (var groups0 = this._groups, groups1 = selection$$1._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
if (node = group0[i] || group1[i]) {
merge[i] = node;
}
}
}
for (; j < m0; ++j) {
merges[j] = groups0[j];
}
return new Selection(merges, this._parents);
};
var selection_order = function() {
for (var groups = this._groups, j = -1, m = groups.length; ++j < m;) {
for (var group = groups[j], i = group.length - 1, next = group[i], node; --i >= 0;) {
if (node = group[i]) {
if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
next = node;
}
}
}
return this;
};
var selection_sort = function(compare) {
if (!compare) compare = ascending$1;
function compareNode(a, b) {
return a && b ? compare(a.__data__, b.__data__) : !a - !b;
}
for (var groups = this._groups, m = groups.length, sortgroups = new Array(m), j = 0; j < m; ++j) {
for (var group = groups[j], n = group.length, sortgroup = sortgroups[j] = new Array(n), node, i = 0; i < n; ++i) {
if (node = group[i]) {
sortgroup[i] = node;
}
}
sortgroup.sort(compareNode);
}
return new Selection(sortgroups, this._parents).order();
};
function ascending$1(a, b) {
return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
}
var selection_call = function() {
var callback = arguments[0];
arguments[0] = this;
callback.apply(null, arguments);
return this;
};
var selection_nodes = function() {
var nodes = new Array(this.size()), i = -1;
this.each(function() { nodes[++i] = this; });
return nodes;
};
var selection_node = function() {
for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
for (var group = groups[j], i = 0, n = group.length; i < n; ++i) {
var node = group[i];
if (node) return node;
}
}
return null;
};
var selection_size = function() {
var size = 0;
this.each(function() { ++size; });
return size;
};
var selection_empty = function() {
return !this.node();
};
var selection_each = function(callback) {
for (var groups = this._groups, j = 0, m = groups.length; j < m; ++j) {
for (var group = groups[j], i = 0, n = group.length, node; i < n; ++i) {
if (node = group[i]) callback.call(node, node.__data__, i, group);
}
}
return this;
};
function attrRemove(name) {
return function() {
this.removeAttribute(name);
};
}
function attrRemoveNS(fullname) {
return function() {
this.removeAttributeNS(fullname.space, fullname.local);
};
}
function attrConstant(name, value) {
return function() {
this.setAttribute(name, value);
};
}
function attrConstantNS(fullname, value) {
return function() {
this.setAttributeNS(fullname.space, fullname.local, value);
};
}
function attrFunction(name, value) {
return function() {
var v = value.apply(this, arguments);
if (v == null) this.removeAttribute(name);
else this.setAttribute(name, v);
};
}
function attrFunctionNS(fullname, value) {
return function() {
var v = value.apply(this, arguments);
if (v == null) this.removeAttributeNS(fullname.space, fullname.local);
else this.setAttributeNS(fullname.space, fullname.local, v);
};
}
var selection_attr = function(name, value) {
var fullname = namespace(name);
if (arguments.length < 2) {
var node = this.node();
return fullname.local
? node.getAttributeNS(fullname.space, fullname.local)
: node.getAttribute(fullname);
}
return this.each((value == null
? (fullname.local ? attrRemoveNS : attrRemove) : (typeof value === "function"
? (fullname.local ? attrFunctionNS : attrFunction)
: (fullname.local ? attrConstantNS : attrConstant)))(fullname, value));
};
var defaultView = function(node) {
return (node.ownerDocument && node.ownerDocument.defaultView) // node is a Node
|| (node.document && node) // node is a Window
|| node.defaultView; // node is a Document
};
function styleRemove(name) {
return function() {
this.style.removeProperty(name);
};
}
function styleConstant(name, value, priority) {
return function() {
this.style.setProperty(name, value, priority);
};
}
function styleFunction(name, value, priority) {
return function() {
var v = value.apply(this, arguments);
if (v == null) this.style.removeProperty(name);
else this.style.setProperty(name, v, priority);
};
}
var selection_style = function(name, value, priority) {
return arguments.length > 1
? this.each((value == null
? styleRemove : typeof value === "function"
? styleFunction
: styleConstant)(name, value, priority == null ? "" : priority))
: styleValue(this.node(), name);
};
function styleValue(node, name) {
return node.style.getPropertyValue(name)
|| defaultView(node).getComputedStyle(node, null).getPropertyValue(name);
}
function propertyRemove(name) {
return function() {
delete this[name];
};
}
function propertyConstant(name, value) {
return function() {
this[name] = value;
};
}
function propertyFunction(name, value) {
return function() {
var v = value.apply(this, arguments);
if (v == null) delete this[name];
else this[name] = v;
};
}
var selection_property = function(name, value) {
return arguments.length > 1
? this.each((value == null
? propertyRemove : typeof value === "function"
? propertyFunction
: propertyConstant)(name, value))
: this.node()[name];
};
function classArray(string) {
return string.trim().split(/^|\s+/);
}
function classList(node) {
return node.classList || new ClassList(node);
}
function ClassList(node) {
this._node = node;
this._names = classArray(node.getAttribute("class") || "");
}
ClassList.prototype = {
add: function(name) {
var i = this._names.indexOf(name);
if (i < 0) {
this._names.push(name);
this._node.setAttribute("class", this._names.join(" "));
}
},
remove: function(name) {
var i = this._names.indexOf(name);
if (i >= 0) {
this._names.splice(i, 1);
this._node.setAttribute("class", this._names.join(" "));
}
},
contains: function(name) {
return this._names.indexOf(name) >= 0;
}
};
function classedAdd(node, names) {
var list = classList(node), i = -1, n = names.length;
while (++i < n) list.add(names[i]);
}
function classedRemove(node, names) {
var list = classList(node), i = -1, n = names.length;
while (++i < n) list.remove(names[i]);
}
function classedTrue(names) {
return function() {
classedAdd(this, names);
};
}
function classedFalse(names) {
return function() {
classedRemove(this, names);
};
}
function classedFunction(names, value) {
return function() {
(value.apply(this, arguments) ? classedAdd : classedRemove)(this, names);
};
}
var selection_classed = function(name, value) {
var names = classArray(name + "");
if (arguments.length < 2) {
var list = classList(this.node()), i = -1, n = names.length;
while (++i < n) if (!list.contains(names[i])) return false;
return true;
}
return this.each((typeof value === "function"
? classedFunction : value
? classedTrue
: classedFalse)(names, value));
};
function textRemove() {
this.textContent = "";
}
function textConstant(value) {
return function() {
this.textContent = value;
};
}
function textFunction(value) {
return function() {
var v = value.apply(this, arguments);
this.textContent = v == null ? "" : v;
};
}
var selection_text = function(value) {
return arguments.length
? this.each(value == null
? textRemove : (typeof value === "function"
? textFunction
: textConstant)(value))
: this.node().textContent;
};
function htmlRemove() {
this.innerHTML = "";
}
function htmlConstant(value) {
return function() {
this.innerHTML = value;
};
}
function htmlFunction(value) {
return function() {
var v = value.apply(this, arguments);
this.innerHTML = v == null ? "" : v;
};
}
var selection_html = function(value) {
return arguments.length
? this.each(value == null
? htmlRemove : (typeof value === "function"
? htmlFunction
: htmlConstant)(value))
: this.node().innerHTML;
};
function raise() {
if (this.nextSibling) this.parentNode.appendChild(this);
}
var selection_raise = function() {
return this.each(raise);
};
function lower() {
if (this.previousSibling) this.parentNode.insertBefore(this, this.parentNode.firstChild);
}
var selection_lower = function() {
return this.each(lower);
};
var selection_append = function(name) {
var create = typeof name === "function" ? name : creator(name);
return this.select(function() {
return this.appendChild(create.apply(this, arguments));
});
};
function constantNull() {
return null;
}
var selection_insert = function(name, before) {
var create = typeof name === "function" ? name : creator(name),
select = before == null ? constantNull : typeof before === "function" ? before : selector(before);
return this.select(function() {
return this.insertBefore(create.apply(this, arguments), select.apply(this, arguments) || null);
});
};
function remove() {
var parent = this.parentNode;
if (parent) parent.removeChild(this);
}
var selection_remove = function() {
return this.each(remove);
};
var selection_datum = function(value) {
return arguments.length
? this.property("__data__", value)
: this.node().__data__;
};
function dispatchEvent(node, type, params) {
var window = defaultView(node),
event = window.CustomEvent;
if (typeof event === "function") {
event = new event(type, params);
} else {
event = window.document.createEvent("Event");
if (params) event.initEvent(type, params.bubbles, params.cancelable), event.detail = params.detail;
else event.initEvent(type, false, false);
}
node.dispatchEvent(event);
}
function dispatchConstant(type, params) {
return function() {
return dispatchEvent(this, type, params);
};
}
function dispatchFunction(type, params) {
return function() {
return dispatchEvent(this, type, params.apply(this, arguments));
};
}
var selection_dispatch = function(type, params) {
return this.each((typeof params === "function"
? dispatchFunction
: dispatchConstant)(type, params));
};
var root = [null];
function Selection(groups, parents) {
this._groups = groups;
this._parents = parents;
}
function selection() {
return new Selection([[document.documentElement]], root);
}
Selection.prototype = selection.prototype = {
constructor: Selection,
select: selection_select,
selectAll: selection_selectAll,
filter: selection_filter,
data: selection_data,
enter: selection_enter,
exit: selection_exit,
merge: selection_merge,
order: selection_order,
sort: selection_sort,
call: selection_call,
nodes: selection_nodes,
node: selection_node,
size: selection_size,
empty: selection_empty,
each: selection_each,
attr: selection_attr,
style: selection_style,
property: selection_property,
classed: selection_classed,
text: selection_text,
html: selection_html,
raise: selection_raise,
lower: selection_lower,
append: selection_append,
insert: selection_insert,
remove: selection_remove,
datum: selection_datum,
on: selection_on,
dispatch: selection_dispatch
};
var select = function(selector) {
return typeof selector === "string"
? new Selection([[document.querySelector(selector)]], [document.documentElement])
: new Selection([[selector]], root);
};
var selectAll = function(selector) {
return typeof selector === "string"
? new Selection([document.querySelectorAll(selector)], [document.documentElement])
: new Selection([selector == null ? [] : selector], root);
};
var touch = function(node, touches, identifier) {
if (arguments.length < 3) identifier = touches, touches = sourceEvent().changedTouches;
for (var i = 0, n = touches ? touches.length : 0, touch; i < n; ++i) {
if ((touch = touches[i]).identifier === identifier) {
return point(node, touch);
}
}
return null;
};
var touches = function(node, touches) {
if (touches == null) touches = sourceEvent().touches;
for (var i = 0, n = touches ? touches.length : 0, points = new Array(n); i < n; ++i) {
points[i] = point(node, touches[i]);
}
return points;
};
function nopropagation() {
exports.event.stopImmediatePropagation();
}
var noevent = function() {
exports.event.preventDefault();
exports.event.stopImmediatePropagation();
};
var dragDisable = function(view) {
var root = view.document.documentElement,
selection = select(view).on("dragstart.drag", noevent, true);
if ("onselectstart" in root) {
selection.on("selectstart.drag", noevent, true);
} else {
root.__noselect = root.style.MozUserSelect;
root.style.MozUserSelect = "none";
}
};
function yesdrag(view, noclick) {
var root = view.document.documentElement,
selection = select(view).on("dragstart.drag", null);
if (noclick) {
selection.on("click.drag", noevent, true);
setTimeout(function() { selection.on("click.drag", null); }, 0);
}
if ("onselectstart" in root) {
selection.on("selectstart.drag", null);
} else {
root.style.MozUserSelect = root.__noselect;
delete root.__noselect;
}
}
var constant$2 = function(x) {
return function() {
return x;
};
};
function DragEvent(target, type, subject, id, active, x, y, dx, dy, dispatch) {
this.target = target;
this.type = type;
this.subject = subject;
this.identifier = id;
this.active = active;
this.x = x;
this.y = y;
this.dx = dx;
this.dy = dy;
this._ = dispatch;
}
DragEvent.prototype.on = function() {
var value = this._.on.apply(this._, arguments);
return value === this._ ? this : value;
};
// Ignore right-click, since that should open the context menu.
function defaultFilter$1() {
return !exports.event.button;
}
function defaultContainer() {
return this.parentNode;
}
function defaultSubject(d) {
return d == null ? {x: exports.event.x, y: exports.event.y} : d;
}
function defaultTouchable() {
return "ontouchstart" in this;
}
var drag = function() {
var filter = defaultFilter$1,
container = defaultContainer,
subject = defaultSubject,
touchable = defaultTouchable,
gestures = {},
listeners = dispatch("start", "drag", "end"),
active = 0,
mousedownx,
mousedowny,
mousemoving,
touchending,
clickDistance2 = 0;
function drag(selection) {
selection
.on("mousedown.drag", mousedowned)
.filter(touchable)
.on("touchstart.drag", touchstarted)
.on("touchmove.drag", touchmoved)
.on("touchend.drag touchcancel.drag", touchended)
.style("touch-action", "none")
.style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
}
function mousedowned() {
if (touchending || !filter.apply(this, arguments)) return;
var gesture = beforestart("mouse", container.apply(this, arguments), mouse, this, arguments);
if (!gesture) return;
select(exports.event.view).on("mousemove.drag", mousemoved, true).on("mouseup.drag", mouseupped, true);
dragDisable(exports.event.view);
nopropagation();
mousemoving = false;
mousedownx = exports.event.clientX;
mousedowny = exports.event.clientY;
gesture("start");
}
function mousemoved() {
noevent();
if (!mousemoving) {
var dx = exports.event.clientX - mousedownx, dy = exports.event.clientY - mousedowny;
mousemoving = dx * dx + dy * dy > clickDistance2;
}
gestures.mouse("drag");
}
function mouseupped() {
select(exports.event.view).on("mousemove.drag mouseup.drag", null);
yesdrag(exports.event.view, mousemoving);
noevent();
gestures.mouse("end");
}
function touchstarted() {
if (!filter.apply(this, arguments)) return;
var touches = exports.event.changedTouches,
c = container.apply(this, arguments),
n = touches.length, i, gesture;
for (i = 0; i < n; ++i) {
if (gesture = beforestart(touches[i].identifier, c, touch, this, arguments)) {
nopropagation();
gesture("start");
}
}
}
function touchmoved() {
var touches = exports.event.changedTouches,
n = touches.length, i, gesture;
for (i = 0; i < n; ++i) {
if (gesture = gestures[touches[i].identifier]) {
noevent();
gesture("drag");
}
}
}
function touchended() {
var touches = exports.event.changedTouches,
n = touches.length, i, gesture;
if (touchending) clearTimeout(touchending);
touchending = setTimeout(function() { touchending = null; }, 500); // Ghost clicks are delayed!
for (i = 0; i < n; ++i) {
if (gesture = gestures[touches[i].identifier]) {
nopropagation();
gesture("end");
}
}
}
function beforestart(id, container, point, that, args) {
var p = point(container, id), s, dx, dy,
sublisteners = listeners.copy();
if (!customEvent(new DragEvent(drag, "beforestart", s, id, active, p[0], p[1], 0, 0, sublisteners), function() {
if ((exports.event.subject = s = subject.apply(that, args)) == null) return false;
dx = s.x - p[0] || 0;
dy = s.y - p[1] || 0;
return true;
})) return;
return function gesture(type) {
var p0 = p, n;
switch (type) {
case "start": gestures[id] = gesture, n = active++; break;
case "end": delete gestures[id], --active; // nobreak
case "drag": p = point(container, id), n = active; break;
}
customEvent(new DragEvent(drag, type, s, id, n, p[0] + dx, p[1] + dy, p[0] - p0[0], p[1] - p0[1], sublisteners), sublisteners.apply, sublisteners, [type, that, args]);
};
}
drag.filter = function(_) {
return arguments.length ? (filter = typeof _ === "function" ? _ : constant$2(!!_), drag) : filter;
};
drag.container = function(_) {
return arguments.length ? (container = typeof _ === "function" ? _ : constant$2(_), drag) : container;
};
drag.subject = function(_) {
return arguments.length ? (subject = typeof _ === "function" ? _ : constant$2(_), drag) : subject;
};
drag.touchable = function(_) {
return arguments.length ? (touchable = typeof _ === "function" ? _ : constant$2(!!_), drag) : touchable;
};
drag.on = function() {
var value = listeners.on.apply(listeners, arguments);
return value === listeners ? drag : value;
};
drag.clickDistance = function(_) {
return arguments.length ? (clickDistance2 = (_ = +_) * _, drag) : Math.sqrt(clickDistance2);
};
return drag;
};
var define = function(constructor, factory, prototype) {
constructor.prototype = factory.prototype = prototype;
prototype.constructor = constructor;
};
function extend(parent, definition) {
var prototype = Object.create(parent.prototype);
for (var key in definition) prototype[key] = definition[key];
return prototype;
}
function Color() {}
var darker = 0.7;
var brighter = 1 / darker;
var reI = "\\s*([+-]?\\d+)\\s*";
var reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*";
var reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*";
var reHex3 = /^#([0-9a-f]{3})$/;
var reHex6 = /^#([0-9a-f]{6})$/;
var reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$");
var reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$");
var reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$");
var reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$");
var reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$");
var reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
var named = {
aliceblue: 0xf0f8ff,
antiquewhite: 0xfaebd7,
aqua: 0x00ffff,
aquamarine: 0x7fffd4,
azure: 0xf0ffff,
beige: 0xf5f5dc,
bisque: 0xffe4c4,
black: 0x000000,
blanchedalmond: 0xffebcd,
blue: 0x0000ff,
blueviolet: 0x8a2be2,
brown: 0xa52a2a,
burlywood: 0xdeb887,
cadetblue: 0x5f9ea0,
chartreuse: 0x7fff00,
chocolate: 0xd2691e,
coral: 0xff7f50,
cornflowerblue: 0x6495ed,
cornsilk: 0xfff8dc,
crimson: 0xdc143c,
cyan: 0x00ffff,
darkblue: 0x00008b,
darkcyan: 0x008b8b,
darkgoldenrod: 0xb8860b,
darkgray: 0xa9a9a9,
darkgreen: 0x006400,
darkgrey: 0xa9a9a9,
darkkhaki: 0xbdb76b,
darkmagenta: 0x8b008b,
darkolivegreen: 0x556b2f,
darkorange: 0xff8c00,
darkorchid: 0x9932cc,
darkred: 0x8b0000,
darksalmon: 0xe9967a,
darkseagreen: 0x8fbc8f,
darkslateblue: 0x483d8b,
darkslategray: 0x2f4f4f,
darkslategrey: 0x2f4f4f,
darkturquoise: 0x00ced1,
darkviolet: 0x9400d3,
deeppink: 0xff1493,
deepskyblue: 0x00bfff,
dimgray: 0x696969,
dimgrey: 0x696969,
dodgerblue: 0x1e90ff,
firebrick: 0xb22222,
floralwhite: 0xfffaf0,
forestgreen: 0x228b22,
fuchsia: 0xff00ff,
gainsboro: 0xdcdcdc,
ghostwhite: 0xf8f8ff,
gold: 0xffd700,
goldenrod: 0xdaa520,
gray: 0x808080,
green: 0x008000,
greenyellow: 0xadff2f,
grey: 0x808080,
honeydew: 0xf0fff0,
hotpink: 0xff69b4,
indianred: 0xcd5c5c,
indigo: 0x4b0082,
ivory: 0xfffff0,
khaki: 0xf0e68c,
lavender: 0xe6e6fa,
lavenderblush: 0xfff0f5,
lawngreen: 0x7cfc00,
lemonchiffon: 0xfffacd,
lightblue: 0xadd8e6,
lightcoral: 0xf08080,
lightcyan: 0xe0ffff,
lightgoldenrodyellow: 0xfafad2,
lightgray: 0xd3d3d3,
lightgreen: 0x90ee90,
lightgrey: 0xd3d3d3,
lightpink: 0xffb6c1,
lightsalmon: 0xffa07a,
lightseagreen: 0x20b2aa,
lightskyblue: 0x87cefa,
lightslategray: 0x778899,
lightslategrey: 0x778899,
lightsteelblue: 0xb0c4de,
lightyellow: 0xffffe0,
lime: 0x00ff00,
limegreen: 0x32cd32,
linen: 0xfaf0e6,
magenta: 0xff00ff,
maroon: 0x800000,
mediumaquamarine: 0x66cdaa,
mediumblue: 0x0000cd,
mediumorchid: 0xba55d3,
mediumpurple: 0x9370db,
mediumseagreen: 0x3cb371,
mediumslateblue: 0x7b68ee,
mediumspringgreen: 0x00fa9a,
mediumturquoise: 0x48d1cc,
mediumvioletred: 0xc71585,
midnightblue: 0x191970,
mintcream: 0xf5fffa,
mistyrose: 0xffe4e1,
moccasin: 0xffe4b5,
navajowhite: 0xffdead,
navy: 0x000080,
oldlace: 0xfdf5e6,
olive: 0x808000,
olivedrab: 0x6b8e23,
orange: 0xffa500,
orangered: 0xff4500,
orchid: 0xda70d6,
palegoldenrod: 0xeee8aa,
palegreen: 0x98fb98,
paleturquoise: 0xafeeee,
palevioletred: 0xdb7093,
papayawhip: 0xffefd5,
peachpuff: 0xffdab9,
peru: 0xcd853f,
pink: 0xffc0cb,
plum: 0xdda0dd,
powderblue: 0xb0e0e6,
purple: 0x800080,
rebeccapurple: 0x663399,
red: 0xff0000,
rosybrown: 0xbc8f8f,
royalblue: 0x4169e1,
saddlebrown: 0x8b4513,
salmon: 0xfa8072,
sandybrown: 0xf4a460,
seagreen: 0x2e8b57,
seashell: 0xfff5ee,
sienna: 0xa0522d,
silver: 0xc0c0c0,
skyblue: 0x87ceeb,
slateblue: 0x6a5acd,
slategray: 0x708090,
slategrey: 0x708090,
snow: 0xfffafa,
springgreen: 0x00ff7f,
steelblue: 0x4682b4,
tan: 0xd2b48c,
teal: 0x008080,
thistle: 0xd8bfd8,
tomato: 0xff6347,
turquoise: 0x40e0d0,
violet: 0xee82ee,
wheat: 0xf5deb3,
white: 0xffffff,
whitesmoke: 0xf5f5f5,
yellow: 0xffff00,
yellowgreen: 0x9acd32
};
define(Color, color, {
displayable: function() {
return this.rgb().displayable();
},
toString: function() {
return this.rgb() + "";
}
});
function color(format) {
var m;
format = (format + "").trim().toLowerCase();
return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), new Rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1)) // #f00
: (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
: (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)