1311 lines
95 KiB
JavaScript
1311 lines
95 KiB
JavaScript
|
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.vega || (g.vega = {})).embed = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
|||
|
/* global define */
|
|||
|
(function (root, factory) {
|
|||
|
/* istanbul ignore next */
|
|||
|
if (typeof define === 'function' && define.amd) {
|
|||
|
define([], factory);
|
|||
|
} else if (typeof exports === 'object') {
|
|||
|
module.exports = factory();
|
|||
|
} else {
|
|||
|
root.compareVersions = factory();
|
|||
|
}
|
|||
|
}(this, function () {
|
|||
|
|
|||
|
var semver = /^v?(?:0|[1-9]\d*)(\.(?:[x*]|0|[1-9]\d*)(\.(?:[x*]|0|[1-9]\d*)(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
|
|||
|
var patch = /-([0-9A-Za-z-.]+)/;
|
|||
|
|
|||
|
function split(v) {
|
|||
|
var temp = v.replace(/^v/, '').split('.');
|
|||
|
var arr = temp.splice(0, 2);
|
|||
|
arr.push(temp.join('.'));
|
|||
|
return arr;
|
|||
|
}
|
|||
|
|
|||
|
function tryParse(v) {
|
|||
|
return isNaN(Number(v)) ? v : Number(v);
|
|||
|
}
|
|||
|
|
|||
|
function validate(version) {
|
|||
|
if (typeof version !== 'string') {
|
|||
|
throw new TypeError('Invalid argument expected string');
|
|||
|
}
|
|||
|
if (!semver.test(version)) {
|
|||
|
throw new Error('Invalid argument not valid semver');
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return function compareVersions(v1, v2) {
|
|||
|
[v1, v2].forEach(validate);
|
|||
|
|
|||
|
var s1 = split(v1);
|
|||
|
var s2 = split(v2);
|
|||
|
|
|||
|
for (var i = 0; i < 3; i++) {
|
|||
|
var n1 = parseInt(s1[i] || 0, 10);
|
|||
|
var n2 = parseInt(s2[i] || 0, 10);
|
|||
|
|
|||
|
if (n1 > n2) return 1;
|
|||
|
if (n2 > n1) return -1;
|
|||
|
}
|
|||
|
|
|||
|
if ([s1[2], s2[2]].every(patch.test.bind(patch))) {
|
|||
|
var p1 = patch.exec(s1[2])[1].split('.').map(tryParse);
|
|||
|
var p2 = patch.exec(s2[2])[1].split('.').map(tryParse);
|
|||
|
|
|||
|
for (i = 0; i < Math.max(p1.length, p2.length); i++) {
|
|||
|
if (p1[i] === undefined || typeof p2[i] === 'string' && typeof p1[i] === 'number') return -1;
|
|||
|
if (p2[i] === undefined || typeof p1[i] === 'string' && typeof p2[i] === 'number') return 1;
|
|||
|
|
|||
|
if (p1[i] > p2[i]) return 1;
|
|||
|
if (p2[i] > p1[i]) return -1;
|
|||
|
}
|
|||
|
} else if ([s1[2], s2[2]].some(patch.test.bind(patch))) {
|
|||
|
return patch.test(s1[2]) ? -1 : 1;
|
|||
|
}
|
|||
|
|
|||
|
return 0;
|
|||
|
};
|
|||
|
|
|||
|
}));
|
|||
|
|
|||
|
},{}],2:[function(require,module,exports){
|
|||
|
// https://d3js.org/d3-selection/ Version 1.1.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 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() {
|
|||
|
return new Local;
|
|||
|
}
|
|||
|
|
|||
|
function Local() {
|
|||
|
this._ = "@" + (++nextId).toString(36);
|
|||
|
}
|
|||
|
|
|||
|
Local.prototype = local.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(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(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() {
|
|||
|
return [];
|
|||
|
}
|
|||
|
|
|||
|
var selectorAll = function(selector) {
|
|||
|
return selector == null ? empty : 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 = 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(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) {
|
|||
|
|
|||
|
for (var groups0 = this._groups, groups1 = selection._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;
|
|||
|
|
|||
|
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(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;
|
|||
|
};
|
|||
|
|
|||
|
exports.creator = creator;
|
|||
|
exports.local = local;
|
|||
|
exports.matcher = matcher$1;
|
|||
|
exports.mouse = mouse;
|
|||
|
exports.namespace = namespace;
|
|||
|
exports.namespaces = namespaces;
|
|||
|
exports.select = select;
|
|||
|
exports.selectAll = selectAll;
|
|||
|
exports.selection = selection;
|
|||
|
exports.selector = selector;
|
|||
|
exports.selectorAll = selectorAll;
|
|||
|
exports.style = styleValue;
|
|||
|
exports.touch = touch;
|
|||
|
exports.touches = touches;
|
|||
|
exports.window = defaultView;
|
|||
|
exports.customEvent = customEvent;
|
|||
|
|
|||
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|||
|
|
|||
|
})));
|
|||
|
|
|||
|
},{}],3:[function(require,module,exports){
|
|||
|
"use strict";
|
|||
|
/**
|
|||
|
* Parse a vega schema url into library and version.
|
|||
|
*/
|
|||
|
function default_1(url) {
|
|||
|
var regex = /\/schema\/([\w-]+)\/([\w\.\-]+)\.json$/g;
|
|||
|
var _a = regex.exec(url).slice(1, 3), library = _a[0], version = _a[1];
|
|||
|
return { library: library, version: version };
|
|||
|
}
|
|||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|||
|
exports.default = default_1;
|
|||
|
|
|||
|
},{}],4:[function(require,module,exports){
|
|||
|
(function (global){
|
|||
|
var d3 = require('d3-selection');
|
|||
|
var vega = (typeof window !== "undefined" ? window['vega'] : typeof global !== "undefined" ? global['vega'] : null);
|
|||
|
var vl = (typeof window !== "undefined" ? window['vl'] : typeof global !== "undefined" ? global['vl'] : null);
|
|||
|
var post = require('./post');
|
|||
|
var versionCompare = require('compare-versions');
|
|||
|
var schemaParser = require('vega-schema-url-parser').default;
|
|||
|
|
|||
|
|
|||
|
var MODES = {
|
|||
|
'vega': 'vega',
|
|||
|
'vega-lite': 'vega-lite'
|
|||
|
};
|
|||
|
|
|||
|
var VERSION = {
|
|||
|
'vega': vega.version,
|
|||
|
'vega-lite': vl ? vl.version : -1
|
|||
|
};
|
|||
|
|
|||
|
var PREPROCESSOR = {
|
|||
|
'vega': function(vgjson) { return vgjson; },
|
|||
|
'vega-lite': function(vljson) { return vl.compile(vljson).spec; }
|
|||
|
};
|
|||
|
|
|||
|
function load(url, arg, prop, el) {
|
|||
|
return vega.loader().load(url).then(function (data) {
|
|||
|
if (!data) {
|
|||
|
throw new Error('No data found at ' + url);
|
|||
|
}
|
|||
|
if (prop === 'config') {
|
|||
|
arg.opt.config = JSON.parse(data);
|
|||
|
return embed(el, arg.spec, arg.opt);
|
|||
|
}
|
|||
|
return embed(el, JSON.parse(data), arg);
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Embed a Vega visualization component in a web page.
|
|||
|
* This function will either throw an exception, or return a promise
|
|||
|
*
|
|||
|
* @param el DOM element in which to place component (DOM node or CSS selector)
|
|||
|
* @param spec String : A URL string from which to load the Vega specification.
|
|||
|
Object : The Vega/Vega-Lite specification as a parsed JSON object.
|
|||
|
* @param opt A JavaScript object containing options for embedding.
|
|||
|
*/
|
|||
|
function embed(el, spec, opt) {
|
|||
|
opt = opt || {};
|
|||
|
var renderer = opt.renderer || 'canvas';
|
|||
|
var actions = opt.actions !== undefined ? opt.actions : true;
|
|||
|
|
|||
|
// Load the visualization specification.
|
|||
|
if (vega.isString(spec)) {
|
|||
|
return load(spec, opt, 'url', el);
|
|||
|
}
|
|||
|
|
|||
|
// Load Vega theme/configuration.
|
|||
|
if (vega.isString(opt.config)) {
|
|||
|
return load(opt.config, {spec: spec, opt: opt}, 'config', el);
|
|||
|
}
|
|||
|
|
|||
|
// Decide mode
|
|||
|
var parsed, mode, vgSpec;
|
|||
|
if (spec.$schema) {
|
|||
|
parsed = schemaParser(spec.$schema);
|
|||
|
if (opt.mode && opt.mode !== MODES[parsed.library]) {
|
|||
|
console.warn("The given visualization spec is written in \"" + parsed.library + "\", "
|
|||
|
+ "but mode argument is assigned as \"" + opt.mode + "\".");
|
|||
|
}
|
|||
|
mode = MODES[parsed.library];
|
|||
|
|
|||
|
if (versionCompare(parsed.version, VERSION[mode]) > 0) {
|
|||
|
console.warn("The input spec uses \"" + mode + "\" " + parsed.version + ", "
|
|||
|
+ "but current version of \"" + mode + "\" is " + VERSION[mode] + ".");
|
|||
|
}
|
|||
|
} else {
|
|||
|
mode = MODES[opt.mode] || MODES.vega;
|
|||
|
}
|
|||
|
|
|||
|
vgSpec = PREPROCESSOR[mode](spec);
|
|||
|
if (mode === MODES['vega-lite']) {
|
|||
|
if (vgSpec.$schema) {
|
|||
|
parsed = schemaParser(vgSpec.$schema);
|
|||
|
|
|||
|
if (versionCompare(parsed.version, VERSION['vega']) > 0) {
|
|||
|
console.warn("The compiled spec uses \"vega\" " + parsed.version + ", "
|
|||
|
+ "but current version of \"vega\" is " + VERSION['vega'] + ".");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// ensure container div has class 'vega-embed'
|
|||
|
var div = d3.select(el)
|
|||
|
.classed('vega-embed', true)
|
|||
|
.html(''); // clear container
|
|||
|
|
|||
|
if (opt.onBeforeParse) {
|
|||
|
// Allow Vega spec to be modified before being used
|
|||
|
vgSpec = opt.onBeforeParse(vgSpec);
|
|||
|
}
|
|||
|
|
|||
|
var runtime = vega.parse(vgSpec, opt.config); // may throw an Error if parsing fails
|
|||
|
|
|||
|
var viewConfig = opt.viewConfig || {};
|
|||
|
if (viewConfig.logLevel === undefined) {
|
|||
|
viewConfig.logLevel = vega.Warn;
|
|||
|
}
|
|||
|
|
|||
|
var view = new vega.View(runtime, viewConfig)
|
|||
|
.initialize(el)
|
|||
|
.renderer(renderer);
|
|||
|
|
|||
|
// Vega-Lite does not need hover so we can improve perf by not activating it
|
|||
|
if (mode !== MODES['vega-lite']) {
|
|||
|
view.hover();
|
|||
|
}
|
|||
|
|
|||
|
if (opt) {
|
|||
|
if (opt.width) {
|
|||
|
view.width(opt.width)
|
|||
|
}
|
|||
|
if (opt.height) {
|
|||
|
view.height(opt.height)
|
|||
|
}
|
|||
|
if (opt.padding) {
|
|||
|
view.padding(opt.padding)
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
view.run();
|
|||
|
|
|||
|
if (actions !== false) {
|
|||
|
// add child div to house action links
|
|||
|
var ctrl = div.append('div')
|
|||
|
.attr('class', 'vega-actions');
|
|||
|
|
|||
|
// add 'Export' action
|
|||
|
if (actions.export !== false) {
|
|||
|
var ext = (renderer==='canvas' ? 'png' : 'svg');
|
|||
|
ctrl.append('a')
|
|||
|
.text('Export as ' + ext.toUpperCase())
|
|||
|
.attr('href', '#')
|
|||
|
.attr('target', '_blank')
|
|||
|
.attr('download', (spec.name || 'vega') + '.' + ext)
|
|||
|
.on('mousedown', function() {
|
|||
|
var that = this;
|
|||
|
view.toImageURL(ext).then(function(url) {
|
|||
|
that.href = url;
|
|||
|
}).catch(function(error) { throw error; });
|
|||
|
d3.event.preventDefault();
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
// add 'View Source' action
|
|||
|
if (actions.source !== false) {
|
|||
|
ctrl.append('a')
|
|||
|
.text('View Source')
|
|||
|
.attr('href', '#')
|
|||
|
.on('click', function() {
|
|||
|
viewSource(JSON.stringify(spec, null, 2), opt.sourceHeader || '', opt.sourceFooter || '');
|
|||
|
d3.event.preventDefault();
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
// add 'Open in Vega Editor' action
|
|||
|
if (actions.editor !== false) {
|
|||
|
var editorUrl = opt.editorUrl || 'https://vega.github.io/editor/'
|
|||
|
ctrl.append('a')
|
|||
|
.text('Open in Vega Editor')
|
|||
|
.attr('href', '#')
|
|||
|
.on('click', function() {
|
|||
|
post(window, editorUrl, {
|
|||
|
spec: JSON.stringify(spec, null, 2),
|
|||
|
mode: mode
|
|||
|
});
|
|||
|
d3.event.preventDefault();
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return Promise.resolve({view: view, spec: spec});
|
|||
|
}
|
|||
|
|
|||
|
function viewSource(source, sourceHeader, sourceFooter) {
|
|||
|
var header = '<html><head>' + sourceHeader + '</head>' + '<body><pre><code class="json">';
|
|||
|
var footer = '</code></pre>' + sourceFooter + '</body></html>';
|
|||
|
var win = window.open('');
|
|||
|
win.document.write(header + source + footer);
|
|||
|
win.document.title = 'Vega JSON Source';
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Embed a Vega visualization component in a web page.
|
|||
|
*
|
|||
|
* @param el DOM element in which to place component (DOM node or CSS selector)
|
|||
|
* @param spec String : A URL string from which to load the Vega specification.
|
|||
|
Object : The Vega/Vega-Lite specification as a parsed JSON object.
|
|||
|
* @param opt A JavaScript object containing options for embedding.
|
|||
|
*/
|
|||
|
function embedMain(el, spec, opt) {
|
|||
|
// Ensure any exceptions will be properly handled
|
|||
|
return new Promise((accept, reject) => {
|
|||
|
embed(el, spec, opt).then(accept, reject);
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
// expose Vega and Vega-Lite libs
|
|||
|
embedMain.vega = vega;
|
|||
|
embedMain.vegalite = vl;
|
|||
|
|
|||
|
// for es5
|
|||
|
module.exports = embedMain;
|
|||
|
// for es 6
|
|||
|
module.exports.default = embedMain;
|
|||
|
|
|||
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|||
|
|
|||
|
},{"./post":5,"compare-versions":1,"d3-selection":2,"vega-schema-url-parser":3}],5:[function(require,module,exports){
|
|||
|
// open editor url in a new window, and pass a message
|
|||
|
module.exports = function(window, url, data) {
|
|||
|
var editor = window.open(url),
|
|||
|
wait = 10000,
|
|||
|
step = 250,
|
|||
|
count = ~~(wait/step);
|
|||
|
|
|||
|
function listen(evt) {
|
|||
|
if (evt.source === editor) {
|
|||
|
count = 0;
|
|||
|
window.removeEventListener('message', listen, false);
|
|||
|
}
|
|||
|
}
|
|||
|
window.addEventListener('message', listen, false);
|
|||
|
|
|||
|
// send message
|
|||
|
// periodically resend until ack received or timeout
|
|||
|
function send() {
|
|||
|
if (count <= 0) return;
|
|||
|
editor.postMessage(data, '*');
|
|||
|
setTimeout(send, step);
|
|||
|
count -= 1;
|
|||
|
}
|
|||
|
setTimeout(send, step);
|
|||
|
};
|
|||
|
|
|||
|
},{}]},{},[4])(4)
|
|||
|
});
|
|||
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJub2RlX21vZHVsZXMvY29tcGFyZS12ZXJzaW9ucy9pbmRleC5qcyIsIm5vZGVfbW9kdWxlcy9kMy1zZWxlY3Rpb24vYnVpbGQvZDMtc2VsZWN0aW9uLmpzIiwibm9kZV9tb2R1bGVzL3ZlZ2Etc2NoZ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