Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vega-view

Package Overview
Dependencies
Maintainers
1
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vega-view - npm Package Compare versions

Comparing version 3.3.3 to 3.4.0

38

build/vega-view.js

@@ -1224,4 +1224,4 @@ (function (global, factory) {

function findSignalHandler(signal, handler) {
var t = signal._targets || [],
function findOperatorHandler(op, handler) {
var t = op._targets || [],
h = t.filter(function(op) {

@@ -1234,22 +1234,34 @@ var u = op._update;

prototype.addSignalListener = function(name, handler) {
var s = lookupSignal(this, name),
h = findSignalHandler(s, handler);
function addOperatorListener(view, name, op, handler) {
var h = findOperatorHandler(op, handler);
if (!h) {
h = trap(this, function() { handler(name, s.value); });
h = trap(this, function() { handler(name, op.value); });
h.handler = handler;
this.on(s, null, h);
view.on(op, null, h);
}
return this;
return view;
}
function removeOperatorListener(view, op, handler) {
var h = findOperatorHandler(op, handler);
if (h) op._targets.remove(h);
return view;
}
prototype.addSignalListener = function(name, handler) {
return addOperatorListener(this, name, lookupSignal(this, name), handler);
};
prototype.removeSignalListener = function(name, handler) {
var s = lookupSignal(this, name),
h = findSignalHandler(s, handler);
return removeOperatorListener(this, lookupSignal(this, name), handler);
};
if (h) s._targets.remove(h);
return this;
prototype.addDataListener = function(name, handler) {
return addOperatorListener(this, name, dataref(this, name).values, handler);
};
prototype.removeDataListener = function(name, handler) {
return removeOperatorListener(this, dataref(this, name).values, handler);
};
prototype.preventDefault = function(_) {

@@ -1256,0 +1268,0 @@ if (arguments.length) {

@@ -1,1 +0,1 @@

!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-parser"),require("vega-runtime"),require("d3-timer")):"function"==typeof define&&define.amd?define(["exports","vega-util","vega-dataflow","vega-scenegraph","d3-array","vega-parser","vega-runtime","d3-timer"],n):n(e.vega={},e.vega,e.vega,e.vega,e.d3,e.vega,e.vega,e.d3)}(this,function(e,c,h,f,d,g,v,t){"use strict";var s="default";function p(e){var a=e._signals.cursor;a||(e._signals.cursor=a=e.add({user:s,item:null})),e.on(e.events("view","mousemove"),a,function(e,n){var t=a.value,r=t?c.isString(t)?t:t.user:s,i=n.item&&n.item.cursor||null;return t&&r===t.user&&i==t.item?t:{user:r,item:i}}),e.add(null,function(e){var n,t=e.cursor,r=this.value;return c.isString(t)||(r=t.item,t=t.user),n=t&&t!==s?t:r||t,"undefined"!=typeof document&&document.body&&(document.body.style.cursor=n),r},{cursor:a})}function r(e,n){var t=e._runtime.data;return t.hasOwnProperty(n)||c.error("Unrecognized data set: "+n),t[n]}function i(e,n){h.isChangeSet(n)||c.error("Second argument to changes must be a changeset.");var t=r(this,e);return t.modified=!0,this.pulse(t.input,n)}function a(e){var n=e.padding();return Math.max(0,e._viewWidth+n.left+n.right)}function o(e){var n=e.padding();return Math.max(0,e._viewHeight+n.top+n.bottom)}function _(e){var n=e.padding(),t=e._origin;return[n.left+t[0],n.top+t[1]]}function m(e,n,t){var r,i,a,s=e._renderer.canvas();return s&&(a=_(e),i=n.changedTouches?n.changedTouches[0]:n,(r=f.point(i,s))[0]-=a[0],r[1]-=a[1]),n.dataflow=e,n.vega=function(e,r,t){var i=r?"group"===r.mark.marktype?r:r.mark.group:null;function a(e){var n,t=i;if(e)for(n=r;n;n=n.mark.group)if(n.mark.name===e){t=n;break}return t&&t.mark&&t.mark.interactive?t:{}}function n(e){if(!e)return t;c.isString(e)&&(e=a(e));for(var n=t.slice();e;)n[0]-=e.x||0,n[1]-=e.y||0,e=e.mark&&e.mark.group;return n}return{view:c.constant(e),item:c.constant(r||{}),group:a,xy:n,x:function(e){return n(e)[0]},y:function(e){return n(e)[1]}}}(e,t,r),n.item=t,n}var y="view",w={trap:!1};function u(e){return e.item}function l(e){var n=e.item.mark.source;return n.source||n}function z(t){return function(e,n){return n.vega.view().changeset().encode(n.item,t)}}function b(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}var k="vega-bind",L="vega-bind-name",n="vega-bind-radio",x="vega-option-";function C(n,e,t){if(e){var r=t.param,i=t.state;return i||(i=t.state={elements:null,active:!1,set:null,update:function(e){e!==n.signal(r.signal)&&(i.source=!0,n.signal(r.signal,e).run())}},r.debounce&&(i.update=c.debounce(r.debounce,i.update))),function(e,n,t,r){var i=b("div",{class:k});i.appendChild(b("span",{class:L},t.name||t.signal)),n.appendChild(i);var a=S;switch(t.input){case"checkbox":a=E;break;case"select":a=A;break;case"radio":a=R;break;case"range":a=D}a(e,i,t,r)}(i,e,r,n.signal(r.signal)),i.active||(n.on(n._signals[r.signal],null,function(){i.source?i.source=!1:i.set(n.signal(r.signal))}),i.active=!0),i}}function S(e,n,t,r){var i=b("input");for(var a in t)"signal"!==a&&"element"!==a&&i.setAttribute("input"===a?"type":a,t[a]);i.setAttribute("name",t.signal),i.value=r,n.appendChild(i),i.addEventListener("input",function(){e.update(i.value)}),e.elements=[i],e.set=function(e){i.value=e}}function E(e,n,t,r){var i={type:"checkbox",name:t.signal};r&&(i.checked=!0);var a=b("input",i);n.appendChild(a),a.addEventListener("change",function(){e.update(a.checked)}),e.elements=[a],e.set=function(e){a.checked=!!e||null}}function A(e,n,r,t){var i=b("select",{name:r.signal});r.options.forEach(function(e){var n={value:e};T(e,t)&&(n.selected=!0),i.appendChild(b("option",n,e+""))}),n.appendChild(i),i.addEventListener("change",function(){e.update(r.options[i.selectedIndex])}),e.elements=[i],e.set=function(e){for(var n=0,t=r.options.length;n<t;++n)if(T(r.options[n],e))return void(i.selectedIndex=n)}}function R(i,e,a,s){var o=b("span",{class:n});e.appendChild(o),i.elements=a.options.map(function(e){var n=x+a.signal+"-"+e,t={id:n,type:"radio",name:a.signal,value:e};T(e,s)&&(t.checked=!0);var r=b("input",t);return r.addEventListener("change",function(){i.update(e)}),o.appendChild(r),o.appendChild(b("label",{for:n},e+"")),r}),i.set=function(e){for(var n=i.elements,t=0,r=n.length;t<r;++t)T(n[t].value,e)&&(n[t].checked=!0)}}function D(e,n,t,r){r=void 0!==r?r:(+t.max+ +t.min)/2;var i=t.min||Math.min(0,+r)||0,a=t.max||Math.max(100,+r)||100,s=t.step||d.tickStep(i,a,100),o=b("input",{type:"range",name:t.signal,min:i,max:a,step:s}),u=b("label",{},+(o.value=r));function l(){u.textContent=o.value,e.update(+o.value)}n.appendChild(o),n.appendChild(u),o.addEventListener("input",l),o.addEventListener("change",l),e.elements=[o],e.set=function(e){o.value=e,u.textContent=e}}function T(e,n){return e===n||e+""==n+""}function O(e,n,t,r,i){return(n=n||new r(e.loader())).initialize(t,a(e),o(e),_(e),i).background(e._background)}function j(n,e){return e?function(){try{e.apply(this,arguments)}catch(e){n.error(e)}}:null}function H(n,t){if("string"==typeof t){if("undefined"==typeof document)return n.error("DOM document instance not found."),null;if(!(t=document.querySelector(t)))return n.error("Signal bind element not found: "+t),null}if(t)try{t.innerHTML=""}catch(e){t=null,n.error(e)}return t}function U(e,n,t){var r=f.renderModule(n),i=r&&r.headless;return i?e.runAsync().then(function(){return O(e,null,null,i,t).renderAsync(e._scenegraph.root)}):Promise.reject("Unrecognized renderer type: "+n)}var M="width",q="height",W="padding",P={skip:!0};function V(e,n){var t=e.autosize(),r=e.padding();return n-(t&&t.contains===W?r.left+r.right:0)}function G(e,n){var t=e.autosize(),r=e.padding();return n-(t&&t.contains===W?r.top+r.bottom:0)}function I(e,n){return n.modified&&c.isArray(n.input.value)&&e.indexOf("_:vega:_")}function B(e,n){return!("parent"===e||n instanceof h.transforms.proxy)}function N(e,n,t,r){var i,a,s=e.element();s&&s.setAttribute("title",null==(i=r)?"":c.isArray(i)?F(i):c.isObject(i)&&!c.isDate(i)?(a=i,Object.keys(a).map(function(e){var n=a[e];return e+": "+(c.isArray(n)?F(n):J(n))}).join("\n")):i+"")}function F(e){return"["+e.map(J).join(", ")+"]"}function J(e){return c.isArray(e)?"[…]":c.isObject(e)&&!c.isDate(e)?"{…}":e}function K(e,n){var t=this;n=n||{},h.Dataflow.call(t),t.loader(n.loader||t._loader),t.logLevel(n.logLevel||0),t._el=null,t._renderType=n.renderer||f.RenderType.Canvas,t._scenegraph=new f.Scenegraph;var r=t._scenegraph.root;t._renderer=null,t._tooltip=n.tooltip||N,t._redraw=!0,t._handler=(new f.CanvasHandler).scene(r),t._preventDefault=!1,t._timers=[],t._eventListeners=[],t._resizeListeners=[];var i,a,s,o,u,l,d=(i=t,a=e,s=n.functions,o=s||g.functionContext,v.parse(a,v.context(i,h.transforms,o)));t._runtime=d,t._signals=d.signals,t._bind=(e.bindings||[]).map(function(e){return{state:null,param:c.extend({},e)}}),d.root&&d.root.set(r),r.source=d.data.root.input,t.pulse(d.data.root.input,t.changeset().insert(r.items)),t._background=d.background||null,t._eventConfig=(u=d.eventConfig,(l=(u=c.extend({},u)).defaults)&&(c.isArray(l.prevent)&&(l.prevent=c.toSet(l.prevent)),c.isArray(l.allow)&&(l.allow=c.toSet(l.allow))),u),t._width=t.width(),t._height=t.height(),t._viewWidth=V(t,t._width),t._viewHeight=G(t,t._height),t._origin=[0,0],t._resize=0,t._autosize=1,function(n){var e=n._signals,t=e[M],r=e[q],i=e[W];function a(){n._autosize=n._resize=1}n._resizeWidth=n.add(null,function(e){n._width=e.size,n._viewWidth=V(n,e.size),a()},{size:t}),n._resizeHeight=n.add(null,function(e){n._height=e.size,n._viewHeight=G(n,e.size),a()},{size:r});var s=n.add(null,a,{pad:i});n._resizeWidth.rank=t.rank+1,n._resizeHeight.rank=r.rank+1,s.rank=i.rank+1}(t),p(t)}var Q=c.inherits(K,h.Dataflow);function X(e,n){return e._signals.hasOwnProperty(n)?e._signals[n]:c.error("Unrecognized signal name: "+c.stringValue(n))}function Y(e,t){var n=(e._targets||[]).filter(function(e){var n=e._update;return n&&n.handler===t});return n.length?n[0]:null}Q.run=function(e){if(h.Dataflow.prototype.run.call(this,e),this._pending)this.resize();else if(this._redraw||this._resize)try{this.render()}catch(e){this.error(e)}return this},Q.render=function(){var n,e,t,r;return this._renderer&&(this._resize&&(this._resize=0,e=_(n=this),t=a(n),r=o(n),n._renderer.background(n._background),n._renderer.resize(t,r,e),n._handler.origin(e),n._resizeListeners.forEach(function(e){try{e(t,r)}catch(e){n.error(e)}})),this._renderer.render(this._scenegraph.root)),this._redraw=!1,this},Q.dirty=function(e){this._redraw=!0,this._renderer&&this._renderer.dirty(e)},Q.container=function(){return this._el},Q.scenegraph=function(){return this._scenegraph},Q.origin=function(){return this._origin.slice()},Q.signal=function(e,n,t){var r=X(this,e);return 1===arguments.length?r.value:this.update(r,n,t)},Q.background=function(e){return arguments.length?(this._background=e,this._resize=1,this):this._background},Q.width=function(e){return arguments.length?this.signal("width",e):this.signal("width")},Q.height=function(e){return arguments.length?this.signal("height",e):this.signal("height")},Q.padding=function(e){return arguments.length?this.signal("padding",e):this.signal("padding")},Q.autosize=function(e){return arguments.length?this.signal("autosize",e):this.signal("autosize")},Q.renderer=function(e){return arguments.length?(f.renderModule(e)||c.error("Unrecognized renderer type: "+e),e!==this._renderType&&(this._renderType=e,this._resetRenderer()),this):this._renderType},Q.tooltip=function(e){return arguments.length?(e!==this._tooltip&&(this._tooltip=e,this._resetRenderer()),this):this._tooltip},Q.loader=function(e){return arguments.length?(e!==this._loader&&(h.Dataflow.prototype.loader.call(this,e),this._resetRenderer()),this):this._loader},Q.resize=function(){return this._autosize=1,this.touch(X(this,"autosize"))},Q._resetRenderer=function(){this._renderer&&(this._renderer=null,this.initialize(this._el))},Q._resizeView=function(t,r,i,a,s,o){this.runAfter(function(e){var n=0;e._autosize=0,e.width()!==i&&(n=1,e.signal(M,i,P),e._resizeWidth.skip(!0)),e.height()!==a&&(n=1,e.signal(q,a,P),e._resizeHeight.skip(!0)),e._viewWidth!==t&&(e._resize=1,e._viewWidth=t),e._viewHeight!==r&&(e._resize=1,e._viewHeight=r),e._origin[0]===s[0]&&e._origin[1]===s[1]||(e._resize=1,e._origin=s),n&&e.run("enter"),o&&e.runAfter(function(){e.resize()})},!1,1)},Q.addEventListener=function(e,n,t){var r=n;return t&&!1===t.trap||((r=j(this,n)).raw=n),this._handler.on(e,r),this},Q.removeEventListener=function(e,n){for(var t,r,i=this._handler.handlers(e),a=i.length;0<=--a;)if(r=i[a].type,t=i[a].handler,e===r&&(n===t||n===t.raw)){this._handler.off(r,t);break}return this},Q.addResizeListener=function(e){var n=this._resizeListeners;return n.indexOf(e)<0&&n.push(e),this},Q.removeResizeListener=function(e){var n=this._resizeListeners,t=n.indexOf(e);return 0<=t&&n.splice(t,1),this},Q.addSignalListener=function(e,n){var t=X(this,e),r=Y(t,n);return r||((r=j(this,function(){n(e,t.value)})).handler=n,this.on(t,null,r)),this},Q.removeSignalListener=function(e,n){var t=X(this,e),r=Y(t,n);return r&&t._targets.remove(r),this},Q.preventDefault=function(e){return arguments.length?(this._preventDefault=e,this):this._preventDefault},Q.timer=function(n,e){this._timers.push(t.interval(function(e){n({timestamp:Date.now(),elapsed:e})},e))},Q.events=function(o,u,e){var n,l=this,d=new h.EventStream(e),t=function(e,n){var t,r,i,a,s;o!==y||(r=u,i=(t=l)._eventConfig.defaults,a=i&&i.prevent,s=i&&i.allow,!1===a||!0===s||!0!==a&&!1!==s&&(a?!a[r]:s?s[r]:!t.preventDefault()))||e.preventDefault();try{d.receive(m(l,e,n))}catch(e){l.error(e)}finally{l.run()}};if("timer"===o)l.timer(t,u);else if(o===y)l.addEventListener(u,t,w);else if("window"===o?"undefined"!=typeof window&&(n=[window]):"undefined"!=typeof document&&(n=document.querySelectorAll(o)),n){for(var r=0,i=n.length;r<i;++r)n[r].addEventListener(u,t);l._eventListeners.push({type:u,sources:n,handler:t})}else l.warn("Can not resolve event source: "+o);return d},Q.finalize=function(){var e,n,t,r=this._tooltip,i=this._timers,a=this._eventListeners;for(e=i.length;0<=--e;)i[e].stop();for(e=a.length;0<=--e;)for(n=(t=a[e]).sources.length;0<=--n;)t.sources[n].removeEventListener(t.type,t.handler);return r&&r.call(this,this._handler,null,null,null),this},Q.hover=function(e,n){return n=[n||"update",(e=[e||"hover"])[0]],this.on(this.events("view","mouseover",u),l,z(e)),this.on(this.events("view","mouseout",u),l,z(n)),this},Q.data=function(e){return r(this,e).values.value},Q.change=i,Q.insert=function(e,n){return i.call(this,e,h.changeset().insert(n))},Q.remove=function(e,n){return i.call(this,e,h.changeset().remove(n))},Q.scale=function(e){var n=this._runtime.scales;return n.hasOwnProperty(e)||c.error("Unrecognized scale or projection: "+e),n[e].value},Q.initialize=function(e,n){var t,r,i,a,s,o,u=this,l=u._renderType,d=f.renderModule(l);return e=u._el=e?H(u,e):null,d||u.error("Unrecognized renderer type: "+l),t=d.handler||f.CanvasHandler,r=e?d.renderer:d.headless,u._renderer=r?O(u,u._renderer,e,r):null,u._handler=(a=(i=u)._handler,s=e,o=new t(i.loader(),j(i,i.tooltip())).scene(i.scenegraph().root).initialize(s,_(i),i),a&&a.handlers().forEach(function(e){o.on(e.type,e.handler)}),o),u._redraw=!0,e&&(n=n?H(u,n):e.appendChild(b("div",{class:"vega-bindings"})),u._bind.forEach(function(e){e.param.element&&(e.element=H(u,e.param.element))}),u._bind.forEach(function(e){C(u,e.element||n,e)})),u},Q.toImageURL=function(r,e){return r!==f.RenderType.Canvas&&r!==f.RenderType.SVG&&r!==f.RenderType.PNG?Promise.reject("Unrecognized image type: "+r):U(this,r,e).then(function(e){return r===f.RenderType.SVG?(n=e.svg(),t=new Blob([n],{type:"image/svg+xml"}),window.URL.createObjectURL(t)):e.canvas().toDataURL("image/png");var n,t})},Q.toCanvas=function(e){return U(this,f.RenderType.Canvas,e).then(function(e){return e.canvas()})},Q.toSVG=function(e){return U(this,f.RenderType.SVG,e).then(function(e){return e.svg()})},Q.getState=function(e){return this._runtime.getState(e||{data:I,signals:B,recurse:!0})},Q.setState=function(e){var n=this;return n.runAfter(function(){n._trigger=!1,n._runtime.setState(e),n.run().runAfter(function(){n._trigger=!0})}),this},e.View=K,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-parser"),require("vega-runtime"),require("d3-timer")):"function"==typeof define&&define.amd?define(["exports","vega-util","vega-dataflow","vega-scenegraph","d3-array","vega-parser","vega-runtime","d3-timer"],n):n(e.vega={},e.vega,e.vega,e.vega,e.d3,e.vega,e.vega,e.d3)}(this,function(e,c,h,f,d,g,v,t){"use strict";var s="default";function p(e){var a=e._signals.cursor;a||(e._signals.cursor=a=e.add({user:s,item:null})),e.on(e.events("view","mousemove"),a,function(e,n){var t=a.value,r=t?c.isString(t)?t:t.user:s,i=n.item&&n.item.cursor||null;return t&&r===t.user&&i==t.item?t:{user:r,item:i}}),e.add(null,function(e){var n,t=e.cursor,r=this.value;return c.isString(t)||(r=t.item,t=t.user),n=t&&t!==s?t:r||t,"undefined"!=typeof document&&document.body&&(document.body.style.cursor=n),r},{cursor:a})}function r(e,n){var t=e._runtime.data;return t.hasOwnProperty(n)||c.error("Unrecognized data set: "+n),t[n]}function i(e,n){h.isChangeSet(n)||c.error("Second argument to changes must be a changeset.");var t=r(this,e);return t.modified=!0,this.pulse(t.input,n)}function a(e){var n=e.padding();return Math.max(0,e._viewWidth+n.left+n.right)}function u(e){var n=e.padding();return Math.max(0,e._viewHeight+n.top+n.bottom)}function _(e){var n=e.padding(),t=e._origin;return[n.left+t[0],n.top+t[1]]}function m(e,n,t){var r,i,a,s=e._renderer.canvas();return s&&(a=_(e),i=n.changedTouches?n.changedTouches[0]:n,(r=f.point(i,s))[0]-=a[0],r[1]-=a[1]),n.dataflow=e,n.vega=function(e,r,t){var i=r?"group"===r.mark.marktype?r:r.mark.group:null;function a(e){var n,t=i;if(e)for(n=r;n;n=n.mark.group)if(n.mark.name===e){t=n;break}return t&&t.mark&&t.mark.interactive?t:{}}function n(e){if(!e)return t;c.isString(e)&&(e=a(e));for(var n=t.slice();e;)n[0]-=e.x||0,n[1]-=e.y||0,e=e.mark&&e.mark.group;return n}return{view:c.constant(e),item:c.constant(r||{}),group:a,xy:n,x:function(e){return n(e)[0]},y:function(e){return n(e)[1]}}}(e,t,r),n.item=t,n}var y="view",w={trap:!1};function o(e){return e.item}function l(e){var n=e.item.mark.source;return n.source||n}function z(t){return function(e,n){return n.vega.view().changeset().encode(n.item,t)}}function b(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}var k="vega-bind",L="vega-bind-name",n="vega-bind-radio",x="vega-option-";function C(n,e,t){if(e){var r=t.param,i=t.state;return i||(i=t.state={elements:null,active:!1,set:null,update:function(e){e!==n.signal(r.signal)&&(i.source=!0,n.signal(r.signal,e).run())}},r.debounce&&(i.update=c.debounce(r.debounce,i.update))),function(e,n,t,r){var i=b("div",{class:k});i.appendChild(b("span",{class:L},t.name||t.signal)),n.appendChild(i);var a=S;switch(t.input){case"checkbox":a=E;break;case"select":a=A;break;case"radio":a=D;break;case"range":a=R}a(e,i,t,r)}(i,e,r,n.signal(r.signal)),i.active||(n.on(n._signals[r.signal],null,function(){i.source?i.source=!1:i.set(n.signal(r.signal))}),i.active=!0),i}}function S(e,n,t,r){var i=b("input");for(var a in t)"signal"!==a&&"element"!==a&&i.setAttribute("input"===a?"type":a,t[a]);i.setAttribute("name",t.signal),i.value=r,n.appendChild(i),i.addEventListener("input",function(){e.update(i.value)}),e.elements=[i],e.set=function(e){i.value=e}}function E(e,n,t,r){var i={type:"checkbox",name:t.signal};r&&(i.checked=!0);var a=b("input",i);n.appendChild(a),a.addEventListener("change",function(){e.update(a.checked)}),e.elements=[a],e.set=function(e){a.checked=!!e||null}}function A(e,n,r,t){var i=b("select",{name:r.signal});r.options.forEach(function(e){var n={value:e};T(e,t)&&(n.selected=!0),i.appendChild(b("option",n,e+""))}),n.appendChild(i),i.addEventListener("change",function(){e.update(r.options[i.selectedIndex])}),e.elements=[i],e.set=function(e){for(var n=0,t=r.options.length;n<t;++n)if(T(r.options[n],e))return void(i.selectedIndex=n)}}function D(i,e,a,s){var u=b("span",{class:n});e.appendChild(u),i.elements=a.options.map(function(e){var n=x+a.signal+"-"+e,t={id:n,type:"radio",name:a.signal,value:e};T(e,s)&&(t.checked=!0);var r=b("input",t);return r.addEventListener("change",function(){i.update(e)}),u.appendChild(r),u.appendChild(b("label",{for:n},e+"")),r}),i.set=function(e){for(var n=i.elements,t=0,r=n.length;t<r;++t)T(n[t].value,e)&&(n[t].checked=!0)}}function R(e,n,t,r){r=void 0!==r?r:(+t.max+ +t.min)/2;var i=t.min||Math.min(0,+r)||0,a=t.max||Math.max(100,+r)||100,s=t.step||d.tickStep(i,a,100),u=b("input",{type:"range",name:t.signal,min:i,max:a,step:s}),o=b("label",{},+(u.value=r));function l(){o.textContent=u.value,e.update(+u.value)}n.appendChild(u),n.appendChild(o),u.addEventListener("input",l),u.addEventListener("change",l),e.elements=[u],e.set=function(e){u.value=e,o.textContent=e}}function T(e,n){return e===n||e+""==n+""}function O(e,n,t,r,i){return(n=n||new r(e.loader())).initialize(t,a(e),u(e),_(e),i).background(e._background)}function j(n,e){return e?function(){try{e.apply(this,arguments)}catch(e){n.error(e)}}:null}function H(n,t){if("string"==typeof t){if("undefined"==typeof document)return n.error("DOM document instance not found."),null;if(!(t=document.querySelector(t)))return n.error("Signal bind element not found: "+t),null}if(t)try{t.innerHTML=""}catch(e){t=null,n.error(e)}return t}function U(e,n,t){var r=f.renderModule(n),i=r&&r.headless;return i?e.runAsync().then(function(){return O(e,null,null,i,t).renderAsync(e._scenegraph.root)}):Promise.reject("Unrecognized renderer type: "+n)}var M="width",q="height",W="padding",P={skip:!0};function V(e,n){var t=e.autosize(),r=e.padding();return n-(t&&t.contains===W?r.left+r.right:0)}function G(e,n){var t=e.autosize(),r=e.padding();return n-(t&&t.contains===W?r.top+r.bottom:0)}function I(e,n){return n.modified&&c.isArray(n.input.value)&&e.indexOf("_:vega:_")}function B(e,n){return!("parent"===e||n instanceof h.transforms.proxy)}function N(e,n,t,r){var i,a,s=e.element();s&&s.setAttribute("title",null==(i=r)?"":c.isArray(i)?F(i):c.isObject(i)&&!c.isDate(i)?(a=i,Object.keys(a).map(function(e){var n=a[e];return e+": "+(c.isArray(n)?F(n):J(n))}).join("\n")):i+"")}function F(e){return"["+e.map(J).join(", ")+"]"}function J(e){return c.isArray(e)?"[…]":c.isObject(e)&&!c.isDate(e)?"{…}":e}function K(e,n){var t=this;n=n||{},h.Dataflow.call(t),t.loader(n.loader||t._loader),t.logLevel(n.logLevel||0),t._el=null,t._renderType=n.renderer||f.RenderType.Canvas,t._scenegraph=new f.Scenegraph;var r=t._scenegraph.root;t._renderer=null,t._tooltip=n.tooltip||N,t._redraw=!0,t._handler=(new f.CanvasHandler).scene(r),t._preventDefault=!1,t._timers=[],t._eventListeners=[],t._resizeListeners=[];var i,a,s,u,o,l,d=(i=t,a=e,s=n.functions,u=s||g.functionContext,v.parse(a,v.context(i,h.transforms,u)));t._runtime=d,t._signals=d.signals,t._bind=(e.bindings||[]).map(function(e){return{state:null,param:c.extend({},e)}}),d.root&&d.root.set(r),r.source=d.data.root.input,t.pulse(d.data.root.input,t.changeset().insert(r.items)),t._background=d.background||null,t._eventConfig=(o=d.eventConfig,(l=(o=c.extend({},o)).defaults)&&(c.isArray(l.prevent)&&(l.prevent=c.toSet(l.prevent)),c.isArray(l.allow)&&(l.allow=c.toSet(l.allow))),o),t._width=t.width(),t._height=t.height(),t._viewWidth=V(t,t._width),t._viewHeight=G(t,t._height),t._origin=[0,0],t._resize=0,t._autosize=1,function(n){var e=n._signals,t=e[M],r=e[q],i=e[W];function a(){n._autosize=n._resize=1}n._resizeWidth=n.add(null,function(e){n._width=e.size,n._viewWidth=V(n,e.size),a()},{size:t}),n._resizeHeight=n.add(null,function(e){n._height=e.size,n._viewHeight=G(n,e.size),a()},{size:r});var s=n.add(null,a,{pad:i});n._resizeWidth.rank=t.rank+1,n._resizeHeight.rank=r.rank+1,s.rank=i.rank+1}(t),p(t)}var Q=c.inherits(K,h.Dataflow);function X(e,n){return e._signals.hasOwnProperty(n)?e._signals[n]:c.error("Unrecognized signal name: "+c.stringValue(n))}function Y(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 Z(e,n,t,r){var i=Y(t,r);return i||((i=j(this,function(){r(n,t.value)})).handler=r,e.on(t,null,i)),e}function $(e,n,t){var r=Y(n,t);return r&&n._targets.remove(r),e}Q.run=function(e){if(h.Dataflow.prototype.run.call(this,e),this._pending)this.resize();else if(this._redraw||this._resize)try{this.render()}catch(e){this.error(e)}return this},Q.render=function(){var n,e,t,r;return this._renderer&&(this._resize&&(this._resize=0,e=_(n=this),t=a(n),r=u(n),n._renderer.background(n._background),n._renderer.resize(t,r,e),n._handler.origin(e),n._resizeListeners.forEach(function(e){try{e(t,r)}catch(e){n.error(e)}})),this._renderer.render(this._scenegraph.root)),this._redraw=!1,this},Q.dirty=function(e){this._redraw=!0,this._renderer&&this._renderer.dirty(e)},Q.container=function(){return this._el},Q.scenegraph=function(){return this._scenegraph},Q.origin=function(){return this._origin.slice()},Q.signal=function(e,n,t){var r=X(this,e);return 1===arguments.length?r.value:this.update(r,n,t)},Q.background=function(e){return arguments.length?(this._background=e,this._resize=1,this):this._background},Q.width=function(e){return arguments.length?this.signal("width",e):this.signal("width")},Q.height=function(e){return arguments.length?this.signal("height",e):this.signal("height")},Q.padding=function(e){return arguments.length?this.signal("padding",e):this.signal("padding")},Q.autosize=function(e){return arguments.length?this.signal("autosize",e):this.signal("autosize")},Q.renderer=function(e){return arguments.length?(f.renderModule(e)||c.error("Unrecognized renderer type: "+e),e!==this._renderType&&(this._renderType=e,this._resetRenderer()),this):this._renderType},Q.tooltip=function(e){return arguments.length?(e!==this._tooltip&&(this._tooltip=e,this._resetRenderer()),this):this._tooltip},Q.loader=function(e){return arguments.length?(e!==this._loader&&(h.Dataflow.prototype.loader.call(this,e),this._resetRenderer()),this):this._loader},Q.resize=function(){return this._autosize=1,this.touch(X(this,"autosize"))},Q._resetRenderer=function(){this._renderer&&(this._renderer=null,this.initialize(this._el))},Q._resizeView=function(t,r,i,a,s,u){this.runAfter(function(e){var n=0;e._autosize=0,e.width()!==i&&(n=1,e.signal(M,i,P),e._resizeWidth.skip(!0)),e.height()!==a&&(n=1,e.signal(q,a,P),e._resizeHeight.skip(!0)),e._viewWidth!==t&&(e._resize=1,e._viewWidth=t),e._viewHeight!==r&&(e._resize=1,e._viewHeight=r),e._origin[0]===s[0]&&e._origin[1]===s[1]||(e._resize=1,e._origin=s),n&&e.run("enter"),u&&e.runAfter(function(){e.resize()})},!1,1)},Q.addEventListener=function(e,n,t){var r=n;return t&&!1===t.trap||((r=j(this,n)).raw=n),this._handler.on(e,r),this},Q.removeEventListener=function(e,n){for(var t,r,i=this._handler.handlers(e),a=i.length;0<=--a;)if(r=i[a].type,t=i[a].handler,e===r&&(n===t||n===t.raw)){this._handler.off(r,t);break}return this},Q.addResizeListener=function(e){var n=this._resizeListeners;return n.indexOf(e)<0&&n.push(e),this},Q.removeResizeListener=function(e){var n=this._resizeListeners,t=n.indexOf(e);return 0<=t&&n.splice(t,1),this},Q.addSignalListener=function(e,n){return Z(this,e,X(this,e),n)},Q.removeSignalListener=function(e,n){return $(this,X(this,e),n)},Q.addDataListener=function(e,n){return Z(this,e,r(this,e).values,n)},Q.removeDataListener=function(e,n){return $(this,r(this,e).values,n)},Q.preventDefault=function(e){return arguments.length?(this._preventDefault=e,this):this._preventDefault},Q.timer=function(n,e){this._timers.push(t.interval(function(e){n({timestamp:Date.now(),elapsed:e})},e))},Q.events=function(u,o,e){var n,l=this,d=new h.EventStream(e),t=function(e,n){var t,r,i,a,s;u!==y||(r=o,i=(t=l)._eventConfig.defaults,a=i&&i.prevent,s=i&&i.allow,!1===a||!0===s||!0!==a&&!1!==s&&(a?!a[r]:s?s[r]:!t.preventDefault()))||e.preventDefault();try{d.receive(m(l,e,n))}catch(e){l.error(e)}finally{l.run()}};if("timer"===u)l.timer(t,o);else if(u===y)l.addEventListener(o,t,w);else if("window"===u?"undefined"!=typeof window&&(n=[window]):"undefined"!=typeof document&&(n=document.querySelectorAll(u)),n){for(var r=0,i=n.length;r<i;++r)n[r].addEventListener(o,t);l._eventListeners.push({type:o,sources:n,handler:t})}else l.warn("Can not resolve event source: "+u);return d},Q.finalize=function(){var e,n,t,r=this._tooltip,i=this._timers,a=this._eventListeners;for(e=i.length;0<=--e;)i[e].stop();for(e=a.length;0<=--e;)for(n=(t=a[e]).sources.length;0<=--n;)t.sources[n].removeEventListener(t.type,t.handler);return r&&r.call(this,this._handler,null,null,null),this},Q.hover=function(e,n){return n=[n||"update",(e=[e||"hover"])[0]],this.on(this.events("view","mouseover",o),l,z(e)),this.on(this.events("view","mouseout",o),l,z(n)),this},Q.data=function(e){return r(this,e).values.value},Q.change=i,Q.insert=function(e,n){return i.call(this,e,h.changeset().insert(n))},Q.remove=function(e,n){return i.call(this,e,h.changeset().remove(n))},Q.scale=function(e){var n=this._runtime.scales;return n.hasOwnProperty(e)||c.error("Unrecognized scale or projection: "+e),n[e].value},Q.initialize=function(e,n){var t,r,i,a,s,u,o=this,l=o._renderType,d=f.renderModule(l);return e=o._el=e?H(o,e):null,d||o.error("Unrecognized renderer type: "+l),t=d.handler||f.CanvasHandler,r=e?d.renderer:d.headless,o._renderer=r?O(o,o._renderer,e,r):null,o._handler=(a=(i=o)._handler,s=e,u=new t(i.loader(),j(i,i.tooltip())).scene(i.scenegraph().root).initialize(s,_(i),i),a&&a.handlers().forEach(function(e){u.on(e.type,e.handler)}),u),o._redraw=!0,e&&(n=n?H(o,n):e.appendChild(b("div",{class:"vega-bindings"})),o._bind.forEach(function(e){e.param.element&&(e.element=H(o,e.param.element))}),o._bind.forEach(function(e){C(o,e.element||n,e)})),o},Q.toImageURL=function(r,e){return r!==f.RenderType.Canvas&&r!==f.RenderType.SVG&&r!==f.RenderType.PNG?Promise.reject("Unrecognized image type: "+r):U(this,r,e).then(function(e){return r===f.RenderType.SVG?(n=e.svg(),t=new Blob([n],{type:"image/svg+xml"}),window.URL.createObjectURL(t)):e.canvas().toDataURL("image/png");var n,t})},Q.toCanvas=function(e){return U(this,f.RenderType.Canvas,e).then(function(e){return e.canvas()})},Q.toSVG=function(e){return U(this,f.RenderType.SVG,e).then(function(e){return e.svg()})},Q.getState=function(e){return this._runtime.getState(e||{data:I,signals:B,recurse:!0})},Q.setState=function(e){var n=this;return n.runAfter(function(){n._trigger=!1,n._runtime.setState(e),n.run().runAfter(function(){n._trigger=!0})}),this},e.View=K,Object.defineProperty(e,"__esModule",{value:!0})});
{
"name": "vega-view",
"version": "3.3.3",
"version": "3.4.0",
"description": "View component and transforms for Vega visualizations.",

@@ -30,8 +30,8 @@ "keywords": [

"dependencies": {
"d3-array": "^1.2.1",
"d3-timer": "^1.0.7",
"d3-array": "^1.2.4",
"d3-timer": "^1.0.9",
"vega-dataflow": "^4.0.4",
"vega-parser": "^3.7.0",
"vega-runtime": "^3.1.0",
"vega-scenegraph": "^3.2.1",
"vega-parser": "^3.8.0",
"vega-runtime": "^3.1.1",
"vega-scenegraph": "^3.2.3",
"vega-util": "^1.7.0"

@@ -41,3 +41,3 @@ },

"eslint": "5",
"rollup": "0.62.0",
"rollup": "0.66.6",
"tape": "4",

@@ -44,0 +44,0 @@ "uglify-js": "3"

@@ -556,2 +556,48 @@ # vega-view

<a name="view_addDataListener" href="#view_addDataListener">#</a>
view.<b>addDataListener</b>(<i>name</i>, <i>handler</i>)
[<>](https://github.com/vega/vega-view/blob/master/src/View.js "Source")
Registers a listener for changes to a named data set with the given *name*
and returns this view instance. If the data set does not exist, an error
will be raised. This method is idempotent: adding the same handler for the
same data set multiple times has no effect beyond the first call.
When the data set value changes, the *handler* function is invoked with two
arguments: the *name* of the signal and the new data set *value*. Listeners
will be invoked when the data set value *changes* during pulse propagation
(e.g., after [view.run()](#view_run) is called). The value passed to the
handler is the same as that returned by the [view.data](#view_data) method.
The returned array of data objects is a *live* array used by the underlying
dataflow. Listeners that wish to modify the returned array should first make
a defensive copy, for example using `value.slice()`.
Data listeners are invoked immediately upon data set update, in the midst
of dataflow evaluation. As a result, other signal values and data transforms
may have yet to update. If you wish to access the values of other signals or
data sets and re-run the dataflow, use the [runAfter](#view_runAfter) method
to schedule a callback that performs the desired actions _after_ dataflow
evaluation completes. Attempting to call the [run](#view_run) method from
within a data listener will result in an error, as recursive invocation is
not allowed.
To remove a listener, use the
[removeDataListener](#view_removeDataListener) method.
```js
view.addDataListener('source', function(name, value) {
console.log(name, value);
});
```
<a name="view_removeDataListener" href="#view_removeDataListener">#</a>
view.<b>removeDataListener</b>(<i>name</i>, <i>handler</i>)
[<>](https://github.com/vega/vega-view/blob/master/src/View.js "Source")
Removes a data set listener registered with the
[addDataListener](#view_addDataListener) method and returns this view
instance. If the data set does not exist, an error will be raised. If the
data set exists but the provided *handler* is not registered, this method
has no effect.
<a name="view_change" href="#view_change">#</a>

@@ -570,2 +616,5 @@ view.<b>change</b>(<i>name</i>, <i>changeset</i>)

Inserted data tuples must be JavaScript objects that have been properly
parsed ahead of time. Any data source `"format"` directives in a Vega JSON
specification will **not** be applied to tuples added through the View API.
Internally, this method takes the provided

@@ -589,2 +638,5 @@ [ChangeSet](https://github.com/vega/vega-dataflow/blob/master/src/ChangeSet.js)

Inserted data tuples must be JavaScript objects that have been properly
parsed ahead of time. Any data source `"format"` directives in a Vega JSON
specification will **not** be applied to tuples added through the View API.
Internally, this method creates a

@@ -591,0 +643,0 @@ [ChangeSet](https://github.com/vega/vega-dataflow/blob/master/src/ChangeSet.js)

import {changeset, isChangeSet} from 'vega-dataflow';
import {error} from 'vega-util';
function dataref(view, name) {
export function dataref(view, name) {
var data = view._runtime.data;

@@ -6,0 +6,0 @@ if (!data.hasOwnProperty(name)) {

import cursor from './cursor';
import {data, change, insert, remove} from './data';
import {data, dataref, change, insert, remove} from './data';
import {initializeEventConfig, events} from './events';

@@ -285,4 +285,4 @@ import hover from './hover';

function findSignalHandler(signal, handler) {
var t = signal._targets || [],
function findOperatorHandler(op, handler) {
var t = op._targets || [],
h = t.filter(function(op) {

@@ -295,22 +295,34 @@ var u = op._update;

prototype.addSignalListener = function(name, handler) {
var s = lookupSignal(this, name),
h = findSignalHandler(s, handler);
function addOperatorListener(view, name, op, handler) {
var h = findOperatorHandler(op, handler);
if (!h) {
h = trap(this, function() { handler(name, s.value); });
h = trap(this, function() { handler(name, op.value); });
h.handler = handler;
this.on(s, null, h);
view.on(op, null, h);
}
return this;
return view;
}
function removeOperatorListener(view, op, handler) {
var h = findOperatorHandler(op, handler);
if (h) op._targets.remove(h);
return view;
}
prototype.addSignalListener = function(name, handler) {
return addOperatorListener(this, name, lookupSignal(this, name), handler);
};
prototype.removeSignalListener = function(name, handler) {
var s = lookupSignal(this, name),
h = findSignalHandler(s, handler);
return removeOperatorListener(this, lookupSignal(this, name), handler);
};
if (h) s._targets.remove(h);
return this;
prototype.addDataListener = function(name, handler) {
return addOperatorListener(this, name, dataref(this, name).values, handler);
};
prototype.removeDataListener = function(name, handler) {
return removeOperatorListener(this, dataref(this, name).values, handler);
};
prototype.preventDefault = function(_) {

@@ -317,0 +329,0 @@ if (arguments.length) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc