Comparing version 1.0.0-beta.7 to 1.0.0-beta.8
@@ -212,2 +212,11 @@ (function (global, factory) { | ||
function axisIndices(datum) { | ||
var index = +datum.grid; | ||
return [ | ||
datum.tick ? index++ : -1, // tick index | ||
datum.label ? index++ : -1, // label index | ||
index + (+datum.domain) // title index | ||
]; | ||
} | ||
function layoutAxis(axis, width, height) { | ||
@@ -217,5 +226,3 @@ var item = axis.items[0], | ||
orient = datum.orient, | ||
ticksIndex = datum.grid ? 1 : 0, | ||
labelIndex = ticksIndex + 1, | ||
titleIndex = labelIndex + (datum.domain ? 2 : 1), | ||
indices = axisIndices(datum), | ||
range = item.range, | ||
@@ -226,11 +233,11 @@ offset = item.offset, | ||
maxExtent = item.maxExtent, | ||
title = datum.title && item.items[titleIndex].items[0], | ||
title = datum.title && item.items[indices[2]].items[0], | ||
titlePadding = item.titlePadding, | ||
titleSize = title ? title.fontSize + titlePadding : 0, | ||
bounds = item.bounds, | ||
x = 0, y = 0, s; | ||
x = 0, y = 0, i, s; | ||
bounds.clear() | ||
.union(item.items[ticksIndex].bounds) | ||
.union(item.items[labelIndex].bounds); | ||
bounds.clear(); | ||
if ((i=indices[0]) > -1) bounds.union(item.items[i].bounds); | ||
if ((i=indices[1]) > -1) bounds.union(item.items[i].bounds); | ||
@@ -237,0 +244,0 @@ // position axis group and title |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("vega-dataflow"),require("vega-scenegraph"),require("vega-util"),require("d3-array"),require("vega-parser"),require("vega-runtime")):"function"==typeof define&&define.amd?define(["exports","vega-dataflow","vega-scenegraph","vega-util","d3-array","vega-parser","vega-runtime"],n):n(e.vega=e.vega||{},e.vega,e.vega,e.vega,e.d3,e.vega,e.vega)}(this,function(e,n,t,i,r,a,s){"use strict";function o(e){n.Transform.call(this,null,e)}function u(e,n,t){return e.bounds_prev.clear().union(e.bounds),n(e.bounds.clear(),e,t)}function h(e){n.Transform.call(this,null,e)}function d(e){n.Transform.call(this,null,e)}function c(e){n.Transform.call(this,null,e)}function l(e,n,i){var r,a,s,o,u,h=n.items,d=Math.max(0,n.width||0),c=Math.max(0,n.height||0),l=(new t.Bounds).set(0,0,d,c),v=l.clone(),p=v.clone(),_=[];for(o=0,u=h.length;o<u;++o)switch(r=h[o],r.role){case J:p.union(f(r,d,c));break;case N:_.push(r);break;case K:case Q:l.union(r.bounds);default:v.union(r.bounds)}if(l.union(p),_.length)for(a={left:0,right:0,margin:i.legendMargin||8},p.union(v),o=0,u=_.length;o<u;++o)s=g(_[o],a,p,d,c),i.autosize===P?l.add(s.x1,0).add(s.x2,0):l.union(s);m(e,n,v,l.union(v),i)}function f(e,n,i){var r,a=e.items[0],s=a.datum,o=s.orient,u=s.grid?1:0,h=u+1,d=h+(s.domain?2:1),c=a.range,l=a.offset,f=a.position,g=a.minExtent,m=a.maxExtent,v=s.title&&a.items[d].items[0],p=a.titlePadding,_=v?v.fontSize+p:0,b=a.bounds,k=0,w=0;switch(b.clear().union(a.items[u].bounds).union(a.items[h].bounds),o){case"top":k=f||0,w=-l,r=Math.max(g,Math.min(m,-b.y1)),v&&(v.auto?(v.y=-(p+r),r+=_):b.union(v.bounds)),b.add(0,-r).add(c,0);break;case"left":k=-l,w=f||0,r=Math.max(g,Math.min(m,-b.x1)),v&&(v.auto?(v.x=-(p+r),r+=_):b.union(v.bounds)),b.add(-r,0).add(0,c);break;case"right":k=n+l,w=f||0,r=Math.max(g,Math.min(m,b.x2)),v&&(v.auto?(v.x=p+r,r+=_):b.union(v.bounds)),b.add(0,0).add(r,c);break;case"bottom":k=f||0,w=i+l,r=Math.max(g,Math.min(m,b.y2)),v&&(v.auto?(v.y=p+r,r+=_):b.union(v.bounds)),b.add(0,0).add(c,r)}return a.x=k+.5,a.y=w+.5,t.boundStroke(b.translate(k,w),a),a.mark.bounds.clear().union(b),b}function g(e,n,i,r,a){var s,o,u=e.items[0],h=u.datum,d=h.orient,c=u.offset,l=u.bounds.clear(),f=0,g=n[d]||0;switch(u.items.forEach(function(e){l.union(e.bounds)}),s=Math.round(l.width())+2*u.padding-1,o=Math.round(l.height())+2*u.padding-1,d){case"left":f-=s+c-Math.floor(i.x1),n.left+=o+n.margin;break;case"right":f+=c+Math.ceil(i.x2),n.right+=o+n.margin;break;case"top-left":f+=c,g+=c;break;case"top-right":f+=r-s-c,g+=c;break;case"bottom-left":f+=c,g+=a-o-c;break;case"bottom-right":f+=r-s-c,g+=a-o-c}return u.x=f,u.y=g,u.width=s,u.height=o,t.boundStroke(l.set(f,g,f+s,g+o),u),u.mark.bounds.clear().union(l),l}function m(e,n,t,i,r){var a=r.autosize,s=e._width,o=e._height;if(!(e._autosize<1)&&a){var u=Math.max(0,n.width||0),h=Math.max(0,Math.ceil(-i.x1)),d=Math.max(0,Math.ceil(i.x2-u)),c=Math.max(0,n.height||0),l=Math.max(0,Math.ceil(-i.y1)),f=Math.max(0,Math.ceil(i.y2-c));a===F?(s=u,o=c,h=0,l=0):a===P?(u=Math.max(0,s-h-d),c=Math.max(0,o-l-f)):a===W&&(s=u+h+d,o=c+l+f,n.width<0&&(u=t.width()),n.height<0&&(c=t.height())),e.autosize(s,o,u,c,[h,l])}}function v(e,n,t){var r={elements:null,set:null,update:function(n){e.signal(t.signal,n).run()}};return i.isString(n)&&(n=document.querySelector(n)),p(r,n,t,e.signal(t.signal)),e.on(e._signals[t.signal],null,function(){r.set(e.signal(t.signal))}),r}function p(e,n,t,i){var r=y("div",{class:Y});r.appendChild(y("span",{class:Z},t.name||t.signal)),n.appendChild(r);var a=_;switch(t.type){case"checkbox":a=b;break;case"select":a=k;break;case"radio":a=w;break;case"range":a=x}a(e,r,t,i)}function _(e,n,t,i){var r=y("input");for(var a in t)"signal"!==a&&"element"!==a&&r.setAttribute(a,t[a]);r.setAttribute("name",t.signal),r.setAttribute("value",i),n.appendChild(r),r.addEventListener("input",function(){e.update(r.value)}),e.elements=[r],e.set=function(e){r.value=e}}function b(e,n,t,i){var r={type:"checkbox",name:t.signal};i&&(r.checked=!0);var a=y("input",r);n.appendChild(a),a.addEventListener("change",function(){e.update(a.checked)}),e.elements=[a],e.set=function(e){a.checked=!!e||null}}function k(e,n,t,i){var r=y("select",{name:t.signal});t.options.forEach(function(e){var n={value:e};e===i&&(n.selected=!0),r.appendChild(y("option",n,e))}),n.appendChild(r),r.addEventListener("change",function(){e.update(t.options[r.selectedIndex])}),e.elements=[r],e.set=function(e){r.selectedIndex=t.options.indexOf(e)}}function w(e,n,t,i){var r=y("span",{class:$});n.appendChild(r),e.elements=t.options.map(function(n){var a=ee+t.signal+"-"+n,s={id:a,type:"radio",name:t.signal,value:n};n===i&&(s.checked=!0);var o=y("input",s);return o.addEventListener("change",function(){e.update(n)}),r.appendChild(o),r.appendChild(y("label",{for:a},n)),o}),e.set=function(n){for(var t=e.elements,i=0,r=t.length;i<r;++i)t[i].value===n&&(t[i].checked=!0)}}function x(e,n,t,i){i=void 0!==i?i:(+t.max+ +t.min)/2;var a=t.min||Math.min(0,+i)||0,s=t.max||Math.max(100,+i)||100,o=t.step||r.tickStep(a,s,100),u=y("input",{type:"range",value:i,name:t.signal,min:a,max:s,step:o}),h=y("label",{},+i);n.appendChild(u),n.appendChild(h),u.addEventListener("input",function(){h.textContent=u.value,e.update(+u.value)}),e.elements=[u],e.set=function(e){u.value=e,h.textContent=e}}function y(e,n,t){var i=document.createElement(e);for(var r in n)i.setAttribute(r,n[r]);return null!=t&&(i.textContent=t),i}function M(e){"undefined"!=typeof document&&document.body&&(document.body.style.cursor=e)}function z(e,n){var t=e._runtime.data;return t.hasOwnProperty(n)||e.error("Unrecognized data set: "+n),t[n]}function C(e){return z(this,e).values.value}function E(e,t){return this.pulse(z(this,e).input,n.changeset().insert(t))}function q(e,t){return this.pulse(z(this,e).input,n.changeset().remove(t))}function S(e){var n=e.padding();return Math.max(0,e._width+n.left+n.right)}function L(e){var n=e.padding();return Math.max(0,e._height+n.top+n.bottom)}function T(e){var n=e.padding(),t=e._origin;return[n.left+t[0],n.top+t[1]]}function D(e){var n=T(e);e._renderer.background(e._background),e._renderer.resize(S(e),L(e),n),e._handler.origin(n)}function R(e,n,t){function r(e){var t,i=s;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 t;i.isString(e)&&(e=r(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}var s=n?"group"===n.mark.marktype?n:n.mark.group:null;return{view:i.constant(e),item:i.constant(n||{}),group:r,xy:a,x:function(e){return a(e)[0]},y:function(e){return a(e)[1]}}}function A(e){return e.item}function O(e){var n=e.item.mark.source;return n.source||n}function V(e){return function(n,t){return t.vega.view().changeset().encode(t.item,e)}}function G(e,n){var t=e.add(null,function(t){e["_"+n]=t.size,e._autosize=e._resize=1},{size:e._signals[n]});return t.rank=0,t}function H(e,n,t,i,r){this.runAfter(function(a){var s=0;a._autosize=0,a.width()!==t&&(s=1,a.width(t),a._resizeWidth.skip(!0)),a.height()!==i&&(s=1,a.height(i),a._resizeHeight.skip(!0)),a._width!==e&&(a._resize=1,a._width=e),a._height!==n&&(a._resize=1,a._height=n),a._origin[0]===r[0]&&a._origin[1]===r[1]||(a._resize=1,a._origin=r),s&&a.run("enter")})}function U(e,i){i=i||{},n.Dataflow.call(this),this.loader(i.loader||this._loader),this.logLevel(i.logLevel||0),this._el=null,this._renderType=i.renderer||de,this._scenegraph=new t.Scenegraph;var r=this._scenegraph.root;this._renderer=null,this._handler=(new t.CanvasHandler).scene(r),this._queue=null,this._eventListeners=[];var a=be(this,e,i.functions);this._runtime=a,this._signals=a.signals,this._bind=e.bindings,a.root&&a.root.set(r),r.source=a.data.root.input,this.pulse(a.data.root.input,this.changeset().insert(r.items)),this._background=a.background||null,this._width=this.width(),this._height=this.height(),this._origin=[0,0],this._resize=0,this._autosize=1,this._resizeWidth=G(this,"width"),this._resizeHeight=G(this,"height"),ie(this)}var I=i.inherits(o,n.Transform);I.transform=function(e,n){var i,r=e.mark,a=t.Marks[r.marktype],s=a.bound,o=r.bounds;return r.bounds_prev.clear().union(o),a.nested?u(r,s):e.modified()?(o.clear(),r.items.forEach(function(e){o.union(u(e,s))})):(i=n.changed(n.REM),n.visit(n.ADD,function(e){o.union(u(e,s))}),n.visit(n.MOD,function(e){i=i||o.alignsWith(e.bounds),o.union(u(e,s))}),i&&(o.clear(),r.items.forEach(function(e){o.union(e.bounds)}))),n.modifies("bounds")};var j=i.inherits(h,n.Transform);j.transform=function(e,n){var i=this.value;i||(i=n.dataflow.scenegraph().mark(e.scenepath,e.markdef),i.source=this,this.value=i,i.group.context=e.scenepath.context);var r="group"===i.marktype?t.GroupItem:t.Item;return n.visit(n.ADD,function(e){r.call(e,i)}),i.items=n.source,n};var B=i.inherits(d,n.Transform);B.transform=function(e,n){var t=n.dataflow;if(n.changed(n.REM)&&t.enqueue(n.materialize(n.REM).rem),n.changed(n.ADD)&&t.enqueue(n.materialize(n.ADD).add),n.changed(n.MOD)&&t.enqueue(n.materialize(n.MOD).mod),n.fields&&n.fields.zindex){var i=n.source&&n.source[0];i&&(i.mark.zdirty=!0)}};var P="fit",W="pad",F="none",J="axis",K="frame",N="legend",Q="scope",X=i.inherits(c,n.Transform);X.transform=function(e,n){var t=n.dataflow;return e.mark.items.forEach(function(n){l(t,n,e)}),n};var Y="vega-bind",Z="vega-bind-name",$="vega-bind-radio",ee="vega-option-",ne=function(e,n){return this._el?v(this,e||this._el,n):this.warn("Bind not supported for headless views."),this},te="default",ie=function(e){var n=e._signals.cursor;n||(e._signals.cursor=n=e.add({user:te,item:null})),e.on(e.events("view","mousemove"),n,function(e,t){var r=n.value,a=r?i.isString(r)?r:r.user:te,s=t.item&&t.item.cursor||null;return r&&a===r.user&&s==r.item?r:{user:a,item:s}}),e.add(null,function(e){var n=e.cursor,t=this.value;return i.isString(n)||(t=n.item,n=n.user),M(n&&n!==te?n:t||n),t},{cursor:n})},re=function(e,n,i){var r,a,s,o=e._renderer.element();return o&&(s=T(e),a=n.changedTouches?n.changedTouches[0]:n,r=t.point(a,o),r[0]-=s[0],r[1]-=s[1]),n.vega=R(e,i,r),n.item=i,n},ae=function(e,t,i){var r,a=this,s=new n.EventStream(i),o=function(e,n){s.receive(re(a,e,n)),a.run()};if("view"===e)return a._handler.on(t,o),s;if("window"===e?"undefined"!=typeof window&&(r=[window]):"undefined"!=typeof document&&(r=document.querySelectorAll(e)),!r)return a.warn("Can not resolve event source: "+e),s;for(var u=0,h=r.length;u<h;++u)r[u].addEventListener(t,o);return a._eventListeners.push({type:t,sources:r,handler:o}),s},se=function(e,n){return this.on(this.events("view","mouseover",A),O,V(e||"hover")),this.on(this.events("view","mouseout",A),O,V(n||"update")),this},oe=function(){for(var e,n,t=this._eventListeners,i=t.length;--i>=0;)for(n=t[i],e=n.sources.length;--e>=0;)n.sources[e].removeEventListener(n.type,n.handler)},ue=function(e,n,t,i){return n=n||new i(e.loader()),n.initialize(t,S(e),L(e),T(e)).background(e._background)},he=function(e,n,t,i){var r=(new i).scene(e.scenegraph().root).initialize(t,T(e),e);return n&&n.handlers().forEach(function(e){r.on(e.type,e.handler)}),r},de="canvas",ce="png",le="svg",fe="none",ge=function(e){var n=this,i=n._renderType,r=t.CanvasHandler,a=t.CanvasRenderer;return i===le&&(r=t.SVGHandler,a=e?t.SVGRenderer:t.SVGStringRenderer),e?("string"==typeof e&&"undefined"!=typeof document&&(e=document.querySelector(e)),e.innerHTML="",n._el=e):n._el=null,n._renderer=i===fe?null:ue(n,n._renderer,e,a),n._handler=he(n,n._handler,e,r),e&&n._bind&&n._bind.forEach(function(t){n.bind(t.element||e,t)}),n},me=function(e,n){return e.runAsync().then(function(){var i=n===le?t.SVGStringRenderer:t.CanvasRenderer;return ue(e,null,null,i).renderAsync(e._scenegraph.root)})},ve=function(e){return e===ce&&(e=de),e!==le&&e!==de?Promise.reject("Unrecognized image type: "+e):me(this,e).then(function(n){return e===de?n.canvas().toDataURL("image/png"):window.URL.createObjectURL(new Blob([n.svg()],{type:"image/svg+xml"}))})},pe=function(){return me(this,de).then(function(e){return e.canvas()})},_e=function(){return me(this,le).then(function(e){return e.svg()})},be=function(e,t,i){var r=i||a.functionContext;return s.parse(t,s.context(e,n.transforms,r))},ke=function(e){var n,t;if(arguments.length){t={skip:!0};for(n in e)this.signal(n,e[n],t);return this.run()}e={};for(n in this._signals)e[n]=this.signal(n);return e},we=i.inherits(U,n.Dataflow);we.run=function(e){n.Dataflow.prototype.run.call(this,e);var t=this._queue;return(this._resize||!t||t.length)&&(this.render(t),this._queue=[]),this},we.render=function(e){return this._renderer&&(this._resize&&(this._resize=0,D(this)),this._renderer.render(this._scenegraph.root,e)),this},we.enqueue=function(e){this._queue&&e&&e.length&&(this._queue=this._queue.concat(e))},we.signal=function(e,n,t){var i=this._signals[e];return 1===arguments.length?i?i.value:void 0:this.update(i,n,t)},we.scenegraph=function(){return this._scenegraph},we.background=function(e){return arguments.length?(this._background=e,this._resize=1,this):this._background},we.width=function(e){return arguments.length?this.signal("width",e):this.signal("width")},we.height=function(e){return arguments.length?this.signal("height",e):this.signal("height")},we.padding=function(e){return arguments.length?this.signal("padding",e):this.signal("padding")},we.renderer=function(e){return arguments.length?(e!==le&&e!==fe&&(e=de),e!==this._renderType&&(this._renderType=e,this._renderer&&(this._renderer=this._queue=null,this.initialize(this._el))),this):this._renderType},we.autosize=H,we.data=C,we.insert=E,we.remove=q,we.initialize=ge,we.toImageURL=ve,we.toCanvas=pe,we.toSVG=_e,we.events=ae,we.finalize=oe,we.hover=se,we.bind=ne,we.state=ke,n.transform("Bound",o),n.transform("Mark",h),n.transform("Render",d),n.transform("ViewLayout",c),e.View=U,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("vega-dataflow"),require("vega-scenegraph"),require("vega-util"),require("d3-array"),require("vega-parser"),require("vega-runtime")):"function"==typeof define&&define.amd?define(["exports","vega-dataflow","vega-scenegraph","vega-util","d3-array","vega-parser","vega-runtime"],n):n(e.vega=e.vega||{},e.vega,e.vega,e.vega,e.d3,e.vega,e.vega)}(this,function(e,n,t,i,r,a,s){"use strict";function o(e){n.Transform.call(this,null,e)}function u(e,n,t){return e.bounds_prev.clear().union(e.bounds),n(e.bounds.clear(),e,t)}function h(e){n.Transform.call(this,null,e)}function d(e){n.Transform.call(this,null,e)}function c(e){n.Transform.call(this,null,e)}function l(e,n,i){var r,a,s,o,u,h=n.items,d=Math.max(0,n.width||0),c=Math.max(0,n.height||0),l=(new t.Bounds).set(0,0,d,c),f=l.clone(),p=f.clone(),_=[];for(o=0,u=h.length;o<u;++o)switch(r=h[o],r.role){case K:p.union(g(r,d,c));break;case Q:_.push(r);break;case N:case X:l.union(r.bounds);default:f.union(r.bounds)}if(l.union(p),_.length)for(a={left:0,right:0,margin:i.legendMargin||8},p.union(f),o=0,u=_.length;o<u;++o)s=m(_[o],a,p,d,c),i.autosize===W?l.add(s.x1,0).add(s.x2,0):l.union(s);v(e,n,f,l.union(f),i)}function f(e){var n=+e.grid;return[e.tick?n++:-1,e.label?n++:-1,n+ +e.domain]}function g(e,n,i){var r,a,s=e.items[0],o=s.datum,u=o.orient,h=f(o),d=s.range,c=s.offset,l=s.position,g=s.minExtent,m=s.maxExtent,v=o.title&&s.items[h[2]].items[0],p=s.titlePadding,_=v?v.fontSize+p:0,b=s.bounds,k=0,w=0;switch(b.clear(),(r=h[0])>-1&&b.union(s.items[r].bounds),(r=h[1])>-1&&b.union(s.items[r].bounds),u){case"top":k=l||0,w=-c,a=Math.max(g,Math.min(m,-b.y1)),v&&(v.auto?(v.y=-(p+a),a+=_):b.union(v.bounds)),b.add(0,-a).add(d,0);break;case"left":k=-c,w=l||0,a=Math.max(g,Math.min(m,-b.x1)),v&&(v.auto?(v.x=-(p+a),a+=_):b.union(v.bounds)),b.add(-a,0).add(0,d);break;case"right":k=n+c,w=l||0,a=Math.max(g,Math.min(m,b.x2)),v&&(v.auto?(v.x=p+a,a+=_):b.union(v.bounds)),b.add(0,0).add(a,d);break;case"bottom":k=l||0,w=i+c,a=Math.max(g,Math.min(m,b.y2)),v&&(v.auto?(v.y=p+a,a+=_):b.union(v.bounds)),b.add(0,0).add(d,a)}return s.x=k+.5,s.y=w+.5,t.boundStroke(b.translate(k,w),s),s.mark.bounds.clear().union(b),b}function m(e,n,i,r,a){var s,o,u=e.items[0],h=u.datum,d=h.orient,c=u.offset,l=u.bounds.clear(),f=0,g=n[d]||0;switch(u.items.forEach(function(e){l.union(e.bounds)}),s=Math.round(l.width())+2*u.padding-1,o=Math.round(l.height())+2*u.padding-1,d){case"left":f-=s+c-Math.floor(i.x1),n.left+=o+n.margin;break;case"right":f+=c+Math.ceil(i.x2),n.right+=o+n.margin;break;case"top-left":f+=c,g+=c;break;case"top-right":f+=r-s-c,g+=c;break;case"bottom-left":f+=c,g+=a-o-c;break;case"bottom-right":f+=r-s-c,g+=a-o-c}return u.x=f,u.y=g,u.width=s,u.height=o,t.boundStroke(l.set(f,g,f+s,g+o),u),u.mark.bounds.clear().union(l),l}function v(e,n,t,i,r){var a=r.autosize,s=e._width,o=e._height;if(!(e._autosize<1)&&a){var u=Math.max(0,n.width||0),h=Math.max(0,Math.ceil(-i.x1)),d=Math.max(0,Math.ceil(i.x2-u)),c=Math.max(0,n.height||0),l=Math.max(0,Math.ceil(-i.y1)),f=Math.max(0,Math.ceil(i.y2-c));a===J?(s=u,o=c,h=0,l=0):a===W?(u=Math.max(0,s-h-d),c=Math.max(0,o-l-f)):a===F&&(s=u+h+d,o=c+l+f,n.width<0&&(u=t.width()),n.height<0&&(c=t.height())),e.autosize(s,o,u,c,[h,l])}}function p(e,n,t){var r={elements:null,set:null,update:function(n){e.signal(t.signal,n).run()}};return i.isString(n)&&(n=document.querySelector(n)),_(r,n,t,e.signal(t.signal)),e.on(e._signals[t.signal],null,function(){r.set(e.signal(t.signal))}),r}function _(e,n,t,i){var r=M("div",{class:Z});r.appendChild(M("span",{class:$},t.name||t.signal)),n.appendChild(r);var a=b;switch(t.type){case"checkbox":a=k;break;case"select":a=w;break;case"radio":a=x;break;case"range":a=y}a(e,r,t,i)}function b(e,n,t,i){var r=M("input");for(var a in t)"signal"!==a&&"element"!==a&&r.setAttribute(a,t[a]);r.setAttribute("name",t.signal),r.setAttribute("value",i),n.appendChild(r),r.addEventListener("input",function(){e.update(r.value)}),e.elements=[r],e.set=function(e){r.value=e}}function k(e,n,t,i){var r={type:"checkbox",name:t.signal};i&&(r.checked=!0);var a=M("input",r);n.appendChild(a),a.addEventListener("change",function(){e.update(a.checked)}),e.elements=[a],e.set=function(e){a.checked=!!e||null}}function w(e,n,t,i){var r=M("select",{name:t.signal});t.options.forEach(function(e){var n={value:e};e===i&&(n.selected=!0),r.appendChild(M("option",n,e))}),n.appendChild(r),r.addEventListener("change",function(){e.update(t.options[r.selectedIndex])}),e.elements=[r],e.set=function(e){r.selectedIndex=t.options.indexOf(e)}}function x(e,n,t,i){var r=M("span",{class:ee});n.appendChild(r),e.elements=t.options.map(function(n){var a=ne+t.signal+"-"+n,s={id:a,type:"radio",name:t.signal,value:n};n===i&&(s.checked=!0);var o=M("input",s);return o.addEventListener("change",function(){e.update(n)}),r.appendChild(o),r.appendChild(M("label",{for:a},n)),o}),e.set=function(n){for(var t=e.elements,i=0,r=t.length;i<r;++i)t[i].value===n&&(t[i].checked=!0)}}function y(e,n,t,i){i=void 0!==i?i:(+t.max+ +t.min)/2;var a=t.min||Math.min(0,+i)||0,s=t.max||Math.max(100,+i)||100,o=t.step||r.tickStep(a,s,100),u=M("input",{type:"range",value:i,name:t.signal,min:a,max:s,step:o}),h=M("label",{},+i);n.appendChild(u),n.appendChild(h),u.addEventListener("input",function(){h.textContent=u.value,e.update(+u.value)}),e.elements=[u],e.set=function(e){u.value=e,h.textContent=e}}function M(e,n,t){var i=document.createElement(e);for(var r in n)i.setAttribute(r,n[r]);return null!=t&&(i.textContent=t),i}function z(e){"undefined"!=typeof document&&document.body&&(document.body.style.cursor=e)}function C(e,n){var t=e._runtime.data;return t.hasOwnProperty(n)||e.error("Unrecognized data set: "+n),t[n]}function E(e){return C(this,e).values.value}function q(e,t){return this.pulse(C(this,e).input,n.changeset().insert(t))}function S(e,t){return this.pulse(C(this,e).input,n.changeset().remove(t))}function L(e){var n=e.padding();return Math.max(0,e._width+n.left+n.right)}function T(e){var n=e.padding();return Math.max(0,e._height+n.top+n.bottom)}function D(e){var n=e.padding(),t=e._origin;return[n.left+t[0],n.top+t[1]]}function R(e){var n=D(e);e._renderer.background(e._background),e._renderer.resize(L(e),T(e),n),e._handler.origin(n)}function A(e,n,t){function r(e){var t,i=s;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 t;i.isString(e)&&(e=r(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}var s=n?"group"===n.mark.marktype?n:n.mark.group:null;return{view:i.constant(e),item:i.constant(n||{}),group:r,xy:a,x:function(e){return a(e)[0]},y:function(e){return a(e)[1]}}}function O(e){return e.item}function V(e){var n=e.item.mark.source;return n.source||n}function G(e){return function(n,t){return t.vega.view().changeset().encode(t.item,e)}}function H(e,n){var t=e.add(null,function(t){e["_"+n]=t.size,e._autosize=e._resize=1},{size:e._signals[n]});return t.rank=0,t}function U(e,n,t,i,r){this.runAfter(function(a){var s=0;a._autosize=0,a.width()!==t&&(s=1,a.width(t),a._resizeWidth.skip(!0)),a.height()!==i&&(s=1,a.height(i),a._resizeHeight.skip(!0)),a._width!==e&&(a._resize=1,a._width=e),a._height!==n&&(a._resize=1,a._height=n),a._origin[0]===r[0]&&a._origin[1]===r[1]||(a._resize=1,a._origin=r),s&&a.run("enter")})}function I(e,i){i=i||{},n.Dataflow.call(this),this.loader(i.loader||this._loader),this.logLevel(i.logLevel||0),this._el=null,this._renderType=i.renderer||ce,this._scenegraph=new t.Scenegraph;var r=this._scenegraph.root;this._renderer=null,this._handler=(new t.CanvasHandler).scene(r),this._queue=null,this._eventListeners=[];var a=ke(this,e,i.functions);this._runtime=a,this._signals=a.signals,this._bind=e.bindings,a.root&&a.root.set(r),r.source=a.data.root.input,this.pulse(a.data.root.input,this.changeset().insert(r.items)),this._background=a.background||null,this._width=this.width(),this._height=this.height(),this._origin=[0,0],this._resize=0,this._autosize=1,this._resizeWidth=H(this,"width"),this._resizeHeight=H(this,"height"),re(this)}var j=i.inherits(o,n.Transform);j.transform=function(e,n){var i,r=e.mark,a=t.Marks[r.marktype],s=a.bound,o=r.bounds;return r.bounds_prev.clear().union(o),a.nested?u(r,s):e.modified()?(o.clear(),r.items.forEach(function(e){o.union(u(e,s))})):(i=n.changed(n.REM),n.visit(n.ADD,function(e){o.union(u(e,s))}),n.visit(n.MOD,function(e){i=i||o.alignsWith(e.bounds),o.union(u(e,s))}),i&&(o.clear(),r.items.forEach(function(e){o.union(e.bounds)}))),n.modifies("bounds")};var B=i.inherits(h,n.Transform);B.transform=function(e,n){var i=this.value;i||(i=n.dataflow.scenegraph().mark(e.scenepath,e.markdef),i.source=this,this.value=i,i.group.context=e.scenepath.context);var r="group"===i.marktype?t.GroupItem:t.Item;return n.visit(n.ADD,function(e){r.call(e,i)}),i.items=n.source,n};var P=i.inherits(d,n.Transform);P.transform=function(e,n){var t=n.dataflow;if(n.changed(n.REM)&&t.enqueue(n.materialize(n.REM).rem),n.changed(n.ADD)&&t.enqueue(n.materialize(n.ADD).add),n.changed(n.MOD)&&t.enqueue(n.materialize(n.MOD).mod),n.fields&&n.fields.zindex){var i=n.source&&n.source[0];i&&(i.mark.zdirty=!0)}};var W="fit",F="pad",J="none",K="axis",N="frame",Q="legend",X="scope",Y=i.inherits(c,n.Transform);Y.transform=function(e,n){var t=n.dataflow;return e.mark.items.forEach(function(n){l(t,n,e)}),n};var Z="vega-bind",$="vega-bind-name",ee="vega-bind-radio",ne="vega-option-",te=function(e,n){return this._el?p(this,e||this._el,n):this.warn("Bind not supported for headless views."),this},ie="default",re=function(e){var n=e._signals.cursor;n||(e._signals.cursor=n=e.add({user:ie,item:null})),e.on(e.events("view","mousemove"),n,function(e,t){var r=n.value,a=r?i.isString(r)?r:r.user:ie,s=t.item&&t.item.cursor||null;return r&&a===r.user&&s==r.item?r:{user:a,item:s}}),e.add(null,function(e){var n=e.cursor,t=this.value;return i.isString(n)||(t=n.item,n=n.user),z(n&&n!==ie?n:t||n),t},{cursor:n})},ae=function(e,n,i){var r,a,s,o=e._renderer.element();return o&&(s=D(e),a=n.changedTouches?n.changedTouches[0]:n,r=t.point(a,o),r[0]-=s[0],r[1]-=s[1]),n.vega=A(e,i,r),n.item=i,n},se=function(e,t,i){var r,a=this,s=new n.EventStream(i),o=function(e,n){s.receive(ae(a,e,n)),a.run()};if("view"===e)return a._handler.on(t,o),s;if("window"===e?"undefined"!=typeof window&&(r=[window]):"undefined"!=typeof document&&(r=document.querySelectorAll(e)),!r)return a.warn("Can not resolve event source: "+e),s;for(var u=0,h=r.length;u<h;++u)r[u].addEventListener(t,o);return a._eventListeners.push({type:t,sources:r,handler:o}),s},oe=function(e,n){return this.on(this.events("view","mouseover",O),V,G(e||"hover")),this.on(this.events("view","mouseout",O),V,G(n||"update")),this},ue=function(){for(var e,n,t=this._eventListeners,i=t.length;--i>=0;)for(n=t[i],e=n.sources.length;--e>=0;)n.sources[e].removeEventListener(n.type,n.handler)},he=function(e,n,t,i){return n=n||new i(e.loader()),n.initialize(t,L(e),T(e),D(e)).background(e._background)},de=function(e,n,t,i){var r=(new i).scene(e.scenegraph().root).initialize(t,D(e),e);return n&&n.handlers().forEach(function(e){r.on(e.type,e.handler)}),r},ce="canvas",le="png",fe="svg",ge="none",me=function(e){var n=this,i=n._renderType,r=t.CanvasHandler,a=t.CanvasRenderer;return i===fe&&(r=t.SVGHandler,a=e?t.SVGRenderer:t.SVGStringRenderer),e?("string"==typeof e&&"undefined"!=typeof document&&(e=document.querySelector(e)),e.innerHTML="",n._el=e):n._el=null,n._renderer=i===ge?null:he(n,n._renderer,e,a),n._handler=de(n,n._handler,e,r),e&&n._bind&&n._bind.forEach(function(t){n.bind(t.element||e,t)}),n},ve=function(e,n){return e.runAsync().then(function(){var i=n===fe?t.SVGStringRenderer:t.CanvasRenderer;return he(e,null,null,i).renderAsync(e._scenegraph.root)})},pe=function(e){return e===le&&(e=ce),e!==fe&&e!==ce?Promise.reject("Unrecognized image type: "+e):ve(this,e).then(function(n){return e===ce?n.canvas().toDataURL("image/png"):window.URL.createObjectURL(new Blob([n.svg()],{type:"image/svg+xml"}))})},_e=function(){return ve(this,ce).then(function(e){return e.canvas()})},be=function(){return ve(this,fe).then(function(e){return e.svg()})},ke=function(e,t,i){var r=i||a.functionContext;return s.parse(t,s.context(e,n.transforms,r))},we=function(e){var n,t;if(arguments.length){t={skip:!0};for(n in e)this.signal(n,e[n],t);return this.run()}e={};for(n in this._signals)e[n]=this.signal(n);return e},xe=i.inherits(I,n.Dataflow);xe.run=function(e){n.Dataflow.prototype.run.call(this,e);var t=this._queue;return(this._resize||!t||t.length)&&(this.render(t),this._queue=[]),this},xe.render=function(e){return this._renderer&&(this._resize&&(this._resize=0,R(this)),this._renderer.render(this._scenegraph.root,e)),this},xe.enqueue=function(e){this._queue&&e&&e.length&&(this._queue=this._queue.concat(e))},xe.signal=function(e,n,t){var i=this._signals[e];return 1===arguments.length?i?i.value:void 0:this.update(i,n,t)},xe.scenegraph=function(){return this._scenegraph},xe.background=function(e){return arguments.length?(this._background=e,this._resize=1,this):this._background},xe.width=function(e){return arguments.length?this.signal("width",e):this.signal("width")},xe.height=function(e){return arguments.length?this.signal("height",e):this.signal("height")},xe.padding=function(e){return arguments.length?this.signal("padding",e):this.signal("padding")},xe.renderer=function(e){return arguments.length?(e!==fe&&e!==ge&&(e=ce),e!==this._renderType&&(this._renderType=e,this._renderer&&(this._renderer=this._queue=null,this.initialize(this._el))),this):this._renderType},xe.autosize=U,xe.data=E,xe.insert=q,xe.remove=S,xe.initialize=me,xe.toImageURL=pe,xe.toCanvas=_e,xe.toSVG=be,xe.events=se,xe.finalize=ue,xe.hover=oe,xe.bind=te,xe.state=we,n.transform("Bound",o),n.transform("Mark",h),n.transform("Render",d),n.transform("ViewLayout",c),e.View=I,Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "vega-view", | ||
"version": "1.0.0-beta.7", | ||
"version": "1.0.0-beta.8", | ||
"description": "View component and transforms for Vega visualizations.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -81,2 +81,11 @@ import {Transform} from 'vega-dataflow'; | ||
function axisIndices(datum) { | ||
var index = +datum.grid; | ||
return [ | ||
datum.tick ? index++ : -1, // tick index | ||
datum.label ? index++ : -1, // label index | ||
index + (+datum.domain) // title index | ||
]; | ||
} | ||
function layoutAxis(axis, width, height) { | ||
@@ -86,5 +95,3 @@ var item = axis.items[0], | ||
orient = datum.orient, | ||
ticksIndex = datum.grid ? 1 : 0, | ||
labelIndex = ticksIndex + 1, | ||
titleIndex = labelIndex + (datum.domain ? 2 : 1), | ||
indices = axisIndices(datum), | ||
range = item.range, | ||
@@ -95,11 +102,11 @@ offset = item.offset, | ||
maxExtent = item.maxExtent, | ||
title = datum.title && item.items[titleIndex].items[0], | ||
title = datum.title && item.items[indices[2]].items[0], | ||
titlePadding = item.titlePadding, | ||
titleSize = title ? title.fontSize + titlePadding : 0, | ||
bounds = item.bounds, | ||
x = 0, y = 0, s; | ||
x = 0, y = 0, i, s; | ||
bounds.clear() | ||
.union(item.items[ticksIndex].bounds) | ||
.union(item.items[labelIndex].bounds); | ||
bounds.clear(); | ||
if ((i=indices[0]) > -1) bounds.union(item.items[i].bounds); | ||
if ((i=indices[1]) > -1) bounds.union(item.items[i].bounds); | ||
@@ -106,0 +113,0 @@ // position axis group and title |
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
104359
2152