Comparing version 5.6.0 to 5.7.0
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vega-util'), require('vega-dataflow'), require('vega-scenegraph'), require('d3-array'), require('vega-functions'), require('vega-runtime'), require('d3-timer')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'vega-util', 'vega-dataflow', 'vega-scenegraph', 'd3-array', 'vega-functions', 'vega-runtime', 'd3-timer'], factory) : | ||
(global = global || self, factory(global.vega = {}, global.vega, global.vega, global.vega, global.d3, global.vega, global.vega, global.d3)); | ||
}(this, (function (exports, vegaUtil, vegaDataflow, vegaScenegraph, d3Array, vegaFunctions, vegaRuntime, d3Timer) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vega-util'), require('vega-dataflow'), require('vega-scenegraph'), require('d3-array'), require('vega-functions'), require('vega-runtime'), require('d3-timer'), require('vega-format')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'vega-util', 'vega-dataflow', 'vega-scenegraph', 'd3-array', 'vega-functions', 'vega-runtime', 'd3-timer', 'vega-format'], factory) : | ||
(global = global || self, factory(global.vega = {}, global.vega, global.vega, global.vega, global.d3, global.vega, global.vega, global.d3, global.vega)); | ||
}(this, (function (exports, vegaUtil, vegaDataflow, vegaScenegraph, d3Array, vegaFunctions, vegaRuntime, d3Timer, vegaFormat) { 'use strict'; | ||
@@ -822,4 +822,4 @@ // initialize aria role and label attributes | ||
function runtime(view, spec, functions) { | ||
var fn = functions || vegaFunctions.functionContext; | ||
return vegaRuntime.parse(spec, vegaRuntime.context(view, vegaDataflow.transforms, fn)); | ||
const fn = functions || vegaFunctions.functionContext; | ||
return vegaRuntime.context(view, vegaDataflow.transforms, fn).parse(spec); | ||
} | ||
@@ -1031,3 +1031,3 @@ | ||
function View(spec, options) { | ||
var view = this; | ||
const view = this; | ||
options = options || {}; | ||
@@ -1039,2 +1039,6 @@ | ||
if (options.logLevel != null) view.logLevel(options.logLevel); | ||
if (options.locale || spec.locale) { | ||
const loc = vegaUtil.extend({}, spec.locale, options.locale); | ||
view.locale(vegaFormat.locale(loc.number, loc.time)); | ||
} | ||
@@ -1045,3 +1049,3 @@ view._el = null; | ||
view._scenegraph = new vegaScenegraph.Scenegraph(); | ||
var root = view._scenegraph.root; | ||
const root = view._scenegraph.root; | ||
@@ -1062,3 +1066,3 @@ // initialize renderer, handler and event management | ||
// initialize dataflow graph | ||
var ctx = runtime(view, spec, options.functions); | ||
const ctx = runtime(view, spec, options.functions); | ||
view._runtime = ctx; | ||
@@ -1065,0 +1069,0 @@ view._signals = ctx.signals; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vega-util"),require("vega-dataflow"),require("vega-scenegraph"),require("d3-array"),require("vega-functions"),require("vega-runtime"),require("d3-timer")):"function"==typeof define&&define.amd?define(["exports","vega-util","vega-dataflow","vega-scenegraph","d3-array","vega-functions","vega-runtime","d3-timer"],t):t((e=e||self).vega={},e.vega,e.vega,e.vega,e.d3,e.vega,e.vega,e.d3)}(this,(function(e,t,n,i,r,s,a,o){"use strict";function u(e,t){e&&(null==t?e.removeAttribute("aria-label"):e.setAttribute("aria-label",t))}function l(e){var n=e._signals.cursor;n||(e._signals.cursor=n=e.add({user:"default",item:null})),e.on(e.events("view","mousemove"),n,(function(e,i){var r=n.value,s=r?t.isString(r)?r:r.user:"default",a=i.item&&i.item.cursor||null;return r&&s===r.user&&a==r.item?r:{user:s,item:a}})),e.add(null,(function(e){var n=e.cursor,i=this.value;return t.isString(n)||(i=n.item,n=n.user),function(e){"undefined"!=typeof document&&document.body&&(document.body.style.cursor=e)}(n&&"default"!==n?n:i||n),i}),{cursor:n})}function c(e,n){var i=e._runtime.data;return t.hasOwnProperty(i,n)||t.error("Unrecognized data set: "+n),i[n]}function d(e,i){n.isChangeSet(i)||t.error("Second argument to changes must be a changeset.");var r=c(this,e);return r.modified=!0,this.pulse(r.input,i)}function h(e){var t=e.padding();return Math.max(0,e._viewWidth+t.left+t.right)}function g(e){var t=e.padding();return Math.max(0,e._viewHeight+t.top+t.bottom)}function f(e){var t=e.padding(),n=e._origin;return[t.left+n[0],t.top+n[1]]}function p(e,n,r){var s,a,o,u=e._renderer,l=u&&u.canvas();return l&&(o=f(e),a=n.changedTouches?n.changedTouches[0]:n,(s=i.point(a,l))[0]-=o[0],s[1]-=o[1]),n.dataflow=e,n.item=r,n.vega=function(e,n,i){var r=n?"group"===n.mark.marktype?n:n.mark.group:null;function s(e){var t,i=r;if(e)for(t=n;t;t=t.mark.group)if(t.mark.name===e){i=t;break}return i&&i.mark&&i.mark.interactive?i:{}}function a(e){if(!e)return i;t.isString(e)&&(e=s(e));for(var n=i.slice();e;)n[0]-=e.x||0,n[1]-=e.y||0,e=e.mark&&e.mark.group;return n}return{view:t.constant(e),item:t.constant(n||{}),group:s,xy:a,x:function(e){return a(e)[0]},y:function(e){return a(e)[1]}}}(e,r,s),n}const v={trap:!1};function _(e,n,i){const r=e._eventConfig&&e._eventConfig[n];return!(!1===r||t.isObject(r)&&!r[i])||(e.warn(`Blocked ${n} ${i} event listener.`),!1)}function m(e){return e.item}function w(e){return e.item.mark.source}function y(e){return function(t,n){return n.vega.view().changeset().encode(n.item,e)}}function b(e,t,n){var i=document.createElement(e);for(var r in t)i.setAttribute(r,t[r]);return null!=n&&(i.textContent=n),i}function z(e,n,i){if(!n)return;const r=i.param;let s=i.state;return s||(s=i.state={elements:null,active:!1,set:null,update:t=>{t!==e.signal(r.signal)&&e.runAsync(null,(function(){s.source=!0,e.signal(r.signal,t)}))}},r.debounce&&(s.update=t.debounce(r.debounce,s.update))),function(e,t,n,i){const r=b("div",{class:"vega-bind"}),s="radio"===n.input?r:r.appendChild(b("label"));s.appendChild(b("span",{class:"vega-bind-name"},n.name||n.signal)),t.appendChild(r);let a=k;switch(n.input){case"checkbox":a=L;break;case"select":a=C;break;case"radio":a=x;break;case"range":a=A}a(e,s,n,i)}(s,n,r,e.signal(r.signal)),s.active||(e.on(e._signals[r.signal],null,()=>{s.source?s.source=!1:s.set(e.signal(r.signal))}),s.active=!0),s}function k(e,t,n,i){const r=b("input");for(const e in n)"signal"!==e&&"element"!==e&&r.setAttribute("input"===e?"type":e,n[e]);r.setAttribute("name",n.signal),r.value=i,t.appendChild(r),r.addEventListener("input",()=>e.update(r.value)),e.elements=[r],e.set=e=>r.value=e}function L(e,t,n,i){const r={type:"checkbox",name:n.signal};i&&(r.checked=!0);const s=b("input",r);t.appendChild(s),s.addEventListener("change",()=>e.update(s.checked)),e.elements=[s],e.set=e=>s.checked=!!e||null}function C(e,t,n,i){const r=b("select",{name:n.signal}),s=n.labels||[];n.options.forEach((e,t)=>{const n={value:e};S(e,i)&&(n.selected=!0),r.appendChild(b("option",n,(s[t]||e)+""))}),t.appendChild(r),r.addEventListener("change",()=>{e.update(n.options[r.selectedIndex])}),e.elements=[r],e.set=e=>{for(let t=0,i=n.options.length;t<i;++t)if(S(n.options[t],e))return void(r.selectedIndex=t)}}function x(e,t,n,i){const r=b("span",{class:"vega-bind-radio"}),s=n.labels||[];t.appendChild(r),e.elements=n.options.map((t,a)=>{const o={type:"radio",name:n.signal,value:t};S(t,i)&&(o.checked=!0);const u=b("input",o);u.addEventListener("change",()=>e.update(t));const l=b("label",{},(s[a]||t)+"");return l.prepend(u),r.appendChild(l),u}),e.set=t=>{const n=e.elements,i=n.length;for(let e=0;e<i;++e)S(n[e].value,t)&&(n[e].checked=!0)}}function A(e,t,n,i){i=void 0!==i?i:(+n.max+ +n.min)/2;const s=null!=n.max?n.max:Math.max(100,+i)||100,a=n.min||Math.min(0,s,+i)||0,o=n.step||r.tickStep(a,s,100),u=b("input",{type:"range",name:n.signal,min:a,max:s,step:o});u.value=i;const l=b("span",{},+i);t.appendChild(u),t.appendChild(l);const c=()=>{l.textContent=u.value,e.update(+u.value)};u.addEventListener("input",c),u.addEventListener("change",c),e.elements=[u],e.set=e=>{u.value=e,l.textContent=e}}function S(e,t){return e===t||e+""==t+""}function E(e,t,n,i,r,s){return(t=t||new i(e.loader())).initialize(n,h(e),g(e),f(e),r,s).background(e.background())}function D(e,t){return t?function(){try{t.apply(this,arguments)}catch(t){e.error(t)}}:null}function R(e,t){if("string"==typeof t){if("undefined"==typeof document)return e.error("DOM document instance not found."),null;if(!(t=document.querySelector(t)))return e.error("Signal bind element not found: "+t),null}if(t)try{t.innerHTML=""}catch(n){t=null,e.error(n)}return t}const T=e=>+e||0;function O(e){return t.isObject(e)?{top:T(e.top),bottom:T(e.bottom),left:T(e.left),right:T(e.right)}:(e=>({top:e,bottom:e,left:e,right:e}))(T(e))}async function j(e,n,r,s){const a=i.renderModule(n),o=a&&a.headless;return o||t.error("Unrecognized renderer type: "+n),await e.runAsync(),E(e,null,null,o,r,s).renderAsync(e._scenegraph.root)}var H={skip:!0};function U(e,t){var n=e.autosize(),i=e.padding();return t-(n&&"padding"===n.contains?i.left+i.right:0)}function M(e,t){var n=e.autosize(),i=e.padding();return t-(n&&"padding"===n.contains?i.top+i.bottom:0)}function q(e,n){return n.modified&&t.isArray(n.input.value)&&e.indexOf("_:vega:_")}function W(e,t){return!("parent"===e||t instanceof n.transforms.proxy)}function V(e,n,i,r){var s=e.element();s&&s.setAttribute("title",function(e){return null==e?"":t.isArray(e)?B(e):t.isObject(e)&&!t.isDate(e)?(n=e,Object.keys(n).map((function(e){var i=n[e];return e+": "+(t.isArray(i)?B(i):G(i))})).join("\n")):e+"";var n}(r))}function B(e){return"["+e.map(G).join(", ")+"]"}function G(e){return t.isArray(e)?"[…]":t.isObject(e)&&!t.isDate(e)?"{…}":e}function P(e,r){r=r||{},n.Dataflow.call(this),r.loader&&this.loader(r.loader),r.logger&&this.logger(r.logger),null!=r.logLevel&&this.logLevel(r.logLevel),this._el=null,this._elBind=null,this._renderType=r.renderer||i.RenderType.Canvas,this._scenegraph=new i.Scenegraph;var o=this._scenegraph.root;this._renderer=null,this._tooltip=r.tooltip||V,this._redraw=!0,this._handler=(new i.CanvasHandler).scene(o),this._preventDefault=!1,this._timers=[],this._eventListeners=[],this._resizeListeners=[],this._eventConfig=function(e){const n=t.extend({defaults:{}},e),i=(e,n)=>{n.forEach(n=>{t.isArray(e[n])&&(e[n]=t.toSet(e[n]))})};return i(n.defaults,["prevent","allow"]),i(n,["view","window","selector"]),n}(e.eventConfig);var u=function(e,t,i){var r=i||s.functionContext;return a.parse(t,a.context(e,n.transforms,r))}(this,e,r.functions);this._runtime=u,this._signals=u.signals,this._bind=(e.bindings||[]).map((function(e){return{state:null,param:t.extend({},e)}})),u.root&&u.root.set(o),o.source=u.data.root.input,this.pulse(u.data.root.input,this.changeset().insert(o.items)),this._width=this.width(),this._height=this.height(),this._viewWidth=U(this,this._width),this._viewHeight=M(this,this._height),this._origin=[0,0],this._resize=0,this._autosize=1,function(e){var t=e._signals,n=t.width,i=t.height,r=t.padding;function s(){e._autosize=e._resize=1}e._resizeWidth=e.add(null,(function(t){e._width=t.size,e._viewWidth=U(e,t.size),s()}),{size:n}),e._resizeHeight=e.add(null,(function(t){e._height=t.size,e._viewHeight=M(e,t.size),s()}),{size:i});var a=e.add(null,s,{pad:r});e._resizeWidth.rank=n.rank+1,e._resizeHeight.rank=i.rank+1,a.rank=r.rank+1}(this),function(e){e.add(null,t=>(e._background=t.bg,e._resize=1,t.bg),{bg:e._signals.background})}(this),l(this),this.description(e.description),r.hover&&this.hover(),r.container&&this.initialize(r.container,r.bind)}var I=t.inherits(P,n.Dataflow);function $(e,n){return t.hasOwnProperty(e._signals,n)?e._signals[n]:t.error("Unrecognized signal name: "+t.stringValue(n))}function N(e,t){var n=(e._targets||[]).filter((function(e){var n=e._update;return n&&n.handler===t}));return n.length?n[0]:null}function F(e,t,n,i){var r=N(n,i);return r||((r=D(this,(function(){i(t,n.value)}))).handler=i,e.on(n,null,r)),e}function J(e,t,n){var i=N(t,n);return i&&t._targets.remove(i),e}I.evaluate=async function(e,t,i){if(await n.Dataflow.prototype.evaluate.call(this,e,t),this._redraw||this._resize)try{this._renderer&&(this._resize&&(this._resize=0,s=f(r=this),a=h(r),o=g(r),r._renderer.background(r.background()),r._renderer.resize(a,o,s),r._handler.origin(s),r._resizeListeners.forEach((function(e){try{e(a,o)}catch(e){r.error(e)}}))),await this._renderer.renderAsync(this._scenegraph.root)),this._redraw=!1}catch(e){this.error(e)}var r,s,a,o;return i&&n.asyncCallback(this,i),this},I.dirty=function(e){this._redraw=!0,this._renderer&&this._renderer.dirty(e)},I.description=function(e){if(arguments.length){const t=null!=e?e+"":null;return t!==this._desc&&u(this._el,this._desc=t),this}return this._desc},I.container=function(){return this._el},I.scenegraph=function(){return this._scenegraph},I.origin=function(){return this._origin.slice()},I.signal=function(e,t,n){var i=$(this,e);return 1===arguments.length?i.value:this.update(i,t,n)},I.width=function(e){return arguments.length?this.signal("width",e):this.signal("width")},I.height=function(e){return arguments.length?this.signal("height",e):this.signal("height")},I.padding=function(e){return arguments.length?this.signal("padding",O(e)):O(this.signal("padding"))},I.autosize=function(e){return arguments.length?this.signal("autosize",e):this.signal("autosize")},I.background=function(e){return arguments.length?this.signal("background",e):this.signal("background")},I.renderer=function(e){return arguments.length?(i.renderModule(e)||t.error("Unrecognized renderer type: "+e),e!==this._renderType&&(this._renderType=e,this._resetRenderer()),this):this._renderType},I.tooltip=function(e){return arguments.length?(e!==this._tooltip&&(this._tooltip=e,this._resetRenderer()),this):this._tooltip},I.loader=function(e){return arguments.length?(e!==this._loader&&(n.Dataflow.prototype.loader.call(this,e),this._resetRenderer()),this):this._loader},I.resize=function(){return this._autosize=1,this.touch($(this,"autosize"))},I._resetRenderer=function(){this._renderer&&(this._renderer=null,this.initialize(this._el,this._elBind))},I._resizeView=function(e,t,n,i,r,s){this.runAfter((function(a){var o=0;a._autosize=0,a.width()!==n&&(o=1,a.signal("width",n,H),a._resizeWidth.skip(!0)),a.height()!==i&&(o=1,a.signal("height",i,H),a._resizeHeight.skip(!0)),a._viewWidth!==e&&(a._resize=1,a._viewWidth=e),a._viewHeight!==t&&(a._resize=1,a._viewHeight=t),a._origin[0]===r[0]&&a._origin[1]===r[1]||(a._resize=1,a._origin=r),o&&a.run("enter"),s&&a.runAfter(e=>e.resize())}),!1,1)},I.addEventListener=function(e,t,n){var i=t;return n&&!1===n.trap||((i=D(this,t)).raw=t),this._handler.on(e,i),this},I.removeEventListener=function(e,t){for(var n,i,r=this._handler.handlers(e),s=r.length;--s>=0;)if(i=r[s].type,n=r[s].handler,e===i&&(t===n||t===n.raw)){this._handler.off(i,n);break}return this},I.addResizeListener=function(e){var t=this._resizeListeners;return t.indexOf(e)<0&&t.push(e),this},I.removeResizeListener=function(e){var t=this._resizeListeners,n=t.indexOf(e);return n>=0&&t.splice(n,1),this},I.addSignalListener=function(e,t){return F(this,e,$(this,e),t)},I.removeSignalListener=function(e,t){return J(this,$(this,e),t)},I.addDataListener=function(e,t){return F(this,e,c(this,e).values,t)},I.removeDataListener=function(e,t){return J(this,c(this,e).values,t)},I.preventDefault=function(e){return arguments.length?(this._preventDefault=e,this):this._preventDefault},I.timer=function(e,t){this._timers.push(o.interval((function(t){e({timestamp:Date.now(),elapsed:t})}),t))},I.events=function(e,t,i){var r,s=this,a=new n.EventStream(i),o=function(n,i){s.runAsync(null,()=>{"view"===e&&function(e,t){var n=e._eventConfig.defaults,i=n.prevent,r=n.allow;return!1!==i&&!0!==r&&(!0===i||!1===r||(i?i[t]:r?!r[t]:e.preventDefault()))}(s,t)&&n.preventDefault(),a.receive(p(s,n,i))})};if("timer"===e)_(s,"timer",t)&&s.timer(o,t);else if("view"===e)_(s,"view",t)&&s.addEventListener(t,o,v);else if("window"===e?_(s,"window",t)&&"undefined"!=typeof window&&(r=[window]):"undefined"!=typeof document&&_(s,"selector",t)&&(r=document.querySelectorAll(e)),r){for(var u=0,l=r.length;u<l;++u)r[u].addEventListener(t,o);s._eventListeners.push({type:t,sources:r,handler:o})}else s.warn("Can not resolve event source: "+e);return a},I.finalize=function(){var e,t,n,i=this._tooltip,r=this._timers,s=this._eventListeners;for(e=r.length;--e>=0;)r[e].stop();for(e=s.length;--e>=0;)for(t=(n=s[e]).sources.length;--t>=0;)n.sources[t].removeEventListener(n.type,n.handler);return i&&i.call(this,this._handler,null,null,null),this},I.hover=function(e,t){return t=[t||"update",(e=[e||"hover"])[0]],this.on(this.events("view","mouseover",m),w,y(e)),this.on(this.events("view","mouseout",m),w,y(t)),this},I.data=function(e,i){return arguments.length<2?c(this,e).values.value:d.call(this,e,n.changeset().remove(t.truthy).insert(i))},I.change=d,I.insert=function(e,t){return d.call(this,e,n.changeset().insert(t))},I.remove=function(e,t){return d.call(this,e,n.changeset().remove(t))},I.scale=function(e){var n=this._runtime.scales;return t.hasOwnProperty(n,e)||t.error("Unrecognized scale or projection: "+e),n[e].value},I.initialize=function(e,t){const n=this,r=n._renderType,s=n._eventConfig.bind,a=i.renderModule(r);e=n._el=e?R(n,e):null,function(e){const t=e.container();t&&(t.setAttribute("role","graphics-document"),t.setAttribute("aria-roleDescription","visualization"),u(t,e.description()))}(n),a||n.error("Unrecognized renderer type: "+r);const o=a.handler||i.CanvasHandler,l=e?a.renderer:a.headless;return n._renderer=l?E(n,n._renderer,e,l):null,n._handler=function(e,t,n,i){var r=new i(e.loader(),D(e,e.tooltip())).scene(e.scenegraph().root).initialize(n,f(e),e);return t&&t.handlers().forEach((function(e){r.on(e.type,e.handler)})),r}(n,n._handler,e,o),n._redraw=!0,e&&"none"!==s&&(t=t?n._elBind=R(n,t):e.appendChild(b("form",{class:"vega-bindings"})),n._bind.forEach((function(e){e.param.element&&"container"!==s&&(e.element=R(n,e.param.element))})),n._bind.forEach((function(e){z(n,e.element||t,e)}))),n},I.toImageURL=async function(e,n){e!==i.RenderType.Canvas&&e!==i.RenderType.SVG&&e!==i.RenderType.PNG&&t.error("Unrecognized image type: "+e);const r=await j(this,e,n);return e===i.RenderType.SVG?function(e,t){var n=new Blob([e],{type:t});return window.URL.createObjectURL(n)}(r.svg(),"image/svg+xml"):r.canvas().toDataURL("image/png")},I.toCanvas=async function(e,t){return(await j(this,i.RenderType.Canvas,e,t)).canvas()},I.toSVG=async function(e){return(await j(this,i.RenderType.SVG,e)).svg()},I.getState=function(e){return this._runtime.getState(e||{data:q,signals:W,recurse:!0})},I.setState=function(e){return this.runAsync(null,t=>{t._trigger=!1,t._runtime.setState(e)},e=>{e._trigger=!0}),this},e.View=P,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("vega-util"),require("vega-dataflow"),require("vega-scenegraph"),require("d3-array"),require("vega-functions"),require("vega-runtime"),require("d3-timer"),require("vega-format")):"function"==typeof define&&define.amd?define(["exports","vega-util","vega-dataflow","vega-scenegraph","d3-array","vega-functions","vega-runtime","d3-timer","vega-format"],n):n((e=e||self).vega={},e.vega,e.vega,e.vega,e.d3,e.vega,e.vega,e.d3,e.vega)}(this,(function(e,n,t,r,i,a,s,o,u){"use strict";function l(e,n){e&&(null==n?e.removeAttribute("aria-label"):e.setAttribute("aria-label",n))}function c(e){var t=e._signals.cursor;t||(e._signals.cursor=t=e.add({user:"default",item:null})),e.on(e.events("view","mousemove"),t,(function(e,r){var i=t.value,a=i?n.isString(i)?i:i.user:"default",s=r.item&&r.item.cursor||null;return i&&a===i.user&&s==i.item?i:{user:a,item:s}})),e.add(null,(function(e){var t=e.cursor,r=this.value;return n.isString(t)||(r=t.item,t=t.user),function(e){"undefined"!=typeof document&&document.body&&(document.body.style.cursor=e)}(t&&"default"!==t?t:r||t),r}),{cursor:t})}function d(e,t){var r=e._runtime.data;return n.hasOwnProperty(r,t)||n.error("Unrecognized data set: "+t),r[t]}function h(e,r){t.isChangeSet(r)||n.error("Second argument to changes must be a changeset.");var i=d(this,e);return i.modified=!0,this.pulse(i.input,r)}function g(e){var n=e.padding();return Math.max(0,e._viewWidth+n.left+n.right)}function f(e){var n=e.padding();return Math.max(0,e._viewHeight+n.top+n.bottom)}function p(e){var n=e.padding(),t=e._origin;return[n.left+t[0],n.top+t[1]]}function v(e,t,i){var a,s,o,u=e._renderer,l=u&&u.canvas();return l&&(o=p(e),s=t.changedTouches?t.changedTouches[0]:t,(a=r.point(s,l))[0]-=o[0],a[1]-=o[1]),t.dataflow=e,t.item=i,t.vega=function(e,t,r){var i=t?"group"===t.mark.marktype?t:t.mark.group:null;function a(e){var n,r=i;if(e)for(n=t;n;n=n.mark.group)if(n.mark.name===e){r=n;break}return r&&r.mark&&r.mark.interactive?r:{}}function s(e){if(!e)return r;n.isString(e)&&(e=a(e));for(var t=r.slice();e;)t[0]-=e.x||0,t[1]-=e.y||0,e=e.mark&&e.mark.group;return t}return{view:n.constant(e),item:n.constant(t||{}),group:a,xy:s,x:function(e){return s(e)[0]},y:function(e){return s(e)[1]}}}(e,i,a),t}const _={trap:!1};function m(e,t,r){const i=e._eventConfig&&e._eventConfig[t];return!(!1===i||n.isObject(i)&&!i[r])||(e.warn(`Blocked ${t} ${r} event listener.`),!1)}function w(e){return e.item}function y(e){return e.item.mark.source}function b(e){return function(n,t){return t.vega.view().changeset().encode(t.item,e)}}function z(e,n,t){var r=document.createElement(e);for(var i in n)r.setAttribute(i,n[i]);return null!=t&&(r.textContent=t),r}function k(e,t,r){if(!t)return;const i=r.param;let a=r.state;return a||(a=r.state={elements:null,active:!1,set:null,update:n=>{n!==e.signal(i.signal)&&e.runAsync(null,(function(){a.source=!0,e.signal(i.signal,n)}))}},i.debounce&&(a.update=n.debounce(i.debounce,a.update))),function(e,n,t,r){const i=z("div",{class:"vega-bind"}),a="radio"===t.input?i:i.appendChild(z("label"));a.appendChild(z("span",{class:"vega-bind-name"},t.name||t.signal)),n.appendChild(i);let s=L;switch(t.input){case"checkbox":s=C;break;case"select":s=x;break;case"radio":s=A;break;case"range":s=S}s(e,a,t,r)}(a,t,i,e.signal(i.signal)),a.active||(e.on(e._signals[i.signal],null,()=>{a.source?a.source=!1:a.set(e.signal(i.signal))}),a.active=!0),a}function L(e,n,t,r){const i=z("input");for(const e in t)"signal"!==e&&"element"!==e&&i.setAttribute("input"===e?"type":e,t[e]);i.setAttribute("name",t.signal),i.value=r,n.appendChild(i),i.addEventListener("input",()=>e.update(i.value)),e.elements=[i],e.set=e=>i.value=e}function C(e,n,t,r){const i={type:"checkbox",name:t.signal};r&&(i.checked=!0);const a=z("input",i);n.appendChild(a),a.addEventListener("change",()=>e.update(a.checked)),e.elements=[a],e.set=e=>a.checked=!!e||null}function x(e,n,t,r){const i=z("select",{name:t.signal}),a=t.labels||[];t.options.forEach((e,n)=>{const t={value:e};E(e,r)&&(t.selected=!0),i.appendChild(z("option",t,(a[n]||e)+""))}),n.appendChild(i),i.addEventListener("change",()=>{e.update(t.options[i.selectedIndex])}),e.elements=[i],e.set=e=>{for(let n=0,r=t.options.length;n<r;++n)if(E(t.options[n],e))return void(i.selectedIndex=n)}}function A(e,n,t,r){const i=z("span",{class:"vega-bind-radio"}),a=t.labels||[];n.appendChild(i),e.elements=t.options.map((n,s)=>{const o={type:"radio",name:t.signal,value:n};E(n,r)&&(o.checked=!0);const u=z("input",o);u.addEventListener("change",()=>e.update(n));const l=z("label",{},(a[s]||n)+"");return l.prepend(u),i.appendChild(l),u}),e.set=n=>{const t=e.elements,r=t.length;for(let e=0;e<r;++e)E(t[e].value,n)&&(t[e].checked=!0)}}function S(e,n,t,r){r=void 0!==r?r:(+t.max+ +t.min)/2;const a=null!=t.max?t.max:Math.max(100,+r)||100,s=t.min||Math.min(0,a,+r)||0,o=t.step||i.tickStep(s,a,100),u=z("input",{type:"range",name:t.signal,min:s,max:a,step:o});u.value=r;const l=z("span",{},+r);n.appendChild(u),n.appendChild(l);const c=()=>{l.textContent=u.value,e.update(+u.value)};u.addEventListener("input",c),u.addEventListener("change",c),e.elements=[u],e.set=e=>{u.value=e,l.textContent=e}}function E(e,n){return e===n||e+""==n+""}function D(e,n,t,r,i,a){return(n=n||new r(e.loader())).initialize(t,g(e),f(e),p(e),i,a).background(e.background())}function R(e,n){return n?function(){try{n.apply(this,arguments)}catch(n){e.error(n)}}:null}function T(e,n){if("string"==typeof n){if("undefined"==typeof document)return e.error("DOM document instance not found."),null;if(!(n=document.querySelector(n)))return e.error("Signal bind element not found: "+n),null}if(n)try{n.innerHTML=""}catch(t){n=null,e.error(t)}return n}const O=e=>+e||0;function j(e){return n.isObject(e)?{top:O(e.top),bottom:O(e.bottom),left:O(e.left),right:O(e.right)}:(e=>({top:e,bottom:e,left:e,right:e}))(O(e))}async function H(e,t,i,a){const s=r.renderModule(t),o=s&&s.headless;return o||n.error("Unrecognized renderer type: "+t),await e.runAsync(),D(e,null,null,o,i,a).renderAsync(e._scenegraph.root)}var U={skip:!0};function q(e,n){var t=e.autosize(),r=e.padding();return n-(t&&"padding"===t.contains?r.left+r.right:0)}function M(e,n){var t=e.autosize(),r=e.padding();return n-(t&&"padding"===t.contains?r.top+r.bottom:0)}function W(e,t){return t.modified&&n.isArray(t.input.value)&&e.indexOf("_:vega:_")}function V(e,n){return!("parent"===e||n instanceof t.transforms.proxy)}function B(e,t,r,i){var a=e.element();a&&a.setAttribute("title",function(e){return null==e?"":n.isArray(e)?G(e):n.isObject(e)&&!n.isDate(e)?(t=e,Object.keys(t).map((function(e){var r=t[e];return e+": "+(n.isArray(r)?G(r):P(r))})).join("\n")):e+"";var t}(i))}function G(e){return"["+e.map(P).join(", ")+"]"}function P(e){return n.isArray(e)?"[…]":n.isObject(e)&&!n.isDate(e)?"{…}":e}function I(e,i){const o=this;if(i=i||{},t.Dataflow.call(o),i.loader&&o.loader(i.loader),i.logger&&o.logger(i.logger),null!=i.logLevel&&o.logLevel(i.logLevel),i.locale||e.locale){const t=n.extend({},e.locale,i.locale);o.locale(u.locale(t.number,t.time))}o._el=null,o._elBind=null,o._renderType=i.renderer||r.RenderType.Canvas,o._scenegraph=new r.Scenegraph;const l=o._scenegraph.root;o._renderer=null,o._tooltip=i.tooltip||B,o._redraw=!0,o._handler=(new r.CanvasHandler).scene(l),o._preventDefault=!1,o._timers=[],o._eventListeners=[],o._resizeListeners=[],o._eventConfig=function(e){const t=n.extend({defaults:{}},e),r=(e,t)=>{t.forEach(t=>{n.isArray(e[t])&&(e[t]=n.toSet(e[t]))})};return r(t.defaults,["prevent","allow"]),r(t,["view","window","selector"]),t}(e.eventConfig);const d=function(e,n,r){const i=r||a.functionContext;return s.context(e,t.transforms,i).parse(n)}(o,e,i.functions);o._runtime=d,o._signals=d.signals,o._bind=(e.bindings||[]).map((function(e){return{state:null,param:n.extend({},e)}})),d.root&&d.root.set(l),l.source=d.data.root.input,o.pulse(d.data.root.input,o.changeset().insert(l.items)),o._width=o.width(),o._height=o.height(),o._viewWidth=q(o,o._width),o._viewHeight=M(o,o._height),o._origin=[0,0],o._resize=0,o._autosize=1,function(e){var n=e._signals,t=n.width,r=n.height,i=n.padding;function a(){e._autosize=e._resize=1}e._resizeWidth=e.add(null,(function(n){e._width=n.size,e._viewWidth=q(e,n.size),a()}),{size:t}),e._resizeHeight=e.add(null,(function(n){e._height=n.size,e._viewHeight=M(e,n.size),a()}),{size:r});var s=e.add(null,a,{pad:i});e._resizeWidth.rank=t.rank+1,e._resizeHeight.rank=r.rank+1,s.rank=i.rank+1}(o),function(e){e.add(null,n=>(e._background=n.bg,e._resize=1,n.bg),{bg:e._signals.background})}(o),c(o),o.description(e.description),i.hover&&o.hover(),i.container&&o.initialize(i.container,i.bind)}var $=n.inherits(I,t.Dataflow);function N(e,t){return n.hasOwnProperty(e._signals,t)?e._signals[t]:n.error("Unrecognized signal name: "+n.stringValue(t))}function F(e,n){var t=(e._targets||[]).filter((function(e){var t=e._update;return t&&t.handler===n}));return t.length?t[0]:null}function J(e,n,t,r){var i=F(t,r);return i||((i=R(this,(function(){r(n,t.value)}))).handler=r,e.on(t,null,i)),e}function K(e,n,t){var r=F(n,t);return r&&n._targets.remove(r),e}$.evaluate=async function(e,n,r){if(await t.Dataflow.prototype.evaluate.call(this,e,n),this._redraw||this._resize)try{this._renderer&&(this._resize&&(this._resize=0,a=p(i=this),s=g(i),o=f(i),i._renderer.background(i.background()),i._renderer.resize(s,o,a),i._handler.origin(a),i._resizeListeners.forEach((function(e){try{e(s,o)}catch(e){i.error(e)}}))),await this._renderer.renderAsync(this._scenegraph.root)),this._redraw=!1}catch(e){this.error(e)}var i,a,s,o;return r&&t.asyncCallback(this,r),this},$.dirty=function(e){this._redraw=!0,this._renderer&&this._renderer.dirty(e)},$.description=function(e){if(arguments.length){const n=null!=e?e+"":null;return n!==this._desc&&l(this._el,this._desc=n),this}return this._desc},$.container=function(){return this._el},$.scenegraph=function(){return this._scenegraph},$.origin=function(){return this._origin.slice()},$.signal=function(e,n,t){var r=N(this,e);return 1===arguments.length?r.value:this.update(r,n,t)},$.width=function(e){return arguments.length?this.signal("width",e):this.signal("width")},$.height=function(e){return arguments.length?this.signal("height",e):this.signal("height")},$.padding=function(e){return arguments.length?this.signal("padding",j(e)):j(this.signal("padding"))},$.autosize=function(e){return arguments.length?this.signal("autosize",e):this.signal("autosize")},$.background=function(e){return arguments.length?this.signal("background",e):this.signal("background")},$.renderer=function(e){return arguments.length?(r.renderModule(e)||n.error("Unrecognized renderer type: "+e),e!==this._renderType&&(this._renderType=e,this._resetRenderer()),this):this._renderType},$.tooltip=function(e){return arguments.length?(e!==this._tooltip&&(this._tooltip=e,this._resetRenderer()),this):this._tooltip},$.loader=function(e){return arguments.length?(e!==this._loader&&(t.Dataflow.prototype.loader.call(this,e),this._resetRenderer()),this):this._loader},$.resize=function(){return this._autosize=1,this.touch(N(this,"autosize"))},$._resetRenderer=function(){this._renderer&&(this._renderer=null,this.initialize(this._el,this._elBind))},$._resizeView=function(e,n,t,r,i,a){this.runAfter((function(s){var o=0;s._autosize=0,s.width()!==t&&(o=1,s.signal("width",t,U),s._resizeWidth.skip(!0)),s.height()!==r&&(o=1,s.signal("height",r,U),s._resizeHeight.skip(!0)),s._viewWidth!==e&&(s._resize=1,s._viewWidth=e),s._viewHeight!==n&&(s._resize=1,s._viewHeight=n),s._origin[0]===i[0]&&s._origin[1]===i[1]||(s._resize=1,s._origin=i),o&&s.run("enter"),a&&s.runAfter(e=>e.resize())}),!1,1)},$.addEventListener=function(e,n,t){var r=n;return t&&!1===t.trap||((r=R(this,n)).raw=n),this._handler.on(e,r),this},$.removeEventListener=function(e,n){for(var t,r,i=this._handler.handlers(e),a=i.length;--a>=0;)if(r=i[a].type,t=i[a].handler,e===r&&(n===t||n===t.raw)){this._handler.off(r,t);break}return this},$.addResizeListener=function(e){var n=this._resizeListeners;return n.indexOf(e)<0&&n.push(e),this},$.removeResizeListener=function(e){var n=this._resizeListeners,t=n.indexOf(e);return t>=0&&n.splice(t,1),this},$.addSignalListener=function(e,n){return J(this,e,N(this,e),n)},$.removeSignalListener=function(e,n){return K(this,N(this,e),n)},$.addDataListener=function(e,n){return J(this,e,d(this,e).values,n)},$.removeDataListener=function(e,n){return K(this,d(this,e).values,n)},$.preventDefault=function(e){return arguments.length?(this._preventDefault=e,this):this._preventDefault},$.timer=function(e,n){this._timers.push(o.interval((function(n){e({timestamp:Date.now(),elapsed:n})}),n))},$.events=function(e,n,r){var i,a=this,s=new t.EventStream(r),o=function(t,r){a.runAsync(null,()=>{"view"===e&&function(e,n){var t=e._eventConfig.defaults,r=t.prevent,i=t.allow;return!1!==r&&!0!==i&&(!0===r||!1===i||(r?r[n]:i?!i[n]:e.preventDefault()))}(a,n)&&t.preventDefault(),s.receive(v(a,t,r))})};if("timer"===e)m(a,"timer",n)&&a.timer(o,n);else if("view"===e)m(a,"view",n)&&a.addEventListener(n,o,_);else if("window"===e?m(a,"window",n)&&"undefined"!=typeof window&&(i=[window]):"undefined"!=typeof document&&m(a,"selector",n)&&(i=document.querySelectorAll(e)),i){for(var u=0,l=i.length;u<l;++u)i[u].addEventListener(n,o);a._eventListeners.push({type:n,sources:i,handler:o})}else a.warn("Can not resolve event source: "+e);return s},$.finalize=function(){var e,n,t,r=this._tooltip,i=this._timers,a=this._eventListeners;for(e=i.length;--e>=0;)i[e].stop();for(e=a.length;--e>=0;)for(n=(t=a[e]).sources.length;--n>=0;)t.sources[n].removeEventListener(t.type,t.handler);return r&&r.call(this,this._handler,null,null,null),this},$.hover=function(e,n){return n=[n||"update",(e=[e||"hover"])[0]],this.on(this.events("view","mouseover",w),y,b(e)),this.on(this.events("view","mouseout",w),y,b(n)),this},$.data=function(e,r){return arguments.length<2?d(this,e).values.value:h.call(this,e,t.changeset().remove(n.truthy).insert(r))},$.change=h,$.insert=function(e,n){return h.call(this,e,t.changeset().insert(n))},$.remove=function(e,n){return h.call(this,e,t.changeset().remove(n))},$.scale=function(e){var t=this._runtime.scales;return n.hasOwnProperty(t,e)||n.error("Unrecognized scale or projection: "+e),t[e].value},$.initialize=function(e,n){const t=this,i=t._renderType,a=t._eventConfig.bind,s=r.renderModule(i);e=t._el=e?T(t,e):null,function(e){const n=e.container();n&&(n.setAttribute("role","graphics-document"),n.setAttribute("aria-roleDescription","visualization"),l(n,e.description()))}(t),s||t.error("Unrecognized renderer type: "+i);const o=s.handler||r.CanvasHandler,u=e?s.renderer:s.headless;return t._renderer=u?D(t,t._renderer,e,u):null,t._handler=function(e,n,t,r){var i=new r(e.loader(),R(e,e.tooltip())).scene(e.scenegraph().root).initialize(t,p(e),e);return n&&n.handlers().forEach((function(e){i.on(e.type,e.handler)})),i}(t,t._handler,e,o),t._redraw=!0,e&&"none"!==a&&(n=n?t._elBind=T(t,n):e.appendChild(z("form",{class:"vega-bindings"})),t._bind.forEach((function(e){e.param.element&&"container"!==a&&(e.element=T(t,e.param.element))})),t._bind.forEach((function(e){k(t,e.element||n,e)}))),t},$.toImageURL=async function(e,t){e!==r.RenderType.Canvas&&e!==r.RenderType.SVG&&e!==r.RenderType.PNG&&n.error("Unrecognized image type: "+e);const i=await H(this,e,t);return e===r.RenderType.SVG?function(e,n){var t=new Blob([e],{type:n});return window.URL.createObjectURL(t)}(i.svg(),"image/svg+xml"):i.canvas().toDataURL("image/png")},$.toCanvas=async function(e,n){return(await H(this,r.RenderType.Canvas,e,n)).canvas()},$.toSVG=async function(e){return(await H(this,r.RenderType.SVG,e)).svg()},$.getState=function(e){return this._runtime.getState(e||{data:W,signals:V,recurse:!0})},$.setState=function(e){return this.runAsync(null,n=>{n._trigger=!1,n._runtime.setState(e)},e=>{e._trigger=!0}),this},e.View=I,Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "vega-view", | ||
"version": "5.6.0", | ||
"version": "5.7.0", | ||
"description": "View component and transforms for Vega visualizations.", | ||
@@ -16,3 +16,3 @@ "keywords": [ | ||
"scripts": { | ||
"rollup": "rollup -g d3-array:d3,d3-timer:d3,vega-dataflow:vega,vega-functions:vega,vega-runtime:vega,vega-scenegraph:vega,vega-util:vega -f umd -n vega -o build/vega-view.js -- index.js", | ||
"rollup": "rollup -g d3-array:d3,d3-timer:d3,vega-dataflow:vega,vega-format:vega,vega-functions:vega,vega-runtime:vega,vega-scenegraph:vega,vega-util:vega -f umd -n vega -o build/vega-view.js -- index.js", | ||
"prebuild": "rimraf build && mkdir build", | ||
@@ -29,9 +29,10 @@ "build": "yarn rollup", | ||
"d3-timer": "^1.0.10", | ||
"vega-dataflow": "^5.5.1", | ||
"vega-functions": "^5.6.0", | ||
"vega-runtime": "^5.0.3", | ||
"vega-scenegraph": "^4.7.0", | ||
"vega-util": "^1.13.2" | ||
"vega-dataflow": "^5.6.0", | ||
"vega-format": "^1.0.0", | ||
"vega-functions": "^5.7.0", | ||
"vega-runtime": "^6.0.0", | ||
"vega-scenegraph": "^4.8.0", | ||
"vega-util": "^1.14.0" | ||
}, | ||
"gitHead": "35e31c5c6b54db9dc3a577b5adad8d15ec274d32" | ||
"gitHead": "48c85218f2202242171aa569f2dca0f53cf2b51f" | ||
} |
import {transforms} from 'vega-dataflow'; | ||
import {functionContext} from 'vega-functions'; | ||
import {context, parse} from 'vega-runtime'; | ||
import {context} from 'vega-runtime'; | ||
export default function(view, spec, functions) { | ||
var fn = functions || functionContext; | ||
return parse(spec, context(view, transforms, fn)); | ||
const fn = functions || functionContext; | ||
return context(view, transforms, fn).parse(spec); | ||
} |
@@ -23,7 +23,9 @@ import {ariaLabel} from './aria'; | ||
import {Dataflow, asyncCallback} from 'vega-dataflow'; | ||
import {error, extend, hasOwnProperty, inherits, stringValue} from 'vega-util'; | ||
import {locale} from 'vega-format'; | ||
import { | ||
CanvasHandler, RenderType, | ||
Scenegraph, renderModule | ||
CanvasHandler, RenderType, Scenegraph, renderModule | ||
} from 'vega-scenegraph'; | ||
import { | ||
error, extend, hasOwnProperty, inherits, stringValue | ||
} from 'vega-util'; | ||
@@ -41,3 +43,3 @@ /** | ||
export default function View(spec, options) { | ||
var view = this; | ||
const view = this; | ||
options = options || {}; | ||
@@ -49,2 +51,6 @@ | ||
if (options.logLevel != null) view.logLevel(options.logLevel); | ||
if (options.locale || spec.locale) { | ||
const loc = extend({}, spec.locale, options.locale); | ||
view.locale(locale(loc.number, loc.time)); | ||
} | ||
@@ -55,3 +61,3 @@ view._el = null; | ||
view._scenegraph = new Scenegraph(); | ||
var root = view._scenegraph.root; | ||
const root = view._scenegraph.root; | ||
@@ -72,3 +78,3 @@ // initialize renderer, handler and event management | ||
// initialize dataflow graph | ||
var ctx = runtime(view, spec, options.functions); | ||
const ctx = runtime(view, spec, options.functions); | ||
view._runtime = ctx; | ||
@@ -75,0 +81,0 @@ view._signals = ctx.signals; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98860
2369
8
+ Addedvega-format@^1.0.0
+ Addedvega-runtime@6.2.0(transitive)
- Removedvega-runtime@5.0.3(transitive)
Updatedvega-dataflow@^5.6.0
Updatedvega-functions@^5.7.0
Updatedvega-runtime@^6.0.0
Updatedvega-scenegraph@^4.8.0
Updatedvega-util@^1.14.0