vega-encode
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -9,4 +9,6 @@ (function (global, factory) { | ||
var Pow = 'pow'; | ||
var Utc = 'utc'; | ||
var Sqrt = 'sqrt'; | ||
var Band = 'band'; | ||
var Time = 'time'; | ||
var Point = 'point'; | ||
@@ -51,5 +53,6 @@ var Linear = 'linear'; | ||
* @param {Array<*>} ticks - The candidate tick values. | ||
* @param {*} count - The tick count or interval function. | ||
* @return {Array<*>} - The filtered tick values. | ||
*/ | ||
function validTicks(scale$$1, ticks) { | ||
function validTicks(scale$$1, ticks, count) { | ||
var range$$1 = scale$$1.range(), | ||
@@ -64,6 +67,18 @@ lo = range$$1[0], | ||
return ticks.filter(function(v) { | ||
ticks = ticks.filter(function(v) { | ||
v = scale$$1(v); | ||
return !(v < lo || v > hi) | ||
}); | ||
if (count > 0 && ticks.length > 1) { | ||
var endpoints = [ticks[0], vegaUtil.peek(ticks)]; | ||
while (ticks.length > count && ticks.length >= 3) { | ||
ticks = ticks.filter(function(_, i) { return !(i % 2); }); | ||
} | ||
if (ticks.length < 3) { | ||
ticks = endpoints; | ||
} | ||
} | ||
return ticks; | ||
} | ||
@@ -187,10 +202,14 @@ | ||
scale$$1 = _.scale, | ||
count = _.values ? _.values.length : tickCount(scale$$1, _.count), | ||
count = _.tickCount ? _.tickCount : (_.values ? _.values.length : tickCount(scale$$1, _.count)), | ||
format$$1 = _.format || tickFormat(scale$$1, count, _.formatSpecifier), | ||
values = _.values ? validTicks(scale$$1, _.values) : tickValues(scale$$1, count); | ||
values = _.values ? validTicks(scale$$1, _.values, count) : tickValues(scale$$1, count); | ||
if (ticks) out.rem = ticks; | ||
ticks = values.map(function(value) { | ||
return vegaDataflow.ingest({value: value, label: format$$1(value)}) | ||
ticks = values.map(function(value, i) { | ||
return vegaDataflow.ingest({ | ||
index: i / (values.length - 1), | ||
value: value, | ||
label: format$$1(value) | ||
}); | ||
}); | ||
@@ -202,2 +221,3 @@ | ||
ticks.push(vegaDataflow.ingest({ | ||
index: -1, | ||
extra: {value: ticks[0].value}, | ||
@@ -769,2 +789,4 @@ label: '' | ||
var INCLUDE_PAD = vegaUtil.toSet([Linear, Log, Pow, Sqrt, Time, Utc]); | ||
var SKIP = vegaUtil.toSet([ | ||
@@ -798,2 +820,5 @@ 'set', 'modified', 'clear', 'type', 'scheme', 'schemeExtent', 'schemeCount', | ||
for (prop in _) if (!SKIP[prop]) { | ||
// padding is a scale property for band/point but not others | ||
if (prop === 'padding' && INCLUDE_PAD[scale$$1.type]) continue; | ||
// invoke scale property setter, raise warning if not found | ||
vegaUtil.isFunction(scale$$1[prop]) | ||
@@ -815,3 +840,4 @@ ? scale$$1[prop](_[prop]) | ||
var domain = _.domain, | ||
zero = _.zero || (_.zero === undefined && INCLUDE_ZERO[scale$$1.type]), | ||
type = scale$$1.type, | ||
zero = _.zero || (_.zero === undefined && INCLUDE_ZERO[type]), | ||
n, mid; | ||
@@ -821,2 +847,7 @@ | ||
// adjust continuous domain for minimum pixel padding | ||
if (INCLUDE_PAD[type] && _.padding && domain[0] !== vegaUtil.peek(domain)) { | ||
domain = padDomain(type, domain, _.range, _.padding, _.exponent); | ||
} | ||
// adjust domain based on zero, min, max settings | ||
@@ -862,2 +893,16 @@ if (zero || _.domainMin != null || _.domainMax != null || _.domainMid != null) { | ||
function padDomain(type, domain, range$$1, pad, exponent) { | ||
var span = Math.abs(vegaUtil.peek(range$$1) - range$$1[0]), | ||
frac = span / (span - 2 * pad), | ||
d = type === Log ? vegaUtil.zoomLog(domain, null, frac) | ||
: type === Sqrt ? vegaUtil.zoomPow(domain, null, frac, 0.5) | ||
: type === Pow ? vegaUtil.zoomPow(domain, null, frac, exponent) | ||
: vegaUtil.zoomLinear(domain, null, frac); | ||
domain = domain.slice(); | ||
domain[0] = d[0]; | ||
domain[domain.length-1] = d[1]; | ||
return domain; | ||
} | ||
function configureRange(scale$$1, _, count) { | ||
@@ -1112,2 +1157,3 @@ var round = _.round || false, | ||
exports.stack = Stack; | ||
exports.validTicks = validTicks; | ||
@@ -1114,0 +1160,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("vega-scale"),require("vega-util"),require("d3-format"),require("vega-dataflow"),require("d3-array"),require("d3-interpolate")):"function"==typeof define&&define.amd?define(["exports","vega-scale","vega-util","d3-format","vega-dataflow","d3-array","d3-interpolate"],n):n((e.vega=e.vega||{},e.vega.transforms=e.vega.transforms||{}),e.vega,e.vega,e.d3,e.vega,e.d3,e.d3)}(this,function(e,n,t,r,a,i,o){"use strict";function u(e,r){var a;return t.isObject(r)&&(a=r.step,r=r.interval),t.isString(r)&&(r="time"===e.type?n.timeInterval(r):"utc"===e.type?n.utcInterval(r):t.error("Only time and utc scales accept interval strings."),a&&(r=r.every(a))),r}function s(e,n){var r=e.range(),a=r[0],i=t.peek(r);return a>i&&(r=i,i=a,a=r),n.filter(function(n){return!((n=e(n))<a||n>i)})}function l(e,n){return e.ticks?e.ticks(n):e.domain()}function f(e,n,t){var r=e.tickFormat?e.tickFormat(n,t):String;return e.type===Q?c(r,d(t)):r}function c(e,n){return function(t){return e(t)?n(t):""}}function d(e){var n=r.formatSpecifier(e||",");if(null==n.precision){switch(n.precision=12,n.type){case"%":n.precision-=2;break;case"e":n.precision-=1}return m(r.format(n),r.format(".1f")(1)[1])}return r.format(n)}function m(e,n){return function(t){var r,a,i=e(t),o=i.indexOf(n);if(o<0)return i;for(a=(r=p(i,o))<i.length?i.slice(r):"";--r>o;)if("0"!==i[r]){++r;break}return i.slice(0,r)+a}}function p(e,n){var t,r=e.lastIndexOf("e");if(r>0)return r;for(r=e.length;--r>n;)if((t=e.charCodeAt(r))>=48&&t<=57)return r+1}function h(e){a.Transform.call(this,null,e)}function v(e){a.Transform.call(this,null,e)}function g(){return a.ingest({})}function y(e){return e.exit}function M(e){a.Transform.call(this,null,e)}function x(e,n,t){if(t)return e.domain();var r=oe[e.type];return r?r(e):l(e,n)}function S(e){var n=e.domain();return n.max=n.pop(),n}function O(e,n){return oe[e.type]?k(n):b(n)}function k(e){return function(n,t,r){var a=r[t+1]||r.max||1/0,i=A(n,e),o=A(a,e);return i&&o?i+"–"+o:o?"< "+o:"≥ "+i}}function A(e,n){return isFinite(e)?n(e):null}function b(e){return function(n){return e(n)}}function D(e){a.Transform.call(this,[],e)}function T(e){return e.source.x}function w(e){return e.source.y}function E(e){return e.target.x}function F(e){return e.target.y}function R(e){a.Transform.call(this,{},e)}function z(e,n,t,r){return"M"+e+","+n+"L"+t+","+r}function C(e,n,t,r){var a=t-e,i=r-n,o=Math.sqrt(a*a+i*i)/2;return"M"+e+","+n+"A"+o+","+o+" "+180*Math.atan2(i,a)/Math.PI+" 0 1 "+t+","+r}function q(e,n,t,r){var a=t-e,i=r-n,o=.2*(a+i),u=.2*(i-a);return"M"+e+","+n+"C"+(e+o)+","+(n+u)+" "+(t+u)+","+(r-o)+" "+t+","+r}function I(e){a.Transform.call(this,null,e)}function _(e){a.Transform.call(this,null,e),this.modified(!0)}function L(e,n,t){var r=P(e,n.domainRaw);if(r>-1)return r;var a,i,o=n.domain,s=n.zero||void 0===n.zero&&le[e.type];return o?((s||null!=n.domainMin||null!=n.domainMax||null!=n.domainMid)&&(a=(o=o.slice()).length-1||1,s&&(o[0]>0&&(o[0]=0),o[a]<0&&(o[a]=0)),null!=n.domainMin&&(o[0]=n.domainMin),null!=n.domainMax&&(o[a]=n.domainMax),null!=n.domainMid&&(((i=n.domainMid)<o[0]||i>o[a])&&t.warn("Scale domainMid exceeds domain min or max.",i),o.splice(a,0,i))),e.domain(o),n.nice&&e.nice&&e.nice(!0!==n.nice&&u(e,n.nice)||null),o.length):0}function P(e,n){return n?(e.domain(n),n.length):-1}function N(e,r,a){var i=r.round||!1,u=r.range;if(null!=r.rangeStep)u=U(e.type,r,a);else if(r.scheme){if(u=j(e.type,r,a),t.isFunction(u))return e.interpolator(u)}else if(u&&e.type===ie)return e.interpolator(o.interpolateRgbBasis(Y(u,r.reverse)));u&&r.interpolate&&e.interpolate?e.interpolate(n.interpolate(r.interpolate,r.interpolateGamma)):t.isFunction(e.round)?e.round(i):t.isFunction(e.rangeRound)&&e.interpolate(i?o.interpolateRound:o.interpolate),u&&e.range(Y(u,r.reverse))}function U(e,r,a){e!==Z&&e!==$&&t.error("Only band and point scales support rangeStep.");var i=(null!=r.paddingOuter?r.paddingOuter:r.padding)||0,o=e===$?1:(null!=r.paddingInner?r.paddingInner:r.padding)||0;return[0,r.rangeStep*n.bandSpace(a,o,i)]}function j(e,r,a){var i,o=r.scheme.toLowerCase(),u=n.scheme(o),s=r.schemeExtent;return u||t.error("Unrecognized scheme name: "+r.scheme),a=e===re?a+1:e===ae?a-1:e===ne||e===te?+r.schemeCount||se:a,e===ie?X(u,s,r.reverse):!s&&(i=n.scheme(o+"-"+a))?i:t.isFunction(u)?G(X(u,s),a):e===ee?u:u.slice(0,a)}function X(e,r,a){return t.isFunction(e)&&(r||a)?n.interpolateRange(e,Y(r||[0,1],a)):e}function Y(e,n){return n?e.slice().reverse():e}function G(e,n){for(var t=new Array(n),r=n-1||1,a=0;a<n;++a)t[a]=e(a/r);return t}function H(e){a.Transform.call(this,null,e)}function V(e){a.Transform.call(this,null,e)}function B(e,n,t,r,a){for(var i,o=(n-e.sum)/2,u=e.length,s=0;s<u;++s)(i=e[s])[r]=o,i[a]=o+=Math.abs(t(i))}function J(e,n,t,r,a){for(var i,o=1/e.sum,u=0,s=e.length,l=0,f=0;l<s;++l)(i=e[l])[r]=u,i[a]=u=o*(f+=Math.abs(t(i)))}function W(e,n,t,r,a){for(var i,o,u=0,s=0,l=e.length,f=0;f<l;++f)(i=t(o=e[f]))<0?(o[r]=s,o[a]=s+=i):(o[r]=u,o[a]=u+=i)}function K(e,n,t,r){var a,i,o,u,s,l,f,c,d,m=[];if(null==n)m.push(e.slice());else for(a={},i=0,o=e.length;i<o;++i)s=e[i],(f=a[l=n.map(function(e){return e(s)})])||(a[l]=f=[],m.push(f)),f.push(s);for(l=0,d=0,u=m.length;l<u;++l){for(i=0,c=0,o=(f=m[l]).length;i<o;++i)c+=Math.abs(r(f[i]));f.sum=c,c>d&&(d=c),t&&f.sort(t)}return m.max=d,m}var Q="log",Z="band",$="point",ee="ordinal",ne="quantile",te="quantize",re="threshold",ae="bin-ordinal",ie="sequential";t.inherits(h,a.Transform).transform=function(e,n){if(this.value&&!e.modified())return n.StopPropagation;var t=n.fork(n.NO_SOURCE|n.NO_FIELDS),r=this.value,i=e.scale,o=e.values?e.values.length:u(i,e.count),c=e.format||f(i,o,e.formatSpecifier),d=e.values?s(i,e.values):l(i,o);return r&&(t.rem=r),r=d.map(function(e){return a.ingest({value:e,label:c(e)})}),e.extra&&r.push(a.ingest({extra:{value:r[0].value},label:""})),t.source=r,t.add=r,this.value=r,t},t.inherits(v,a.Transform).transform=function(e,n){var r=n.dataflow,i=n.fork(n.NO_SOURCE|n.NO_FIELDS),o=e.item||g,u=e.key||a.tupleid,s=this.value;return t.isArray(i.encode)&&(i.encode=null),s||(n=n.addAll(),this.value=s=t.fastmap().test(y),s.lookup=function(e){return s.get(u(e))}),(e.modified("key")||n.modified(u))&&t.error("DataJoin does not support modified key function or fields."),n.visit(n.ADD,function(e){var n=u(e),t=s.get(n);t?t.exit?(s.empty--,i.add.push(t)):i.mod.push(t):(s.set(n,t=o(e)),i.add.push(t)),t.datum=e,t.exit=!1}),n.visit(n.MOD,function(e){var n=u(e),t=s.get(n);t&&(t.datum=e,i.mod.push(t))}),n.visit(n.REM,function(e){var n=u(e),t=s.get(n);e!==t.datum||t.exit||(i.rem.push(t),t.exit=!0,++s.empty)}),n.changed(n.ADD_MOD)&&i.modifies("datum"),e.clean&&s.empty>r.cleanThreshold&&r.runAfter(s.clean),i},t.inherits(M,a.Transform).transform=function(e,n){var r=n.fork(n.ADD_REM),a=e.encoders,i=n.encode;if(t.isArray(i)){if(!r.changed()&&!i.every(function(e){return a[e]}))return n.StopPropagation;i=i[0]}var o="enter"===i,u=a.update||t.falsy,s=a.enter||t.falsy,l=a.exit||t.falsy,f=(i&&!o?a[i]:u)||t.falsy;if(n.changed(n.ADD)&&(n.visit(n.ADD,function(n){s(n,e),u(n,e),f!==t.falsy&&f!==u&&f(n,e)}),r.modifies(s.output),r.modifies(u.output),f!==t.falsy&&f!==u&&r.modifies(f.output)),n.changed(n.REM)&&l!==t.falsy&&(n.visit(n.REM,function(n){l(n,e)}),r.modifies(l.output)),o||f!==t.falsy){var c=n.MOD|(e.modified()?n.REFLOW:0);o?(n.visit(c,function(n){var t=s(n,e);(f(n,e)||t)&&r.mod.push(n)}),r.mod.length&&r.modifies(s.output)):n.visit(c,function(n){f(n,e)&&r.mod.push(n)}),r.mod.length&&r.modifies(f.output)}return r.changed()?r:n.StopPropagation};var oe={};oe[ne]=function(e){var n=[-1/0].concat(e.quantiles());return n.max=1/0,n},oe[te]=function(e){var n=e.domain(),r=n[0],a=t.peek(n),i=e.range().length,o=new Array(i),u=0;for(o[0]=-1/0;++u<i;)o[u]=(u*a-(u-i)*r)/i;return o.max=1/0,o},oe[re]=function(e){var n=[-1/0].concat(e.domain());return n.max=1/0,n},oe["bin-linear"]=S,oe[ae]=S,t.inherits(D,a.Transform).transform=function(e,r){if(null!=this.value&&!e.modified())return r.StopPropagation;var i=r.fork(r.NO_SOURCE|r.NO_FIELDS),o=0,s=this.value,l="gradient"===e.type,c=e.scale,d=null==e.count?5:u(c,e.count),m=e.format||f(c,d,e.formatSpecifier),p=e.values||x(c,d,l);if(m=O(c,m),s&&(i.rem=s),l)var h=e.values?c.domain():p,v=n.scaleFraction(c,h[0],t.peek(h));else{var g,y=e.size;t.isFunction(y)?(e.values||0!==c(p[0])||(p=p.slice(1)),g=p.reduce(function(n,t){return Math.max(n,y(t,e))},0)):y=t.constant(g=y||8)}return s=p.map(function(n,t){var r=a.ingest({index:t,label:m(n,t,p),value:n});return l?r.perc=v(n):(r.offset=g,r.size=y(n,e),r.total=Math.round(o),o+=r.size),r}),i.source=s,i.add=s,this.value=s,i};var ue=t.fastmap({line:z,"line-radial":function(e,n,t,r){return z(n*Math.cos(e),n*Math.sin(e),r*Math.cos(t),r*Math.sin(t))},arc:C,"arc-radial":function(e,n,t,r){return C(n*Math.cos(e),n*Math.sin(e),r*Math.cos(t),r*Math.sin(t))},curve:q,"curve-radial":function(e,n,t,r){return q(n*Math.cos(e),n*Math.sin(e),r*Math.cos(t),r*Math.sin(t))},"orthogonal-horizontal":function(e,n,t,r){return"M"+e+","+n+"V"+r+"H"+t},"orthogonal-vertical":function(e,n,t,r){return"M"+e+","+n+"H"+t+"V"+r},"orthogonal-radial":function(e,n,t,r){var a=Math.cos(e),i=Math.sin(e),o=Math.cos(t),u=Math.sin(t);return"M"+n*a+","+n*i+"A"+n+","+n+" 0 0,"+((Math.abs(t-e)>Math.PI?t<=e:t>e)?1:0)+" "+n*o+","+n*u+"L"+r*o+","+r*u},"diagonal-horizontal":function(e,n,t,r){var a=(e+t)/2;return"M"+e+","+n+"C"+a+","+n+" "+a+","+r+" "+t+","+r},"diagonal-vertical":function(e,n,t,r){var a=(n+r)/2;return"M"+e+","+n+"C"+e+","+a+" "+t+","+a+" "+t+","+r},"diagonal-radial":function(e,n,t,r){var a=Math.cos(e),i=Math.sin(e),o=Math.cos(t),u=Math.sin(t),s=(n+r)/2;return"M"+n*a+","+n*i+"C"+s*a+","+s*i+" "+s*o+","+s*u+" "+r*o+","+r*u}});R.Definition={type:"LinkPath",metadata:{modifies:!0},params:[{name:"sourceX",type:"field",default:"source.x"},{name:"sourceY",type:"field",default:"source.y"},{name:"targetX",type:"field",default:"target.x"},{name:"targetY",type:"field",default:"target.y"},{name:"orient",type:"enum",default:"vertical",values:["horizontal","vertical","radial"]},{name:"shape",type:"enum",default:"line",values:["line","arc","curve","diagonal","orthogonal"]},{name:"as",type:"string",default:"path"}]},t.inherits(R,a.Transform).transform=function(e,n){var r=e.sourceX||T,a=e.sourceY||w,i=e.targetX||E,o=e.targetY||F,u=e.as||"path",s=e.orient||"vertical",l=e.shape||"line",f=ue.get(l+"-"+s)||ue.get(l);return f||t.error("LinkPath unsupported type: "+e.shape+(e.orient?"-"+e.orient:"")),n.visit(n.SOURCE,function(e){e[u]=f(r(e),a(e),i(e),o(e))}),n.reflow(e.modified()).modifies(u)},I.Definition={type:"Pie",metadata:{modifies:!0},params:[{name:"field",type:"field"},{name:"startAngle",type:"number",default:0},{name:"endAngle",type:"number",default:6.283185307179586},{name:"sort",type:"boolean",default:!1},{name:"as",type:"string",array:!0,length:2,default:["startAngle","endAngle"]}]},t.inherits(I,a.Transform).transform=function(e,n){var r,a,o,u=e.as||["startAngle","endAngle"],s=u[0],l=u[1],f=e.field||t.one,c=e.startAngle||0,d=null!=e.endAngle?e.endAngle:2*Math.PI,m=n.source,p=m.map(f),h=p.length,v=c,g=(d-c)/i.sum(p),y=i.range(h);for(e.sort&&y.sort(function(e,n){return p[e]-p[n]}),r=0;r<h;++r)o=p[y[r]],(a=m[y[r]])[s]=v,a[l]=v+=o*g;return this.value=p,n.reflow(e.modified()).modifies(u)};var se=5,le=t.toSet(["linear","pow","sqrt"]),fe=t.toSet(["set","modified","clear","type","scheme","schemeExtent","schemeCount","domain","domainMin","domainMid","domainMax","domainRaw","nice","zero","range","rangeStep","round","reverse","interpolate","interpolateGamma"]);t.inherits(_,a.Transform).transform=function(e,r){var a,i=r.dataflow,o=this.value;o&&!e.modified("type")||(this.value=o=n.scale((e.type||"linear").toLowerCase())());for(a in e)fe[a]||(t.isFunction(o[a])?o[a](e[a]):i.warn("Unsupported scale property: "+a));return N(o,e,L(o,e,i)),r.fork(r.NO_SOURCE|r.NO_FIELDS)},t.inherits(H,a.Transform).transform=function(e,n){var t=e.modified("sort")||n.changed(n.ADD)||n.modified(e.sort.fields)||n.modified("datum");return t&&n.source.sort(e.sort),this.modified(t),n};V.Definition={type:"Stack",metadata:{modifies:!0},params:[{name:"field",type:"field"},{name:"groupby",type:"field",array:!0},{name:"sort",type:"compare"},{name:"offset",type:"enum",default:"zero",values:["zero","center","normalize"]},{name:"as",type:"string",array:!0,length:2,default:["y0","y1"]}]},t.inherits(V,a.Transform).transform=function(e,n){var r,a,i,o,u=e.as||["y0","y1"],s=u[0],l=u[1],f=e.field||t.one,c="center"===e.offset?B:"normalize"===e.offset?J:W;for(a=0,i=(r=K(n.source,e.groupby,e.sort,f)).length,o=r.max;a<i;++a)c(r[a],o,f,s,l);return n.reflow(e.modified()).modifies(u)},e.axisticks=h,e.datajoin=v,e.encode=M,e.legendentries=D,e.linkpath=R,e.pie=I,e.scale=_,e.sortitems=H,e.stack=V,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("vega-scale"),require("vega-util"),require("d3-format"),require("vega-dataflow"),require("d3-array"),require("d3-interpolate")):"function"==typeof define&&define.amd?define(["exports","vega-scale","vega-util","d3-format","vega-dataflow","d3-array","d3-interpolate"],n):n((e.vega=e.vega||{},e.vega.transforms=e.vega.transforms||{}),e.vega,e.vega,e.d3,e.vega,e.d3,e.d3)}(this,function(e,n,t,r,a,i,o){"use strict";function u(e,r){var a;return t.isObject(r)&&(a=r.step,r=r.interval),t.isString(r)&&(r="time"===e.type?n.timeInterval(r):"utc"===e.type?n.utcInterval(r):t.error("Only time and utc scales accept interval strings."),a&&(r=r.every(a))),r}function s(e,n,r){var a=e.range(),i=a[0],o=t.peek(a);if(i>o&&(a=o,o=i,i=a),n=n.filter(function(n){return!((n=e(n))<i||n>o)}),r>0&&n.length>1){for(var u=[n[0],t.peek(n)];n.length>r&&n.length>=3;)n=n.filter(function(e,n){return!(n%2)});n.length<3&&(n=u)}return n}function l(e,n){return e.ticks?e.ticks(n):e.domain()}function f(e,n,t){var r=e.tickFormat?e.tickFormat(n,t):String;return e.type===Z?c(r,d(t)):r}function c(e,n){return function(t){return e(t)?n(t):""}}function d(e){var n=r.formatSpecifier(e||",");if(null==n.precision){switch(n.precision=12,n.type){case"%":n.precision-=2;break;case"e":n.precision-=1}return m(r.format(n),r.format(".1f")(1)[1])}return r.format(n)}function m(e,n){return function(t){var r,a,i=e(t),o=i.indexOf(n);if(o<0)return i;for(a=(r=p(i,o))<i.length?i.slice(r):"";--r>o;)if("0"!==i[r]){++r;break}return i.slice(0,r)+a}}function p(e,n){var t,r=e.lastIndexOf("e");if(r>0)return r;for(r=e.length;--r>n;)if((t=e.charCodeAt(r))>=48&&t<=57)return r+1}function h(e){a.Transform.call(this,null,e)}function v(e){a.Transform.call(this,null,e)}function g(){return a.ingest({})}function y(e){return e.exit}function M(e){a.Transform.call(this,null,e)}function x(e,n,t){if(t)return e.domain();var r=le[e.type];return r?r(e):l(e,n)}function k(e){var n=e.domain();return n.max=n.pop(),n}function S(e,n){return le[e.type]?O(n):A(n)}function O(e){return function(n,t,r){var a=r[t+1]||r.max||1/0,i=b(n,e),o=b(a,e);return i&&o?i+"–"+o:o?"< "+o:"≥ "+i}}function b(e,n){return isFinite(e)?n(e):null}function A(e){return function(n){return e(n)}}function D(e){a.Transform.call(this,[],e)}function T(e){return e.source.x}function w(e){return e.source.y}function z(e){return e.target.x}function C(e){return e.target.y}function E(e){a.Transform.call(this,{},e)}function F(e,n,t,r){return"M"+e+","+n+"L"+t+","+r}function R(e,n,t,r){var a=t-e,i=r-n,o=Math.sqrt(a*a+i*i)/2;return"M"+e+","+n+"A"+o+","+o+" "+180*Math.atan2(i,a)/Math.PI+" 0 1 "+t+","+r}function L(e,n,t,r){var a=t-e,i=r-n,o=.2*(a+i),u=.2*(i-a);return"M"+e+","+n+"C"+(e+o)+","+(n+u)+" "+(t+u)+","+(r-o)+" "+t+","+r}function P(e){a.Transform.call(this,null,e)}function q(e){a.Transform.call(this,null,e),this.modified(!0)}function I(e,n,r){var a=_(e,n.domainRaw);if(a>-1)return a;var i,o,s=n.domain,l=e.type,f=n.zero||void 0===n.zero&&de[l];return s?(me[l]&&n.padding&&s[0]!==t.peek(s)&&(s=N(l,s,n.range,n.padding,n.exponent)),(f||null!=n.domainMin||null!=n.domainMax||null!=n.domainMid)&&(i=(s=s.slice()).length-1||1,f&&(s[0]>0&&(s[0]=0),s[i]<0&&(s[i]=0)),null!=n.domainMin&&(s[0]=n.domainMin),null!=n.domainMax&&(s[i]=n.domainMax),null!=n.domainMid&&(((o=n.domainMid)<s[0]||o>s[i])&&r.warn("Scale domainMid exceeds domain min or max.",o),s.splice(i,0,o))),e.domain(s),n.nice&&e.nice&&e.nice(!0!==n.nice&&u(e,n.nice)||null),s.length):0}function _(e,n){return n?(e.domain(n),n.length):-1}function N(e,n,r,a,i){var o=Math.abs(t.peek(r)-r[0]),u=o/(o-2*a),s=e===Z?t.zoomLog(n,null,u):e===ee?t.zoomPow(n,null,u,.5):e===$?t.zoomPow(n,null,u,i):t.zoomLinear(n,null,u);return n=n.slice(),n[0]=s[0],n[n.length-1]=s[1],n}function U(e,r,a){var i=r.round||!1,u=r.range;if(null!=r.rangeStep)u=j(e.type,r,a);else if(r.scheme){if(u=X(e.type,r,a),t.isFunction(u))return e.interpolator(u)}else if(u&&e.type===se)return e.interpolator(o.interpolateRgbBasis(G(u,r.reverse)));u&&r.interpolate&&e.interpolate?e.interpolate(n.interpolate(r.interpolate,r.interpolateGamma)):t.isFunction(e.round)?e.round(i):t.isFunction(e.rangeRound)&&e.interpolate(i?o.interpolateRound:o.interpolate),u&&e.range(G(u,r.reverse))}function j(e,r,a){e!==ne&&e!==te&&t.error("Only band and point scales support rangeStep.");var i=(null!=r.paddingOuter?r.paddingOuter:r.padding)||0,o=e===te?1:(null!=r.paddingInner?r.paddingInner:r.padding)||0;return[0,r.rangeStep*n.bandSpace(a,o,i)]}function X(e,r,a){var i,o=r.scheme.toLowerCase(),u=n.scheme(o),s=r.schemeExtent;return u||t.error("Unrecognized scheme name: "+r.scheme),a=e===oe?a+1:e===ue?a-1:e===ae||e===ie?+r.schemeCount||ce:a,e===se?Y(u,s,r.reverse):!s&&(i=n.scheme(o+"-"+a))?i:t.isFunction(u)?H(Y(u,s),a):e===re?u:u.slice(0,a)}function Y(e,r,a){return t.isFunction(e)&&(r||a)?n.interpolateRange(e,G(r||[0,1],a)):e}function G(e,n){return n?e.slice().reverse():e}function H(e,n){for(var t=new Array(n),r=n-1||1,a=0;a<n;++a)t[a]=e(a/r);return t}function V(e){a.Transform.call(this,null,e)}function B(e){a.Transform.call(this,null,e)}function J(e,n,t,r,a){for(var i,o=(n-e.sum)/2,u=e.length,s=0;s<u;++s)(i=e[s])[r]=o,i[a]=o+=Math.abs(t(i))}function W(e,n,t,r,a){for(var i,o=1/e.sum,u=0,s=e.length,l=0,f=0;l<s;++l)(i=e[l])[r]=u,i[a]=u=o*(f+=Math.abs(t(i)))}function K(e,n,t,r,a){for(var i,o,u=0,s=0,l=e.length,f=0;f<l;++f)(i=t(o=e[f]))<0?(o[r]=s,o[a]=s+=i):(o[r]=u,o[a]=u+=i)}function Q(e,n,t,r){var a,i,o,u,s,l,f,c,d,m=[];if(null==n)m.push(e.slice());else for(a={},i=0,o=e.length;i<o;++i)s=e[i],(f=a[l=n.map(function(e){return e(s)})])||(a[l]=f=[],m.push(f)),f.push(s);for(l=0,d=0,u=m.length;l<u;++l){for(i=0,c=0,o=(f=m[l]).length;i<o;++i)c+=Math.abs(r(f[i]));f.sum=c,c>d&&(d=c),t&&f.sort(t)}return m.max=d,m}var Z="log",$="pow",ee="sqrt",ne="band",te="point",re="ordinal",ae="quantile",ie="quantize",oe="threshold",ue="bin-ordinal",se="sequential";t.inherits(h,a.Transform).transform=function(e,n){if(this.value&&!e.modified())return n.StopPropagation;var t=n.fork(n.NO_SOURCE|n.NO_FIELDS),r=this.value,i=e.scale,o=e.tickCount?e.tickCount:e.values?e.values.length:u(i,e.count),c=e.format||f(i,o,e.formatSpecifier),d=e.values?s(i,e.values,o):l(i,o);return r&&(t.rem=r),r=d.map(function(e,n){return a.ingest({index:n/(d.length-1),value:e,label:c(e)})}),e.extra&&r.push(a.ingest({index:-1,extra:{value:r[0].value},label:""})),t.source=r,t.add=r,this.value=r,t},t.inherits(v,a.Transform).transform=function(e,n){var r=n.dataflow,i=n.fork(n.NO_SOURCE|n.NO_FIELDS),o=e.item||g,u=e.key||a.tupleid,s=this.value;return t.isArray(i.encode)&&(i.encode=null),s||(n=n.addAll(),this.value=s=t.fastmap().test(y),s.lookup=function(e){return s.get(u(e))}),(e.modified("key")||n.modified(u))&&t.error("DataJoin does not support modified key function or fields."),n.visit(n.ADD,function(e){var n=u(e),t=s.get(n);t?t.exit?(s.empty--,i.add.push(t)):i.mod.push(t):(s.set(n,t=o(e)),i.add.push(t)),t.datum=e,t.exit=!1}),n.visit(n.MOD,function(e){var n=u(e),t=s.get(n);t&&(t.datum=e,i.mod.push(t))}),n.visit(n.REM,function(e){var n=u(e),t=s.get(n);e!==t.datum||t.exit||(i.rem.push(t),t.exit=!0,++s.empty)}),n.changed(n.ADD_MOD)&&i.modifies("datum"),e.clean&&s.empty>r.cleanThreshold&&r.runAfter(s.clean),i},t.inherits(M,a.Transform).transform=function(e,n){var r=n.fork(n.ADD_REM),a=e.encoders,i=n.encode;if(t.isArray(i)){if(!r.changed()&&!i.every(function(e){return a[e]}))return n.StopPropagation;i=i[0]}var o="enter"===i,u=a.update||t.falsy,s=a.enter||t.falsy,l=a.exit||t.falsy,f=(i&&!o?a[i]:u)||t.falsy;if(n.changed(n.ADD)&&(n.visit(n.ADD,function(n){s(n,e),u(n,e),f!==t.falsy&&f!==u&&f(n,e)}),r.modifies(s.output),r.modifies(u.output),f!==t.falsy&&f!==u&&r.modifies(f.output)),n.changed(n.REM)&&l!==t.falsy&&(n.visit(n.REM,function(n){l(n,e)}),r.modifies(l.output)),o||f!==t.falsy){var c=n.MOD|(e.modified()?n.REFLOW:0);o?(n.visit(c,function(n){var t=s(n,e);(f(n,e)||t)&&r.mod.push(n)}),r.mod.length&&r.modifies(s.output)):n.visit(c,function(n){f(n,e)&&r.mod.push(n)}),r.mod.length&&r.modifies(f.output)}return r.changed()?r:n.StopPropagation};var le={};le[ae]=function(e){var n=[-1/0].concat(e.quantiles());return n.max=1/0,n},le[ie]=function(e){var n=e.domain(),r=n[0],a=t.peek(n),i=e.range().length,o=new Array(i),u=0;for(o[0]=-1/0;++u<i;)o[u]=(u*a-(u-i)*r)/i;return o.max=1/0,o},le[oe]=function(e){var n=[-1/0].concat(e.domain());return n.max=1/0,n},le["bin-linear"]=k,le[ue]=k,t.inherits(D,a.Transform).transform=function(e,r){if(null!=this.value&&!e.modified())return r.StopPropagation;var i=r.fork(r.NO_SOURCE|r.NO_FIELDS),o=0,s=this.value,l="gradient"===e.type,c=e.scale,d=null==e.count?5:u(c,e.count),m=e.format||f(c,d,e.formatSpecifier),p=e.values||x(c,d,l);if(m=S(c,m),s&&(i.rem=s),l)var h=e.values?c.domain():p,v=n.scaleFraction(c,h[0],t.peek(h));else{var g,y=e.size;t.isFunction(y)?(e.values||0!==c(p[0])||(p=p.slice(1)),g=p.reduce(function(n,t){return Math.max(n,y(t,e))},0)):y=t.constant(g=y||8)}return s=p.map(function(n,t){var r=a.ingest({index:t,label:m(n,t,p),value:n});return l?r.perc=v(n):(r.offset=g,r.size=y(n,e),r.total=Math.round(o),o+=r.size),r}),i.source=s,i.add=s,this.value=s,i};var fe=t.fastmap({line:F,"line-radial":function(e,n,t,r){return F(n*Math.cos(e),n*Math.sin(e),r*Math.cos(t),r*Math.sin(t))},arc:R,"arc-radial":function(e,n,t,r){return R(n*Math.cos(e),n*Math.sin(e),r*Math.cos(t),r*Math.sin(t))},curve:L,"curve-radial":function(e,n,t,r){return L(n*Math.cos(e),n*Math.sin(e),r*Math.cos(t),r*Math.sin(t))},"orthogonal-horizontal":function(e,n,t,r){return"M"+e+","+n+"V"+r+"H"+t},"orthogonal-vertical":function(e,n,t,r){return"M"+e+","+n+"H"+t+"V"+r},"orthogonal-radial":function(e,n,t,r){var a=Math.cos(e),i=Math.sin(e),o=Math.cos(t),u=Math.sin(t);return"M"+n*a+","+n*i+"A"+n+","+n+" 0 0,"+((Math.abs(t-e)>Math.PI?t<=e:t>e)?1:0)+" "+n*o+","+n*u+"L"+r*o+","+r*u},"diagonal-horizontal":function(e,n,t,r){var a=(e+t)/2;return"M"+e+","+n+"C"+a+","+n+" "+a+","+r+" "+t+","+r},"diagonal-vertical":function(e,n,t,r){var a=(n+r)/2;return"M"+e+","+n+"C"+e+","+a+" "+t+","+a+" "+t+","+r},"diagonal-radial":function(e,n,t,r){var a=Math.cos(e),i=Math.sin(e),o=Math.cos(t),u=Math.sin(t),s=(n+r)/2;return"M"+n*a+","+n*i+"C"+s*a+","+s*i+" "+s*o+","+s*u+" "+r*o+","+r*u}});E.Definition={type:"LinkPath",metadata:{modifies:!0},params:[{name:"sourceX",type:"field",default:"source.x"},{name:"sourceY",type:"field",default:"source.y"},{name:"targetX",type:"field",default:"target.x"},{name:"targetY",type:"field",default:"target.y"},{name:"orient",type:"enum",default:"vertical",values:["horizontal","vertical","radial"]},{name:"shape",type:"enum",default:"line",values:["line","arc","curve","diagonal","orthogonal"]},{name:"as",type:"string",default:"path"}]},t.inherits(E,a.Transform).transform=function(e,n){var r=e.sourceX||T,a=e.sourceY||w,i=e.targetX||z,o=e.targetY||C,u=e.as||"path",s=e.orient||"vertical",l=e.shape||"line",f=fe.get(l+"-"+s)||fe.get(l);return f||t.error("LinkPath unsupported type: "+e.shape+(e.orient?"-"+e.orient:"")),n.visit(n.SOURCE,function(e){e[u]=f(r(e),a(e),i(e),o(e))}),n.reflow(e.modified()).modifies(u)},P.Definition={type:"Pie",metadata:{modifies:!0},params:[{name:"field",type:"field"},{name:"startAngle",type:"number",default:0},{name:"endAngle",type:"number",default:6.283185307179586},{name:"sort",type:"boolean",default:!1},{name:"as",type:"string",array:!0,length:2,default:["startAngle","endAngle"]}]},t.inherits(P,a.Transform).transform=function(e,n){var r,a,o,u=e.as||["startAngle","endAngle"],s=u[0],l=u[1],f=e.field||t.one,c=e.startAngle||0,d=null!=e.endAngle?e.endAngle:2*Math.PI,m=n.source,p=m.map(f),h=p.length,v=c,g=(d-c)/i.sum(p),y=i.range(h);for(e.sort&&y.sort(function(e,n){return p[e]-p[n]}),r=0;r<h;++r)o=p[y[r]],(a=m[y[r]])[s]=v,a[l]=v+=o*g;return this.value=p,n.reflow(e.modified()).modifies(u)};var ce=5,de=t.toSet(["linear",$,ee]),me=t.toSet(["linear",Z,$,ee,"time","utc"]),pe=t.toSet(["set","modified","clear","type","scheme","schemeExtent","schemeCount","domain","domainMin","domainMid","domainMax","domainRaw","nice","zero","range","rangeStep","round","reverse","interpolate","interpolateGamma"]);t.inherits(q,a.Transform).transform=function(e,r){var a,i=r.dataflow,o=this.value;o&&!e.modified("type")||(this.value=o=n.scale((e.type||"linear").toLowerCase())());for(a in e)if(!pe[a]){if("padding"===a&&me[o.type])continue;t.isFunction(o[a])?o[a](e[a]):i.warn("Unsupported scale property: "+a)}return U(o,e,I(o,e,i)),r.fork(r.NO_SOURCE|r.NO_FIELDS)},t.inherits(V,a.Transform).transform=function(e,n){var t=e.modified("sort")||n.changed(n.ADD)||n.modified(e.sort.fields)||n.modified("datum");return t&&n.source.sort(e.sort),this.modified(t),n};B.Definition={type:"Stack",metadata:{modifies:!0},params:[{name:"field",type:"field"},{name:"groupby",type:"field",array:!0},{name:"sort",type:"compare"},{name:"offset",type:"enum",default:"zero",values:["zero","center","normalize"]},{name:"as",type:"string",array:!0,length:2,default:["y0","y1"]}]},t.inherits(B,a.Transform).transform=function(e,n){var r,a,i,o,u=e.as||["y0","y1"],s=u[0],l=u[1],f=e.field||t.one,c="center"===e.offset?J:"normalize"===e.offset?W:K;for(a=0,i=(r=Q(n.source,e.groupby,e.sort,f)).length,o=r.max;a<i;++a)c(r[a],o,f,s,l);return n.reflow(e.modified()).modifies(u)},e.axisticks=h,e.datajoin=v,e.encode=M,e.legendentries=D,e.linkpath=E,e.pie=P,e.scale=q,e.sortitems=V,e.stack=B,e.validTicks=s,Object.defineProperty(e,"__esModule",{value:!0})}); |
@@ -10,1 +10,2 @@ export {default as axisticks} from './src/AxisTicks'; | ||
export {default as stack} from './src/Stack'; | ||
export {validTicks} from './src/ticks'; |
{ | ||
"name": "vega-encode", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Visual encoding transforms for Vega dataflows.", | ||
@@ -35,3 +35,3 @@ "keywords": [ | ||
"vega-dataflow": "3", | ||
"vega-scale": "2", | ||
"vega-scale": "^2.1", | ||
"vega-util": "1" | ||
@@ -38,0 +38,0 @@ }, |
@@ -35,10 +35,14 @@ import {tickCount, tickFormat, tickValues, validTicks} from './ticks'; | ||
scale = _.scale, | ||
count = _.values ? _.values.length : tickCount(scale, _.count), | ||
count = _.tickCount ? _.tickCount : (_.values ? _.values.length : tickCount(scale, _.count)), | ||
format = _.format || tickFormat(scale, count, _.formatSpecifier), | ||
values = _.values ? validTicks(scale, _.values) : tickValues(scale, count); | ||
values = _.values ? validTicks(scale, _.values, count) : tickValues(scale, count); | ||
if (ticks) out.rem = ticks; | ||
ticks = values.map(function(value) { | ||
return ingest({value: value, label: format(value)}) | ||
ticks = values.map(function(value, i) { | ||
return ingest({ | ||
index: i / (values.length - 1), | ||
value: value, | ||
label: format(value) | ||
}); | ||
}); | ||
@@ -50,2 +54,3 @@ | ||
ticks.push(ingest({ | ||
index: -1, | ||
extra: {value: ticks[0].value}, | ||
@@ -52,0 +57,0 @@ label: '' |
export var Log = 'log'; | ||
export var Pow = 'pow'; | ||
export var Utc = 'utc'; | ||
export var Sqrt = 'sqrt'; | ||
export var Band = 'band'; | ||
export var Time = 'time'; | ||
export var Point = 'point'; | ||
@@ -6,0 +8,0 @@ export var Linear = 'linear'; |
import {tickCount} from './ticks'; | ||
import {Transform} from 'vega-dataflow'; | ||
import {error, inherits, isFunction, toSet} from 'vega-util'; | ||
import { | ||
error, inherits, isFunction, peek, toSet, | ||
zoomLinear, zoomLog, zoomPow | ||
} from 'vega-util'; | ||
import { | ||
Ordinal, Band, Point, | ||
Linear, Pow, Sqrt, Sequential, | ||
Quantile, Quantize, Threshold, BinOrdinal | ||
Linear, Log, Pow, Sqrt, Sequential, | ||
Quantile, Quantize, Threshold, BinOrdinal, | ||
Time, Utc | ||
} from './scale-types'; | ||
@@ -29,2 +33,4 @@ | ||
var INCLUDE_PAD = toSet([Linear, Log, Pow, Sqrt, Time, Utc]); | ||
var SKIP = toSet([ | ||
@@ -58,2 +64,5 @@ 'set', 'modified', 'clear', 'type', 'scheme', 'schemeExtent', 'schemeCount', | ||
for (prop in _) if (!SKIP[prop]) { | ||
// padding is a scale property for band/point but not others | ||
if (prop === 'padding' && INCLUDE_PAD[scale.type]) continue; | ||
// invoke scale property setter, raise warning if not found | ||
isFunction(scale[prop]) | ||
@@ -75,3 +84,4 @@ ? scale[prop](_[prop]) | ||
var domain = _.domain, | ||
zero = _.zero || (_.zero === undefined && INCLUDE_ZERO[scale.type]), | ||
type = scale.type, | ||
zero = _.zero || (_.zero === undefined && INCLUDE_ZERO[type]), | ||
n, mid; | ||
@@ -81,2 +91,7 @@ | ||
// adjust continuous domain for minimum pixel padding | ||
if (INCLUDE_PAD[type] && _.padding && domain[0] !== peek(domain)) { | ||
domain = padDomain(type, domain, _.range, _.padding, _.exponent); | ||
} | ||
// adjust domain based on zero, min, max settings | ||
@@ -122,2 +137,16 @@ if (zero || _.domainMin != null || _.domainMax != null || _.domainMid != null) { | ||
function padDomain(type, domain, range, pad, exponent) { | ||
var span = Math.abs(peek(range) - range[0]), | ||
frac = span / (span - 2 * pad), | ||
d = type === Log ? zoomLog(domain, null, frac) | ||
: type === Sqrt ? zoomPow(domain, null, frac, 0.5) | ||
: type === Pow ? zoomPow(domain, null, frac, exponent) | ||
: zoomLinear(domain, null, frac); | ||
domain = domain.slice(); | ||
domain[0] = d[0]; | ||
domain[domain.length-1] = d[1]; | ||
return domain; | ||
} | ||
function configureRange(scale, _, count) { | ||
@@ -124,0 +153,0 @@ var round = _.round || false, |
@@ -38,5 +38,6 @@ import {Log} from './scale-types'; | ||
* @param {Array<*>} ticks - The candidate tick values. | ||
* @param {*} count - The tick count or interval function. | ||
* @return {Array<*>} - The filtered tick values. | ||
*/ | ||
export function validTicks(scale, ticks) { | ||
export function validTicks(scale, ticks, count) { | ||
var range = scale.range(), | ||
@@ -51,6 +52,18 @@ lo = range[0], | ||
return ticks.filter(function(v) { | ||
ticks = ticks.filter(function(v) { | ||
v = scale(v); | ||
return !(v < lo || v > hi) | ||
}); | ||
if (count > 0 && ticks.length > 1) { | ||
var endpoints = [ticks[0], peek(ticks)]; | ||
while (ticks.length > count && ticks.length >= 3) { | ||
ticks = ticks.filter(function(_, i) { return !(i % 2); }); | ||
} | ||
if (ticks.length < 3) { | ||
ticks = endpoints; | ||
} | ||
} | ||
return ticks; | ||
} | ||
@@ -57,0 +70,0 @@ |
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
86006
2002
19
Updatedvega-scale@^2.1