Comparing version 2.0.0 to 2.1.0
@@ -96,3 +96,85 @@ (function (global, factory) { | ||
var Feature = 'Feature'; | ||
var FeatureCollection = 'FeatureCollection'; | ||
var MultiPoint = 'MultiPoint'; | ||
/** | ||
* Consolidate an array of [longitude, latitude] points or GeoJSON features | ||
* into a combined GeoJSON object. This transform is particularly useful for | ||
* combining geo data for a Projection's fit argument. The resulting GeoJSON | ||
* data is available as this transform's value. Input pulses are unchanged. | ||
* @constructor | ||
* @param {object} params - The parameters for this operator. | ||
* @param {Array<function(object): *>} [params.fields] - A two-element array | ||
* of field accessors for the longitude and latitude values. | ||
* @param {function(object): *} params.geojson - A field accessor for | ||
* retrieving GeoJSON feature data. | ||
*/ | ||
function GeoJSON(params) { | ||
vegaDataflow.Transform.call(this, null, params); | ||
} | ||
GeoJSON.Definition = { | ||
"type": "GeoJSON", | ||
"metadata": {}, | ||
"params": [ | ||
{ "name": "fields", "type": "field", "array": true, "length": 2 }, | ||
{ "name": "geojson", "type": "field" }, | ||
] | ||
}; | ||
var prototype$1 = vegaUtil.inherits(GeoJSON, vegaDataflow.Transform); | ||
prototype$1.transform = function(_, pulse) { | ||
var features = this._features, | ||
points = this._points, | ||
fields = _.fields, | ||
lon = fields && fields[0], | ||
lat = fields && fields[1], | ||
geojson = _.geojson, | ||
flag = pulse.ADD, | ||
mod; | ||
mod = _.modified() | ||
|| pulse.changed(pulse.REM) | ||
|| pulse.modified(vegaUtil.accessorFields(geojson)) | ||
|| (lon && (pulse.modified(vegaUtil.accessorFields(lon)))) | ||
|| (lat && (pulse.modified(vegaUtil.accessorFields(lat)))); | ||
if (!this.value || mod) { | ||
flag = pulse.SOURCE; | ||
this._features = (features = []); | ||
this._points = (points = []); | ||
} | ||
if (geojson) { | ||
pulse.visit(flag, function(t) { | ||
features.push(geojson(t)); | ||
}); | ||
} | ||
if (lon && lat) { | ||
pulse.visit(flag, function(t) { | ||
var x = lon(t), | ||
y = lat(t); | ||
if (x != null && y != null && (x = +x) === x && (y = +y) === y) { | ||
points.push([x, y]); | ||
} | ||
}); | ||
features = features.concat({ | ||
type: Feature, | ||
geometry: { | ||
type: MultiPoint, | ||
coordinates: points | ||
} | ||
}); | ||
} | ||
this.value = { | ||
type: FeatureCollection, | ||
features: features | ||
}; | ||
}; | ||
/** | ||
* Map GeoJSON data to an SVG path string. | ||
@@ -122,5 +204,5 @@ * @constructor | ||
var prototype$1 = vegaUtil.inherits(GeoPath, vegaDataflow.Transform); | ||
var prototype$2 = vegaUtil.inherits(GeoPath, vegaDataflow.Transform); | ||
prototype$1.transform = function(_, pulse) { | ||
prototype$2.transform = function(_, pulse) { | ||
var out = pulse.fork(pulse.ALL), | ||
@@ -172,5 +254,5 @@ path = this.value, | ||
var prototype$2 = vegaUtil.inherits(GeoPoint, vegaDataflow.Transform); | ||
var prototype$3 = vegaUtil.inherits(GeoPoint, vegaDataflow.Transform); | ||
prototype$2.transform = function(_, pulse) { | ||
prototype$3.transform = function(_, pulse) { | ||
var proj = _.projection, | ||
@@ -231,5 +313,5 @@ lon = _.fields[0], | ||
var prototype$3 = vegaUtil.inherits(GeoShape, vegaDataflow.Transform); | ||
var prototype$4 = vegaUtil.inherits(GeoShape, vegaDataflow.Transform); | ||
prototype$3.transform = function(_, pulse) { | ||
prototype$4.transform = function(_, pulse) { | ||
var out = pulse.fork(pulse.ALL), | ||
@@ -292,5 +374,5 @@ shape = this.value, | ||
var prototype$4 = vegaUtil.inherits(Graticule, vegaDataflow.Transform); | ||
var prototype$5 = vegaUtil.inherits(Graticule, vegaDataflow.Transform); | ||
prototype$4.transform = function(_, pulse) { | ||
prototype$5.transform = function(_, pulse) { | ||
var out = pulse.fork(), | ||
@@ -330,5 +412,5 @@ src = this.value, | ||
var prototype$5 = vegaUtil.inherits(Projection, vegaDataflow.Transform); | ||
var prototype$6 = vegaUtil.inherits(Projection, vegaDataflow.Transform); | ||
prototype$5.transform = function(_, pulse) { | ||
prototype$6.transform = function(_, pulse) { | ||
var proj = this.value; | ||
@@ -354,3 +436,3 @@ | ||
function fit(proj, _) { | ||
var data = geoJSON(_.fit); | ||
var data = collectGeoJSON(_.fit); | ||
_.extent ? proj.fitExtent(_.extent, data) | ||
@@ -360,8 +442,2 @@ : _.size ? proj.fitSize(_.size, data) : 0; | ||
function geoJSON(data) { | ||
return !vegaUtil.isArray(data) ? data | ||
: data.length > 1 ? {type: 'FeatureCollection', features: data} | ||
: data[0]; | ||
} | ||
function create(type) { | ||
@@ -377,3 +453,19 @@ var constructor = vegaProjection.projection((type || 'mercator').toLowerCase()); | ||
function collectGeoJSON(features) { | ||
features = vegaUtil.array(features); | ||
return features.length === 1 | ||
? features[0] | ||
: { | ||
type: FeatureCollection, | ||
features: features.reduce(function(list, f) { | ||
(f && f.type === FeatureCollection) | ||
? list.push.apply(list, f.features) | ||
: list.push(f); | ||
return list; | ||
}, []) | ||
}; | ||
} | ||
exports.contour = Contour; | ||
exports.geojson = GeoJSON; | ||
exports.geopath = GeoPath; | ||
@@ -380,0 +472,0 @@ exports.geopoint = GeoPoint; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vega-dataflow"),require("vega-util"),require("d3-array"),require("d3-contour"),require("vega-projection"),require("d3-geo")):"function"==typeof define&&define.amd?define(["exports","vega-dataflow","vega-util","d3-array","d3-contour","vega-projection","d3-geo"],t):t((e.vega=e.vega||{},e.vega.transforms=e.vega.transforms||{}),e.vega,e.vega,e.d3,e.d3,e.vega,e.d3)}(this,function(e,t,n,r,i,a,o){"use strict";function u(e){t.Transform.call(this,null,e)}function s(e){return function(t){for(var n=r.extent(t),i=n[0],a=n[1]-i,o=[],u=1;u<=e;++u)o.push(i+a*u/(e+1));return o}}function f(e){t.Transform.call(this,null,e)}function l(e){t.Transform.call(this,null,e)}function d(e){t.Transform.call(this,null,e)}function m(e,t){var n=function(n){return e(t(n))};return n.context=function(t){return e.context(t),n},n}function c(e){t.Transform.call(this,[],e),this.generator=o.geoGraticule()}function p(e){t.Transform.call(this,null,e),this.modified(!0)}function h(e,t){var n=y(t.fit);t.extent?e.fitExtent(t.extent,n):t.size&&e.fitSize(t.size,n)}function y(e){return n.isArray(e)?e.length>1?{type:"FeatureCollection",features:e}:e[0]:e}function g(e){var t=a.projection((e||"mercator").toLowerCase());return t||n.error("Unrecognized projection type: "+e),t()}function v(e,t,r){n.isFunction(e[t])&&e[t](r)}var j=["values","size"],D=["x","y","size","cellSize","bandwidth"];u.Definition={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}]},n.inherits(u,t.Transform).transform=function(e,n){if(this.value&&!n.changed()&&!e.modified())return n.StopPropagation;var r,a,o,u=n.fork(n.NO_SOURCE|n.NO_FIELDS),f=e.count||10;return e.values?(r=i.contours(),a=j,o=e.values):(r=i.contourDensity(),a=D,o=n.materialize(n.SOURCE).source),r.thresholds(e.thresholds||(e.nice?f:s(f))),a.forEach(function(t){null!=e[t]&&r[t](e[t])}),this.value&&(u.rem=this.value),this.value=u.source=u.add=r(o).map(t.ingest),u},f.Definition={type:"GeoPath",metadata:{modifies:!0},params:[{name:"projection",type:"projection"},{name:"field",type:"field"},{name:"as",type:"string",default:"path"}]},n.inherits(f,t.Transform).transform=function(e,t){function r(e){e[f]=u(s(e))}var i,o=t.fork(t.ALL),u=this.value,s=e.field||n.identity,f=e.as||"path";return!u||e.modified()?(this.value=u=a.getProjectionPath(e.projection).context(null),o.materialize().reflow().visit(o.SOURCE,r)):(u.context(null),i=s===n.identity||t.modified(s.fields),o.visit(i?o.ADD_MOD:o.ADD,r)),o.modifies(f)},l.Definition={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"]}]},n.inherits(l,t.Transform).transform=function(e,t){function n(e){var t=i([a(e),o(e)]);t?(e[s]=t[0],e[f]=t[1]):(e[s]=void 0,e[f]=void 0)}var r,i=e.projection,a=e.fields[0],o=e.fields[1],u=e.as||["x","y"],s=u[0],f=u[1];return e.modified()?t=t.materialize().reflow(!0).visit(t.SOURCE,n):(r=t.modified(a.fields)||t.modified(o.fields),t.visit(r?t.ADD_MOD:t.ADD,n)),t.modifies(u)},d.Definition={type:"GeoShape",metadata:{modifies:!0},params:[{name:"projection",type:"projection"},{name:"field",type:"field",default:"datum"},{name:"as",type:"string",default:"shape"}]},n.inherits(d,t.Transform).transform=function(e,t){var r=t.fork(t.ALL),i=this.value,o=e.field||n.field("datum"),u=e.as||"shape",s=r.ADD_MOD;return i&&!e.modified()||(this.value=i=m(a.getProjectionPath(e.projection),o),r.materialize().reflow(),s=r.SOURCE),r.visit(s,function(e){e[u]=i}),r.modifies(u)},c.Definition={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}]},n.inherits(c,t.Transform).transform=function(e,r){var i,a=r.fork(),o=this.value,u=this.generator;if(!o.length||e.modified())for(var s in e)n.isFunction(u[s])&&u[s](e[s]);return i=u(),o.length?a.mod.push(t.replace(o[0],i)):a.add.push(t.ingest(i)),o[0]=i,a.source=o,a},n.inherits(p,t.Transform).transform=function(e,t){var n=this.value;return!n||e.modified("type")?(this.value=n=g(e.type),a.projectionProperties.forEach(function(t){null!=e[t]&&v(n,t,e[t])})):a.projectionProperties.forEach(function(t){e.modified(t)&&v(n,t,e[t])}),null!=e.pointRadius&&n.path.pointRadius(e.pointRadius),e.fit&&h(n,e),t.fork(t.NO_SOURCE|t.NO_FIELDS)},e.contour=u,e.geopath=f,e.geopoint=l,e.geoshape=d,e.graticule=c,e.projection=p,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("vega-projection"),require("d3-geo")):"function"==typeof define&&define.amd?define(["exports","vega-dataflow","vega-util","d3-array","d3-contour","vega-projection","d3-geo"],t):t((e.vega=e.vega||{},e.vega.transforms=e.vega.transforms||{}),e.vega,e.vega,e.d3,e.d3,e.vega,e.d3)}(this,function(e,t,n,r,i,a,o){"use strict";function s(e){t.Transform.call(this,null,e)}function u(e){return function(t){for(var n=r.extent(t),i=n[0],a=n[1]-i,o=[],s=1;s<=e;++s)o.push(i+a*s/(e+1));return o}}function f(e){t.Transform.call(this,null,e)}function l(e){t.Transform.call(this,null,e)}function d(e){t.Transform.call(this,null,e)}function c(e){t.Transform.call(this,null,e)}function m(e,t){var n=function(n){return e(t(n))};return n.context=function(t){return e.context(t),n},n}function p(e){t.Transform.call(this,[],e),this.generator=o.geoGraticule()}function h(e){t.Transform.call(this,null,e),this.modified(!0)}function y(e,t){var n=j(t.fit);t.extent?e.fitExtent(t.extent,n):t.size&&e.fitSize(t.size,n)}function g(e){var t=a.projection((e||"mercator").toLowerCase());return t||n.error("Unrecognized projection type: "+e),t()}function v(e,t,r){n.isFunction(e[t])&&e[t](r)}function j(e){return 1===(e=n.array(e)).length?e[0]:{type:x,features:e.reduce(function(e,t){return t&&t.type===x?e.push.apply(e,t.features):e.push(t),e},[])}}var D=["values","size"],b=["x","y","size","cellSize","bandwidth"];s.Definition={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}]},n.inherits(s,t.Transform).transform=function(e,n){if(this.value&&!n.changed()&&!e.modified())return n.StopPropagation;var r,a,o,s=n.fork(n.NO_SOURCE|n.NO_FIELDS),f=e.count||10;return e.values?(r=i.contours(),a=D,o=e.values):(r=i.contourDensity(),a=b,o=n.materialize(n.SOURCE).source),r.thresholds(e.thresholds||(e.nice?f:u(f))),a.forEach(function(t){null!=e[t]&&r[t](e[t])}),this.value&&(s.rem=this.value),this.value=s.source=s.add=r(o).map(t.ingest),s};var x="FeatureCollection";f.Definition={type:"GeoJSON",metadata:{},params:[{name:"fields",type:"field",array:!0,length:2},{name:"geojson",type:"field"}]},n.inherits(f,t.Transform).transform=function(e,t){var r,i=this._features,a=this._points,o=e.fields,s=o&&o[0],u=o&&o[1],f=e.geojson,l=t.ADD;r=e.modified()||t.changed(t.REM)||t.modified(n.accessorFields(f))||s&&t.modified(n.accessorFields(s))||u&&t.modified(n.accessorFields(u)),this.value&&!r||(l=t.SOURCE,this._features=i=[],this._points=a=[]),f&&t.visit(l,function(e){i.push(f(e))}),s&&u&&(t.visit(l,function(e){var t=s(e),n=u(e);null!=t&&null!=n&&(t=+t)===t&&(n=+n)===n&&a.push([t,n])}),i=i.concat({type:"Feature",geometry:{type:"MultiPoint",coordinates:a}})),this.value={type:x,features:i}},l.Definition={type:"GeoPath",metadata:{modifies:!0},params:[{name:"projection",type:"projection"},{name:"field",type:"field"},{name:"as",type:"string",default:"path"}]},n.inherits(l,t.Transform).transform=function(e,t){function r(e){e[f]=s(u(e))}var i,o=t.fork(t.ALL),s=this.value,u=e.field||n.identity,f=e.as||"path";return!s||e.modified()?(this.value=s=a.getProjectionPath(e.projection).context(null),o.materialize().reflow().visit(o.SOURCE,r)):(s.context(null),i=u===n.identity||t.modified(u.fields),o.visit(i?o.ADD_MOD:o.ADD,r)),o.modifies(f)},d.Definition={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"]}]},n.inherits(d,t.Transform).transform=function(e,t){function n(e){var t=i([a(e),o(e)]);t?(e[u]=t[0],e[f]=t[1]):(e[u]=void 0,e[f]=void 0)}var r,i=e.projection,a=e.fields[0],o=e.fields[1],s=e.as||["x","y"],u=s[0],f=s[1];return e.modified()?t=t.materialize().reflow(!0).visit(t.SOURCE,n):(r=t.modified(a.fields)||t.modified(o.fields),t.visit(r?t.ADD_MOD:t.ADD,n)),t.modifies(s)},c.Definition={type:"GeoShape",metadata:{modifies:!0},params:[{name:"projection",type:"projection"},{name:"field",type:"field",default:"datum"},{name:"as",type:"string",default:"shape"}]},n.inherits(c,t.Transform).transform=function(e,t){var r=t.fork(t.ALL),i=this.value,o=e.field||n.field("datum"),s=e.as||"shape",u=r.ADD_MOD;return i&&!e.modified()||(this.value=i=m(a.getProjectionPath(e.projection),o),r.materialize().reflow(),u=r.SOURCE),r.visit(u,function(e){e[s]=i}),r.modifies(s)},p.Definition={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}]},n.inherits(p,t.Transform).transform=function(e,r){var i,a=r.fork(),o=this.value,s=this.generator;if(!o.length||e.modified())for(var u in e)n.isFunction(s[u])&&s[u](e[u]);return i=s(),o.length?a.mod.push(t.replace(o[0],i)):a.add.push(t.ingest(i)),o[0]=i,a.source=o,a},n.inherits(h,t.Transform).transform=function(e,t){var n=this.value;return!n||e.modified("type")?(this.value=n=g(e.type),a.projectionProperties.forEach(function(t){null!=e[t]&&v(n,t,e[t])})):a.projectionProperties.forEach(function(t){e.modified(t)&&v(n,t,e[t])}),null!=e.pointRadius&&n.path.pointRadius(e.pointRadius),e.fit&&y(n,e),t.fork(t.NO_SOURCE|t.NO_FIELDS)},e.contour=s,e.geojson=f,e.geopath=l,e.geopoint=d,e.geoshape=c,e.graticule=p,e.projection=h,Object.defineProperty(e,"__esModule",{value:!0})}); |
export {default as contour} from './src/Contour'; | ||
export {default as geojson} from './src/GeoJSON'; | ||
export {default as geopath} from './src/GeoPath'; | ||
@@ -3,0 +4,0 @@ export {default as geopoint} from './src/GeoPoint'; |
{ | ||
"name": "vega-geo", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Geographic data transforms for Vega dataflows.", | ||
@@ -42,4 +42,5 @@ "keywords": [ | ||
"tape": "4", | ||
"uglify-js": "3" | ||
"uglify-js": "3", | ||
"vega-transforms": "1" | ||
} | ||
} |
@@ -8,2 +8,3 @@ # vega-geo | ||
- [**Contour**](https://vega.github.io/vega/docs/transforms/contour/) [<>](https://github.com/vega/vega-geo/blob/master/src/Contour.js "Source") | ||
- [**GeoJSON**](https://vega.github.io/vega/docs/transforms/geojson/) [<>](https://github.com/vega/vega-geo/blob/master/src/GeoJSON.js "Source") | ||
- [**GeoPath**](https://vega.github.io/vega/docs/transforms/geopath/) [<>](https://github.com/vega/vega-geo/blob/master/src/GeoPath.js "Source") | ||
@@ -10,0 +11,0 @@ - [**GeoPoint**](https://vega.github.io/vega/docs/transforms/geopoint/) [<>](https://github.com/vega/vega-geo/blob/master/src/GeoPoint.js "Source") |
@@ -0,4 +1,5 @@ | ||
import {FeatureCollection} from './constants'; | ||
import {Transform} from 'vega-dataflow'; | ||
import {projection, projectionProperties} from 'vega-projection'; | ||
import {error, inherits, isArray, isFunction} from 'vega-util'; | ||
import {array, error, inherits, isFunction} from 'vega-util'; | ||
@@ -38,3 +39,3 @@ /** | ||
function fit(proj, _) { | ||
var data = geoJSON(_.fit); | ||
var data = collectGeoJSON(_.fit); | ||
_.extent ? proj.fitExtent(_.extent, data) | ||
@@ -44,8 +45,2 @@ : _.size ? proj.fitSize(_.size, data) : 0; | ||
function geoJSON(data) { | ||
return !isArray(data) ? data | ||
: data.length > 1 ? {type: 'FeatureCollection', features: data} | ||
: data[0]; | ||
} | ||
function create(type) { | ||
@@ -59,2 +54,17 @@ var constructor = projection((type || 'mercator').toLowerCase()); | ||
if (isFunction(proj[key])) proj[key](value); | ||
} | ||
export function collectGeoJSON(features) { | ||
features = array(features); | ||
return features.length === 1 | ||
? features[0] | ||
: { | ||
type: FeatureCollection, | ||
features: features.reduce(function(list, f) { | ||
(f && f.type === FeatureCollection) | ||
? list.push.apply(list, f.features) | ||
: list.push(f); | ||
return list; | ||
}, []) | ||
}; | ||
} |
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
40742
16
824
20
5