vega-scale
Advanced tools
Comparing version 5.0.0 to 6.0.0
@@ -35,78 +35,9 @@ (function (global, factory) { | ||
function isValidScaleType(type) { | ||
switch (type) { | ||
case Identity: | ||
case Linear: | ||
case Log: | ||
case Pow: | ||
case Sqrt: | ||
case Symlog: | ||
case Time: | ||
case UTC: | ||
case Sequential: | ||
case Quantile: | ||
case Quantize: | ||
case Threshold: | ||
case Ordinal: | ||
case Point: | ||
case Band: | ||
case BinOrdinal: | ||
return true; | ||
} | ||
return false; | ||
} | ||
// categories | ||
const Continuous = 'continuous'; | ||
const Discrete = 'discrete'; | ||
const Discretizing = 'discretizing'; | ||
const Interpolating = 'interpolating'; | ||
const Temporal = 'temporal'; | ||
function isTemporal(key) { | ||
return key === Time || key === UTC; | ||
} | ||
function isQuantile(key) { | ||
return key === Quantile; | ||
} | ||
function isSequential(key) { | ||
return key && key.startsWith(Sequential); | ||
} | ||
function isDiverging(key) { | ||
return key && key.startsWith(Diverging); | ||
} | ||
function isInterpolating(key) { | ||
return isSequential(key) || isDiverging(key); | ||
} | ||
function isLogarithmic(key) { | ||
return key === Log || key.endsWith('-log'); | ||
} | ||
function isContinuous(key) { | ||
switch (key) { | ||
case Linear: | ||
case Log: | ||
case Pow: | ||
case Sqrt: | ||
case Symlog: | ||
case Time: | ||
case UTC: | ||
case Sequential: | ||
return true; | ||
} | ||
return false; | ||
} | ||
function isDiscrete(key) { | ||
return key === BinOrdinal | ||
|| key === Ordinal | ||
|| key === Band | ||
|| key === Point; | ||
} | ||
function isDiscretizing(key) { | ||
return key === BinOrdinal | ||
|| key === Quantile | ||
|| key === Quantize | ||
|| key === Threshold; | ||
} | ||
function invertRange(scale) { | ||
@@ -395,7 +326,10 @@ return function(_) { | ||
// scale registry | ||
const scales = {}; | ||
/** | ||
* Augment scales with their type and needed inverse methods. | ||
*/ | ||
function create(type, constructor) { | ||
return function scale() { | ||
function create(type, constructor, metadata) { | ||
const ctr = function scale() { | ||
var s = constructor(); | ||
@@ -412,57 +346,92 @@ | ||
}; | ||
ctr.metadata = vegaUtil.toSet(vegaUtil.array(metadata)); | ||
return ctr; | ||
} | ||
function scale(type, scale) { | ||
function scale(type, scale, metadata) { | ||
if (arguments.length > 1) { | ||
scales[type] = create(type, scale); | ||
scales[type] = create(type, scale, metadata); | ||
return this; | ||
} else { | ||
return vegaUtil.hasOwnProperty(scales, type) ? scales[type] : undefined; | ||
return isValidScaleType(type) ? scales[type] : undefined; | ||
} | ||
} | ||
var scales = { | ||
// identity scale | ||
[Identity]: $.scaleIdentity, | ||
// identity scale | ||
scale(Identity, $.scaleIdentity); | ||
// continuous scales | ||
[Linear]: $.scaleLinear, | ||
[Log]: $.scaleLog, | ||
[Pow]: $.scalePow, | ||
[Sqrt]: $.scaleSqrt, | ||
[Symlog]: $.scaleSymlog, | ||
[Time]: $.scaleTime, | ||
[UTC]: $.scaleUtc, | ||
// continuous scales | ||
scale(Linear, $.scaleLinear, Continuous); | ||
scale(Log, $.scaleLog, [Continuous, Log]); | ||
scale(Pow, $.scalePow, Continuous); | ||
scale(Sqrt, $.scaleSqrt, Continuous); | ||
scale(Symlog, $.scaleSymlog, Continuous); | ||
scale(Time, $.scaleTime, [Continuous, Temporal]); | ||
scale(UTC, $.scaleUtc, [Continuous, Temporal]); | ||
// sequential scales | ||
[Sequential]: $.scaleSequential, // backwards compat | ||
[Sequential+'-'+Linear]: $.scaleSequential, | ||
[Sequential+'-'+Log]: $.scaleSequentialLog, | ||
[Sequential+'-'+Pow]: $.scaleSequentialPow, | ||
[Sequential+'-'+Sqrt]: $.scaleSequentialSqrt, | ||
[Sequential+'-'+Symlog]: $.scaleSequentialSymlog, | ||
// sequential scales | ||
scale(Sequential, $.scaleSequential, [Continuous, Interpolating]); // backwards compat | ||
scale(`${Sequential}-${Linear}`, $.scaleSequential, [Continuous, Interpolating]); | ||
scale(`${Sequential}-${Log}`, $.scaleSequentialLog, [Continuous, Interpolating, Log]); | ||
scale(`${Sequential}-${Pow}`, $.scaleSequentialPow, [Continuous, Interpolating]); | ||
scale(`${Sequential}-${Sqrt}`, $.scaleSequentialSqrt, [Continuous, Interpolating]); | ||
scale(`${Sequential}-${Symlog}`, $.scaleSequentialSymlog, [Continuous, Interpolating]); | ||
// diverging scales | ||
[Diverging+'-'+Linear]: $.scaleDiverging, | ||
[Diverging+'-'+Log]: $.scaleDivergingLog, | ||
[Diverging+'-'+Pow]: $.scaleDivergingPow, | ||
[Diverging+'-'+Sqrt]: $.scaleDivergingSqrt, | ||
[Diverging+'-'+Symlog]: $.scaleDivergingSymlog, | ||
// diverging scales | ||
scale(`${Diverging}-${Linear}`, $.scaleDiverging, [Continuous, Interpolating]); | ||
scale(`${Diverging}-${Log}`, $.scaleDivergingLog, [Continuous, Interpolating, Log]); | ||
scale(`${Diverging}-${Pow}`, $.scaleDivergingPow, [Continuous, Interpolating]); | ||
scale(`${Diverging}-${Sqrt}`, $.scaleDivergingSqrt, [Continuous, Interpolating]); | ||
scale(`${Diverging}-${Symlog}`, $.scaleDivergingSymlog, [Continuous, Interpolating]); | ||
// discretizing scales | ||
[Quantile]: $.scaleQuantile, | ||
[Quantize]: $.scaleQuantize, | ||
[Threshold]: $.scaleThreshold, | ||
// discretizing scales | ||
scale(Quantile, $.scaleQuantile, [Discretizing, Quantile]); | ||
scale(Quantize, $.scaleQuantize, Discretizing); | ||
scale(Threshold, $.scaleThreshold, Discretizing); | ||
// discrete scales | ||
[BinOrdinal]: scaleBinOrdinal, | ||
[Ordinal]: $.scaleOrdinal, | ||
[Band]: band, | ||
[Point]: point | ||
}; | ||
// discrete scales | ||
scale(BinOrdinal, scaleBinOrdinal, [Discrete, Discretizing]); | ||
scale(Ordinal, $.scaleOrdinal, Discrete); | ||
scale(Band, band, Discrete); | ||
scale(Point, point, Discrete); | ||
for (var key in scales) { | ||
scale(key, scales[key]); | ||
function isValidScaleType(type) { | ||
return vegaUtil.hasOwnProperty(scales, type); | ||
} | ||
function hasType(key, type) { | ||
const s = scales[key]; | ||
return s && s.metadata[type]; | ||
} | ||
function isContinuous(key) { | ||
return hasType(key, Continuous); | ||
} | ||
function isDiscrete(key) { | ||
return hasType(key, Discrete); | ||
} | ||
function isDiscretizing(key) { | ||
return hasType(key, Discretizing); | ||
} | ||
function isLogarithmic(key) { | ||
return hasType(key, Log); | ||
} | ||
function isTemporal(key) { | ||
return hasType(key, Temporal); | ||
} | ||
function isInterpolating(key) { | ||
return hasType(key, Interpolating); | ||
} | ||
function isQuantile(key) { | ||
return hasType(key, Quantile); | ||
} | ||
const scaleProps = ['clamp', 'base', 'constant', 'exponent']; | ||
@@ -661,7 +630,5 @@ | ||
exports.isDiscretizing = isDiscretizing; | ||
exports.isDiverging = isDiverging; | ||
exports.isInterpolating = isInterpolating; | ||
exports.isLogarithmic = isLogarithmic; | ||
exports.isQuantile = isQuantile; | ||
exports.isSequential = isSequential; | ||
exports.isTemporal = isTemporal; | ||
@@ -668,0 +635,0 @@ exports.isValidScaleType = isValidScaleType; |
@@ -1,1 +0,1 @@ | ||
!function(e,a){"object"==typeof exports&&"undefined"!=typeof module?a(exports,require("vega-util"),require("d3-array"),require("d3-scale"),require("d3-interpolate")):"function"==typeof define&&define.amd?define(["exports","vega-util","d3-array","d3-scale","d3-interpolate"],a):a((e=e||self).vega={},e.vega,e.d3,e.d3,e.d3)}(this,(function(e,a,c,f,d){"use strict";function n(e,a,c){var f=e-a+2*c;return e?f>0?f:1:0}const b="identity",r="linear",t="log",i="pow",u="sqrt",o="symlog",l="time",s="utc",g="sequential",p="diverging",h="quantile",v="quantize",m="threshold",y="ordinal",w="point",q="band",O="bin-ordinal";function S(e){return e&&e.startsWith(g)}function k(e){return e&&e.startsWith(p)}function G(){var e,a,d=f.scaleOrdinal().unknown(void 0),b=d.domain,r=d.range,t=[0,1],i=!1,u=0,o=0,l=.5;function s(){var f=b().length,d=t[1]<t[0],s=t[d-0],g=t[1-d],p=n(f,u,o);e=(g-s)/(p||1),i&&(e=Math.floor(e)),s+=(g-s-e*(f-u))*l,a=e*(1-u),i&&(s=Math.round(s),a=Math.round(a));var h=c.range(f).map((function(a){return s+e*a}));return r(d?h.reverse():h)}return delete d.unknown,d.domain=function(e){return arguments.length?(b(e),s()):b()},d.range=function(e){return arguments.length?(t=[+e[0],+e[1]],s()):t.slice()},d.rangeRound=function(e){return t=[+e[0],+e[1]],i=!0,s()},d.bandwidth=function(){return a},d.step=function(){return e},d.round=function(e){return arguments.length?(i=!!e,s()):i},d.padding=function(e){return arguments.length?(o=Math.max(0,Math.min(1,e)),u=o,s()):u},d.paddingInner=function(e){return arguments.length?(u=Math.max(0,Math.min(1,e)),s()):u},d.paddingOuter=function(e){return arguments.length?(o=Math.max(0,Math.min(1,e)),s()):o},d.align=function(e){return arguments.length?(l=Math.max(0,Math.min(1,e)),s()):l},d.invertRange=function(e){if(null!=e[0]&&null!=e[1]){var f,d,n,i=+e[0],u=+e[1],o=t[1]<t[0],l=o?r().reverse():r(),s=l.length-1;if(i==i&&u==u&&(u<i&&(n=i,i=u,u=n),!(u<l[0]||i>t[1-o])))return f=Math.max(0,c.bisectRight(l,i)-1),d=i===u?f:c.bisectRight(l,u)-1,i-l[f]>a+1e-10&&++f,o&&(n=f,f=s-d,d=s-n),f>d?void 0:b().slice(f,d+1)}},d.invert=function(e){var a=d.invertRange([e,e]);return a?a[0]:a},d.copy=function(){return G().domain(b()).range(t).round(i).paddingInner(u).paddingOuter(o).align(l)},s()}var M=Array.prototype.map;function R(e){return M.call(e,(function(e){return+e}))}var x=Array.prototype.slice;function B(e,c){return arguments.length>1?(P[e]=function(e,a){return function(){var c=a();return c.invertRange||(c.invertRange=c.invert?function(e){return function(a){var c,f=a[0],d=a[1];return d<f&&(c=f,f=d,d=c),[e.invert(f),e.invert(d)]}}(c):c.invertExtent?function(e){return function(a){var c,f,d,n,b=e.range(),r=a[0],t=a[1],i=-1;for(t<r&&(f=r,r=t,t=f),d=0,n=b.length;d<n;++d)b[d]>=r&&b[d]<=t&&(i<0&&(i=d),c=d);if(!(i<0))return r=e.invertExtent(b[i]),t=e.invertExtent(b[c]),[void 0===r[0]?r[1]:r[0],void 0===t[1]?t[0]:t[1]]}}(c):void 0),c.type=e,c}}(e,c),this):a.hasOwnProperty(P,e)?P[e]:void 0}var P={[b]:f.scaleIdentity,[r]:f.scaleLinear,[t]:f.scaleLog,[i]:f.scalePow,[u]:f.scaleSqrt,[o]:f.scaleSymlog,[l]:f.scaleTime,[s]:f.scaleUtc,[g]:f.scaleSequential,[g+"-"+r]:f.scaleSequential,[g+"-"+t]:f.scaleSequentialLog,[g+"-"+i]:f.scaleSequentialPow,[g+"-"+u]:f.scaleSequentialSqrt,[g+"-"+o]:f.scaleSequentialSymlog,[p+"-"+r]:f.scaleDiverging,[p+"-"+t]:f.scaleDivergingLog,[p+"-"+i]:f.scaleDivergingPow,[p+"-"+u]:f.scaleDivergingSqrt,[p+"-"+o]:f.scaleDivergingSymlog,[h]:f.scaleQuantile,[v]:f.scaleQuantize,[m]:f.scaleThreshold,[O]:function e(){var d=[],n=[];function b(e){return null==e||e!=e?void 0:n[(c.bisect(d,e)-1)%n.length]}return b.domain=function(e){return arguments.length?(d=R(e),b):d.slice()},b.range=function(e){return arguments.length?(n=x.call(e),b):n.slice()},b.tickFormat=function(e,c){return f.tickFormat(d[0],a.peek(d),null==e?10:e,c)},b.copy=function(){return e().domain(b.domain()).range(b.range())},b},[y]:f.scaleOrdinal,[q]:G,[w]:function(){return function e(a){var c=a.copy;return a.padding=a.paddingOuter,delete a.paddingInner,a.copy=function(){return e(c())},a}(G().paddingInner(1))}};for(var I in P)B(I,P[I]);const D=["clamp","base","constant","exponent"];function L(e,a,c){return d.piecewise(T(a||"rgb",c),e)}function T(e,a){var c=d[function(e){return"interpolate"+e.toLowerCase().split("-").map((function(e){return e[0].toUpperCase()+e.slice(1)})).join("")}(e)];return null!=a&&c&&c.gamma?c.gamma(a):c}function C(e){for(var a=e.length/6|0,c=new Array(a),f=0;f<a;)c[f]="#"+e.slice(6*f,6*++f);return c}function F(e,a){for(let c in e)z(c,a(e[c]))}const j={};function z(e,a){return e=e&&e.toLowerCase(),arguments.length>1?(j[e]=a,this):j[e]}F({category10:"1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf",category20:"1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5",category20b:"393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6",category20c:"3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9",tableau10:"4c78a8f58518e4575672b7b254a24beeca3bb279a2ff9da69d755dbab0ac",tableau20:"4c78a89ecae9f58518ffbf7954a24b88d27ab79a20f2cf5b43989483bcb6e45756ff9d9879706ebab0acd67195fcbfd2b279a2d6a5c99e765fd8b5a5",accent:"7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666",dark2:"1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666",paired:"a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928",pastel1:"fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2",pastel2:"b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc",set1:"e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999",set2:"66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3",set3:"8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f"},C),F({blues:"cfe1f2bed8eca8cee58fc1de74b2d75ba3cf4592c63181bd206fb2125ca40a4a90",greens:"d3eecdc0e6baabdda594d3917bc77d60ba6c46ab5e329a512089430e7735036429",greys:"e2e2e2d4d4d4c4c4c4b1b1b19d9d9d8888887575756262624d4d4d3535351e1e1e",oranges:"fdd8b3fdc998fdb87bfda55efc9244f87f2cf06b18e4580bd14904b93d029f3303",purples:"e2e1efd4d4e8c4c5e0b4b3d6a3a0cc928ec3827cb97566ae684ea25c3696501f8c",reds:"fdc9b4fcb49afc9e80fc8767fa7051f6573fec3f2fdc2a25c81b1db21218970b13",blueGreen:"d5efedc1e8e0a7ddd18bd2be70c6a958ba9144ad77319c5d2089460e7736036429",bluePurple:"ccddecbad0e4a8c2dd9ab0d4919cc98d85be8b6db28a55a6873c99822287730f71",greenBlue:"d3eecec5e8c3b1e1bb9bd8bb82cec269c2ca51b2cd3c9fc7288abd1675b10b60a1",orangeRed:"fddcaffdcf9bfdc18afdad77fb9562f67d53ee6545e24932d32d1ebf130da70403",purpleBlue:"dbdaebc8cee4b1c3de97b7d87bacd15b9fc93a90c01e7fb70b70ab056199045281",purpleBlueGreen:"dbd8eac8cee4b0c3de93b7d872acd1549fc83892bb1c88a3097f8702736b016353",purpleRed:"dcc9e2d3b3d7ce9eccd186c0da6bb2e14da0e23189d91e6fc61159ab07498f023a",redPurple:"fccfccfcbec0faa9b8f98faff571a5ec539ddb3695c41b8aa908808d0179700174",yellowGreen:"e4f4acd1eca0b9e2949ed68880c97c62bb6e47aa5e3297502083440e723b036034",yellowOrangeBrown:"feeaa1fedd84fecc63feb746fca031f68921eb7215db5e0bc54c05ab3d038f3204",yellowOrangeRed:"fee087fed16ffebd59fea849fd903efc7335f9522bee3423de1b20ca0b22af0225",blueOrange:"134b852f78b35da2cb9dcae1d2e5eff2f0ebfce0bafbbf74e8932fc5690d994a07",brownBlueGreen:"704108a0651ac79548e3c78af3e6c6eef1eac9e9e48ed1c74da79e187a72025147",purpleGreen:"5b1667834792a67fb6c9aed3e6d6e8eff0efd9efd5aedda971bb75368e490e5e29",purpleOrange:"4114696647968f83b7b9b4d6dadbebf3eeeafce0bafbbf74e8932fc5690d994a07",redBlue:"8c0d25bf363adf745ef4ae91fbdbc9f2efeed2e5ef9dcae15da2cb2f78b3134b85",redGrey:"8c0d25bf363adf745ef4ae91fcdccbfaf4f1e2e2e2c0c0c0969696646464343434",yellowGreenBlue:"eff9bddbf1b4bde5b594d5b969c5be45b4c22c9ec02182b82163aa23479c1c3185",redYellowBlue:"a50026d4322cf16e43fcac64fedd90faf8c1dcf1ecabd6e875abd04a74b4313695",redYellowGreen:"a50026d4322cf16e43fcac63fedd8df9f7aed7ee8ea4d86e64bc6122964f006837",pinkYellowGreen:"8e0152c0267edd72adf0b3d6faddedf5f3efe1f2cab6de8780bb474f9125276419",spectral:"9e0142d13c4bf0704afcac63fedd8dfbf8b0e0f3a1a9dda269bda94288b55e4fa2",viridis:"440154470e61481a6c482575472f7d443a834144873d4e8a39568c35608d31688e2d708e2a788e27818e23888e21918d1f988b1fa08822a8842ab07f35b77943bf7154c56866cc5d7ad1518fd744a5db36bcdf27d2e21be9e51afde725",magma:"0000040404130b0924150e3720114b2c11603b0f704a107957157e651a80721f817f24828c29819a2e80a8327db6377ac43c75d1426fde4968e95462f1605df76f5cfa7f5efc8f65fe9f6dfeaf78febf84fece91fddea0fcedaffcfdbf",inferno:"0000040403130c0826170c3b240c4f330a5f420a68500d6c5d126e6b176e781c6d86216b932667a12b62ae305cbb3755c73e4cd24644dd513ae65c30ed6925f3771af8850ffb9506fca50afcb519fac62df6d645f2e661f3f484fcffa4",plasma:"0d088723069033059742039d5002a25d01a66a00a87801a88405a7900da49c179ea72198b12a90ba3488c33d80cb4779d35171da5a69e16462e76e5bed7953f2834cf68f44fa9a3dfca636fdb32ffec029fcce25f9dc24f5ea27f0f921",rainbow:"6e40aa883eb1a43db3bf3cafd83fa4ee4395fe4b83ff576eff6659ff7847ff8c38f3a130e2b72fcfcc36bee044aff05b8ff4576ff65b52f6673af27828ea8d1ddfa319d0b81cbecb23abd82f96e03d82e14c6edb5a5dd0664dbf6e40aa",sinebow:"ff4040fc582af47218e78d0bd5a703bfbf00a7d5038de70b72f41858fc2a40ff402afc5818f4720be78d03d5a700bfbf03a7d50b8de71872f42a58fc4040ff582afc7218f48d0be7a703d5bf00bfd503a7e70b8df41872fc2a58ff4040",browns:"eedbbdecca96e9b97ae4a865dc9856d18954c7784cc0673fb85536ad44339f3632",tealBlues:"bce4d89dd3d181c3cb65b3c245a2b9368fae347da0306a932c5985",teals:"bbdfdfa2d4d58ac9c975bcbb61b0af4da5a43799982b8b8c1e7f7f127273006667",warmGreys:"dcd4d0cec5c1c0b8b4b3aaa7a59c9998908c8b827f7e7673726866665c5a59504e",goldGreen:"f4d166d5ca60b6c35c98bb597cb25760a6564b9c533f8f4f33834a257740146c36",goldOrange:"f4d166f8be5cf8aa4cf5983bf3852aef701be2621fd65322c54923b142239e3a26",goldRed:"f4d166f6be59f9aa51fc964ef6834bee734ae56249db5247cf4244c43141b71d3e",lightGreyRed:"efe9e6e1dad7d5cbc8c8bdb9bbaea9cd967ddc7b43e15f19df4011dc000b",lightGreyTeal:"e4eaead6dcddc8ced2b7c2c7a6b4bc64b0bf22a6c32295c11f85be1876bc",lightMulti:"e0f1f2c4e9d0b0de9fd0e181f6e072f6c053f3993ef77440ef4a3c",lightOrange:"f2e7daf7d5baf9c499fab184fa9c73f68967ef7860e8645bde515bd43d5b",lightTealBlue:"e3e9e0c0dccf9aceca7abfc859afc0389fb9328dad2f7ca0276b95255988",darkBlue:"3232322d46681a5c930074af008cbf05a7ce25c0dd38daed50f3faffffff",darkGold:"3c3c3c584b37725e348c7631ae8b2bcfa424ecc31ef9de30fff184ffffff",darkGreen:"3a3a3a215748006f4d048942489e4276b340a6c63dd2d836ffeb2cffffaa",darkMulti:"3737371f5287197d8c29a86995ce3fffe800ffffff",darkRed:"3434347036339e3c38cc4037e75d1eec8620eeab29f0ce32ffeb2c"},e=>L(C(e))),Object.defineProperty(e,"scaleImplicit",{enumerable:!0,get:function(){return f.scaleImplicit}}),Object.defineProperty(e,"tickFormat",{enumerable:!0,get:function(){return f.tickFormat}}),e.Band=q,e.BinOrdinal=O,e.Diverging=p,e.Identity=b,e.Linear=r,e.Log=t,e.Ordinal=y,e.Point=w,e.Pow=i,e.Quantile=h,e.Quantize=v,e.Sequential=g,e.Sqrt=u,e.Symlog=o,e.Threshold=m,e.Time=l,e.UTC=s,e.bandSpace=n,e.interpolate=T,e.interpolateColors=L,e.interpolateRange=function(e,c){var f=c[0],d=a.peek(c)-f;return function(a){return e(f+a*d)}},e.isContinuous=function(e){switch(e){case r:case t:case i:case u:case o:case l:case s:case g:return!0}return!1},e.isDiscrete=function(e){return e===O||e===y||e===q||e===w},e.isDiscretizing=function(e){return e===O||e===h||e===v||e===m},e.isDiverging=k,e.isInterpolating=function(e){return S(e)||k(e)},e.isLogarithmic=function(e){return e===t||e.endsWith("-log")},e.isQuantile=function(e){return e===h},e.isSequential=S,e.isTemporal=function(e){return e===l||e===s},e.isValidScaleType=function(e){switch(e){case b:case r:case t:case i:case u:case o:case l:case s:case g:case h:case v:case m:case y:case w:case q:case O:return!0}return!1},e.quantizeInterpolator=function(e,a){for(var c=new Array(a),f=a+1,d=0;d<a;)c[d]=e(++d/f);return c},e.scale=B,e.scaleCopy=function(e){const a=e.type,c=e.copy();return c.type=a,c},e.scaleFraction=function(e,c,f){var d,n,b,r=f-c;return r&&Number.isFinite(r)?(d=(n=e.type).indexOf("-"),n=d<0?n:n.slice(d+1),b=B(n)().domain([c,f]).range([0,1]),D.forEach(a=>e[a]?b[a](e[a]()):0),b):a.constant(.5)},e.scheme=z,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,a){"object"==typeof exports&&"undefined"!=typeof module?a(exports,require("vega-util"),require("d3-array"),require("d3-scale"),require("d3-interpolate")):"function"==typeof define&&define.amd?define(["exports","vega-util","d3-array","d3-scale","d3-interpolate"],a):a((e=e||self).vega={},e.vega,e.d3,e.d3,e.d3)}(this,(function(e,a,f,c,d){"use strict";function n(e,a,f){var c=e-a+2*f;return e?c>0?c:1:0}const b="log",t="quantile",r="continuous",i="discrete",o="discretizing",u="interpolating",l="temporal";function s(){var e,a,d=c.scaleOrdinal().unknown(void 0),b=d.domain,t=d.range,r=[0,1],i=!1,o=0,u=0,l=.5;function g(){var c=b().length,d=r[1]<r[0],s=r[d-0],g=r[1-d],p=n(c,o,u);e=(g-s)/(p||1),i&&(e=Math.floor(e)),s+=(g-s-e*(c-o))*l,a=e*(1-o),i&&(s=Math.round(s),a=Math.round(a));var m=f.range(c).map((function(a){return s+e*a}));return t(d?m.reverse():m)}return delete d.unknown,d.domain=function(e){return arguments.length?(b(e),g()):b()},d.range=function(e){return arguments.length?(r=[+e[0],+e[1]],g()):r.slice()},d.rangeRound=function(e){return r=[+e[0],+e[1]],i=!0,g()},d.bandwidth=function(){return a},d.step=function(){return e},d.round=function(e){return arguments.length?(i=!!e,g()):i},d.padding=function(e){return arguments.length?(u=Math.max(0,Math.min(1,e)),o=u,g()):o},d.paddingInner=function(e){return arguments.length?(o=Math.max(0,Math.min(1,e)),g()):o},d.paddingOuter=function(e){return arguments.length?(u=Math.max(0,Math.min(1,e)),g()):u},d.align=function(e){return arguments.length?(l=Math.max(0,Math.min(1,e)),g()):l},d.invertRange=function(e){if(null!=e[0]&&null!=e[1]){var c,d,n,i=+e[0],o=+e[1],u=r[1]<r[0],l=u?t().reverse():t(),s=l.length-1;if(i==i&&o==o&&(o<i&&(n=i,i=o,o=n),!(o<l[0]||i>r[1-u])))return c=Math.max(0,f.bisectRight(l,i)-1),d=i===o?c:f.bisectRight(l,o)-1,i-l[c]>a+1e-10&&++c,u&&(n=c,c=s-d,d=s-n),c>d?void 0:b().slice(c,d+1)}},d.invert=function(e){var a=d.invertRange([e,e]);return a?a[0]:a},d.copy=function(){return s().domain(b()).range(r).round(i).paddingInner(o).paddingOuter(u).align(l)},g()}var g=Array.prototype.map;function p(e){return g.call(e,(function(e){return+e}))}var m=Array.prototype.slice;const v={};function y(e,f,c){return arguments.length>1?(v[e]=function(e,f,c){const d=function(){var a=f();return a.invertRange||(a.invertRange=a.invert?function(e){return function(a){var f,c=a[0],d=a[1];return d<c&&(f=c,c=d,d=f),[e.invert(c),e.invert(d)]}}(a):a.invertExtent?function(e){return function(a){var f,c,d,n,b=e.range(),t=a[0],r=a[1],i=-1;for(r<t&&(c=t,t=r,r=c),d=0,n=b.length;d<n;++d)b[d]>=t&&b[d]<=r&&(i<0&&(i=d),f=d);if(!(i<0))return t=e.invertExtent(b[i]),r=e.invertExtent(b[f]),[void 0===t[0]?t[1]:t[0],void 0===r[1]?r[0]:r[1]]}}(a):void 0),a.type=e,a};return d.metadata=a.toSet(a.array(c)),d}(e,f,c),this):h(e)?v[e]:void 0}function h(e){return a.hasOwnProperty(v,e)}function q(e,a){const f=v[e];return f&&f.metadata[a]}y("identity",c.scaleIdentity),y("linear",c.scaleLinear,r),y(b,c.scaleLog,[r,b]),y("pow",c.scalePow,r),y("sqrt",c.scaleSqrt,r),y("symlog",c.scaleSymlog,r),y("time",c.scaleTime,[r,l]),y("utc",c.scaleUtc,[r,l]),y("sequential",c.scaleSequential,[r,u]),y("sequential-linear",c.scaleSequential,[r,u]),y(`sequential-${b}`,c.scaleSequentialLog,[r,u,b]),y("sequential-pow",c.scaleSequentialPow,[r,u]),y("sequential-sqrt",c.scaleSequentialSqrt,[r,u]),y("sequential-symlog",c.scaleSequentialSymlog,[r,u]),y("diverging-linear",c.scaleDiverging,[r,u]),y(`diverging-${b}`,c.scaleDivergingLog,[r,u,b]),y("diverging-pow",c.scaleDivergingPow,[r,u]),y("diverging-sqrt",c.scaleDivergingSqrt,[r,u]),y("diverging-symlog",c.scaleDivergingSymlog,[r,u]),y(t,c.scaleQuantile,[o,t]),y("quantize",c.scaleQuantize,o),y("threshold",c.scaleThreshold,o),y("bin-ordinal",(function e(){var d=[],n=[];function b(e){return null==e||e!=e?void 0:n[(f.bisect(d,e)-1)%n.length]}return b.domain=function(e){return arguments.length?(d=p(e),b):d.slice()},b.range=function(e){return arguments.length?(n=m.call(e),b):n.slice()},b.tickFormat=function(e,f){return c.tickFormat(d[0],a.peek(d),null==e?10:e,f)},b.copy=function(){return e().domain(b.domain()).range(b.range())},b}),[i,o]),y("ordinal",c.scaleOrdinal,i),y("band",s,i),y("point",(function(){return function e(a){var f=a.copy;return a.padding=a.paddingOuter,delete a.paddingInner,a.copy=function(){return e(f())},a}(s().paddingInner(1))}),i);const w=["clamp","base","constant","exponent"];function O(e,a,f){return d.piecewise(S(a||"rgb",f),e)}function S(e,a){var f=d[function(e){return"interpolate"+e.toLowerCase().split("-").map((function(e){return e[0].toUpperCase()+e.slice(1)})).join("")}(e)];return null!=a&&f&&f.gamma?f.gamma(a):f}function k(e){for(var a=e.length/6|0,f=new Array(a),c=0;c<a;)f[c]="#"+e.slice(6*c,6*++c);return f}function G(e,a){for(let f in e)R(f,a(e[f]))}const M={};function R(e,a){return e=e&&e.toLowerCase(),arguments.length>1?(M[e]=a,this):M[e]}G({category10:"1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf",category20:"1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5",category20b:"393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6",category20c:"3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9",tableau10:"4c78a8f58518e4575672b7b254a24beeca3bb279a2ff9da69d755dbab0ac",tableau20:"4c78a89ecae9f58518ffbf7954a24b88d27ab79a20f2cf5b43989483bcb6e45756ff9d9879706ebab0acd67195fcbfd2b279a2d6a5c99e765fd8b5a5",accent:"7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666",dark2:"1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666",paired:"a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928",pastel1:"fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2",pastel2:"b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc",set1:"e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999",set2:"66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3",set3:"8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f"},k),G({blues:"cfe1f2bed8eca8cee58fc1de74b2d75ba3cf4592c63181bd206fb2125ca40a4a90",greens:"d3eecdc0e6baabdda594d3917bc77d60ba6c46ab5e329a512089430e7735036429",greys:"e2e2e2d4d4d4c4c4c4b1b1b19d9d9d8888887575756262624d4d4d3535351e1e1e",oranges:"fdd8b3fdc998fdb87bfda55efc9244f87f2cf06b18e4580bd14904b93d029f3303",purples:"e2e1efd4d4e8c4c5e0b4b3d6a3a0cc928ec3827cb97566ae684ea25c3696501f8c",reds:"fdc9b4fcb49afc9e80fc8767fa7051f6573fec3f2fdc2a25c81b1db21218970b13",blueGreen:"d5efedc1e8e0a7ddd18bd2be70c6a958ba9144ad77319c5d2089460e7736036429",bluePurple:"ccddecbad0e4a8c2dd9ab0d4919cc98d85be8b6db28a55a6873c99822287730f71",greenBlue:"d3eecec5e8c3b1e1bb9bd8bb82cec269c2ca51b2cd3c9fc7288abd1675b10b60a1",orangeRed:"fddcaffdcf9bfdc18afdad77fb9562f67d53ee6545e24932d32d1ebf130da70403",purpleBlue:"dbdaebc8cee4b1c3de97b7d87bacd15b9fc93a90c01e7fb70b70ab056199045281",purpleBlueGreen:"dbd8eac8cee4b0c3de93b7d872acd1549fc83892bb1c88a3097f8702736b016353",purpleRed:"dcc9e2d3b3d7ce9eccd186c0da6bb2e14da0e23189d91e6fc61159ab07498f023a",redPurple:"fccfccfcbec0faa9b8f98faff571a5ec539ddb3695c41b8aa908808d0179700174",yellowGreen:"e4f4acd1eca0b9e2949ed68880c97c62bb6e47aa5e3297502083440e723b036034",yellowOrangeBrown:"feeaa1fedd84fecc63feb746fca031f68921eb7215db5e0bc54c05ab3d038f3204",yellowOrangeRed:"fee087fed16ffebd59fea849fd903efc7335f9522bee3423de1b20ca0b22af0225",blueOrange:"134b852f78b35da2cb9dcae1d2e5eff2f0ebfce0bafbbf74e8932fc5690d994a07",brownBlueGreen:"704108a0651ac79548e3c78af3e6c6eef1eac9e9e48ed1c74da79e187a72025147",purpleGreen:"5b1667834792a67fb6c9aed3e6d6e8eff0efd9efd5aedda971bb75368e490e5e29",purpleOrange:"4114696647968f83b7b9b4d6dadbebf3eeeafce0bafbbf74e8932fc5690d994a07",redBlue:"8c0d25bf363adf745ef4ae91fbdbc9f2efeed2e5ef9dcae15da2cb2f78b3134b85",redGrey:"8c0d25bf363adf745ef4ae91fcdccbfaf4f1e2e2e2c0c0c0969696646464343434",yellowGreenBlue:"eff9bddbf1b4bde5b594d5b969c5be45b4c22c9ec02182b82163aa23479c1c3185",redYellowBlue:"a50026d4322cf16e43fcac64fedd90faf8c1dcf1ecabd6e875abd04a74b4313695",redYellowGreen:"a50026d4322cf16e43fcac63fedd8df9f7aed7ee8ea4d86e64bc6122964f006837",pinkYellowGreen:"8e0152c0267edd72adf0b3d6faddedf5f3efe1f2cab6de8780bb474f9125276419",spectral:"9e0142d13c4bf0704afcac63fedd8dfbf8b0e0f3a1a9dda269bda94288b55e4fa2",viridis:"440154470e61481a6c482575472f7d443a834144873d4e8a39568c35608d31688e2d708e2a788e27818e23888e21918d1f988b1fa08822a8842ab07f35b77943bf7154c56866cc5d7ad1518fd744a5db36bcdf27d2e21be9e51afde725",magma:"0000040404130b0924150e3720114b2c11603b0f704a107957157e651a80721f817f24828c29819a2e80a8327db6377ac43c75d1426fde4968e95462f1605df76f5cfa7f5efc8f65fe9f6dfeaf78febf84fece91fddea0fcedaffcfdbf",inferno:"0000040403130c0826170c3b240c4f330a5f420a68500d6c5d126e6b176e781c6d86216b932667a12b62ae305cbb3755c73e4cd24644dd513ae65c30ed6925f3771af8850ffb9506fca50afcb519fac62df6d645f2e661f3f484fcffa4",plasma:"0d088723069033059742039d5002a25d01a66a00a87801a88405a7900da49c179ea72198b12a90ba3488c33d80cb4779d35171da5a69e16462e76e5bed7953f2834cf68f44fa9a3dfca636fdb32ffec029fcce25f9dc24f5ea27f0f921",rainbow:"6e40aa883eb1a43db3bf3cafd83fa4ee4395fe4b83ff576eff6659ff7847ff8c38f3a130e2b72fcfcc36bee044aff05b8ff4576ff65b52f6673af27828ea8d1ddfa319d0b81cbecb23abd82f96e03d82e14c6edb5a5dd0664dbf6e40aa",sinebow:"ff4040fc582af47218e78d0bd5a703bfbf00a7d5038de70b72f41858fc2a40ff402afc5818f4720be78d03d5a700bfbf03a7d50b8de71872f42a58fc4040ff582afc7218f48d0be7a703d5bf00bfd503a7e70b8df41872fc2a58ff4040",browns:"eedbbdecca96e9b97ae4a865dc9856d18954c7784cc0673fb85536ad44339f3632",tealBlues:"bce4d89dd3d181c3cb65b3c245a2b9368fae347da0306a932c5985",teals:"bbdfdfa2d4d58ac9c975bcbb61b0af4da5a43799982b8b8c1e7f7f127273006667",warmGreys:"dcd4d0cec5c1c0b8b4b3aaa7a59c9998908c8b827f7e7673726866665c5a59504e",goldGreen:"f4d166d5ca60b6c35c98bb597cb25760a6564b9c533f8f4f33834a257740146c36",goldOrange:"f4d166f8be5cf8aa4cf5983bf3852aef701be2621fd65322c54923b142239e3a26",goldRed:"f4d166f6be59f9aa51fc964ef6834bee734ae56249db5247cf4244c43141b71d3e",lightGreyRed:"efe9e6e1dad7d5cbc8c8bdb9bbaea9cd967ddc7b43e15f19df4011dc000b",lightGreyTeal:"e4eaead6dcddc8ced2b7c2c7a6b4bc64b0bf22a6c32295c11f85be1876bc",lightMulti:"e0f1f2c4e9d0b0de9fd0e181f6e072f6c053f3993ef77440ef4a3c",lightOrange:"f2e7daf7d5baf9c499fab184fa9c73f68967ef7860e8645bde515bd43d5b",lightTealBlue:"e3e9e0c0dccf9aceca7abfc859afc0389fb9328dad2f7ca0276b95255988",darkBlue:"3232322d46681a5c930074af008cbf05a7ce25c0dd38daed50f3faffffff",darkGold:"3c3c3c584b37725e348c7631ae8b2bcfa424ecc31ef9de30fff184ffffff",darkGreen:"3a3a3a215748006f4d048942489e4276b340a6c63dd2d836ffeb2cffffaa",darkMulti:"3737371f5287197d8c29a86995ce3fffe800ffffff",darkRed:"3434347036339e3c38cc4037e75d1eec8620eeab29f0ce32ffeb2c"},e=>O(k(e))),Object.defineProperty(e,"scaleImplicit",{enumerable:!0,get:function(){return c.scaleImplicit}}),Object.defineProperty(e,"tickFormat",{enumerable:!0,get:function(){return c.tickFormat}}),e.Band="band",e.BinOrdinal="bin-ordinal",e.Diverging="diverging",e.Identity="identity",e.Linear="linear",e.Log=b,e.Ordinal="ordinal",e.Point="point",e.Pow="pow",e.Quantile=t,e.Quantize="quantize",e.Sequential="sequential",e.Sqrt="sqrt",e.Symlog="symlog",e.Threshold="threshold",e.Time="time",e.UTC="utc",e.bandSpace=n,e.interpolate=S,e.interpolateColors=O,e.interpolateRange=function(e,f){var c=f[0],d=a.peek(f)-c;return function(a){return e(c+a*d)}},e.isContinuous=function(e){return q(e,r)},e.isDiscrete=function(e){return q(e,i)},e.isDiscretizing=function(e){return q(e,o)},e.isInterpolating=function(e){return q(e,u)},e.isLogarithmic=function(e){return q(e,b)},e.isQuantile=function(e){return q(e,t)},e.isTemporal=function(e){return q(e,l)},e.isValidScaleType=h,e.quantizeInterpolator=function(e,a){for(var f=new Array(a),c=a+1,d=0;d<a;)f[d]=e(++d/c);return f},e.scale=y,e.scaleCopy=function(e){const a=e.type,f=e.copy();return f.type=a,f},e.scaleFraction=function(e,f,c){var d,n,b,t=c-f;return t&&Number.isFinite(t)?(d=(n=e.type).indexOf("-"),n=d<0?n:n.slice(d+1),b=y(n)().domain([f,c]).range([0,1]),w.forEach(a=>e[a]?b[a](e[a]()):0),b):a.constant(.5)},e.scheme=R,Object.defineProperty(e,"__esModule",{value:!0})})); |
24
index.js
@@ -20,13 +20,3 @@ export {default as bandSpace} from './src/scales/bandSpace'; | ||
Band, | ||
Point, | ||
isValidScaleType, | ||
isTemporal, | ||
isQuantile, | ||
isSequential, | ||
isDiverging, | ||
isInterpolating, | ||
isContinuous, | ||
isLogarithmic, | ||
isDiscrete, | ||
isDiscretizing | ||
Point | ||
} from './src/scales/types'; | ||
@@ -43,3 +33,13 @@ | ||
export {default as scale} from './src/scales'; | ||
export { | ||
scale, | ||
isValidScaleType, | ||
isContinuous, | ||
isDiscrete, | ||
isDiscretizing, | ||
isInterpolating, | ||
isLogarithmic, | ||
isQuantile, | ||
isTemporal | ||
} from './src/scales'; | ||
@@ -46,0 +46,0 @@ export {scheme} from './src/schemes'; |
{ | ||
"name": "vega-scale", | ||
"version": "5.0.0", | ||
"version": "6.0.0", | ||
"description": "Scales and color schemes for visual encoding.", | ||
@@ -15,2 +15,3 @@ "keywords": [ | ||
"module": "index", | ||
"types": "index.d.ts", | ||
"repository": "vega/vega", | ||
@@ -28,8 +29,8 @@ "scripts": { | ||
"dependencies": { | ||
"d3-array": "^2.3.3", | ||
"d3-interpolate": "^1.3.2", | ||
"d3-scale": "^3.2.0", | ||
"vega-util": "^1.12.0" | ||
"d3-array": "^2.4.0", | ||
"d3-interpolate": "^1.4.0", | ||
"d3-scale": "^3.2.1", | ||
"vega-util": "^1.12.1" | ||
}, | ||
"gitHead": "8180e8ca9379dec7f1722ce0ebd2aa01083be7b2" | ||
"gitHead": "b690910bacfcb2580511e262400e496d9b14b04f" | ||
} |
@@ -12,3 +12,3 @@ # vega-scale | ||
<a name="scale" href="#scale">#</a> | ||
vega.<b>scale</b>(<i>type</i>[, <i>scale</i>]) | ||
vega.<b>scale</b>(<i>type</i>[, <i>scale</i>, <i>metadata</i>]) | ||
[<>](https://github.com/vega/vega/blob/master/packages/vega-scale/src/scales.js "Source") | ||
@@ -18,2 +18,11 @@ | ||
The *metadata* argument provides additional information to guide appropriate use of scales within Vega. The *metadata* can be either a string or string array. The valid string values are: | ||
* `"continuous"` - the scale is defined over a continuous-valued domain. | ||
* `"discrete"` - the scale is defined over a discrete domain and range. | ||
* `"discretizing"` - the scale discretizes a continuous domain to a discrete range. | ||
* `"interpolating"` - the scale range is defined using a color interpolator. | ||
* `"log"` - the scale performs a logarithmic transform of the continuous domain. | ||
* `"temporal"` - the scale domain is defined over date-time values. | ||
By default, the scale registry includes entries for all scale types provided by the [d3-scale](https://github.com/d3/d3-scale) module. Scales created using the constructor returned by this method have an additional `type` property indicating the scale type. All scales supporting either an `invert` or `invertExtent` method are augmented with an additional `invertRange` function that returns an array of corresponding domain values for a given interval in the scale's output range. | ||
@@ -92,8 +101,2 @@ | ||
<a name="timeInterval" href="#timeInterval">#</a> | ||
vega.<b>timeInterval</b>(<i>unit</i>[, <i>type</i>]) | ||
[<>](https://github.com/vega/vega/blob/master/packages/vega-scale/src/timeInterval.js "Source") | ||
Given a string _unit_, return a corresponding [D3 time interval](https://github.com/d3/d3-time#_interval) function. Valid _unit_ strings are: `"millisecond"`, `"second"`, `"minute"`, `"hour"`, `"day"`, `"week"`, `"month"`, and `"year"`. The optional _type_ indicates the time zone to use, either `"time"` (default, for local time) or `"utc"` (for [Coordinated Universal Time](https://en.wikipedia.org/wiki/Coordinated_Universal_Time)). | ||
<a name="quantizeInterpolator" href="#quantizeInterpolator">#</a> | ||
@@ -100,0 +103,0 @@ vega.<b>quantizeInterpolator</b>(<i>interpolator</i>, <i>count</i>]) |
@@ -1,2 +0,2 @@ | ||
import getScale from './scales'; | ||
import {scale as getScale} from './scales'; | ||
import {constant, peek} from 'vega-util'; | ||
@@ -3,0 +3,0 @@ import * as $ from 'd3-interpolate'; |
@@ -1,2 +0,2 @@ | ||
import {hasOwnProperty} from 'vega-util'; | ||
import {array, hasOwnProperty, toSet} from 'vega-util'; | ||
import invertRange from './scales/invertRange'; | ||
@@ -10,3 +10,8 @@ import invertRangeExtent from './scales/invertRangeExtent'; | ||
Quantile, Quantize, Threshold, | ||
BinOrdinal, Ordinal, Band, Point | ||
BinOrdinal, Ordinal, Band, Point, | ||
Continuous as C, | ||
Discrete as D, | ||
Discretizing as Z, | ||
Interpolating as I, | ||
Temporal as T | ||
} from './scales/types'; | ||
@@ -25,7 +30,10 @@ | ||
// scale registry | ||
const scales = {}; | ||
/** | ||
* Augment scales with their type and needed inverse methods. | ||
*/ | ||
function create(type, constructor) { | ||
return function scale() { | ||
function create(type, constructor, metadata) { | ||
const ctr = function scale() { | ||
var s = constructor(); | ||
@@ -42,55 +50,90 @@ | ||
}; | ||
ctr.metadata = toSet(array(metadata)); | ||
return ctr; | ||
} | ||
export default function scale(type, scale) { | ||
export function scale(type, scale, metadata) { | ||
if (arguments.length > 1) { | ||
scales[type] = create(type, scale); | ||
scales[type] = create(type, scale, metadata); | ||
return this; | ||
} else { | ||
return hasOwnProperty(scales, type) ? scales[type] : undefined; | ||
return isValidScaleType(type) ? scales[type] : undefined; | ||
} | ||
} | ||
var scales = { | ||
// identity scale | ||
[Identity]: $.scaleIdentity, | ||
// identity scale | ||
scale(Identity, $.scaleIdentity); | ||
// continuous scales | ||
[Linear]: $.scaleLinear, | ||
[Log]: $.scaleLog, | ||
[Pow]: $.scalePow, | ||
[Sqrt]: $.scaleSqrt, | ||
[Symlog]: $.scaleSymlog, | ||
[Time]: $.scaleTime, | ||
[UTC]: $.scaleUtc, | ||
// continuous scales | ||
scale(Linear, $.scaleLinear, C); | ||
scale(Log, $.scaleLog, [C, Log]); | ||
scale(Pow, $.scalePow, C); | ||
scale(Sqrt, $.scaleSqrt, C); | ||
scale(Symlog, $.scaleSymlog, C); | ||
scale(Time, $.scaleTime, [C, T]); | ||
scale(UTC, $.scaleUtc, [C, T]); | ||
// sequential scales | ||
[Sequential]: $.scaleSequential, // backwards compat | ||
[Sequential+'-'+Linear]: $.scaleSequential, | ||
[Sequential+'-'+Log]: $.scaleSequentialLog, | ||
[Sequential+'-'+Pow]: $.scaleSequentialPow, | ||
[Sequential+'-'+Sqrt]: $.scaleSequentialSqrt, | ||
[Sequential+'-'+Symlog]: $.scaleSequentialSymlog, | ||
// sequential scales | ||
scale(Sequential, $.scaleSequential, [C, I]); // backwards compat | ||
scale(`${Sequential}-${Linear}`, $.scaleSequential, [C, I]); | ||
scale(`${Sequential}-${Log}`, $.scaleSequentialLog, [C, I, Log]); | ||
scale(`${Sequential}-${Pow}`, $.scaleSequentialPow, [C, I]); | ||
scale(`${Sequential}-${Sqrt}`, $.scaleSequentialSqrt, [C, I]); | ||
scale(`${Sequential}-${Symlog}`, $.scaleSequentialSymlog, [C, I]); | ||
// diverging scales | ||
[Diverging+'-'+Linear]: $.scaleDiverging, | ||
[Diverging+'-'+Log]: $.scaleDivergingLog, | ||
[Diverging+'-'+Pow]: $.scaleDivergingPow, | ||
[Diverging+'-'+Sqrt]: $.scaleDivergingSqrt, | ||
[Diverging+'-'+Symlog]: $.scaleDivergingSymlog, | ||
// diverging scales | ||
scale(`${Diverging}-${Linear}`, $.scaleDiverging, [C, I]); | ||
scale(`${Diverging}-${Log}`, $.scaleDivergingLog, [C, I, Log]); | ||
scale(`${Diverging}-${Pow}`, $.scaleDivergingPow, [C, I]); | ||
scale(`${Diverging}-${Sqrt}`, $.scaleDivergingSqrt, [C, I]); | ||
scale(`${Diverging}-${Symlog}`, $.scaleDivergingSymlog, [C, I]); | ||
// discretizing scales | ||
[Quantile]: $.scaleQuantile, | ||
[Quantize]: $.scaleQuantize, | ||
[Threshold]: $.scaleThreshold, | ||
// discretizing scales | ||
scale(Quantile, $.scaleQuantile, [Z, Quantile]); | ||
scale(Quantize, $.scaleQuantize, Z); | ||
scale(Threshold, $.scaleThreshold, Z); | ||
// discrete scales | ||
[BinOrdinal]: scaleBinOrdinal, | ||
[Ordinal]: $.scaleOrdinal, | ||
[Band]: scaleBand, | ||
[Point]: scalePoint | ||
}; | ||
// discrete scales | ||
scale(BinOrdinal, scaleBinOrdinal, [D, Z]); | ||
scale(Ordinal, $.scaleOrdinal, D); | ||
scale(Band, scaleBand, D); | ||
scale(Point, scalePoint, D); | ||
for (var key in scales) { | ||
scale(key, scales[key]); | ||
export function isValidScaleType(type) { | ||
return hasOwnProperty(scales, type); | ||
} | ||
function hasType(key, type) { | ||
const s = scales[key]; | ||
return s && s.metadata[type]; | ||
} | ||
export function isContinuous(key) { | ||
return hasType(key, C); | ||
} | ||
export function isDiscrete(key) { | ||
return hasType(key, D); | ||
} | ||
export function isDiscretizing(key) { | ||
return hasType(key, Z); | ||
} | ||
export function isLogarithmic(key) { | ||
return hasType(key, Log); | ||
} | ||
export function isTemporal(key) { | ||
return hasType(key, T); | ||
} | ||
export function isInterpolating(key) { | ||
return hasType(key, I); | ||
} | ||
export function isQuantile(key) { | ||
return hasType(key, Quantile); | ||
} |
@@ -24,80 +24,7 @@ export const Identity = 'identity'; | ||
export function isValidScaleType(type) { | ||
switch (type) { | ||
case Identity: | ||
case Linear: | ||
case Log: | ||
case Pow: | ||
case Sqrt: | ||
case Symlog: | ||
case Time: | ||
case UTC: | ||
case Sequential: | ||
case Quantile: | ||
case Quantize: | ||
case Threshold: | ||
case Ordinal: | ||
case Point: | ||
case Band: | ||
case BinOrdinal: | ||
return true; | ||
} | ||
return false; | ||
} | ||
export function isTemporal(key) { | ||
return key === Time || key === UTC; | ||
} | ||
export function isBinned(key) { | ||
return key === BinOrdinal; | ||
} | ||
export function isQuantile(key) { | ||
return key === Quantile; | ||
} | ||
export function isSequential(key) { | ||
return key && key.startsWith(Sequential); | ||
} | ||
export function isDiverging(key) { | ||
return key && key.startsWith(Diverging); | ||
} | ||
export function isInterpolating(key) { | ||
return isSequential(key) || isDiverging(key); | ||
} | ||
export function isLogarithmic(key) { | ||
return key === Log || key.endsWith('-log'); | ||
} | ||
export function isContinuous(key) { | ||
switch (key) { | ||
case Linear: | ||
case Log: | ||
case Pow: | ||
case Sqrt: | ||
case Symlog: | ||
case Time: | ||
case UTC: | ||
case Sequential: | ||
return true; | ||
} | ||
return false; | ||
} | ||
export function isDiscrete(key) { | ||
return key === BinOrdinal | ||
|| key === Ordinal | ||
|| key === Band | ||
|| key === Point; | ||
} | ||
export function isDiscretizing(key) { | ||
return key === BinOrdinal | ||
|| key === Quantile | ||
|| key === Quantize | ||
|| key === Threshold; | ||
} | ||
// categories | ||
export const Continuous = 'continuous'; | ||
export const Discrete = 'discrete'; | ||
export const Discretizing = 'discretizing'; | ||
export const Interpolating = 'interpolating'; | ||
export const Temporal = 'temporal'; |
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
19
104
61449
1097
Updatedd3-array@^2.4.0
Updatedd3-interpolate@^1.4.0
Updatedd3-scale@^3.2.1
Updatedvega-util@^1.12.1