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 5.2.2 to 5.3.0

92

build/vega-view.js

@@ -55,3 +55,3 @@ (function (global, factory) {

var data = view._runtime.data;
if (!data.hasOwnProperty(name)) {
if (!vegaUtil.hasOwnProperty(data, name)) {
vegaUtil.error('Unrecognized data set: ' + name);

@@ -62,4 +62,6 @@ }

function data(name) {
return dataref(this, name).values.value;
function data(name, values) {
return arguments.length < 1
? dataref(this, name).values.value
: change.call(this, name, vegaDataflow.changeset().remove(vegaUtil.truthy).insert(values));
}

@@ -202,6 +204,6 @@

var VIEW = 'view',
TIMER = 'timer',
WINDOW = 'window',
NO_TRAP = {trap: false};
const VIEW = 'view',
TIMER = 'timer',
WINDOW = 'window',
NO_TRAP = {trap: false};

@@ -214,15 +216,14 @@ /**

function initializeEventConfig(config) {
config = vegaUtil.extend({}, config);
const events = vegaUtil.extend({defaults: {}}, config);
var def = config.defaults;
if (def) {
if (vegaUtil.isArray(def.prevent)) {
def.prevent = vegaUtil.toSet(def.prevent);
}
if (vegaUtil.isArray(def.allow)) {
def.allow = vegaUtil.toSet(def.allow);
}
}
const unpack = (obj, keys) => {
keys.forEach(k => {
if (vegaUtil.isArray(obj[k])) obj[k] = vegaUtil.toSet(obj[k]);
});
};
return config;
unpack(events.defaults, ['prevent', 'allow']);
unpack(events, ['view', 'window', 'selector']);
return events;
}

@@ -232,4 +233,4 @@

var def = view._eventConfig.defaults,
prevent = def && def.prevent,
allow = def && def.allow;
prevent = def.prevent,
allow = def.allow;

@@ -243,2 +244,13 @@ return prevent === false || allow === true ? false

function permit(view, key, type) {
const rule = view._eventConfig && view._eventConfig[key];
if (rule === false || (vegaUtil.isObject(rule) && !rule[type])) {
view.warn(`Blocked ${key} ${type} event listener.`);
return false;
}
return true;
}
/**

@@ -265,8 +277,12 @@ * Create a new event stream from an event source.

if (source === TIMER) {
view.timer(send, type);
if (permit(view, 'timer', type)) {
view.timer(send, type);
}
}
else if (source === VIEW) {
// send traps errors, so use {trap: false} option
view.addEventListener(type, send, NO_TRAP);
if (permit(view, 'view', type)) {
// send traps errors, so use {trap: false} option
view.addEventListener(type, send, NO_TRAP);
}
}

@@ -276,5 +292,9 @@

if (source === WINDOW) {
if (typeof window !== 'undefined') sources = [window];
if (permit(view, 'window', type) && typeof window !== 'undefined') {
sources = [window];
}
} else if (typeof document !== 'undefined') {
sources = document.querySelectorAll(source);
if (permit(view, 'selector', type)) {
sources = document.querySelectorAll(source);
}
}

@@ -306,4 +326,3 @@

// grab upstream collector feeding the mark operator
var source = event.item.mark.source;
return source.source || source;
return event.item.mark.source;
}

@@ -579,4 +598,4 @@

var min = param.min || Math.min(0, +value) || 0,
max = param.max || Math.max(100, +value) || 100,
var max = param.max != null ? param.max : Math.max(100, +value) || 100,
min = param.min || Math.min(0, max, +value) || 0,
step = param.step || d3Array.tickStep(min, max, 100);

@@ -654,2 +673,3 @@

type = view._renderType,
config = view._eventConfig.bind,
module = vegaScenegraph.renderModule(type),

@@ -673,3 +693,3 @@ Handler, Renderer;

// initialize signal bindings
if (el) {
if (el && config !== 'none') {
elBind = elBind ? (view._elBind = lookup(view, elBind))

@@ -679,3 +699,3 @@ : el.appendChild(element('div', {'class': 'vega-bindings'}));

view._bind.forEach(function(_) {
if (_.param.element) {
if (_.param.element && config !== 'container') {
_.element = lookup(view, _.param.element);

@@ -785,3 +805,3 @@ }

var scales = this._runtime.scales;
if (!scales.hasOwnProperty(name)) {
if (!vegaUtil.hasOwnProperty(scales, name)) {
vegaUtil.error('Unrecognized scale or projection: ' + name);

@@ -1012,2 +1032,5 @@ }

// initialize event configuration
view._eventConfig = initializeEventConfig(spec.eventConfig);
// initialize dataflow graph

@@ -1035,5 +1058,2 @@ var ctx = runtime(view, spec, options.functions);

// initialize event configuration
view._eventConfig = initializeEventConfig(ctx.eventConfig);
// initialize view size

@@ -1109,3 +1129,3 @@ view._width = view.width();

function lookupSignal(view, name) {
return view._signals.hasOwnProperty(name)
return vegaUtil.hasOwnProperty(view._signals, name)
? view._signals[name]

@@ -1112,0 +1132,0 @@ : vegaUtil.error('Unrecognized signal name: ' + vegaUtil.stringValue(name));

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

@@ -26,11 +26,11 @@ "keywords": [

"dependencies": {
"d3-array": "^2.0.3",
"d3-array": "^2.3.1",
"d3-timer": "^1.0.9",
"vega-dataflow": "^5.2.1",
"vega-functions": "^5.3.0",
"vega-functions": "^5.3.1",
"vega-runtime": "^5.0.1",
"vega-scenegraph": "^4.2.0",
"vega-util": "^1.10.0"
"vega-util": "^1.11.0"
},
"gitHead": "d2576ca617d8165211ffe6c23582b9dc1b88db7d"
"gitHead": "b45fc90406ce2de167073b73d4ae5cf79c5e1705"
}

@@ -204,4 +204,4 @@ import element from './element';

var min = param.min || Math.min(0, +value) || 0,
max = param.max || Math.max(100, +value) || 100,
var max = param.max != null ? param.max : Math.max(100, +value) || 100,
min = param.min || Math.min(0, max, +value) || 0,
step = param.step || tickStep(min, max, 100);

@@ -208,0 +208,0 @@

import {changeset, isChangeSet} from 'vega-dataflow';
import {error} from 'vega-util';
import {error, hasOwnProperty, truthy} from 'vega-util';
export function dataref(view, name) {
var data = view._runtime.data;
if (!data.hasOwnProperty(name)) {
if (!hasOwnProperty(data, name)) {
error('Unrecognized data set: ' + name);

@@ -12,4 +12,6 @@ }

export function data(name) {
return dataref(this, name).values.value;
export function data(name, values) {
return arguments.length < 1
? dataref(this, name).values.value
: change.call(this, name, changeset().remove(truthy).insert(values));
}

@@ -16,0 +18,0 @@

import eventExtend from './events-extend';
import {EventStream} from 'vega-dataflow';
import {extend, isArray, toSet} from 'vega-util';
import {extend, isArray, isObject, toSet} from 'vega-util';
var VIEW = 'view',
TIMER = 'timer',
WINDOW = 'window',
NO_TRAP = {trap: false};
const VIEW = 'view',
TIMER = 'timer',
WINDOW = 'window',
NO_TRAP = {trap: false};

@@ -16,15 +16,14 @@ /**

export function initializeEventConfig(config) {
config = extend({}, config);
const events = extend({defaults: {}}, config);
var def = config.defaults;
if (def) {
if (isArray(def.prevent)) {
def.prevent = toSet(def.prevent);
}
if (isArray(def.allow)) {
def.allow = toSet(def.allow);
}
}
const unpack = (obj, keys) => {
keys.forEach(k => {
if (isArray(obj[k])) obj[k] = toSet(obj[k]);
});
};
return config;
unpack(events.defaults, ['prevent', 'allow']);
unpack(events, ['view', 'window', 'selector']);
return events;
}

@@ -34,4 +33,4 @@

var def = view._eventConfig.defaults,
prevent = def && def.prevent,
allow = def && def.allow;
prevent = def.prevent,
allow = def.allow;

@@ -45,2 +44,13 @@ return prevent === false || allow === true ? false

function permit(view, key, type) {
const rule = view._eventConfig && view._eventConfig[key];
if (rule === false || (isObject(rule) && !rule[type])) {
view.warn(`Blocked ${key} ${type} event listener.`);
return false;
}
return true;
}
/**

@@ -67,8 +77,12 @@ * Create a new event stream from an event source.

if (source === TIMER) {
view.timer(send, type);
if (permit(view, 'timer', type)) {
view.timer(send, type);
}
}
else if (source === VIEW) {
// send traps errors, so use {trap: false} option
view.addEventListener(type, send, NO_TRAP);
if (permit(view, 'view', type)) {
// send traps errors, so use {trap: false} option
view.addEventListener(type, send, NO_TRAP);
}
}

@@ -78,5 +92,9 @@

if (source === WINDOW) {
if (typeof window !== 'undefined') sources = [window];
if (permit(view, 'window', type) && typeof window !== 'undefined') {
sources = [window];
}
} else if (typeof document !== 'undefined') {
sources = document.querySelectorAll(source);
if (permit(view, 'selector', type)) {
sources = document.querySelectorAll(source);
}
}

@@ -83,0 +101,0 @@

@@ -7,4 +7,3 @@ function itemFilter(event) {

// grab upstream collector feeding the mark operator
var source = event.item.mark.source;
return source.source || source;
return event.item.mark.source;
}

@@ -11,0 +10,0 @@

@@ -10,2 +10,3 @@ import bind from './bind';

type = view._renderType,
config = view._eventConfig.bind,
module = renderModule(type),

@@ -29,3 +30,3 @@ Handler, Renderer;

// initialize signal bindings
if (el) {
if (el && config !== 'none') {
elBind = elBind ? (view._elBind = lookup(view, elBind))

@@ -35,3 +36,3 @@ : el.appendChild(element('div', {'class': 'vega-bindings'}));

view._bind.forEach(function(_) {
if (_.param.element) {
if (_.param.element && config !== 'container') {
_.element = lookup(view, _.param.element);

@@ -38,0 +39,0 @@ }

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

import {error} from 'vega-util';
import {error, hasOwnProperty} from 'vega-util';
export function scale(name) {
var scales = this._runtime.scales;
if (!scales.hasOwnProperty(name)) {
if (!hasOwnProperty(scales, name)) {
error('Unrecognized scale or projection: ' + name);

@@ -7,0 +7,0 @@ }

@@ -20,3 +20,3 @@ import cursor from './cursor';

import {asyncCallback, Dataflow} from 'vega-dataflow';
import {error, extend, inherits, stringValue} from 'vega-util';
import {error, extend, inherits, hasOwnProperty, stringValue} from 'vega-util';
import {

@@ -62,2 +62,5 @@ CanvasHandler, Scenegraph,

// initialize event configuration
view._eventConfig = initializeEventConfig(spec.eventConfig);
// initialize dataflow graph

@@ -85,5 +88,2 @@ var ctx = runtime(view, spec, options.functions);

// initialize event configuration
view._eventConfig = initializeEventConfig(ctx.eventConfig);
// initialize view size

@@ -159,3 +159,3 @@ view._width = view.width();

function lookupSignal(view, name) {
return view._signals.hasOwnProperty(name)
return hasOwnProperty(view._signals, name)
? view._signals[name]

@@ -162,0 +162,0 @@ : error('Unrecognized signal name: ' + stringValue(name));

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