Bar graph added.

This commit is contained in:
prabhatdev
2020-07-28 00:48:25 +05:30
parent d0a6e2667d
commit 194b41124d
3468 changed files with 640611 additions and 169 deletions

27
node_modules/vega-geo/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,27 @@
Copyright (c) 2015-2018, University of Washington Interactive Data Lab
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

21
node_modules/vega-geo/README.md generated vendored Normal file
View File

@@ -0,0 +1,21 @@
# vega-geo
Geographic data transforms for Vega dataflows.
This package provides the following Vega data transforms:
- [**Contour**](https://vega.github.io/vega/docs/transforms/contour/) [<>](https://github.com/vega/vega/blob/master/packages/vega-geo/src/Contour.js "Source") _deprecated!_
- [**GeoJSON**](https://vega.github.io/vega/docs/transforms/geojson/) [<>](https://github.com/vega/vega/blob/master/packages/vega-geo/src/GeoJSON.js "Source")
- [**GeoPath**](https://vega.github.io/vega/docs/transforms/geopath/) [<>](https://github.com/vega/vega/blob/master/packages/vega-geo/src/GeoPath.js "Source")
- [**GeoPoint**](https://vega.github.io/vega/docs/transforms/geopoint/) [<>](https://github.com/vega/vega/blob/master/packages/vega-geo/src/GeoPoint.js "Source")
- [**GeoShape**](https://vega.github.io/vega/docs/transforms/geoshape/) [<>](https://github.com/vega/vega/blob/master/packages/vega-geo/src/GeoShape.js "Source")
- [**Graticule**](https://vega.github.io/vega/docs/transforms/graticule/) [<>](https://github.com/vega/vega/blob/master/packages/vega-geo/src/Graticule.js "Source")
- [**Heatmap**](https://vega.github.io/vega/docs/transforms/heatmap/) [<>](https://github.com/vega/vega/blob/master/packages/vega-geo/src/Heatmap.js "Source")
- [**Isocontour**](https://vega.github.io/vega/docs/transforms/isocontour/) [<>](https://github.com/vega/vega/blob/master/packages/vega-geo/src/Isocontour.js "Source")
- [**KDE2D**](https://vega.github.io/vega/docs/transforms/kde2d/) [<>](https://github.com/vega/vega/blob/master/packages/vega-geo/src/KDE2D.js "Source")
And provides the following internal transform:
- **Projection** [<>](https://github.com/vega/vega/blob/master/packages/vega-geo/src/Projection.js "Source")
For more information about cartographic projections, see the [Vega Projections documentation](https://vega.github.io/vega/docs/projections/).

1245
node_modules/vega-geo/build/vega-geo.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

1
node_modules/vega-geo/build/vega-geo.min.js generated vendored Normal file

File diff suppressed because one or more lines are too long

10
node_modules/vega-geo/index.js generated vendored Normal file
View File

@@ -0,0 +1,10 @@
export {default as contour} from './src/Contour';
export {default as geojson} from './src/GeoJSON';
export {default as geopath} from './src/GeoPath';
export {default as geopoint} from './src/GeoPoint';
export {default as geoshape} from './src/GeoShape';
export {default as graticule} from './src/Graticule';
export {default as heatmap} from './src/Heatmap';
export {default as isocontour} from './src/Isocontour';
export {default as kde2d} from './src/KDE2D';
export {default as projection} from './src/Projection';

75
node_modules/vega-geo/package.json generated vendored Normal file
View File

@@ -0,0 +1,75 @@
{
"_from": "vega-geo@~4.3.4",
"_id": "vega-geo@4.3.4",
"_inBundle": false,
"_integrity": "sha512-sfMK1XGCLzMnfmy7fBJ2D+h8NG5WDwnSiPvcsjgwwAyonlUgCZWKdrNouAyLaRODy5ICZUEj/GDILSBdlIfUCg==",
"_location": "/vega-geo",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "vega-geo@~4.3.4",
"name": "vega-geo",
"escapedName": "vega-geo",
"rawSpec": "~4.3.4",
"saveSpec": null,
"fetchSpec": "~4.3.4"
},
"_requiredBy": [
"/vega"
],
"_resolved": "https://registry.npmjs.org/vega-geo/-/vega-geo-4.3.4.tgz",
"_shasum": "1bd26e438a304ff2596d51f57acee0e119e81313",
"_spec": "vega-geo@~4.3.4",
"_where": "/home/prabhatdev/Documents/opensource/gitHubStats/waka-readme-stats/node_modules/vega",
"author": {
"name": "Jeffrey Heer",
"url": "http://idl.cs.washington.edu"
},
"bugs": {
"url": "https://github.com/vega/vega/issues"
},
"bundleDependencies": false,
"dependencies": {
"d3-array": "^2.4.0",
"d3-color": "^1.4.1",
"d3-geo": "^1.12.1",
"vega-canvas": "^1.2.2",
"vega-dataflow": "^5.6.0",
"vega-projection": "^1.4.2",
"vega-statistics": "^1.7.5",
"vega-util": "^1.14.0"
},
"deprecated": false,
"description": "Geographic data transforms for Vega dataflows.",
"devDependencies": {
"vega-transforms": "*"
},
"gitHead": "62565bbe084a422c4a0cbc6e19c6f7c45a3e5137",
"homepage": "https://github.com/vega/vega#readme",
"keywords": [
"vega",
"geo",
"projection",
"graticule"
],
"license": "BSD-3-Clause",
"main": "build/vega-geo.js",
"module": "index",
"name": "vega-geo",
"repository": {
"type": "git",
"url": "git+https://github.com/vega/vega.git"
},
"scripts": {
"build": "yarn rollup",
"postbuild": "terser build/vega-geo.js -c -m -o build/vega-geo.min.js",
"postpublish": "git push && git push --tags",
"prebuild": "rimraf build && mkdir build",
"prepublishOnly": "yarn test && yarn build",
"pretest": "yarn prebuild && yarn rollup",
"rollup": "rollup -g d3-array:d3,d3-color:d3,d3-geo:d3,vega-canvas:vega,vega-dataflow:vega,vega-projection:vega,vega-statistics:vega,vega-util:vega -f umd -n vega.transforms -o build/vega-geo.js -- index.js",
"test": "tape 'test/**/*-test.js'"
},
"version": "4.3.4"
}

87
node_modules/vega-geo/src/Contour.js generated vendored Normal file
View File

@@ -0,0 +1,87 @@
import {Transform, ingest} from 'vega-dataflow';
import {inherits, isArray} from 'vega-util';
import {transform} from './Isocontour';
import {params} from './KDE2D';
import contours from './util/contours';
import density2D from './util/density2D';
import quantize from './util/quantize';
/**
* Generate contours based on kernel-density estimation of point data.
* @constructor
* @param {object} params - The parameters for this operator.
* @param {Array<number>} params.size - The dimensions [width, height] over which to compute contours.
* If the values parameter is provided, this must be the dimensions of the input data.
* If density estimation is performed, this is the output view dimensions in pixels.
* @param {Array<number>} [params.values] - An array of numeric values representing an
* width x height grid of values over which to compute contours. If unspecified, this
* transform will instead attempt to compute contours for the kernel density estimate
* using values drawn from data tuples in the input pulse.
* @param {function(object): number} [params.x] - The pixel x-coordinate accessor for density estimation.
* @param {function(object): number} [params.y] - The pixel y-coordinate accessor for density estimation.
* @param {function(object): number} [params.weight] - The data point weight accessor for density estimation.
* @param {number} [params.cellSize] - Contour density calculation cell size.
* @param {number} [params.bandwidth] - Kernel density estimation bandwidth.
* @param {Array<number>} [params.thresholds] - Contour threshold array. If
* this parameter is set, the count and nice 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.
* @param {boolean} [params.smooth] - Boolean flag indicating if the contour
* polygons should be smoothed using linear interpolation. The default is
* true. The parameter is ignored when using density estimation.
*/
export default function Contour(params) {
Transform.call(this, null, params);
}
Contour.Definition = {
'type': 'Contour',
'metadata': {'generates': true},
'params': [
{ 'name': 'size', 'type': 'number', 'array': true, 'length': 2, 'required': true },
{ 'name': 'values', 'type': 'number', 'array': true },
{ 'name': 'x', 'type': 'field' },
{ 'name': 'y', 'type': 'field' },
{ 'name': 'weight', 'type': 'field' },
{ 'name': 'cellSize', 'type': 'number' },
{ 'name': 'bandwidth', 'type': 'number' },
{ 'name': 'count', 'type': 'number' },
{ 'name': 'nice', 'type': 'boolean', 'default': false },
{ 'name': 'thresholds', 'type': 'number', 'array': true },
{ 'name': 'smooth', 'type': 'boolean', 'default': true }
]
};
var prototype = inherits(Contour, Transform);
prototype.transform = function(_, pulse) {
if (this.value && !pulse.changed() && !_.modified()) {
return pulse.StopPropagation;
}
var out = pulse.fork(pulse.NO_SOURCE | pulse.NO_FIELDS),
contour = contours().smooth(_.smooth !== false),
values = _.values,
thresh = _.thresholds || quantize(_.count || 10, _.nice, !!values),
size = _.size, grid, post;
if (!values) {
values = pulse.materialize(pulse.SOURCE).source;
grid = params(density2D(), _)(values, true);
post = transform(grid, grid.scale || 1, grid.scale || 1, 0, 0);
size = [grid.width, grid.height];
values = grid.values;
}
thresh = isArray(thresh) ? thresh : thresh(values);
values = contour.size(size)(values, thresh);
if (post) values.forEach(post);
if (this.value) out.rem = this.value;
this.value = out.source = out.add = (values || []).map(ingest);
return out;
};

81
node_modules/vega-geo/src/GeoJSON.js generated vendored Normal file
View File

@@ -0,0 +1,81 @@
import {Feature, FeatureCollection, MultiPoint} from './constants';
import {Transform} from 'vega-dataflow';
import {accessorFields, identity, inherits} from 'vega-util';
/**
* 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.
*/
export default function GeoJSON(params) {
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 = inherits(GeoJSON, Transform);
prototype.transform = function(_, pulse) {
var features = this._features,
points = this._points,
fields = _.fields,
lon = fields && fields[0],
lat = fields && fields[1],
geojson = _.geojson || (!fields && identity),
flag = pulse.ADD,
mod;
mod = _.modified()
|| pulse.changed(pulse.REM)
|| pulse.modified(accessorFields(geojson))
|| (lon && (pulse.modified(accessorFields(lon))))
|| (lat && (pulse.modified(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
};
};

66
node_modules/vega-geo/src/GeoPath.js generated vendored Normal file
View File

@@ -0,0 +1,66 @@
import {Transform} from 'vega-dataflow';
import {getProjectionPath} from 'vega-projection';
import {identity, inherits} from 'vega-util';
/**
* Map GeoJSON data to an SVG path string.
* @constructor
* @param {object} params - The parameters for this operator.
* @param {function(number, number): *} params.projection - The cartographic
* projection to apply.
* @param {function(object): *} [params.field] - The field with GeoJSON data,
* or null if the tuple itself is a GeoJSON feature.
* @param {string} [params.as='path'] - The output field in which to store
* the generated path data (default 'path').
*/
export default function GeoPath(params) {
Transform.call(this, null, params);
}
GeoPath.Definition = {
'type': 'GeoPath',
'metadata': {'modifies': true},
'params': [
{ 'name': 'projection', 'type': 'projection' },
{ 'name': 'field', 'type': 'field' },
{ 'name': 'pointRadius', 'type': 'number', 'expr': true },
{ 'name': 'as', 'type': 'string', 'default': 'path' }
]
};
var prototype = inherits(GeoPath, Transform);
prototype.transform = function(_, pulse) {
var out = pulse.fork(pulse.ALL),
path = this.value,
field = _.field || identity,
as = _.as || 'path',
flag = out.SOURCE;
function set(t) { t[as] = path(field(t)); }
if (!path || _.modified()) {
// parameters updated, reset and reflow
this.value = path = getProjectionPath(_.projection);
out.materialize().reflow();
} else {
flag = field === identity || pulse.modified(field.fields)
? out.ADD_MOD
: out.ADD;
}
var prev = initPath(path, _.pointRadius);
out.visit(flag, set);
path.pointRadius(prev);
return out.modifies(as);
};
function initPath(path, pointRadius) {
var prev = path.pointRadius();
path.context(null);
if (pointRadius != null) {
path.pointRadius(pointRadius);
}
return prev;
}

60
node_modules/vega-geo/src/GeoPoint.js generated vendored Normal file
View File

@@ -0,0 +1,60 @@
import {Transform} from 'vega-dataflow';
import {inherits} from 'vega-util';
/**
* Geo-code a longitude/latitude point to an x/y coordinate.
* @constructor
* @param {object} params - The parameters for this operator.
* @param {function(number, number): *} params.projection - The cartographic
* projection to apply.
* @param {Array<function(object): *>} params.fields - A two-element array of
* field accessors for the longitude and latitude values.
* @param {Array<string>} [params.as] - A two-element array of field names
* under which to store the result. Defaults to ['x','y'].
*/
export default function GeoPoint(params) {
Transform.call(this, null, params);
}
GeoPoint.Definition = {
'type': 'GeoPoint',
'metadata': {'modifies': true},
'params': [
{ 'name': 'projection', 'type': 'projection', 'required': true },
{ 'name': 'fields', 'type': 'field', 'array': true, 'required': true, 'length': 2 },
{ 'name': 'as', 'type': 'string', 'array': true, 'length': 2, 'default': ['x', 'y'] }
]
};
var prototype = inherits(GeoPoint, Transform);
prototype.transform = function(_, pulse) {
var proj = _.projection,
lon = _.fields[0],
lat = _.fields[1],
as = _.as || ['x', 'y'],
x = as[0],
y = as[1],
mod;
function set(t) {
var xy = proj([lon(t), lat(t)]);
if (xy) {
t[x] = xy[0];
t[y] = xy[1];
} else {
t[x] = undefined;
t[y] = undefined;
}
}
if (_.modified()) {
// parameters updated, reflow
pulse = pulse.materialize().reflow(true).visit(pulse.SOURCE, set);
} else {
mod = pulse.modified(lon.fields) || pulse.modified(lat.fields);
pulse.visit(mod ? pulse.ADD_MOD : pulse.ADD, set);
}
return pulse.modifies(as);
};

70
node_modules/vega-geo/src/GeoShape.js generated vendored Normal file
View File

@@ -0,0 +1,70 @@
import {Transform} from 'vega-dataflow';
import {getProjectionPath} from 'vega-projection';
import {field, inherits} from 'vega-util';
/**
* Annotate items with a geopath shape generator.
* @constructor
* @param {object} params - The parameters for this operator.
* @param {function(number, number): *} params.projection - The cartographic
* projection to apply.
* @param {function(object): *} [params.field] - The field with GeoJSON data,
* or null if the tuple itself is a GeoJSON feature.
* @param {string} [params.as='shape'] - The output field in which to store
* the generated path data (default 'shape').
*/
export default function GeoShape(params) {
Transform.call(this, null, params);
}
GeoShape.Definition = {
'type': 'GeoShape',
'metadata': {'modifies': true, 'nomod': true},
'params': [
{ 'name': 'projection', 'type': 'projection' },
{ 'name': 'field', 'type': 'field', 'default': 'datum' },
{ 'name': 'pointRadius', 'type': 'number', 'expr': true },
{ 'name': 'as', 'type': 'string', 'default': 'shape' }
]
};
var prototype = inherits(GeoShape, Transform);
prototype.transform = function(_, pulse) {
var out = pulse.fork(pulse.ALL),
shape = this.value,
as = _.as || 'shape',
flag = out.ADD;
if (!shape || _.modified()) {
// parameters updated, reset and reflow
this.value = shape = shapeGenerator(
getProjectionPath(_.projection),
_.field || field('datum'),
_.pointRadius
);
out.materialize().reflow();
flag = out.SOURCE;
}
out.visit(flag, function(t) { t[as] = shape; });
return out.modifies(as);
};
function shapeGenerator(path, field, pointRadius) {
var shape = pointRadius == null
? function(_) { return path(field(_)); }
: function(_) {
var prev = path.pointRadius(),
value = path.pointRadius(pointRadius)(field(_));
path.pointRadius(prev);
return value;
};
shape.context = function(_) {
path.context(_);
return shape;
};
return shape;
}

54
node_modules/vega-geo/src/Graticule.js generated vendored Normal file
View File

@@ -0,0 +1,54 @@
import {Transform, ingest, replace} from 'vega-dataflow';
import {inherits, isFunction} from 'vega-util';
import {geoGraticule} from 'd3-geo';
/**
* GeoJSON feature generator for creating graticules.
* @constructor
*/
export default function Graticule(params) {
Transform.call(this, [], params);
this.generator = geoGraticule();
}
Graticule.Definition = {
'type': 'Graticule',
'metadata': {'changes': true, 'generates': true},
'params': [
{ 'name': 'extent', 'type': 'array', 'array': true, 'length': 2,
'content': {'type': 'number', 'array': true, 'length': 2} },
{ 'name': 'extentMajor', 'type': 'array', 'array': true, 'length': 2,
'content': {'type': 'number', 'array': true, 'length': 2} },
{ 'name': 'extentMinor', 'type': 'array', 'array': true, 'length': 2,
'content': {'type': 'number', 'array': true, 'length': 2} },
{ 'name': 'step', 'type': 'number', 'array': true, 'length': 2 },
{ 'name': 'stepMajor', 'type': 'number', 'array': true, 'length': 2, 'default': [90, 360] },
{ 'name': 'stepMinor', 'type': 'number', 'array': true, 'length': 2, 'default': [10, 10] },
{ 'name': 'precision', 'type': 'number', 'default': 2.5 }
]
};
var prototype = inherits(Graticule, Transform);
prototype.transform = function(_, pulse) {
var src = this.value,
gen = this.generator, t;
if (!src.length || _.modified()) {
for (var prop in _) {
if (isFunction(gen[prop])) {
gen[prop](_[prop]);
}
}
}
t = gen();
if (src.length) {
pulse.mod.push(replace(src[0], t));
} else {
pulse.add.push(ingest(t));
}
src[0] = t;
return pulse;
};

149
node_modules/vega-geo/src/Heatmap.js generated vendored Normal file
View File

@@ -0,0 +1,149 @@
import {max} from 'd3-array';
import {rgb} from 'd3-color';
import {canvas} from 'vega-canvas';
import {Transform} from 'vega-dataflow';
import {
accessorFields, constant, extend, identity,
inherits, isFunction, toSet, zero
} from 'vega-util';
/**
* Render a heatmap image for input raster grid data.
* @constructor
* @param {object} params - The parameters for this operator.
* @param {function(object): *} [params.field] - The field with raster grid
* data. If unspecified, the tuple itself is interpreted as a raster grid.
* @param {string} [params.color] - A constant color value or function for
* individual pixel color. If a function, it will be invoked with an input
* object that includes $x, $y, $value, and $max fields for the grid.
* @param {number} [params.opacity] - A constant opacity value or function for
* individual pixel opacity. If a function, it will be invoked with an input
* object that includes $x, $y, $value, and $max fields for the grid.
* @param {string} [params.resolve] - The method for resolving maximum values
* across multiple input grids. If 'independent' (the default), maximum
* calculation will be performed separately for each grid. If 'shared',
* a single global maximum will be used for all input grids.
* @param {string} [params.as='image'] - The output field in which to store
* the generated bitmap canvas images (default 'image').
*/
export default function Heatmap(params) {
Transform.call(this, null, params);
}
Heatmap.Definition = {
'type': 'heatmap',
'metadata': {'modifies': true},
'params': [
{ 'name': 'field', 'type': 'field' },
{ 'name': 'color', 'type': 'string', 'expr': true},
{ 'name': 'opacity', 'type': 'number', 'expr': true},
{ 'name': 'resolve', 'type': 'enum', 'values': ['shared', 'independent'], 'default': 'independent' },
{ 'name': 'as', 'type': 'string', 'default': 'image' }
]
};
var prototype = inherits(Heatmap, Transform);
prototype.transform = function(_, pulse) {
if (!pulse.changed() && !_.modified()) {
return pulse.StopPropagation;
}
var source = pulse.materialize(pulse.SOURCE).source,
shared = _.resolve === 'shared',
field = _.field || identity,
opacity = opacity_(_.opacity, _),
color = color_(_.color, _),
as = _.as || 'image',
obj = {
$x: 0, $y: 0, $value: 0,
$max: shared ? max(source.map(t => max(field(t).values))) : 0
};
source.forEach(t => {
const v = field(t);
// build proxy data object
const o = extend({}, t, obj);
// set maximum value if not globally shared
if (!shared) o.$max = max(v.values || []);
// generate canvas image
// optimize color/opacity if not pixel-dependent
t[as] = toCanvas(v, o,
color.dep ? color : constant(color(o)),
opacity.dep ? opacity : constant(opacity(o))
);
});
return pulse.reflow(true).modifies(as);
};
// get image color function
function color_(color, _) {
let f;
if (isFunction(color)) {
f = obj => rgb(color(obj, _));
f.dep = dependency(color);
} else {
// default to mid-grey
f = constant(rgb(color || '#888'));
}
return f;
}
// get image opacity function
function opacity_(opacity, _) {
let f;
if (isFunction(opacity)) {
f = obj => opacity(obj, _);
f.dep = dependency(opacity);
} else if (opacity) {
f = constant(opacity);
} else {
// default to [0, max] opacity gradient
f = obj => (obj.$value / obj.$max) || 0;
f.dep = true;
}
return f;
}
// check if function depends on individual pixel data
function dependency(f) {
if (!isFunction(f)) return false;
const set = toSet(accessorFields(f));
return set.$x || set.$y || set.$value || set.$max;
}
// render raster grid to canvas
function toCanvas(grid, obj, color, opacity) {
const n = grid.width,
m = grid.height,
x1 = grid.x1 || 0,
y1 = grid.y1 || 0,
x2 = grid.x2 || n,
y2 = grid.y2 || m,
val = grid.values,
value = val ? i => val[i] : zero,
can = canvas(x2 - x1, y2 - y1),
ctx = can.getContext('2d'),
img = ctx.getImageData(0, 0, x2 - x1, y2 - y1),
pix = img.data;
for (let j=y1, k=0; j<y2; ++j) {
obj.$y = j - y1;
for (let i=x1, r=j*n; i<x2; ++i, k+=4) {
obj.$x = i - x1;
obj.$value = value(i + r);
const v = color(obj);
pix[k+0] = v.r;
pix[k+1] = v.g;
pix[k+2] = v.b;
pix[k+3] = ~~(255 * opacity(obj));
}
}
ctx.putImageData(img, 0, 0);
return can;
}

139
node_modules/vega-geo/src/Isocontour.js generated vendored Normal file
View File

@@ -0,0 +1,139 @@
import {max} from 'd3-array';
import {Transform, ingest, rederive} from 'vega-dataflow';
import {identity, inherits, isArray, isFunction, isNumber} from 'vega-util';
import contours from './util/contours';
import quantize from './util/quantize';
/**
* Generate isocontours (level sets) based on input raster grid data.
* @constructor
* @param {object} params - The parameters for this operator.
* @param {function(object): *} [params.field] - The field with raster grid
* data. If unspecified, the tuple itself is interpreted as a raster grid.
* @param {Array<number>} [params.thresholds] - Contour threshold array. If
* specified, the levels, nice, resolve, and zero parameters are ignored.
* @param {number} [params.levels] - The desired number of contour levels.
* @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 levels.
* @param {string} [params.resolve] - The method for resolving thresholds
* across multiple input grids. If 'independent' (the default), threshold
* calculation will be performed separately for each grid. If 'shared', a
* single set of threshold values will be used for all input grids.
* @param {boolean} [params.zero] - Boolean flag indicating if the contour
* threshold values should include zero.
* @param {boolean} [params.smooth] - Boolean flag indicating if the contour
* polygons should be smoothed using linear interpolation. The default is
* true. The parameter is ignored when using density estimation.
* @param {boolean} [params.scale] - Optional numerical value by which to
* scale the output isocontour coordinates. This parameter can be useful
* to scale the contours to match a desired output resolution.
* @param {string} [params.as='contour'] - The output field in which to store
* the generated isocontour data (default 'contour').
*/
export default function Isocontour(params) {
Transform.call(this, null, params);
}
Isocontour.Definition = {
'type': 'Isocontour',
'metadata': {'generates': true},
'params': [
{ 'name': 'field', 'type': 'field' },
{ 'name': 'thresholds', 'type': 'number', 'array': true },
{ 'name': 'levels', 'type': 'number' },
{ 'name': 'nice', 'type': 'boolean', 'default': false },
{ 'name': 'resolve', 'type': 'enum', 'values': ['shared', 'independent'], 'default': 'independent' },
{ 'name': 'zero', 'type': 'boolean', 'default': true },
{ 'name': 'smooth', 'type': 'boolean', 'default': true },
{ 'name': 'scale', 'type': 'number', 'expr': true },
{ 'name': 'translate', 'type': 'number', 'array': true, 'expr': true },
{ 'name': 'as', 'type': 'string', 'null': true, 'default': 'contour' }
]
};
var prototype = inherits(Isocontour, Transform);
prototype.transform = function(_, pulse) {
if (this.value && !pulse.changed() && !_.modified()) {
return pulse.StopPropagation;
}
var out = pulse.fork(pulse.NO_SOURCE | pulse.NO_FIELDS),
source = pulse.materialize(pulse.SOURCE).source,
field = _.field || identity,
contour = contours().smooth(_.smooth !== false),
tz = _.thresholds || levels(source, field, _),
as = _.as === null ? null : _.as || 'contour',
values = [];
source.forEach(t => {
const grid = field(t);
// generate contour paths in GeoJSON format
const paths = contour.size([grid.width, grid.height])(
grid.values, isArray(tz) ? tz : tz(grid.values)
);
// adjust contour path coordinates as needed
transformPaths(paths, grid, t, _);
// ingest; copy source data properties to output
paths.forEach(p => {
values.push(rederive(t, ingest(as != null ? {[as]: p} : p)));
});
});
if (this.value) out.rem = this.value;
this.value = out.source = out.add = values;
return out;
};
function levels(values, f, _) {
const q = quantize(_.levels || 10, _.nice, _.zero !== false);
return _.resolve !== 'shared'
? q
: q(values.map(t => max(f(t).values)));
}
function transformPaths(paths, grid, datum, _) {
let s = _.scale || grid.scale,
t = _.translate || grid.translate;
if (isFunction(s)) s = s(datum, _);
if (isFunction(t)) t = t(datum, _);
if ((s === 1 || s == null) && !t) return;
const sx = (isNumber(s) ? s : s[0]) || 1,
sy = (isNumber(s) ? s : s[1]) || 1,
tx = t && t[0] || 0,
ty = t && t[1] || 0;
paths.forEach(transform(grid, sx, sy, tx, ty));
}
export function transform(grid, sx, sy, tx, ty) {
const x1 = grid.x1 || 0,
y1 = grid.y1 || 0,
flip = sx * sy < 0;
function transformPolygon(coordinates) {
coordinates.forEach(transformRing);
}
function transformRing(coordinates) {
if (flip) coordinates.reverse(); // maintain winding order
coordinates.forEach(transformPoint);
}
function transformPoint(coordinates) {
coordinates[0] = (coordinates[0] - x1) * sx + tx;
coordinates[1] = (coordinates[1] - y1) * sy + ty;
}
return function(geometry) {
geometry.coordinates.forEach(transformPolygon);
return geometry;
};
}

112
node_modules/vega-geo/src/KDE2D.js generated vendored Normal file
View File

@@ -0,0 +1,112 @@
import density2D from './util/density2D';
import {Transform, ingest} from 'vega-dataflow';
import {accessorName, inherits} from 'vega-util';
/**
* Perform 2D kernel-density estimation of point data.
* @constructor
* @param {object} params - The parameters for this operator.
* @param {Array<number>} params.size - The [width, height] extent (in
* units of input pixels) over which to perform density estimation.
* @param {function(object): number} params.x - The x-coordinate accessor.
* @param {function(object): number} params.y - The y-coordinate accessor.
* @param {function(object): number} [params.weight] - The weight accessor.
* @param {Array<function(object): *>} [params.groupby] - An array of accessors
* to groupby.
* @param {number} [params.cellSize] - Contour density calculation cell size.
* This parameter determines the level of spatial approximation. For example,
* the default value of 4 maps to 2x reductions in both x- and y- dimensions.
* A value of 1 will result in an output raster grid whose dimensions exactly
* matches the size parameter.
* @param {Array<number>} [params.bandwidth] - The KDE kernel bandwidths,
* in pixels. The input can be a two-element array specifying separate
* x and y bandwidths, or a single-element array specifying both. If the
* bandwidth is unspecified or less than zero, the bandwidth will be
* automatically determined.
* @param {boolean} [params.counts=false] - A boolean flag indicating if the
* output values should be probability estimates (false, default) or
* smoothed counts (true).
* @param {string} [params.as='grid'] - The output field in which to store
* the generated raster grid (default 'grid').
*/
export default function KDE2D(params) {
Transform.call(this, null, params);
}
KDE2D.Definition = {
'type': 'KDE2D',
'metadata': {'generates': true},
'params': [
{ 'name': 'size', 'type': 'number', 'array': true, 'length': 2, 'required': true },
{ 'name': 'x', 'type': 'field', 'required': true },
{ 'name': 'y', 'type': 'field', 'required': true },
{ 'name': 'weight', 'type': 'field' },
{ 'name': 'groupby', 'type': 'field', 'array': true },
{ 'name': 'cellSize', 'type': 'number' },
{ 'name': 'bandwidth', 'type': 'number', 'array': true, 'length': 2 },
{ 'name': 'counts', 'type': 'boolean', 'default': false },
{ 'name': 'as', 'type': 'string', 'default': 'grid'}
]
};
var prototype = inherits(KDE2D, Transform);
const PARAMS = ['x', 'y', 'weight', 'size', 'cellSize', 'bandwidth'];
export function params(obj, _) {
PARAMS.forEach(param => _[param] != null ? obj[param](_[param]) : 0);
return obj;
}
prototype.transform = function(_, pulse) {
if (this.value && !pulse.changed() && !_.modified())
return pulse.StopPropagation;
var out = pulse.fork(pulse.NO_SOURCE | pulse.NO_FIELDS),
source = pulse.materialize(pulse.SOURCE).source,
groups = partition(source, _.groupby),
names = (_.groupby || []).map(accessorName),
kde = params(density2D(), _),
as = _.as || 'grid',
values = [];
function set(t, vals) {
for (let i=0; i<names.length; ++i) t[names[i]] = vals[i];
return t;
}
// generate density raster grids
values = groups.map(g => ingest(
set({[as]: kde(g, _.counts)}, g.dims)
));
if (this.value) out.rem = this.value;
this.value = out.source = out.add = values;
return out;
};
export function partition(data, groupby) {
var groups = [],
get = f => f(t),
map, i, n, t, k, g;
// partition data points into groups
if (groupby == null) {
groups.push(data);
} else {
for (map={}, i=0, n=data.length; i<n; ++i) {
t = data[i];
k = groupby.map(get);
g = map[k];
if (!g) {
map[k] = (g = []);
g.dims = k;
groups.push(g);
}
g.push(t);
}
}
return groups;
}

69
node_modules/vega-geo/src/Projection.js generated vendored Normal file
View File

@@ -0,0 +1,69 @@
import {Feature, FeatureCollection} from './constants';
import {Transform} from 'vega-dataflow';
import {projection, projectionProperties} from 'vega-projection';
import {array, error, inherits, isFunction} from 'vega-util';
/**
* Maintains a cartographic projection.
* @constructor
* @param {object} params - The parameters for this operator.
*/
export default function Projection(params) {
Transform.call(this, null, params);
this.modified(true); // always treat as modified
}
var prototype = inherits(Projection, Transform);
prototype.transform = function(_, pulse) {
var proj = this.value;
if (!proj || _.modified('type')) {
this.value = (proj = create(_.type));
projectionProperties.forEach(function(prop) {
if (_[prop] != null) set(proj, prop, _[prop]);
});
} else {
projectionProperties.forEach(function(prop) {
if (_.modified(prop)) set(proj, prop, _[prop]);
});
}
if (_.pointRadius != null) proj.path.pointRadius(_.pointRadius);
if (_.fit) fit(proj, _);
return pulse.fork(pulse.NO_SOURCE | pulse.NO_FIELDS);
};
function fit(proj, _) {
var data = collectGeoJSON(_.fit);
_.extent ? proj.fitExtent(_.extent, data)
: _.size ? proj.fitSize(_.size, data) : 0;
}
function create(type) {
var constructor = projection((type || 'mercator').toLowerCase());
if (!constructor) error('Unrecognized projection type: ' + type);
return constructor();
}
function set(proj, key, value) {
if (isFunction(proj[key])) proj[key](value);
}
export function collectGeoJSON(data) {
data = array(data);
return data.length === 1 ? data[0]
: {
type: FeatureCollection,
features: data.reduce((a, f) => a.concat(featurize(f)), [])
};
}
function featurize(f) {
return f.type === FeatureCollection
? f.features
: array(f).filter(d => d != null).map(
d => d.type === Feature ? d : {type: Feature, geometry: d}
);
}

3
node_modules/vega-geo/src/constants.js generated vendored Normal file
View File

@@ -0,0 +1,3 @@
export var Feature = 'Feature';
export var FeatureCollection = 'FeatureCollection';
export var MultiPoint = 'MultiPoint';

218
node_modules/vega-geo/src/util/contours.js generated vendored Normal file
View File

@@ -0,0 +1,218 @@
import {error} from 'vega-util';
function noop() {}
const cases = [
[],
[[[1.0, 1.5], [0.5, 1.0]]],
[[[1.5, 1.0], [1.0, 1.5]]],
[[[1.5, 1.0], [0.5, 1.0]]],
[[[1.0, 0.5], [1.5, 1.0]]],
[[[1.0, 1.5], [0.5, 1.0]], [[1.0, 0.5], [1.5, 1.0]]],
[[[1.0, 0.5], [1.0, 1.5]]],
[[[1.0, 0.5], [0.5, 1.0]]],
[[[0.5, 1.0], [1.0, 0.5]]],
[[[1.0, 1.5], [1.0, 0.5]]],
[[[0.5, 1.0], [1.0, 0.5]], [[1.5, 1.0], [1.0, 1.5]]],
[[[1.5, 1.0], [1.0, 0.5]]],
[[[0.5, 1.0], [1.5, 1.0]]],
[[[1.0, 1.5], [1.5, 1.0]]],
[[[0.5, 1.0], [1.0, 1.5]]],
[]
];
// Implementation adapted from d3/d3-contour. Thanks!
export default function() {
var dx = 1,
dy = 1,
smooth = smoothLinear;
function contours(values, tz) {
return tz.map(value => contour(values, value));
}
// Accumulate, smooth contour rings, assign holes to exterior rings.
// Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js
function contour(values, value) {
var polygons = [],
holes = [];
isorings(values, value, function(ring) {
smooth(ring, values, value);
if (area(ring) > 0) polygons.push([ring]);
else holes.push(ring);
});
holes.forEach(function(hole) {
for (var i = 0, n = polygons.length, polygon; i < n; ++i) {
if (contains((polygon = polygons[i])[0], hole) !== -1) {
polygon.push(hole);
return;
}
}
});
return {
type: 'MultiPolygon',
value: value,
coordinates: polygons
};
}
// Marching squares with isolines stitched into rings.
// Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js
function isorings(values, value, callback) {
var fragmentByStart = new Array,
fragmentByEnd = new Array,
x, y, t0, t1, t2, t3;
// Special case for the first row (y = -1, t2 = t3 = 0).
x = y = -1;
t1 = values[0] >= value;
cases[t1 << 1].forEach(stitch);
while (++x < dx - 1) {
t0 = t1, t1 = values[x + 1] >= value;
cases[t0 | t1 << 1].forEach(stitch);
}
cases[t1 << 0].forEach(stitch);
// General case for the intermediate rows.
while (++y < dy - 1) {
x = -1;
t1 = values[y * dx + dx] >= value;
t2 = values[y * dx] >= value;
cases[t1 << 1 | t2 << 2].forEach(stitch);
while (++x < dx - 1) {
t0 = t1, t1 = values[y * dx + dx + x + 1] >= value;
t3 = t2, t2 = values[y * dx + x + 1] >= value;
cases[t0 | t1 << 1 | t2 << 2 | t3 << 3].forEach(stitch);
}
cases[t1 | t2 << 3].forEach(stitch);
}
// Special case for the last row (y = dy - 1, t0 = t1 = 0).
x = -1;
t2 = values[y * dx] >= value;
cases[t2 << 2].forEach(stitch);
while (++x < dx - 1) {
t3 = t2, t2 = values[y * dx + x + 1] >= value;
cases[t2 << 2 | t3 << 3].forEach(stitch);
}
cases[t2 << 3].forEach(stitch);
function stitch(line) {
var start = [line[0][0] + x, line[0][1] + y],
end = [line[1][0] + x, line[1][1] + y],
startIndex = index(start),
endIndex = index(end),
f, g;
if (f = fragmentByEnd[startIndex]) {
if (g = fragmentByStart[endIndex]) {
delete fragmentByEnd[f.end];
delete fragmentByStart[g.start];
if (f === g) {
f.ring.push(end);
callback(f.ring);
} else {
fragmentByStart[f.start] = fragmentByEnd[g.end] = {start: f.start, end: g.end, ring: f.ring.concat(g.ring)};
}
} else {
delete fragmentByEnd[f.end];
f.ring.push(end);
fragmentByEnd[f.end = endIndex] = f;
}
} else if (f = fragmentByStart[endIndex]) {
if (g = fragmentByEnd[startIndex]) {
delete fragmentByStart[f.start];
delete fragmentByEnd[g.end];
if (f === g) {
f.ring.push(end);
callback(f.ring);
} else {
fragmentByStart[g.start] = fragmentByEnd[f.end] = {start: g.start, end: f.end, ring: g.ring.concat(f.ring)};
}
} else {
delete fragmentByStart[f.start];
f.ring.unshift(start);
fragmentByStart[f.start = startIndex] = f;
}
} else {
fragmentByStart[startIndex] = fragmentByEnd[endIndex] = {start: startIndex, end: endIndex, ring: [start, end]};
}
}
}
function index(point) {
return point[0] * 2 + point[1] * (dx + 1) * 4;
}
function smoothLinear(ring, values, value) {
ring.forEach(function(point) {
var x = point[0],
y = point[1],
xt = x | 0,
yt = y | 0,
v0,
v1 = values[yt * dx + xt];
if (x > 0 && x < dx && xt === x) {
v0 = values[yt * dx + xt - 1];
point[0] = x + (value - v0) / (v1 - v0) - 0.5;
}
if (y > 0 && y < dy && yt === y) {
v0 = values[(yt - 1) * dx + xt];
point[1] = y + (value - v0) / (v1 - v0) - 0.5;
}
});
}
contours.contour = contour;
contours.size = function(_) {
if (!arguments.length) return [dx, dy];
var _0 = Math.floor(_[0]), _1 = Math.floor(_[1]);
if (!(_0 >= 0 && _1 >= 0)) error('invalid size');
return dx = _0, dy = _1, contours;
};
contours.smooth = function(_) {
return arguments.length ? (smooth = _ ? smoothLinear : noop, contours) : smooth === smoothLinear;
};
return contours;
}
function area(ring) {
var i = 0,
n = ring.length,
area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1];
while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1];
return area;
}
function contains(ring, hole) {
var i = -1, n = hole.length, c;
while (++i < n) if (c = ringContains(ring, hole[i])) return c;
return 0;
}
function ringContains(ring, point) {
var x = point[0], y = point[1], contains = -1;
for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) {
var pi = ring[i], xi = pi[0], yi = pi[1], pj = ring[j], xj = pj[0], yj = pj[1];
if (segmentContains(pi, pj, point)) return 0;
if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) contains = -contains;
}
return contains;
}
function segmentContains(a, b, c) {
var i; return collinear(a, b, c) && within(a[i = +(a[0] === b[0])], c[i], b[i]);
}
function collinear(a, b, c) {
return (b[0] - a[0]) * (c[1] - a[1]) === (c[0] - a[0]) * (b[1] - a[1]);
}
function within(p, q, r) {
return p <= q && q <= r || r <= q && q <= p;
}

150
node_modules/vega-geo/src/util/density2D.js generated vendored Normal file
View File

@@ -0,0 +1,150 @@
import {bandwidthNRD} from 'vega-statistics';
import {array, constant, error, isFunction, one} from 'vega-util';
import {sum} from 'd3-array';
function radius(bw, data, f) {
const v = bw >= 0 ? bw : bandwidthNRD(data, f);
return Math.round((Math.sqrt(4 * v * v + 1) - 1) / 2);
}
function number(_) {
return isFunction(_) ? _ : constant(+_);
}
// Implementation adapted from d3/d3-contour. Thanks!
export default function() {
var x = d => d[0],
y = d => d[1],
weight = one,
bandwidth = [-1, -1],
dx = 960,
dy = 500,
k = 2; // log2(cellSize)
function density(data, counts) {
const rx = radius(bandwidth[0], data, x) >> k, // blur x-radius
ry = radius(bandwidth[1], data, y) >> k, // blur y-radius
ox = rx ? rx + 2 : 0, // x-offset padding for blur
oy = ry ? ry + 2 : 0, // y-offset padding for blur
n = 2 * ox + (dx >> k), // grid width
m = 2 * oy + (dy >> k), // grid height
values0 = new Float32Array(n * m),
values1 = new Float32Array(n * m);
let values = values0;
data.forEach(d => {
const xi = ox + (+x(d) >> k),
yi = oy + (+y(d) >> k);
if (xi >= 0 && xi < n && yi >= 0 && yi < m) {
values0[xi + yi * n] += +weight(d);
}
});
if (rx > 0 && ry > 0) {
blurX(n, m, values0, values1, rx);
blurY(n, m, values1, values0, ry);
blurX(n, m, values0, values1, rx);
blurY(n, m, values1, values0, ry);
blurX(n, m, values0, values1, rx);
blurY(n, m, values1, values0, ry);
} else if (rx > 0) {
blurX(n, m, values0, values1, rx);
blurX(n, m, values1, values0, rx);
blurX(n, m, values0, values1, rx);
values = values1;
} else if (ry > 0) {
blurY(n, m, values0, values1, ry);
blurY(n, m, values1, values0, ry);
blurY(n, m, values0, values1, ry);
values = values1;
}
// scale density estimates
// density in points per square pixel or probability density
let s = counts ? Math.pow(2, -2 * k) : 1 / sum(values);
for (let i=0, sz=n*m; i<sz; ++i) values[i] *= s;
return {
values: values,
scale: 1 << k,
width: n,
height: m,
x1: ox,
y1: oy,
x2: ox + (dx >> k),
y2: oy + (dy >> k)
};
}
density.x = function(_) {
return arguments.length ? (x = number(_), density) : x;
};
density.y = function(_) {
return arguments.length ? (y = number(_), density) : y;
};
density.weight = function(_) {
return arguments.length ? (weight = number(_), density) : weight;
};
density.size = function(_) {
if (!arguments.length) return [dx, dy];
var _0 = +_[0], _1 = +_[1];
if (!(_0 >= 0 && _1 >= 0)) error('invalid size');
return dx = _0, dy = _1, density;
};
density.cellSize = function(_) {
if (!arguments.length) return 1 << k;
if (!((_ = +_) >= 1)) error('invalid cell size');
k = Math.floor(Math.log(_) / Math.LN2);
return density;
};
density.bandwidth = function(_) {
if (!arguments.length) return bandwidth;
_ = array(_);
if (_.length === 1) _ = [+_[0], +_[0]];
if (_.length !== 2) error('invalid bandwidth');
return bandwidth = _, density;
};
return density;
}
function blurX(n, m, source, target, r) {
const w = (r << 1) + 1;
for (let j = 0; j < m; ++j) {
for (let i = 0, sr = 0; i < n + r; ++i) {
if (i < n) {
sr += source[i + j * n];
}
if (i >= r) {
if (i >= w) {
sr -= source[i - w + j * n];
}
target[i - r + j * n] = sr / Math.min(i + 1, n - 1 + w - i, w);
}
}
}
}
function blurY(n, m, source, target, r) {
const w = (r << 1) + 1;
for (let i = 0; i < n; ++i) {
for (let j = 0, sr = 0; j < m + r; ++j) {
if (j < m) {
sr += source[i + j * n];
}
if (j >= r) {
if (j >= w) {
sr -= source[i + (j - w) * n];
}
target[i + (j - r) * n] = sr / Math.min(j + 1, m - 1 + w - j, w);
}
}
}
}

13
node_modules/vega-geo/src/util/quantize.js generated vendored Normal file
View File

@@ -0,0 +1,13 @@
import {range, tickStep} from 'd3-array';
import {extent} from 'vega-util';
export default function(k, nice, zero) {
return function(values) {
var ex = extent(values),
start = zero ? Math.min(ex[0], 0) : ex[0],
stop = ex[1],
span = stop - start,
step = nice ? tickStep(start, stop, k) : (span / (k + 1));
return range(step, stop, step);
};
}