Comparing version 1.0.0 to 1.1.0
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vega-dataflow'), require('vega-util'), require('d3-contour'), require('d3-geo')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'vega-dataflow', 'vega-util', 'd3-contour', 'd3-geo'], factory) : | ||
(factory((global.vega = global.vega || {}),global.vega,global.vega,global.d3,global.d3)); | ||
}(this, (function (exports,vegaDataflow,vegaUtil,d3Contour,d3Geo) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vega-dataflow'), require('vega-util'), require('d3-array'), require('d3-contour'), require('d3-geo')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'vega-dataflow', 'vega-util', 'd3-array', 'd3-contour', 'd3-geo'], factory) : | ||
(factory((global.vega = global.vega || {}),global.vega,global.vega,global.d3,global.d3,global.d3)); | ||
}(this, (function (exports,vegaDataflow,vegaUtil,d3Array,d3Contour,d3Geo) { 'use strict'; | ||
var CONTOUR_PARAMS = ['values', 'size', 'thresholds']; | ||
var DENSITY_PARAMS = ['x', 'y', 'size', 'cellSize', 'bandwidth', 'thresholds']; | ||
var CONTOUR_PARAMS = ['values', 'size']; | ||
var DENSITY_PARAMS = ['x', 'y', 'size', 'cellSize', 'bandwidth']; | ||
@@ -25,3 +25,10 @@ /** | ||
* @param {number} [params.bandwidth] - Kernel density estimation bandwidth. | ||
* @param {number} [params.thresholds] - Contour threshold array or desired number of contours. | ||
* @param {Array<number>} [params.thresholds] - Contour threshold array. If | ||
* this parameter is set, the thresholdCount and thresholdNice parameters | ||
* will be ignored. | ||
* @param {number} [params.count] - The desired number of contours. | ||
* @param {boolean} [params.nice] - Boolean flag indicating if the contour | ||
* threshold values should be automatically aligned to "nice" | ||
* human-friendly values. Setting this flag may cause the number of | ||
* thresholds to deviate from the specified count. | ||
*/ | ||
@@ -39,2 +46,3 @@ function Contour(params) { | ||
var out = pulse.fork(pulse.NO_SOURCE | pulse.NO_FIELDS), | ||
count = _.count || 10, | ||
contour, params, values; | ||
@@ -52,2 +60,6 @@ | ||
// set threshold parameter | ||
contour.thresholds(_.thresholds || (_.nice ? count : quantize(count))); | ||
// set all other parameters | ||
params.forEach(function(param) { | ||
@@ -63,2 +75,11 @@ if (_[param] != null) contour[param](_[param]); | ||
function quantize(k) { | ||
return function(values) { | ||
var ex = d3Array.extent(values), x0 = ex[0], dx = ex[1] - x0, | ||
t = [], i = 1; | ||
for (; i<=k; ++i) t.push(x0 + dx * i / (k + 1)); | ||
return t; | ||
}; | ||
} | ||
var defaultPath = d3Geo.geoPath(); | ||
@@ -383,3 +404,5 @@ | ||
{ "name": "bandwidth", "type": "number" }, | ||
{ "name": "thresholds", "type": "number" } | ||
{ "name": "count", "type": "number" }, | ||
{ "name": "nice", "type": "number", "default": false }, | ||
{ "name": "thresholds", "type": "number", "array": true } | ||
] | ||
@@ -386,0 +409,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vega-dataflow"),require("vega-util"),require("d3-contour"),require("d3-geo")):"function"==typeof define&&define.amd?define(["exports","vega-dataflow","vega-util","d3-contour","d3-geo"],t):t(e.vega=e.vega||{},e.vega,e.vega,e.d3,e.d3)}(this,function(e,t,r,n,a){"use strict";function i(e){t.Transform.call(this,null,e)}function o(e,t){return function r(){var n=t();return n.type=e,n.path=a.geoPath().projection(n),n.copy=n.copy||function(){var e=r();return j.forEach(function(t){n.hasOwnProperty(t)&&e[t](n[t]())}),e.path.pointRadius(n.path.pointRadius()),e},n}}function s(e,t){return arguments.length>1?(q[e]=o(e,t),this):q.hasOwnProperty(e)?q[e]:null}function u(e){return e&&e.path||x}function l(e){t.Transform.call(this,null,e)}function f(e){t.Transform.call(this,null,e)}function c(e){t.Transform.call(this,null,e)}function d(e,t){var r=function(r){return e(t(r))};return r.context=function(t){return e.context(t),r},r}function m(e){t.Transform.call(this,[],e),this.generator=a.geoGraticule()}function p(e){t.Transform.call(this,null,e),this.modified(!0)}function h(e,t){var r=g(t.fit);t.extent?e.fitExtent(t.extent,r):t.size&&e.fitSize(t.size,r)}function g(e){return r.isArray(e)?e.length>1?{type:"FeatureCollection",features:e}:e[0]:e}function y(e){var t=s((e||"mercator").toLowerCase());return t||r.error("Unrecognized projection type: "+e),t()}function v(e,t,n){r.isFunction(e[t])&&e[t](n)}var b=["values","size","thresholds"],E=["x","y","size","cellSize","bandwidth","thresholds"];r.inherits(i,t.Transform).transform=function(e,r){if(this.value&&!r.changed()&&!e.modified())return r.StopPropagation;var a,i,o,s=r.fork(r.NO_SOURCE|r.NO_FIELDS);return e.values?(a=n.contours(),i=b,o=e.values):(a=n.contourDensity(),i=E,o=r.materialize(r.SOURCE).source),i.forEach(function(t){null!=e[t]&&a[t](e[t])}),this.value&&(s.rem=this.value),this.value=s.source=s.add=a(o).map(t.ingest),s};var x=a.geoPath(),j=["clipAngle","clipExtent","scale","translate","center","rotate","parallels","precision","coefficient","distance","fraction","lobes","parallel","radius","ratio","spacing","tilt"],q={albers:a.geoAlbers,albersusa:a.geoAlbersUsa,azimuthalequalarea:a.geoAzimuthalEqualArea,azimuthalequidistant:a.geoAzimuthalEquidistant,conicconformal:a.geoConicConformal,conicequalarea:a.geoConicEqualArea,conicequidistant:a.geoConicEquidistant,equirectangular:a.geoEquirectangular,gnomonic:a.geoGnomonic,mercator:a.geoMercator,orthographic:a.geoOrthographic,stereographic:a.geoStereographic,transversemercator:a.geoTransverseMercator};for(var z in q)s(z,q[z]);r.inherits(l,t.Transform).transform=function(e,t){function n(e){e[l]=o(s(e))}var a,i=t.fork(t.ALL),o=this.value,s=e.field||r.identity,l=e.as||"path";return!o||e.modified()?(this.value=o=u(e.projection).context(null),i.materialize().reflow().visit(i.SOURCE,n)):(o.context(null),a=s===r.identity||t.modified(s.fields),i.visit(a?i.ADD_MOD:i.ADD,n)),i.modifies(l)},r.inherits(f,t.Transform).transform=function(e,t){function r(e){var t=a([i(e),o(e)]);t?(e[u]=t[0],e[l]=t[1]):(e[u]=void 0,e[l]=void 0)}var n,a=e.projection,i=e.fields[0],o=e.fields[1],s=e.as||["x","y"],u=s[0],l=s[1];return e.modified()?t.materialize().reflow(!0).visit(t.SOURCE,r):(n=t.modified(i.fields)||t.modified(o.fields),t.visit(n?t.ADD_MOD:t.ADD,r)),t.modifies(s)},r.inherits(c,t.Transform).transform=function(e,t){var n=t.fork(t.ALL),a=this.value,i=e.field||r.field("datum"),o=e.as||"shape",s=n.ADD_MOD;return a&&!e.modified()||(this.value=a=d(u(e.projection),i),n.materialize().reflow(),s=n.SOURCE),n.visit(s,function(e){e[o]=a}),n.modifies(o)},r.inherits(m,t.Transform).transform=function(e,n){var a,i=n.fork(),o=this.value,s=this.generator;if(!o.length||e.modified())for(var u in e)r.isFunction(s[u])&&s[u](e[u]);return a=s(),o.length?(a._id=o[0]._id,i.mod.push(a)):i.add.push(t.ingest(a)),o[0]=a,i.source=o,i},r.inherits(p,t.Transform).transform=function(e,t){var r=this.value;return!r||e.modified("type")?(this.value=r=y(e.type),j.forEach(function(t){null!=e[t]&&v(r,t,e[t])})):j.forEach(function(t){e.modified(t)&&v(r,t,e[t])}),null!=e.pointRadius&&r.path.pointRadius(e.pointRadius),e.fit&&h(r,e),t.fork(t.NO_SOURCE|t.NO_FIELDS)};var O={type:"Contour",metadata:{generates:!0,source:!0},params:[{name:"size",type:"number",array:!0,length:2,required:!0},{name:"values",type:"number",array:!0},{name:"x",type:"field"},{name:"y",type:"field"},{name:"cellSize",type:"number"},{name:"bandwidth",type:"number"},{name:"thresholds",type:"number"}]},D={type:"GeoPath",metadata:{modifies:!0},params:[{name:"projection",type:"projection"},{name:"field",type:"field"},{name:"as",type:"string",default:"path"}]},A={type:"GeoPoint",metadata:{modifies:!0},params:[{name:"projection",type:"projection",required:!0},{name:"fields",type:"field",array:!0,required:!0,length:2},{name:"as",type:"string",array:!0,length:2,default:["x","y"]}]},S={type:"GeoShape",metadata:{modifies:!0},params:[{name:"projection",type:"projection"},{name:"field",type:"field",default:"datum"},{name:"as",type:"string",default:"shape"}]},C={type:"Graticule",metadata:{source:!0,generates:!0,changes:!0},params:[{name:"extent",type:"array",array:!0,length:2,content:{type:"number",array:!0,length:2}},{name:"extentMajor",type:"array",array:!0,length:2,content:{type:"number",array:!0,length:2}},{name:"extentMinor",type:"array",array:!0,length:2,content:{type:"number",array:!0,length:2}},{name:"step",type:"number",array:!0,length:2},{name:"stepMajor",type:"number",array:!0,length:2,default:[90,360]},{name:"stepMinor",type:"number",array:!0,length:2,default:[10,10]},{name:"precision",type:"number",default:2.5}]};t.register(O,i),t.register(D,l),t.register(A,f),t.register(S,c),t.register(C,m),t.transform("Projection",p),e.transform=t.transform,e.definition=t.definition,e.projection=s,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vega-dataflow"),require("vega-util"),require("d3-array"),require("d3-contour"),require("d3-geo")):"function"==typeof define&&define.amd?define(["exports","vega-dataflow","vega-util","d3-array","d3-contour","d3-geo"],t):t(e.vega=e.vega||{},e.vega,e.vega,e.d3,e.d3,e.d3)}(this,function(e,t,r,n,a,i){"use strict";function o(e){t.Transform.call(this,null,e)}function u(e){return function(t){for(var r=n.extent(t),a=r[0],i=r[1]-a,o=[],u=1;u<=e;++u)o.push(a+i*u/(e+1));return o}}function s(e,t){return function r(){var n=t();return n.type=e,n.path=i.geoPath().projection(n),n.copy=n.copy||function(){var e=r();return z.forEach(function(t){n.hasOwnProperty(t)&&e[t](n[t]())}),e.path.pointRadius(n.path.pointRadius()),e},n}}function l(e,t){return arguments.length>1?(O[e]=s(e,t),this):O.hasOwnProperty(e)?O[e]:null}function f(e){return e&&e.path||j}function c(e){t.Transform.call(this,null,e)}function d(e){t.Transform.call(this,null,e)}function m(e){t.Transform.call(this,null,e)}function p(e,t){var r=function(r){return e(t(r))};return r.context=function(t){return e.context(t),r},r}function h(e){t.Transform.call(this,[],e),this.generator=i.geoGraticule()}function y(e){t.Transform.call(this,null,e),this.modified(!0)}function g(e,t){var r=v(t.fit);t.extent?e.fitExtent(t.extent,r):t.size&&e.fitSize(t.size,r)}function v(e){return r.isArray(e)?e.length>1?{type:"FeatureCollection",features:e}:e[0]:e}function b(e){var t=l((e||"mercator").toLowerCase());return t||r.error("Unrecognized projection type: "+e),t()}function x(e,t,n){r.isFunction(e[t])&&e[t](n)}var E=["values","size"],q=["x","y","size","cellSize","bandwidth"];r.inherits(o,t.Transform).transform=function(e,r){if(this.value&&!r.changed()&&!e.modified())return r.StopPropagation;var n,i,o,s=r.fork(r.NO_SOURCE|r.NO_FIELDS),l=e.count||10;return e.values?(n=a.contours(),i=E,o=e.values):(n=a.contourDensity(),i=q,o=r.materialize(r.SOURCE).source),n.thresholds(e.thresholds||(e.nice?l:u(l))),i.forEach(function(t){null!=e[t]&&n[t](e[t])}),this.value&&(s.rem=this.value),this.value=s.source=s.add=n(o).map(t.ingest),s};var j=i.geoPath(),z=["clipAngle","clipExtent","scale","translate","center","rotate","parallels","precision","coefficient","distance","fraction","lobes","parallel","radius","ratio","spacing","tilt"],O={albers:i.geoAlbers,albersusa:i.geoAlbersUsa,azimuthalequalarea:i.geoAzimuthalEqualArea,azimuthalequidistant:i.geoAzimuthalEquidistant,conicconformal:i.geoConicConformal,conicequalarea:i.geoConicEqualArea,conicequidistant:i.geoConicEquidistant,equirectangular:i.geoEquirectangular,gnomonic:i.geoGnomonic,mercator:i.geoMercator,orthographic:i.geoOrthographic,stereographic:i.geoStereographic,transversemercator:i.geoTransverseMercator};for(var D in O)l(D,O[D]);r.inherits(c,t.Transform).transform=function(e,t){function n(e){e[s]=o(u(e))}var a,i=t.fork(t.ALL),o=this.value,u=e.field||r.identity,s=e.as||"path";return!o||e.modified()?(this.value=o=f(e.projection).context(null),i.materialize().reflow().visit(i.SOURCE,n)):(o.context(null),a=u===r.identity||t.modified(u.fields),i.visit(a?i.ADD_MOD:i.ADD,n)),i.modifies(s)},r.inherits(d,t.Transform).transform=function(e,t){function r(e){var t=a([i(e),o(e)]);t?(e[s]=t[0],e[l]=t[1]):(e[s]=void 0,e[l]=void 0)}var n,a=e.projection,i=e.fields[0],o=e.fields[1],u=e.as||["x","y"],s=u[0],l=u[1];return e.modified()?t.materialize().reflow(!0).visit(t.SOURCE,r):(n=t.modified(i.fields)||t.modified(o.fields),t.visit(n?t.ADD_MOD:t.ADD,r)),t.modifies(u)},r.inherits(m,t.Transform).transform=function(e,t){var n=t.fork(t.ALL),a=this.value,i=e.field||r.field("datum"),o=e.as||"shape",u=n.ADD_MOD;return a&&!e.modified()||(this.value=a=p(f(e.projection),i),n.materialize().reflow(),u=n.SOURCE),n.visit(u,function(e){e[o]=a}),n.modifies(o)},r.inherits(h,t.Transform).transform=function(e,n){var a,i=n.fork(),o=this.value,u=this.generator;if(!o.length||e.modified())for(var s in e)r.isFunction(u[s])&&u[s](e[s]);return a=u(),o.length?(a._id=o[0]._id,i.mod.push(a)):i.add.push(t.ingest(a)),o[0]=a,i.source=o,i},r.inherits(y,t.Transform).transform=function(e,t){var r=this.value;return!r||e.modified("type")?(this.value=r=b(e.type),z.forEach(function(t){null!=e[t]&&x(r,t,e[t])})):z.forEach(function(t){e.modified(t)&&x(r,t,e[t])}),null!=e.pointRadius&&r.path.pointRadius(e.pointRadius),e.fit&&g(r,e),t.fork(t.NO_SOURCE|t.NO_FIELDS)};var A={type:"Contour",metadata:{generates:!0,source:!0},params:[{name:"size",type:"number",array:!0,length:2,required:!0},{name:"values",type:"number",array:!0},{name:"x",type:"field"},{name:"y",type:"field"},{name:"cellSize",type:"number"},{name:"bandwidth",type:"number"},{name:"count",type:"number"},{name:"nice",type:"number",default:!1},{name:"thresholds",type:"number",array:!0}]},S={type:"GeoPath",metadata:{modifies:!0},params:[{name:"projection",type:"projection"},{name:"field",type:"field"},{name:"as",type:"string",default:"path"}]},C={type:"GeoPoint",metadata:{modifies:!0},params:[{name:"projection",type:"projection",required:!0},{name:"fields",type:"field",array:!0,required:!0,length:2},{name:"as",type:"string",array:!0,length:2,default:["x","y"]}]},T={type:"GeoShape",metadata:{modifies:!0},params:[{name:"projection",type:"projection"},{name:"field",type:"field",default:"datum"},{name:"as",type:"string",default:"shape"}]},R={type:"Graticule",metadata:{source:!0,generates:!0,changes:!0},params:[{name:"extent",type:"array",array:!0,length:2,content:{type:"number",array:!0,length:2}},{name:"extentMajor",type:"array",array:!0,length:2,content:{type:"number",array:!0,length:2}},{name:"extentMinor",type:"array",array:!0,length:2,content:{type:"number",array:!0,length:2}},{name:"step",type:"number",array:!0,length:2},{name:"stepMajor",type:"number",array:!0,length:2,default:[90,360]},{name:"stepMinor",type:"number",array:!0,length:2,default:[10,10]},{name:"precision",type:"number",default:2.5}]};t.register(A,o),t.register(S,c),t.register(C,d),t.register(T,m),t.register(R,h),t.transform("Projection",y),e.transform=t.transform,e.definition=t.definition,e.projection=l,Object.defineProperty(e,"__esModule",{value:!0})}); |
@@ -11,4 +11,6 @@ export default { | ||
{ "name": "bandwidth", "type": "number" }, | ||
{ "name": "thresholds", "type": "number" } | ||
{ "name": "count", "type": "number" }, | ||
{ "name": "nice", "type": "number", "default": false }, | ||
{ "name": "thresholds", "type": "number", "array": true } | ||
] | ||
} |
{ | ||
"name": "vega-geo", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Geographic data transforms for Vega dataflows.", | ||
@@ -25,3 +25,3 @@ "keywords": [ | ||
"build": "npm run test && uglifyjs build/vega-geo.js -c -m -o build/vega-geo.min.js", | ||
"pretest": "rm -rf build && mkdir build && rollup -g d3-contour:d3,d3-geo:d3,vega-dataflow:vega,vega-util:vega -f umd -n vega -o build/vega-geo.js -- index.js", | ||
"pretest": "rm -rf build && mkdir build && rollup -g d3-array:d3,d3-contour:d3,d3-geo:d3,vega-dataflow:vega,vega-util:vega -f umd -n vega -o build/vega-geo.js -- index.js", | ||
"test": "tape 'test/**/*-test.js' && eslint index.js src test", | ||
@@ -32,2 +32,3 @@ "prepublish": "npm run build", | ||
"dependencies": { | ||
"d3-array": "1", | ||
"d3-contour": "1", | ||
@@ -34,0 +35,0 @@ "d3-geo": "1", |
import {ingest, Transform} from 'vega-dataflow'; | ||
import {inherits} from 'vega-util'; | ||
import {extent} from 'd3-array'; | ||
import {contours, contourDensity} from 'd3-contour'; | ||
var CONTOUR_PARAMS = ['values', 'size', 'thresholds']; | ||
var DENSITY_PARAMS = ['x', 'y', 'size', 'cellSize', 'bandwidth', 'thresholds']; | ||
var CONTOUR_PARAMS = ['values', 'size']; | ||
var DENSITY_PARAMS = ['x', 'y', 'size', 'cellSize', 'bandwidth']; | ||
@@ -23,3 +24,10 @@ /** | ||
* @param {number} [params.bandwidth] - Kernel density estimation bandwidth. | ||
* @param {number} [params.thresholds] - Contour threshold array or desired number of contours. | ||
* @param {Array<number>} [params.thresholds] - Contour threshold array. If | ||
* this parameter is set, the thresholdCount and thresholdNice parameters | ||
* will be ignored. | ||
* @param {number} [params.count] - The desired number of contours. | ||
* @param {boolean} [params.nice] - Boolean flag indicating if the contour | ||
* threshold values should be automatically aligned to "nice" | ||
* human-friendly values. Setting this flag may cause the number of | ||
* thresholds to deviate from the specified count. | ||
*/ | ||
@@ -37,2 +45,3 @@ export default function Contour(params) { | ||
var out = pulse.fork(pulse.NO_SOURCE | pulse.NO_FIELDS), | ||
count = _.count || 10, | ||
contour, params, values; | ||
@@ -50,2 +59,6 @@ | ||
// set threshold parameter | ||
contour.thresholds(_.thresholds || (_.nice ? count : quantize(count))); | ||
// set all other parameters | ||
params.forEach(function(param) { | ||
@@ -60,1 +73,10 @@ if (_[param] != null) contour[param](_[param]); | ||
}; | ||
function quantize(k) { | ||
return function(values) { | ||
var ex = extent(values), x0 = ex[0], dx = ex[1] - x0, | ||
t = [], i = 1; | ||
for (; i<=k; ++i) t.push(x0 + dx * i / (k + 1)); | ||
return t; | ||
}; | ||
} |
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
39797
828
5
+ Addedd3-array@1