You've already forked wakapi-readme-stats
Bar graph added.
This commit is contained in:
27
node_modules/vega-loader/LICENSE
generated
vendored
Normal file
27
node_modules/vega-loader/LICENSE
generated
vendored
Normal 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.
|
||||
153
node_modules/vega-loader/README.md
generated
vendored
Normal file
153
node_modules/vega-loader/README.md
generated
vendored
Normal file
@@ -0,0 +1,153 @@
|
||||
# vega-loader
|
||||
|
||||
Network request and file loading utilities.
|
||||
|
||||
## API Reference
|
||||
|
||||
* [File Loading](#file-loading)
|
||||
* [Data Format Parsing](#data-format-parsing)
|
||||
|
||||
### File Loading
|
||||
|
||||
<a name="loader" href="#loader">#</a>
|
||||
vega.<b>loader</b>([<i>options</i>])
|
||||
[<>](https://github.com/vega/vega/blob/master/packages/vega-loader/src/loader.js "Source")
|
||||
|
||||
Creates a new loader instance with default *options*. A loader object provides methods for loading files from the network or disk, and for sanitizing requested URLs and filenames. If provided, the key-value pairs in the *options* object will be passed as default options to the various loader methods.
|
||||
|
||||
The *options* object can include the following entries:
|
||||
|
||||
- *baseURL*: A base URL prefix to append to provided *uri* values. This can
|
||||
be useful for applications that load multiple data sets from the same domain.
|
||||
- *mode*: A string explicitly indicating the loading mode. One of `'file'` (server-side only) or `'http'`. If set to `'file'` mode, later *uri* parameters may safely omit a `'file://'` prefix.
|
||||
- *defaultProtocol*: The default protocol to use for protocol-relative *uri* values (e.g., `'//vega.github.io'`). Defaults to `'http'`.
|
||||
- *target*: The browser `target` attribute for hyperlinks. Only applies when sanitizing *uri* values for use as a hyperlink.
|
||||
- *rel*: The browser `rel` attribute for hyperlinks. Only applies when sanitizing *uri* values for use as a hyperlink.
|
||||
- *http*: HTTP request parameters passed to underlying calls to [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API); see [RequestInit](https://fetch.spec.whatwg.org/#requestinit) for allowed properties.
|
||||
- *crossOrigin*: Specifies the [`crossOrigin` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image) to apply to an Image. Only applies when [sanitize](#load_sanitize) is invoked with the option `"context": "image"`. If this property is defined and maps to a value of `null` or `undefined`, then a `no-cors` fetch will be performed for the Image. This property can be used to override Vega's default behavior of using `crossOrigin="anonymous"`, which allows images loaded from a different host to be included in exported visualization images (and thereby avoid "tainted canvas errors"), so long as the server provides permission via proper CORS headers.
|
||||
|
||||
<a name="load" href="#load">#</a>
|
||||
loader.<b>load</b>(<i>uri</i>[, <i>options</i>])
|
||||
[<>](https://github.com/vega/vega/blob/master/packages/vega-loader/src/loader.js "Source")
|
||||
|
||||
Loads a file from either the network or disk, and returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) for asyncronously accessing the loaded content. This method does not perform any parsing, it simply returns the loaded data as either a Buffer or String instance, depending on the execution environment. To subsequently parse loaded data, use the [read](#read) method.
|
||||
|
||||
The *uri* argument is a value indicating the file to load. This is typically either an absolute or relative URL string. If running server-side via node.js, this argument might also be a file path (e.g., `'file:///path/to/file.txt'`).
|
||||
|
||||
If provided, the *options* argument will be combined with any default options passed to the [loader](#loader) constructor. In the case of identical property names, values from the *options* argument for this method will be used.
|
||||
|
||||
```js
|
||||
var loader = vega.loader();
|
||||
loader.load('data.json').then(function(data) {
|
||||
// do something with loaded data
|
||||
}).catch(function(error) {
|
||||
// error handling here
|
||||
});
|
||||
```
|
||||
|
||||
<a name="load_sanitize" href="load_sanitize">#</a>
|
||||
loader.<b>sanitize</b>(<i>uri</i>, <i>options</i>)
|
||||
[<>](https://github.com/vega/vega/blob/master/packages/vega-loader/src/loader.js "Source")
|
||||
|
||||
URI sanitizer function, which takes a *uri* and *options* object as input, and returns a Promise that resolves to a return object that includes a sanitized URL under the *href* property. This method is used internally by [load](#load) to ensure the URL is valid and to add additional protocol and hostname information, if needed. This method accepts the same *options* object accepted by [load](#load) and returns a Promise. If sanitization is successful, the Promise resolves to a return object containing the URL string as (_href_), along with a non-enumerable boolean _localFile_ flag, indicating if the file should be loaded from the local filesystem. The Promise rejects if the *uri* is invalid or disallowed. This method is over-writable for clients who wish to implement custom sanitization.
|
||||
|
||||
If provided, the *options* argument will be combined with any default options passed to the [loader](#loader) constructor. In the case of identical property names, values from the *options* argument for this method will be used.
|
||||
|
||||
<a name="load_http" href="load_http">#</a>
|
||||
loader.<b>http</b>(<i>url</i>, <i>options</i>)
|
||||
[<>](https://github.com/vega/vega/blob/master/packages/vega-loader/src/loader.js "Source")
|
||||
|
||||
Function used internally by [load](#load) for servicing HTTP requests. Uses [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) by default. Clients may overwrite this method to perform custom HTTP request handling.
|
||||
|
||||
If provided, the *options* argument may include any valid fetch [RequestInit](https://fetch.spec.whatwg.org/#requestinit) properties. The provided *options* will be combined with any default options passed to the [loader](#loader) constructor under the *http* property. In the case of identical property names, values from the *options* argument for this method will be used.
|
||||
|
||||
<a name="load_file" href="load_file">#</a>
|
||||
loader.<b>file</b>(<i>filename</i>)
|
||||
[<>](https://github.com/vega/vega/blob/master/packages/vega-loader/src/loader.js "Source")
|
||||
|
||||
Function used internally by [load](#load) for local file system requests. This method is over-writable for clients who wish to implement custom file loading. Uses the node.js [fs](https://nodejs.org/api/fs.html) module by default.
|
||||
|
||||
### Data Format Parsing
|
||||
|
||||
<a name="read" href="#read">#</a>
|
||||
vega.<b>read</b>(<i>data</i>, <i>schema</i>[, <i>dateParse</i>])
|
||||
[<>](https://github.com/vega/vega/blob/master/packages/vega-loader/src/read.js "Source")
|
||||
|
||||
Parse loaded *data* according to a given format *schema*. The *data* argument should be either a String or Buffer instance, typically the result of calling [load](#load).
|
||||
|
||||
The *schema* object contents may depend on the data format (see below). Common options include:
|
||||
|
||||
- *type*: The data format type, such as `json`, `csv`, `tsv`, or `topojson`.
|
||||
- *property*: For JSON types, specifies a property of the loaded JSON to reference. This is useful if a loaded JSON file contains multiple data sets and one would like to parse data under a specific property.
|
||||
- *parse*: When set to `'auto'`, the method will perform type inference (using the [inferTypes](#inferTypes) method) to determine data types of each field. Alternatively, callers can specify parsing rules by providing an object mapping field names to data types (for example: `{'timestamp': 'date', 'price': 'number'}`). The valid data type options are `'boolean'`, `'integer'`, `'number'`, `'date'`, and `'string'`.
|
||||
|
||||
The `'date'` data type also accepts an optional format string (`'date:format'`). If provided, the optional *dateParse* function is used to generate date-time parsers for a date format string. If *dateParse* is unspecified, the [d3-time-format](https://github.com/d3/d3-time-format) library is used by default. Date-time format strings may be quoted (`date:'%A'`), but quoting is not required. In addition, parsing of date-time format strings to UTC time is supported (`'utc:format'`).
|
||||
|
||||
```js
|
||||
// read loaded csv data, automatically infer value types
|
||||
var data = null;
|
||||
loader.load('data/stocks.csv').then(function(data) {
|
||||
data = vega.read(csv_data, {type: 'csv', parse: 'auto'});
|
||||
});
|
||||
```
|
||||
|
||||
```js
|
||||
// read loaded csv data, using provided value types
|
||||
var data = null;
|
||||
loader.load('data/stocks.csv').then(function(data) {
|
||||
data = vega.read(data, {
|
||||
type: 'csv',
|
||||
parse: {'date': 'date', 'price': 'number'}
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
```js
|
||||
// read loaded topojson data, extract mesh of countries
|
||||
var topojson = null;
|
||||
loader.load('data/world-110m.json').then(function(data) {
|
||||
topojson = vega.read(data, {type: 'topojson', mesh: 'countries'});
|
||||
});
|
||||
```
|
||||
|
||||
<a name="inferType" href="#inferType">#</a>
|
||||
vega.<b>inferType</b>(<i>values</i>[, <i>field</i>])
|
||||
[<>](https://github.com/vega/vega/blob/master/packages/vega-loader/src/type.js "Source")
|
||||
|
||||
Given an array of *values*, infers their data type as one of `'boolean'`, `'integer'`, `'number'`, `'date'`, or `'string'`. An optional *field* accessor can be used to first extract values from the input array, and is equivalent to first calling `values.map(field)`.
|
||||
|
||||
<a name="inferTypes" href="#inferTypes">#</a>
|
||||
vega.<b>inferTypes</b>(<i>data</i>, <i>fields</i>)
|
||||
[<>](https://github.com/vega/vega/blob/master/packages/vega-loader/src/type.js "Source")
|
||||
|
||||
Given an array of *data* objects and a list of string-typed field names (*fields*), infers the data type for each field. Returns an object that maps field names to inferred types, determined using the [inferType](#inferType) method.
|
||||
|
||||
<a name="typeParsers" href="#typeParsers">#</a>
|
||||
vega.<b>typeParsers</b>
|
||||
[<>](https://github.com/vega/vega/blob/master/packages/vega-loader/src/type.js "Source")
|
||||
|
||||
An object containing a set of parsing functions for converting input values to a specified data type. All parsing functions return `null` if the input is `null`, `undefined` or the empty string (`''`).
|
||||
|
||||
The supported functions are:
|
||||
|
||||
- typeParsers.<b>boolean</b>(<i>value</i>): Parse the input *value* to a Boolean.
|
||||
- typeParsers.<b>integer</b>(<i>value</i>): Parse the input *value* to an integer Number.
|
||||
- typeParsers.<b>number</b>(<i>value</i>): Parse the input *value* to a Number.
|
||||
- typeParsers.<b>date</b>(<i>value</i>[, <i>parser</i>]): Parse the input *value* to a Date. If provided, the *parser* function is used to interpret the *value*; otherwise `Date.parse` is used.
|
||||
- typeParsers.<b>string</b>(<i>value</i>): Parse the input *value* to a String. If *value* is not already string-typed, it is coerced to a String.
|
||||
|
||||
<a name="formats" href="#formats">#</a>
|
||||
vega.<b>formats</b>(<i>name</i>[, <i>format</i>])
|
||||
[<>](https://github.com/vega/vega/blob/master/packages/vega-loader/src/formats/index.js "Source")
|
||||
|
||||
Registry function for data format parsers. If invoked with two arguments, adds a new *format* parser with the provided *name*. Otherwise, returns an existing parser with the given *name*. The method signature of a format parser is:
|
||||
|
||||
- <b>format</b>(<i>data</i>, <i>options</i>)
|
||||
|
||||
A format parser that accepts two arguments, the input *data* to parse (e.g., a block of CSV text) and a set of format-specific *options*. The following data formats are registered by default:
|
||||
|
||||
- *dsv*: Delimiter-separated values format. Each line of text is a record, with each field separated by a delimiter string. Accepts a *delimiter* option indicating the delimiter string used to separate field values.
|
||||
- *csv*: Comma-separated values format. A *dsv* instance with a comma (`,`) delimiter.
|
||||
- *tsv*: Tab-separated values format. A *dsv* instance with a tab (`\t`) delimiter.
|
||||
- *json*: [JavaScript Object Notation (JSON)](https://en.wikipedia.org/wiki/JSON) format. Accepts a *property* option, indicating a sub-property of the parsed JSON to return; useful if a data array is nested within a larger object. Also accepts a *copy* option (default `false`), which will defensively copy a JSON Object that was passed to Vega directly, rather than parsed from a string.
|
||||
- *topojson*: [TopoJSON](https://github.com/mbostock/topojson/wiki) format for compressed encoding of geographic data. Requires either a *feature* option indicating the name of the geographic feature to extract (e.g., extracts individual paths for all countries), or a *mesh* option indicating a feature name for which a single mesh should be extracted (e.g., all country boundaries in a single path). Please see the [TopoJSON documentation](https://github.com/mbostock/topojson/wiki) for more.
|
||||
443
node_modules/vega-loader/build/vega-loader.js
generated
vendored
Normal file
443
node_modules/vega-loader/build/vega-loader.js
generated
vendored
Normal file
@@ -0,0 +1,443 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vega-util'), require('d3-dsv'), require('topojson-client'), require('vega-format')) :
|
||||
typeof define === 'function' && define.amd ? define(['exports', 'vega-util', 'd3-dsv', 'topojson-client', 'vega-format'], factory) :
|
||||
(global = global || self, factory(global.vega = {}, global.vega, global.d3, global.topojson, global.vega));
|
||||
}(this, (function (exports, vegaUtil, d3Dsv, topojsonClient, vegaFormat) { 'use strict';
|
||||
|
||||
// Matches absolute URLs with optional protocol
|
||||
// https://... file://... //...
|
||||
const protocol_re = /^([A-Za-z]+:)?\/\//;
|
||||
|
||||
// Matches allowed URIs. From https://github.com/cure53/DOMPurify/blob/master/src/regexp.js with added file://
|
||||
const allowed_re = /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp|file|data):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i; // eslint-disable-line no-useless-escape
|
||||
const whitespace_re = /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205f\u3000]/g; // eslint-disable-line no-control-regex
|
||||
|
||||
|
||||
// Special treatment in node.js for the file: protocol
|
||||
const fileProtocol = 'file://';
|
||||
|
||||
/**
|
||||
* Factory for a loader constructor that provides methods for requesting
|
||||
* files from either the network or disk, and for sanitizing request URIs.
|
||||
* @param {function} fetch - The Fetch API for HTTP network requests.
|
||||
* If null or undefined, HTTP loading will be disabled.
|
||||
* @param {object} fs - The file system interface for file loading.
|
||||
* If null or undefined, local file loading will be disabled.
|
||||
* @return {function} A loader constructor with the following signature:
|
||||
* param {object} [options] - Optional default loading options to use.
|
||||
* return {object} - A new loader instance.
|
||||
*/
|
||||
function loaderFactory(fetch, fs) {
|
||||
return function(options) {
|
||||
return {
|
||||
options: options || {},
|
||||
sanitize: sanitize,
|
||||
load: load,
|
||||
fileAccess: !!fs,
|
||||
file: fileLoader(fs),
|
||||
http: httpLoader(fetch)
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an external resource, typically either from the web or from the local
|
||||
* filesystem. This function uses {@link sanitize} to first sanitize the uri,
|
||||
* then calls either {@link http} (for web requests) or {@link file} (for
|
||||
* filesystem loading).
|
||||
* @param {string} uri - The resource indicator (e.g., URL or filename).
|
||||
* @param {object} [options] - Optional loading options. These options will
|
||||
* override any existing default options.
|
||||
* @return {Promise} - A promise that resolves to the loaded content.
|
||||
*/
|
||||
async function load(uri, options) {
|
||||
const opt = await this.sanitize(uri, options),
|
||||
url = opt.href;
|
||||
|
||||
return opt.localFile
|
||||
? this.file(url)
|
||||
: this.http(url, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* URI sanitizer function.
|
||||
* @param {string} uri - The uri (url or filename) to sanity check.
|
||||
* @param {object} options - An options hash.
|
||||
* @return {Promise} - A promise that resolves to an object containing
|
||||
* sanitized uri data, or rejects it the input uri is deemed invalid.
|
||||
* The properties of the resolved object are assumed to be
|
||||
* valid attributes for an HTML 'a' tag. The sanitized uri *must* be
|
||||
* provided by the 'href' property of the returned object.
|
||||
*/
|
||||
async function sanitize(uri, options) {
|
||||
options = vegaUtil.extend({}, this.options, options);
|
||||
|
||||
const fileAccess = this.fileAccess,
|
||||
result = {href: null};
|
||||
|
||||
let isFile, loadFile, base;
|
||||
|
||||
const isAllowed = allowed_re.test(uri.replace(whitespace_re, ''));
|
||||
|
||||
if (uri == null || typeof uri !== 'string' || !isAllowed) {
|
||||
vegaUtil.error('Sanitize failure, invalid URI: ' + vegaUtil.stringValue(uri));
|
||||
}
|
||||
|
||||
const hasProtocol = protocol_re.test(uri);
|
||||
|
||||
// if relative url (no protocol/host), prepend baseURL
|
||||
if ((base = options.baseURL) && !hasProtocol) {
|
||||
// Ensure that there is a slash between the baseURL (e.g. hostname) and url
|
||||
if (!uri.startsWith('/') && base[base.length-1] !== '/') {
|
||||
uri = '/' + uri;
|
||||
}
|
||||
uri = base + uri;
|
||||
}
|
||||
|
||||
// should we load from file system?
|
||||
loadFile = (isFile = uri.startsWith(fileProtocol))
|
||||
|| options.mode === 'file'
|
||||
|| options.mode !== 'http' && !hasProtocol && fileAccess;
|
||||
|
||||
if (isFile) {
|
||||
// strip file protocol
|
||||
uri = uri.slice(fileProtocol.length);
|
||||
} else if (uri.startsWith('//')) {
|
||||
if (options.defaultProtocol === 'file') {
|
||||
// if is file, strip protocol and set loadFile flag
|
||||
uri = uri.slice(2);
|
||||
loadFile = true;
|
||||
} else {
|
||||
// if relative protocol (starts with '//'), prepend default protocol
|
||||
uri = (options.defaultProtocol || 'http') + ':' + uri;
|
||||
}
|
||||
}
|
||||
|
||||
// set non-enumerable mode flag to indicate local file load
|
||||
Object.defineProperty(result, 'localFile', {value: !!loadFile});
|
||||
|
||||
// set uri
|
||||
result.href = uri;
|
||||
|
||||
// set default result target, if specified
|
||||
if (options.target) {
|
||||
result.target = options.target + '';
|
||||
}
|
||||
|
||||
// set default result rel, if specified (#1542)
|
||||
if (options.rel) {
|
||||
result.rel = options.rel + '';
|
||||
}
|
||||
|
||||
// provide control over cross-origin image handling (#2238)
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image
|
||||
if (options.context === 'image' && options.crossOrigin) {
|
||||
result.crossOrigin = options.crossOrigin + '';
|
||||
}
|
||||
|
||||
// return
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* File system loader factory.
|
||||
* @param {object} fs - The file system interface.
|
||||
* @return {function} - A file loader with the following signature:
|
||||
* param {string} filename - The file system path to load.
|
||||
* param {string} filename - The file system path to load.
|
||||
* return {Promise} A promise that resolves to the file contents.
|
||||
*/
|
||||
function fileLoader(fs) {
|
||||
return fs
|
||||
? function(filename) {
|
||||
return new Promise(function(accept, reject) {
|
||||
fs.readFile(filename, function(error, data) {
|
||||
if (error) reject(error);
|
||||
else accept(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
: fileReject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default file system loader that simply rejects.
|
||||
*/
|
||||
async function fileReject() {
|
||||
vegaUtil.error('No file system access.');
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP request handler factory.
|
||||
* @param {function} fetch - The Fetch API method.
|
||||
* @return {function} - An http loader with the following signature:
|
||||
* param {string} url - The url to request.
|
||||
* param {object} options - An options hash.
|
||||
* return {Promise} - A promise that resolves to the file contents.
|
||||
*/
|
||||
function httpLoader(fetch) {
|
||||
return fetch
|
||||
? async function(url, options) {
|
||||
const opt = vegaUtil.extend({}, this.options.http, options),
|
||||
type = options && options.response,
|
||||
response = await fetch(url, opt);
|
||||
|
||||
return !response.ok
|
||||
? vegaUtil.error(response.status + '' + response.statusText)
|
||||
: vegaUtil.isFunction(response[type]) ? response[type]()
|
||||
: response.text();
|
||||
}
|
||||
: httpReject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default http request handler that simply rejects.
|
||||
*/
|
||||
async function httpReject() {
|
||||
vegaUtil.error('No HTTP fetch method available.');
|
||||
}
|
||||
|
||||
var typeParsers = {
|
||||
boolean: vegaUtil.toBoolean,
|
||||
integer: vegaUtil.toNumber,
|
||||
number: vegaUtil.toNumber,
|
||||
date: vegaUtil.toDate,
|
||||
string: vegaUtil.toString,
|
||||
unknown: vegaUtil.identity
|
||||
};
|
||||
|
||||
var typeTests = [
|
||||
isBoolean,
|
||||
isInteger,
|
||||
isNumber,
|
||||
isDate
|
||||
];
|
||||
|
||||
var typeList = [
|
||||
'boolean',
|
||||
'integer',
|
||||
'number',
|
||||
'date'
|
||||
];
|
||||
|
||||
function inferType(values, field) {
|
||||
if (!values || !values.length) return 'unknown';
|
||||
|
||||
const n = values.length,
|
||||
m = typeTests.length,
|
||||
a = typeTests.map((_, i) => i + 1);
|
||||
|
||||
for (let i = 0, t = 0, j, value; i < n; ++i) {
|
||||
value = field ? values[i][field] : values[i];
|
||||
for (j = 0; j < m; ++j) {
|
||||
if (a[j] && isValid(value) && !typeTests[j](value)) {
|
||||
a[j] = 0;
|
||||
++t;
|
||||
if (t === typeTests.length) return 'string';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return typeList[
|
||||
a.reduce((u, v) => u === 0 ? v : u, 0) - 1
|
||||
];
|
||||
}
|
||||
|
||||
function inferTypes(data, fields) {
|
||||
return fields.reduce(function(types, field) {
|
||||
types[field] = inferType(data, field);
|
||||
return types;
|
||||
}, {});
|
||||
}
|
||||
|
||||
// -- Type Checks ----
|
||||
|
||||
function isValid(_) {
|
||||
return _ != null && _ === _;
|
||||
}
|
||||
|
||||
function isBoolean(_) {
|
||||
return _ === 'true' || _ === 'false' || _ === true || _ === false;
|
||||
}
|
||||
|
||||
function isDate(_) {
|
||||
return !Number.isNaN(Date.parse(_));
|
||||
}
|
||||
|
||||
function isNumber(_) {
|
||||
return !Number.isNaN(+_) && !(_ instanceof Date);
|
||||
}
|
||||
|
||||
function isInteger(_) {
|
||||
return isNumber(_) && Number.isInteger(+_);
|
||||
}
|
||||
|
||||
function delimitedFormat(delimiter) {
|
||||
const parse = function(data, format) {
|
||||
const delim = {delimiter: delimiter};
|
||||
return dsv(data, format ? vegaUtil.extend(format, delim) : delim);
|
||||
};
|
||||
|
||||
parse.responseType = 'text';
|
||||
|
||||
return parse;
|
||||
}
|
||||
|
||||
function dsv(data, format) {
|
||||
if (format.header) {
|
||||
data = format.header
|
||||
.map(vegaUtil.stringValue)
|
||||
.join(format.delimiter) + '\n' + data;
|
||||
}
|
||||
return d3Dsv.dsvFormat(format.delimiter).parse(data + '');
|
||||
}
|
||||
|
||||
dsv.responseType = 'text';
|
||||
|
||||
function isBuffer(_) {
|
||||
return (typeof Buffer === 'function' && vegaUtil.isFunction(Buffer.isBuffer))
|
||||
? Buffer.isBuffer(_) : false;
|
||||
}
|
||||
|
||||
function json(data, format) {
|
||||
const prop = (format && format.property) ? vegaUtil.field(format.property) : vegaUtil.identity;
|
||||
return vegaUtil.isObject(data) && !isBuffer(data)
|
||||
? parseJSON(prop(data))
|
||||
: prop(JSON.parse(data));
|
||||
}
|
||||
|
||||
json.responseType = 'json';
|
||||
|
||||
function parseJSON(data, format) {
|
||||
return (format && format.copy)
|
||||
? JSON.parse(JSON.stringify(data))
|
||||
: data;
|
||||
}
|
||||
|
||||
const filters = {
|
||||
interior: (a, b) => a !== b,
|
||||
exterior: (a, b) => a === b
|
||||
};
|
||||
|
||||
function topojson(data, format) {
|
||||
let method, object, property, filter;
|
||||
data = json(data, format);
|
||||
|
||||
if (format && format.feature) {
|
||||
method = topojsonClient.feature;
|
||||
property = format.feature;
|
||||
} else if (format && format.mesh) {
|
||||
method = topojsonClient.mesh;
|
||||
property = format.mesh;
|
||||
filter = filters[format.filter];
|
||||
} else {
|
||||
vegaUtil.error('Missing TopoJSON feature or mesh parameter.');
|
||||
}
|
||||
|
||||
object = (object = data.objects[property])
|
||||
? method(data, object, filter)
|
||||
: vegaUtil.error('Invalid TopoJSON object: ' + property);
|
||||
|
||||
return object && object.features || [object];
|
||||
}
|
||||
|
||||
topojson.responseType = 'json';
|
||||
|
||||
const format = {
|
||||
dsv: dsv,
|
||||
csv: delimitedFormat(','),
|
||||
tsv: delimitedFormat('\t'),
|
||||
json: json,
|
||||
topojson: topojson
|
||||
};
|
||||
|
||||
function formats(name, reader) {
|
||||
if (arguments.length > 1) {
|
||||
format[name] = reader;
|
||||
return this;
|
||||
} else {
|
||||
return vegaUtil.hasOwnProperty(format, name) ? format[name] : null;
|
||||
}
|
||||
}
|
||||
|
||||
function responseType(type) {
|
||||
const f = formats(type);
|
||||
return f && f.responseType || 'text';
|
||||
}
|
||||
|
||||
function read(data, schema, timeParser, utcParser) {
|
||||
schema = schema || {};
|
||||
|
||||
const reader = formats(schema.type || 'json');
|
||||
if (!reader) vegaUtil.error('Unknown data format type: ' + schema.type);
|
||||
|
||||
data = reader(data, schema);
|
||||
if (schema.parse) parse(data, schema.parse, timeParser, utcParser);
|
||||
|
||||
if (vegaUtil.hasOwnProperty(data, 'columns')) delete data.columns;
|
||||
return data;
|
||||
}
|
||||
|
||||
function parse(data, types, timeParser, utcParser) {
|
||||
if (!data.length) return; // early exit for empty data
|
||||
|
||||
const locale = vegaFormat.timeFormatDefaultLocale();
|
||||
timeParser = timeParser || locale.timeParse;
|
||||
utcParser = utcParser || locale.utcParse;
|
||||
|
||||
var fields = data.columns || Object.keys(data[0]),
|
||||
parsers, datum, field, i, j, n, m;
|
||||
|
||||
if (types === 'auto') types = inferTypes(data, fields);
|
||||
|
||||
fields = Object.keys(types);
|
||||
parsers = fields.map(function(field) {
|
||||
var type = types[field],
|
||||
parts, pattern;
|
||||
|
||||
if (type && (type.startsWith('date:') || type.startsWith('utc:'))) {
|
||||
parts = type.split(/:(.+)?/, 2); // split on first :
|
||||
pattern = parts[1];
|
||||
|
||||
if ((pattern[0] === '\'' && pattern[pattern.length-1] === '\'') ||
|
||||
(pattern[0] === '"' && pattern[pattern.length-1] === '"')) {
|
||||
pattern = pattern.slice(1, -1);
|
||||
}
|
||||
|
||||
const parse = parts[0] === 'utc' ? utcParser : timeParser;
|
||||
return parse(pattern);
|
||||
}
|
||||
|
||||
if (!typeParsers[type]) {
|
||||
throw Error('Illegal format pattern: ' + field + ':' + type);
|
||||
}
|
||||
|
||||
return typeParsers[type];
|
||||
});
|
||||
|
||||
for (i=0, n=data.length, m=fields.length; i<n; ++i) {
|
||||
datum = data[i];
|
||||
for (j=0; j<m; ++j) {
|
||||
field = fields[j];
|
||||
datum[field] = parsers[j](datum[field]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var loader = loaderFactory(
|
||||
typeof fetch !== 'undefined' && fetch, // use built-in fetch API
|
||||
null // no file system access
|
||||
);
|
||||
|
||||
exports.format = format;
|
||||
exports.formats = formats;
|
||||
exports.inferType = inferType;
|
||||
exports.inferTypes = inferTypes;
|
||||
exports.loader = loader;
|
||||
exports.read = read;
|
||||
exports.responseType = responseType;
|
||||
exports.typeParsers = typeParsers;
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
})));
|
||||
1
node_modules/vega-loader/build/vega-loader.min.js
generated
vendored
Normal file
1
node_modules/vega-loader/build/vega-loader.min.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vega-util"),require("d3-dsv"),require("topojson-client"),require("vega-format")):"function"==typeof define&&define.amd?define(["exports","vega-util","d3-dsv","topojson-client","vega-format"],t):t((e=e||self).vega={},e.vega,e.d3,e.topojson,e.vega)}(this,(function(e,t,n,r,o){"use strict";const i=/^([A-Za-z]+:)?\/\//,s=/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp|file|data):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i,u=/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205f\u3000]/g;async function a(e,t){const n=await this.sanitize(e,t),r=n.href;return n.localFile?this.file(r):this.http(r,t)}async function f(e,n){n=t.extend({},this.options,n);const r=this.fileAccess,o={href:null};let a,f,c;const l=s.test(e.replace(u,""));null!=e&&"string"==typeof e&&l||t.error("Sanitize failure, invalid URI: "+t.stringValue(e));const p=i.test(e);return(c=n.baseURL)&&!p&&(e.startsWith("/")||"/"===c[c.length-1]||(e="/"+e),e=c+e),f=(a=e.startsWith("file://"))||"file"===n.mode||"http"!==n.mode&&!p&&r,a?e=e.slice("file://".length):e.startsWith("//")&&("file"===n.defaultProtocol?(e=e.slice(2),f=!0):e=(n.defaultProtocol||"http")+":"+e),Object.defineProperty(o,"localFile",{value:!!f}),o.href=e,n.target&&(o.target=n.target+""),n.rel&&(o.rel=n.rel+""),"image"===n.context&&n.crossOrigin&&(o.crossOrigin=n.crossOrigin+""),o}function c(e){return e?function(t){return new Promise((function(n,r){e.readFile(t,(function(e,t){e?r(e):n(t)}))}))}:l}async function l(){t.error("No file system access.")}function p(e){return e?async function(n,r){const o=t.extend({},this.options.http,r),i=r&&r.response,s=await e(n,o);return s.ok?t.isFunction(s[i])?s[i]():s.text():t.error(s.status+""+s.statusText)}:d}async function d(){t.error("No HTTP fetch method available.")}var h={boolean:t.toBoolean,integer:t.toNumber,number:t.toNumber,date:t.toDate,string:t.toString,unknown:t.identity},m=[function(e){return"true"===e||"false"===e||!0===e||!1===e},function(e){return b(e)&&Number.isInteger(+e)},b,function(e){return!Number.isNaN(Date.parse(e))}],g=["boolean","integer","number","date"];function y(e,t){if(!e||!e.length)return"unknown";const n=e.length,r=m.length,o=m.map((e,t)=>t+1);for(let s,u,a=0,f=0;a<n;++a)for(u=t?e[a][t]:e[a],s=0;s<r;++s)if(o[s]&&(null!=(i=u)&&i==i)&&!m[s](u)&&(o[s]=0,++f,f===m.length))return"string";var i;return g[o.reduce((e,t)=>0===e?t:e,0)-1]}function v(e,t){return t.reduce((function(t,n){return t[n]=y(e,n),t}),{})}function b(e){return!(Number.isNaN(+e)||e instanceof Date)}function j(e){const n=function(n,r){const o={delimiter:e};return N(n,r?t.extend(r,o):o)};return n.responseType="text",n}function N(e,r){return r.header&&(e=r.header.map(t.stringValue).join(r.delimiter)+"\n"+e),n.dsvFormat(r.delimiter).parse(e+"")}function O(e,n){const r=n&&n.property?t.field(n.property):t.identity;return!t.isObject(e)||(o=e,"function"==typeof Buffer&&t.isFunction(Buffer.isBuffer)&&Buffer.isBuffer(o))?r(JSON.parse(e)):function(e,t){return t&&t.copy?JSON.parse(JSON.stringify(e)):e}(r(e));var o}N.responseType="text",O.responseType="json";const x={interior:(e,t)=>e!==t,exterior:(e,t)=>e===t};function T(e,n){let o,i,s,u;return e=O(e,n),n&&n.feature?(o=r.feature,s=n.feature):n&&n.mesh?(o=r.mesh,s=n.mesh,u=x[n.filter]):t.error("Missing TopoJSON feature or mesh parameter."),i=(i=e.objects[s])?o(e,i,u):t.error("Invalid TopoJSON object: "+s),i&&i.features||[i]}T.responseType="json";const P={dsv:N,csv:j(","),tsv:j("\t"),json:O,topojson:T};function w(e,n){return arguments.length>1?(P[e]=n,this):t.hasOwnProperty(P,e)?P[e]:null}var z=function(e,t){return function(n){return{options:n||{},sanitize:f,load:a,fileAccess:!!t,file:c(t),http:p(e)}}}("undefined"!=typeof fetch&&fetch,null);e.format=P,e.formats=w,e.inferType=y,e.inferTypes=v,e.loader=z,e.read=function(e,n,r,i){const s=w((n=n||{}).type||"json");return s||t.error("Unknown data format type: "+n.type),e=s(e,n),n.parse&&function(e,t,n,r){if(!e.length)return;const i=o.timeFormatDefaultLocale();n=n||i.timeParse,r=r||i.utcParse;var s,u,a,f,c,l,p,d=e.columns||Object.keys(e[0]);"auto"===t&&(t=v(e,d));for(d=Object.keys(t),s=d.map((function(e){var o,i,s=t[e];if(s&&(s.startsWith("date:")||s.startsWith("utc:"))){return("'"===(i=(o=s.split(/:(.+)?/,2))[1])[0]&&"'"===i[i.length-1]||'"'===i[0]&&'"'===i[i.length-1])&&(i=i.slice(1,-1)),("utc"===o[0]?r:n)(i)}if(!h[s])throw Error("Illegal format pattern: "+e+":"+s);return h[s]})),f=0,l=e.length,p=d.length;f<l;++f)for(u=e[f],c=0;c<p;++c)a=d[c],u[a]=s[c](u[a])}(e,n.parse,r,i),t.hasOwnProperty(e,"columns")&&delete e.columns,e},e.responseType=function(e){const t=w(e);return t&&t.responseType||"text"},e.typeParsers=h,Object.defineProperty(e,"__esModule",{value:!0})}));
|
||||
442
node_modules/vega-loader/build/vega-loader.node.js
generated
vendored
Normal file
442
node_modules/vega-loader/build/vega-loader.node.js
generated
vendored
Normal file
@@ -0,0 +1,442 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var vegaUtil = require('vega-util');
|
||||
var d3Dsv = require('d3-dsv');
|
||||
var topojsonClient = require('topojson-client');
|
||||
var vegaFormat = require('vega-format');
|
||||
|
||||
// Matches absolute URLs with optional protocol
|
||||
// https://... file://... //...
|
||||
const protocol_re = /^([A-Za-z]+:)?\/\//;
|
||||
|
||||
// Matches allowed URIs. From https://github.com/cure53/DOMPurify/blob/master/src/regexp.js with added file://
|
||||
const allowed_re = /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp|file|data):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i; // eslint-disable-line no-useless-escape
|
||||
const whitespace_re = /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205f\u3000]/g; // eslint-disable-line no-control-regex
|
||||
|
||||
|
||||
// Special treatment in node.js for the file: protocol
|
||||
const fileProtocol = 'file://';
|
||||
|
||||
/**
|
||||
* Factory for a loader constructor that provides methods for requesting
|
||||
* files from either the network or disk, and for sanitizing request URIs.
|
||||
* @param {function} fetch - The Fetch API for HTTP network requests.
|
||||
* If null or undefined, HTTP loading will be disabled.
|
||||
* @param {object} fs - The file system interface for file loading.
|
||||
* If null or undefined, local file loading will be disabled.
|
||||
* @return {function} A loader constructor with the following signature:
|
||||
* param {object} [options] - Optional default loading options to use.
|
||||
* return {object} - A new loader instance.
|
||||
*/
|
||||
function loaderFactory(fetch, fs) {
|
||||
return function(options) {
|
||||
return {
|
||||
options: options || {},
|
||||
sanitize: sanitize,
|
||||
load: load,
|
||||
fileAccess: !!fs,
|
||||
file: fileLoader(fs),
|
||||
http: httpLoader(fetch)
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an external resource, typically either from the web or from the local
|
||||
* filesystem. This function uses {@link sanitize} to first sanitize the uri,
|
||||
* then calls either {@link http} (for web requests) or {@link file} (for
|
||||
* filesystem loading).
|
||||
* @param {string} uri - The resource indicator (e.g., URL or filename).
|
||||
* @param {object} [options] - Optional loading options. These options will
|
||||
* override any existing default options.
|
||||
* @return {Promise} - A promise that resolves to the loaded content.
|
||||
*/
|
||||
async function load(uri, options) {
|
||||
const opt = await this.sanitize(uri, options),
|
||||
url = opt.href;
|
||||
|
||||
return opt.localFile
|
||||
? this.file(url)
|
||||
: this.http(url, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* URI sanitizer function.
|
||||
* @param {string} uri - The uri (url or filename) to sanity check.
|
||||
* @param {object} options - An options hash.
|
||||
* @return {Promise} - A promise that resolves to an object containing
|
||||
* sanitized uri data, or rejects it the input uri is deemed invalid.
|
||||
* The properties of the resolved object are assumed to be
|
||||
* valid attributes for an HTML 'a' tag. The sanitized uri *must* be
|
||||
* provided by the 'href' property of the returned object.
|
||||
*/
|
||||
async function sanitize(uri, options) {
|
||||
options = vegaUtil.extend({}, this.options, options);
|
||||
|
||||
const fileAccess = this.fileAccess,
|
||||
result = {href: null};
|
||||
|
||||
let isFile, loadFile, base;
|
||||
|
||||
const isAllowed = allowed_re.test(uri.replace(whitespace_re, ''));
|
||||
|
||||
if (uri == null || typeof uri !== 'string' || !isAllowed) {
|
||||
vegaUtil.error('Sanitize failure, invalid URI: ' + vegaUtil.stringValue(uri));
|
||||
}
|
||||
|
||||
const hasProtocol = protocol_re.test(uri);
|
||||
|
||||
// if relative url (no protocol/host), prepend baseURL
|
||||
if ((base = options.baseURL) && !hasProtocol) {
|
||||
// Ensure that there is a slash between the baseURL (e.g. hostname) and url
|
||||
if (!uri.startsWith('/') && base[base.length-1] !== '/') {
|
||||
uri = '/' + uri;
|
||||
}
|
||||
uri = base + uri;
|
||||
}
|
||||
|
||||
// should we load from file system?
|
||||
loadFile = (isFile = uri.startsWith(fileProtocol))
|
||||
|| options.mode === 'file'
|
||||
|| options.mode !== 'http' && !hasProtocol && fileAccess;
|
||||
|
||||
if (isFile) {
|
||||
// strip file protocol
|
||||
uri = uri.slice(fileProtocol.length);
|
||||
} else if (uri.startsWith('//')) {
|
||||
if (options.defaultProtocol === 'file') {
|
||||
// if is file, strip protocol and set loadFile flag
|
||||
uri = uri.slice(2);
|
||||
loadFile = true;
|
||||
} else {
|
||||
// if relative protocol (starts with '//'), prepend default protocol
|
||||
uri = (options.defaultProtocol || 'http') + ':' + uri;
|
||||
}
|
||||
}
|
||||
|
||||
// set non-enumerable mode flag to indicate local file load
|
||||
Object.defineProperty(result, 'localFile', {value: !!loadFile});
|
||||
|
||||
// set uri
|
||||
result.href = uri;
|
||||
|
||||
// set default result target, if specified
|
||||
if (options.target) {
|
||||
result.target = options.target + '';
|
||||
}
|
||||
|
||||
// set default result rel, if specified (#1542)
|
||||
if (options.rel) {
|
||||
result.rel = options.rel + '';
|
||||
}
|
||||
|
||||
// provide control over cross-origin image handling (#2238)
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image
|
||||
if (options.context === 'image' && options.crossOrigin) {
|
||||
result.crossOrigin = options.crossOrigin + '';
|
||||
}
|
||||
|
||||
// return
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* File system loader factory.
|
||||
* @param {object} fs - The file system interface.
|
||||
* @return {function} - A file loader with the following signature:
|
||||
* param {string} filename - The file system path to load.
|
||||
* param {string} filename - The file system path to load.
|
||||
* return {Promise} A promise that resolves to the file contents.
|
||||
*/
|
||||
function fileLoader(fs) {
|
||||
return fs
|
||||
? function(filename) {
|
||||
return new Promise(function(accept, reject) {
|
||||
fs.readFile(filename, function(error, data) {
|
||||
if (error) reject(error);
|
||||
else accept(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
: fileReject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default file system loader that simply rejects.
|
||||
*/
|
||||
async function fileReject() {
|
||||
vegaUtil.error('No file system access.');
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP request handler factory.
|
||||
* @param {function} fetch - The Fetch API method.
|
||||
* @return {function} - An http loader with the following signature:
|
||||
* param {string} url - The url to request.
|
||||
* param {object} options - An options hash.
|
||||
* return {Promise} - A promise that resolves to the file contents.
|
||||
*/
|
||||
function httpLoader(fetch) {
|
||||
return fetch
|
||||
? async function(url, options) {
|
||||
const opt = vegaUtil.extend({}, this.options.http, options),
|
||||
type = options && options.response,
|
||||
response = await fetch(url, opt);
|
||||
|
||||
return !response.ok
|
||||
? vegaUtil.error(response.status + '' + response.statusText)
|
||||
: vegaUtil.isFunction(response[type]) ? response[type]()
|
||||
: response.text();
|
||||
}
|
||||
: httpReject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default http request handler that simply rejects.
|
||||
*/
|
||||
async function httpReject() {
|
||||
vegaUtil.error('No HTTP fetch method available.');
|
||||
}
|
||||
|
||||
var typeParsers = {
|
||||
boolean: vegaUtil.toBoolean,
|
||||
integer: vegaUtil.toNumber,
|
||||
number: vegaUtil.toNumber,
|
||||
date: vegaUtil.toDate,
|
||||
string: vegaUtil.toString,
|
||||
unknown: vegaUtil.identity
|
||||
};
|
||||
|
||||
var typeTests = [
|
||||
isBoolean,
|
||||
isInteger,
|
||||
isNumber,
|
||||
isDate
|
||||
];
|
||||
|
||||
var typeList = [
|
||||
'boolean',
|
||||
'integer',
|
||||
'number',
|
||||
'date'
|
||||
];
|
||||
|
||||
function inferType(values, field) {
|
||||
if (!values || !values.length) return 'unknown';
|
||||
|
||||
const n = values.length,
|
||||
m = typeTests.length,
|
||||
a = typeTests.map((_, i) => i + 1);
|
||||
|
||||
for (let i = 0, t = 0, j, value; i < n; ++i) {
|
||||
value = field ? values[i][field] : values[i];
|
||||
for (j = 0; j < m; ++j) {
|
||||
if (a[j] && isValid(value) && !typeTests[j](value)) {
|
||||
a[j] = 0;
|
||||
++t;
|
||||
if (t === typeTests.length) return 'string';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return typeList[
|
||||
a.reduce((u, v) => u === 0 ? v : u, 0) - 1
|
||||
];
|
||||
}
|
||||
|
||||
function inferTypes(data, fields) {
|
||||
return fields.reduce(function(types, field) {
|
||||
types[field] = inferType(data, field);
|
||||
return types;
|
||||
}, {});
|
||||
}
|
||||
|
||||
// -- Type Checks ----
|
||||
|
||||
function isValid(_) {
|
||||
return _ != null && _ === _;
|
||||
}
|
||||
|
||||
function isBoolean(_) {
|
||||
return _ === 'true' || _ === 'false' || _ === true || _ === false;
|
||||
}
|
||||
|
||||
function isDate(_) {
|
||||
return !Number.isNaN(Date.parse(_));
|
||||
}
|
||||
|
||||
function isNumber(_) {
|
||||
return !Number.isNaN(+_) && !(_ instanceof Date);
|
||||
}
|
||||
|
||||
function isInteger(_) {
|
||||
return isNumber(_) && Number.isInteger(+_);
|
||||
}
|
||||
|
||||
function delimitedFormat(delimiter) {
|
||||
const parse = function(data, format) {
|
||||
const delim = {delimiter: delimiter};
|
||||
return dsv(data, format ? vegaUtil.extend(format, delim) : delim);
|
||||
};
|
||||
|
||||
parse.responseType = 'text';
|
||||
|
||||
return parse;
|
||||
}
|
||||
|
||||
function dsv(data, format) {
|
||||
if (format.header) {
|
||||
data = format.header
|
||||
.map(vegaUtil.stringValue)
|
||||
.join(format.delimiter) + '\n' + data;
|
||||
}
|
||||
return d3Dsv.dsvFormat(format.delimiter).parse(data + '');
|
||||
}
|
||||
|
||||
dsv.responseType = 'text';
|
||||
|
||||
function isBuffer(_) {
|
||||
return (typeof Buffer === 'function' && vegaUtil.isFunction(Buffer.isBuffer))
|
||||
? Buffer.isBuffer(_) : false;
|
||||
}
|
||||
|
||||
function json(data, format) {
|
||||
const prop = (format && format.property) ? vegaUtil.field(format.property) : vegaUtil.identity;
|
||||
return vegaUtil.isObject(data) && !isBuffer(data)
|
||||
? parseJSON(prop(data))
|
||||
: prop(JSON.parse(data));
|
||||
}
|
||||
|
||||
json.responseType = 'json';
|
||||
|
||||
function parseJSON(data, format) {
|
||||
return (format && format.copy)
|
||||
? JSON.parse(JSON.stringify(data))
|
||||
: data;
|
||||
}
|
||||
|
||||
const filters = {
|
||||
interior: (a, b) => a !== b,
|
||||
exterior: (a, b) => a === b
|
||||
};
|
||||
|
||||
function topojson(data, format) {
|
||||
let method, object, property, filter;
|
||||
data = json(data, format);
|
||||
|
||||
if (format && format.feature) {
|
||||
method = topojsonClient.feature;
|
||||
property = format.feature;
|
||||
} else if (format && format.mesh) {
|
||||
method = topojsonClient.mesh;
|
||||
property = format.mesh;
|
||||
filter = filters[format.filter];
|
||||
} else {
|
||||
vegaUtil.error('Missing TopoJSON feature or mesh parameter.');
|
||||
}
|
||||
|
||||
object = (object = data.objects[property])
|
||||
? method(data, object, filter)
|
||||
: vegaUtil.error('Invalid TopoJSON object: ' + property);
|
||||
|
||||
return object && object.features || [object];
|
||||
}
|
||||
|
||||
topojson.responseType = 'json';
|
||||
|
||||
const format = {
|
||||
dsv: dsv,
|
||||
csv: delimitedFormat(','),
|
||||
tsv: delimitedFormat('\t'),
|
||||
json: json,
|
||||
topojson: topojson
|
||||
};
|
||||
|
||||
function formats(name, reader) {
|
||||
if (arguments.length > 1) {
|
||||
format[name] = reader;
|
||||
return this;
|
||||
} else {
|
||||
return vegaUtil.hasOwnProperty(format, name) ? format[name] : null;
|
||||
}
|
||||
}
|
||||
|
||||
function responseType(type) {
|
||||
const f = formats(type);
|
||||
return f && f.responseType || 'text';
|
||||
}
|
||||
|
||||
function read(data, schema, timeParser, utcParser) {
|
||||
schema = schema || {};
|
||||
|
||||
const reader = formats(schema.type || 'json');
|
||||
if (!reader) vegaUtil.error('Unknown data format type: ' + schema.type);
|
||||
|
||||
data = reader(data, schema);
|
||||
if (schema.parse) parse(data, schema.parse, timeParser, utcParser);
|
||||
|
||||
if (vegaUtil.hasOwnProperty(data, 'columns')) delete data.columns;
|
||||
return data;
|
||||
}
|
||||
|
||||
function parse(data, types, timeParser, utcParser) {
|
||||
if (!data.length) return; // early exit for empty data
|
||||
|
||||
const locale = vegaFormat.timeFormatDefaultLocale();
|
||||
timeParser = timeParser || locale.timeParse;
|
||||
utcParser = utcParser || locale.utcParse;
|
||||
|
||||
var fields = data.columns || Object.keys(data[0]),
|
||||
parsers, datum, field, i, j, n, m;
|
||||
|
||||
if (types === 'auto') types = inferTypes(data, fields);
|
||||
|
||||
fields = Object.keys(types);
|
||||
parsers = fields.map(function(field) {
|
||||
var type = types[field],
|
||||
parts, pattern;
|
||||
|
||||
if (type && (type.startsWith('date:') || type.startsWith('utc:'))) {
|
||||
parts = type.split(/:(.+)?/, 2); // split on first :
|
||||
pattern = parts[1];
|
||||
|
||||
if ((pattern[0] === '\'' && pattern[pattern.length-1] === '\'') ||
|
||||
(pattern[0] === '"' && pattern[pattern.length-1] === '"')) {
|
||||
pattern = pattern.slice(1, -1);
|
||||
}
|
||||
|
||||
const parse = parts[0] === 'utc' ? utcParser : timeParser;
|
||||
return parse(pattern);
|
||||
}
|
||||
|
||||
if (!typeParsers[type]) {
|
||||
throw Error('Illegal format pattern: ' + field + ':' + type);
|
||||
}
|
||||
|
||||
return typeParsers[type];
|
||||
});
|
||||
|
||||
for (i=0, n=data.length, m=fields.length; i<n; ++i) {
|
||||
datum = data[i];
|
||||
for (j=0; j<m; ++j) {
|
||||
field = fields[j];
|
||||
datum[field] = parsers[j](datum[field]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var loader = loaderFactory(
|
||||
require('node-fetch'),
|
||||
require('fs')
|
||||
);
|
||||
|
||||
exports.format = format;
|
||||
exports.formats = formats;
|
||||
exports.inferType = inferType;
|
||||
exports.inferTypes = inferTypes;
|
||||
exports.loader = loader;
|
||||
exports.read = read;
|
||||
exports.responseType = responseType;
|
||||
exports.typeParsers = typeParsers;
|
||||
22
node_modules/vega-loader/index.browser.js
generated
vendored
Normal file
22
node_modules/vega-loader/index.browser.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import loaderFactory from './src/loader';
|
||||
|
||||
export var loader = loaderFactory(
|
||||
typeof fetch !== 'undefined' && fetch, // use built-in fetch API
|
||||
null // no file system access
|
||||
);
|
||||
|
||||
export {
|
||||
default as read
|
||||
} from './src/read';
|
||||
|
||||
export {
|
||||
inferType,
|
||||
inferTypes,
|
||||
typeParsers
|
||||
} from './src/type';
|
||||
|
||||
export {
|
||||
format,
|
||||
formats,
|
||||
responseType
|
||||
} from './src/formats/index';
|
||||
22
node_modules/vega-loader/index.js
generated
vendored
Normal file
22
node_modules/vega-loader/index.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import loaderFactory from './src/loader';
|
||||
|
||||
export var loader = loaderFactory(
|
||||
require('node-fetch'),
|
||||
require('fs')
|
||||
);
|
||||
|
||||
export {
|
||||
default as read
|
||||
} from './src/read';
|
||||
|
||||
export {
|
||||
inferType,
|
||||
inferTypes,
|
||||
typeParsers
|
||||
} from './src/type';
|
||||
|
||||
export {
|
||||
format,
|
||||
formats,
|
||||
responseType
|
||||
} from './src/formats/index';
|
||||
85
node_modules/vega-loader/package.json
generated
vendored
Normal file
85
node_modules/vega-loader/package.json
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
{
|
||||
"_from": "vega-loader@~4.3.0",
|
||||
"_id": "vega-loader@4.3.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-XrwwJ1xWnsVS2N2M4vdvzieUdXWegdD31t04sCPQ5C3US58NYlq1ho1Md+5FVrtl0uCd0wG/mk700Jp7yPhN+w==",
|
||||
"_location": "/vega-loader",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "vega-loader@~4.3.0",
|
||||
"name": "vega-loader",
|
||||
"escapedName": "vega-loader",
|
||||
"rawSpec": "~4.3.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "~4.3.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/vega",
|
||||
"/vega-dataflow",
|
||||
"/vega-scenegraph"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/vega-loader/-/vega-loader-4.3.0.tgz",
|
||||
"_shasum": "f32d70e2dd57d753e4160aae2e1f48c20e0d00e5",
|
||||
"_spec": "vega-loader@~4.3.0",
|
||||
"_where": "/home/prabhatdev/Documents/opensource/gitHubStats/waka-readme-stats/node_modules/vega",
|
||||
"author": {
|
||||
"name": "Jeffrey Heer",
|
||||
"url": "http://idl.cs.washington.edu"
|
||||
},
|
||||
"browser": {
|
||||
"./build/vega-loader.node.js": "./build/vega-loader.js",
|
||||
"./index.js": "./index.browser.js"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/vega/vega/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"d3-dsv": "^1.2.0",
|
||||
"node-fetch": "^2.6.0",
|
||||
"topojson-client": "^3.1.0",
|
||||
"vega-format": "^1.0.0",
|
||||
"vega-util": "^1.14.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Network request and file loading utilities.",
|
||||
"gitHead": "48c85218f2202242171aa569f2dca0f53cf2b51f",
|
||||
"homepage": "https://github.com/vega/vega#readme",
|
||||
"jsdelivr": "build/vega-loader.min.js",
|
||||
"keywords": [
|
||||
"vega",
|
||||
"loader",
|
||||
"file",
|
||||
"http",
|
||||
"fetch",
|
||||
"json",
|
||||
"csv",
|
||||
"tsv",
|
||||
"topojson",
|
||||
"parse",
|
||||
"type",
|
||||
"inference"
|
||||
],
|
||||
"license": "BSD-3-Clause",
|
||||
"main": "build/vega-loader.node.js",
|
||||
"module": "index",
|
||||
"name": "vega-loader",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vega/vega.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yarn rollup",
|
||||
"postbuild": "terser build/vega-loader.js -c -m -o build/vega-loader.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 -f cjs -g d3-dsv:d3,vega-format:vega,vega-util:vega,topojson-client:topojson -n vega -o build/vega-loader.node.js -- index.js && rollup -f umd -g d3-dsv:d3,vega-format:vega,vega-util:vega,topojson-client:topojson -n vega -o build/vega-loader.js -- index.browser.js",
|
||||
"test": "tape 'test/**/*-test.js'"
|
||||
},
|
||||
"unpkg": "build/vega-loader.min.js",
|
||||
"version": "4.3.0"
|
||||
}
|
||||
24
node_modules/vega-loader/src/formats/dsv.js
generated
vendored
Normal file
24
node_modules/vega-loader/src/formats/dsv.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import {dsvFormat} from 'd3-dsv';
|
||||
import {extend, stringValue} from 'vega-util';
|
||||
|
||||
export function delimitedFormat(delimiter) {
|
||||
const parse = function(data, format) {
|
||||
const delim = {delimiter: delimiter};
|
||||
return dsv(data, format ? extend(format, delim) : delim);
|
||||
};
|
||||
|
||||
parse.responseType = 'text';
|
||||
|
||||
return parse;
|
||||
}
|
||||
|
||||
export default function dsv(data, format) {
|
||||
if (format.header) {
|
||||
data = format.header
|
||||
.map(stringValue)
|
||||
.join(format.delimiter) + '\n' + data;
|
||||
}
|
||||
return dsvFormat(format.delimiter).parse(data + '');
|
||||
}
|
||||
|
||||
dsv.responseType = 'text';
|
||||
26
node_modules/vega-loader/src/formats/index.js
generated
vendored
Normal file
26
node_modules/vega-loader/src/formats/index.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import {delimitedFormat, default as dsv} from './dsv';
|
||||
import json from './json';
|
||||
import topojson from './topojson';
|
||||
import {hasOwnProperty} from 'vega-util';
|
||||
|
||||
export const format = {
|
||||
dsv: dsv,
|
||||
csv: delimitedFormat(','),
|
||||
tsv: delimitedFormat('\t'),
|
||||
json: json,
|
||||
topojson: topojson
|
||||
};
|
||||
|
||||
export function formats(name, reader) {
|
||||
if (arguments.length > 1) {
|
||||
format[name] = reader;
|
||||
return this;
|
||||
} else {
|
||||
return hasOwnProperty(format, name) ? format[name] : null;
|
||||
}
|
||||
}
|
||||
|
||||
export function responseType(type) {
|
||||
const f = formats(type);
|
||||
return f && f.responseType || 'text';
|
||||
}
|
||||
21
node_modules/vega-loader/src/formats/json.js
generated
vendored
Normal file
21
node_modules/vega-loader/src/formats/json.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import {field, identity, isFunction, isObject} from 'vega-util';
|
||||
|
||||
function isBuffer(_) {
|
||||
return (typeof Buffer === 'function' && isFunction(Buffer.isBuffer))
|
||||
? Buffer.isBuffer(_) : false;
|
||||
}
|
||||
|
||||
export default function json(data, format) {
|
||||
const prop = (format && format.property) ? field(format.property) : identity;
|
||||
return isObject(data) && !isBuffer(data)
|
||||
? parseJSON(prop(data))
|
||||
: prop(JSON.parse(data));
|
||||
}
|
||||
|
||||
json.responseType = 'json';
|
||||
|
||||
function parseJSON(data, format) {
|
||||
return (format && format.copy)
|
||||
? JSON.parse(JSON.stringify(data))
|
||||
: data;
|
||||
}
|
||||
32
node_modules/vega-loader/src/formats/topojson.js
generated
vendored
Normal file
32
node_modules/vega-loader/src/formats/topojson.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import json from './json';
|
||||
import {feature, mesh} from 'topojson-client';
|
||||
import {error} from 'vega-util';
|
||||
|
||||
const filters = {
|
||||
interior: (a, b) => a !== b,
|
||||
exterior: (a, b) => a === b
|
||||
};
|
||||
|
||||
export default function topojson(data, format) {
|
||||
let method, object, property, filter;
|
||||
data = json(data, format);
|
||||
|
||||
if (format && format.feature) {
|
||||
method = feature;
|
||||
property = format.feature;
|
||||
} else if (format && format.mesh) {
|
||||
method = mesh;
|
||||
property = format.mesh;
|
||||
filter = filters[format.filter];
|
||||
} else {
|
||||
error('Missing TopoJSON feature or mesh parameter.');
|
||||
}
|
||||
|
||||
object = (object = data.objects[property])
|
||||
? method(data, object, filter)
|
||||
: error('Invalid TopoJSON object: ' + property);
|
||||
|
||||
return object && object.features || [object];
|
||||
}
|
||||
|
||||
topojson.responseType = 'json';
|
||||
194
node_modules/vega-loader/src/loader.js
generated
vendored
Normal file
194
node_modules/vega-loader/src/loader.js
generated
vendored
Normal file
@@ -0,0 +1,194 @@
|
||||
import {error, extend, isFunction, stringValue} from 'vega-util';
|
||||
|
||||
// Matches absolute URLs with optional protocol
|
||||
// https://... file://... //...
|
||||
const protocol_re = /^([A-Za-z]+:)?\/\//;
|
||||
|
||||
// Matches allowed URIs. From https://github.com/cure53/DOMPurify/blob/master/src/regexp.js with added file://
|
||||
const allowed_re = /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp|file|data):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i; // eslint-disable-line no-useless-escape
|
||||
const whitespace_re = /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205f\u3000]/g; // eslint-disable-line no-control-regex
|
||||
|
||||
|
||||
// Special treatment in node.js for the file: protocol
|
||||
const fileProtocol = 'file://';
|
||||
|
||||
/**
|
||||
* Factory for a loader constructor that provides methods for requesting
|
||||
* files from either the network or disk, and for sanitizing request URIs.
|
||||
* @param {function} fetch - The Fetch API for HTTP network requests.
|
||||
* If null or undefined, HTTP loading will be disabled.
|
||||
* @param {object} fs - The file system interface for file loading.
|
||||
* If null or undefined, local file loading will be disabled.
|
||||
* @return {function} A loader constructor with the following signature:
|
||||
* param {object} [options] - Optional default loading options to use.
|
||||
* return {object} - A new loader instance.
|
||||
*/
|
||||
export default function(fetch, fs) {
|
||||
return function(options) {
|
||||
return {
|
||||
options: options || {},
|
||||
sanitize: sanitize,
|
||||
load: load,
|
||||
fileAccess: !!fs,
|
||||
file: fileLoader(fs),
|
||||
http: httpLoader(fetch)
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an external resource, typically either from the web or from the local
|
||||
* filesystem. This function uses {@link sanitize} to first sanitize the uri,
|
||||
* then calls either {@link http} (for web requests) or {@link file} (for
|
||||
* filesystem loading).
|
||||
* @param {string} uri - The resource indicator (e.g., URL or filename).
|
||||
* @param {object} [options] - Optional loading options. These options will
|
||||
* override any existing default options.
|
||||
* @return {Promise} - A promise that resolves to the loaded content.
|
||||
*/
|
||||
async function load(uri, options) {
|
||||
const opt = await this.sanitize(uri, options),
|
||||
url = opt.href;
|
||||
|
||||
return opt.localFile
|
||||
? this.file(url)
|
||||
: this.http(url, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* URI sanitizer function.
|
||||
* @param {string} uri - The uri (url or filename) to sanity check.
|
||||
* @param {object} options - An options hash.
|
||||
* @return {Promise} - A promise that resolves to an object containing
|
||||
* sanitized uri data, or rejects it the input uri is deemed invalid.
|
||||
* The properties of the resolved object are assumed to be
|
||||
* valid attributes for an HTML 'a' tag. The sanitized uri *must* be
|
||||
* provided by the 'href' property of the returned object.
|
||||
*/
|
||||
async function sanitize(uri, options) {
|
||||
options = extend({}, this.options, options);
|
||||
|
||||
const fileAccess = this.fileAccess,
|
||||
result = {href: null};
|
||||
|
||||
let isFile, loadFile, base;
|
||||
|
||||
const isAllowed = allowed_re.test(uri.replace(whitespace_re, ''));
|
||||
|
||||
if (uri == null || typeof uri !== 'string' || !isAllowed) {
|
||||
error('Sanitize failure, invalid URI: ' + stringValue(uri));
|
||||
}
|
||||
|
||||
const hasProtocol = protocol_re.test(uri);
|
||||
|
||||
// if relative url (no protocol/host), prepend baseURL
|
||||
if ((base = options.baseURL) && !hasProtocol) {
|
||||
// Ensure that there is a slash between the baseURL (e.g. hostname) and url
|
||||
if (!uri.startsWith('/') && base[base.length-1] !== '/') {
|
||||
uri = '/' + uri;
|
||||
}
|
||||
uri = base + uri;
|
||||
}
|
||||
|
||||
// should we load from file system?
|
||||
loadFile = (isFile = uri.startsWith(fileProtocol))
|
||||
|| options.mode === 'file'
|
||||
|| options.mode !== 'http' && !hasProtocol && fileAccess;
|
||||
|
||||
if (isFile) {
|
||||
// strip file protocol
|
||||
uri = uri.slice(fileProtocol.length);
|
||||
} else if (uri.startsWith('//')) {
|
||||
if (options.defaultProtocol === 'file') {
|
||||
// if is file, strip protocol and set loadFile flag
|
||||
uri = uri.slice(2);
|
||||
loadFile = true;
|
||||
} else {
|
||||
// if relative protocol (starts with '//'), prepend default protocol
|
||||
uri = (options.defaultProtocol || 'http') + ':' + uri;
|
||||
}
|
||||
}
|
||||
|
||||
// set non-enumerable mode flag to indicate local file load
|
||||
Object.defineProperty(result, 'localFile', {value: !!loadFile});
|
||||
|
||||
// set uri
|
||||
result.href = uri;
|
||||
|
||||
// set default result target, if specified
|
||||
if (options.target) {
|
||||
result.target = options.target + '';
|
||||
}
|
||||
|
||||
// set default result rel, if specified (#1542)
|
||||
if (options.rel) {
|
||||
result.rel = options.rel + '';
|
||||
}
|
||||
|
||||
// provide control over cross-origin image handling (#2238)
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image
|
||||
if (options.context === 'image' && options.crossOrigin) {
|
||||
result.crossOrigin = options.crossOrigin + '';
|
||||
}
|
||||
|
||||
// return
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* File system loader factory.
|
||||
* @param {object} fs - The file system interface.
|
||||
* @return {function} - A file loader with the following signature:
|
||||
* param {string} filename - The file system path to load.
|
||||
* param {string} filename - The file system path to load.
|
||||
* return {Promise} A promise that resolves to the file contents.
|
||||
*/
|
||||
function fileLoader(fs) {
|
||||
return fs
|
||||
? function(filename) {
|
||||
return new Promise(function(accept, reject) {
|
||||
fs.readFile(filename, function(error, data) {
|
||||
if (error) reject(error);
|
||||
else accept(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
: fileReject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default file system loader that simply rejects.
|
||||
*/
|
||||
async function fileReject() {
|
||||
error('No file system access.');
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP request handler factory.
|
||||
* @param {function} fetch - The Fetch API method.
|
||||
* @return {function} - An http loader with the following signature:
|
||||
* param {string} url - The url to request.
|
||||
* param {object} options - An options hash.
|
||||
* return {Promise} - A promise that resolves to the file contents.
|
||||
*/
|
||||
function httpLoader(fetch) {
|
||||
return fetch
|
||||
? async function(url, options) {
|
||||
const opt = extend({}, this.options.http, options),
|
||||
type = options && options.response,
|
||||
response = await fetch(url, opt);
|
||||
|
||||
return !response.ok
|
||||
? error(response.status + '' + response.statusText)
|
||||
: isFunction(response[type]) ? response[type]()
|
||||
: response.text();
|
||||
}
|
||||
: httpReject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default http request handler that simply rejects.
|
||||
*/
|
||||
async function httpReject() {
|
||||
error('No HTTP fetch method available.');
|
||||
}
|
||||
63
node_modules/vega-loader/src/read.js
generated
vendored
Normal file
63
node_modules/vega-loader/src/read.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
import {inferTypes, typeParsers} from './type';
|
||||
import {formats} from './formats/index';
|
||||
import {timeFormatDefaultLocale} from 'vega-format';
|
||||
import {error, hasOwnProperty} from 'vega-util';
|
||||
|
||||
export default function(data, schema, timeParser, utcParser) {
|
||||
schema = schema || {};
|
||||
|
||||
const reader = formats(schema.type || 'json');
|
||||
if (!reader) error('Unknown data format type: ' + schema.type);
|
||||
|
||||
data = reader(data, schema);
|
||||
if (schema.parse) parse(data, schema.parse, timeParser, utcParser);
|
||||
|
||||
if (hasOwnProperty(data, 'columns')) delete data.columns;
|
||||
return data;
|
||||
}
|
||||
|
||||
function parse(data, types, timeParser, utcParser) {
|
||||
if (!data.length) return; // early exit for empty data
|
||||
|
||||
const locale = timeFormatDefaultLocale();
|
||||
timeParser = timeParser || locale.timeParse;
|
||||
utcParser = utcParser || locale.utcParse;
|
||||
|
||||
var fields = data.columns || Object.keys(data[0]),
|
||||
parsers, datum, field, i, j, n, m;
|
||||
|
||||
if (types === 'auto') types = inferTypes(data, fields);
|
||||
|
||||
fields = Object.keys(types);
|
||||
parsers = fields.map(function(field) {
|
||||
var type = types[field],
|
||||
parts, pattern;
|
||||
|
||||
if (type && (type.startsWith('date:') || type.startsWith('utc:'))) {
|
||||
parts = type.split(/:(.+)?/, 2); // split on first :
|
||||
pattern = parts[1];
|
||||
|
||||
if ((pattern[0] === '\'' && pattern[pattern.length-1] === '\'') ||
|
||||
(pattern[0] === '"' && pattern[pattern.length-1] === '"')) {
|
||||
pattern = pattern.slice(1, -1);
|
||||
}
|
||||
|
||||
const parse = parts[0] === 'utc' ? utcParser : timeParser;
|
||||
return parse(pattern);
|
||||
}
|
||||
|
||||
if (!typeParsers[type]) {
|
||||
throw Error('Illegal format pattern: ' + field + ':' + type);
|
||||
}
|
||||
|
||||
return typeParsers[type];
|
||||
});
|
||||
|
||||
for (i=0, n=data.length, m=fields.length; i<n; ++i) {
|
||||
datum = data[i];
|
||||
for (j=0; j<m; ++j) {
|
||||
field = fields[j];
|
||||
datum[field] = parsers[j](datum[field]);
|
||||
}
|
||||
}
|
||||
}
|
||||
76
node_modules/vega-loader/src/type.js
generated
vendored
Normal file
76
node_modules/vega-loader/src/type.js
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
import {identity, toBoolean, toDate, toNumber, toString} from 'vega-util';
|
||||
|
||||
export var typeParsers = {
|
||||
boolean: toBoolean,
|
||||
integer: toNumber,
|
||||
number: toNumber,
|
||||
date: toDate,
|
||||
string: toString,
|
||||
unknown: identity
|
||||
};
|
||||
|
||||
var typeTests = [
|
||||
isBoolean,
|
||||
isInteger,
|
||||
isNumber,
|
||||
isDate
|
||||
];
|
||||
|
||||
var typeList = [
|
||||
'boolean',
|
||||
'integer',
|
||||
'number',
|
||||
'date'
|
||||
];
|
||||
|
||||
export function inferType(values, field) {
|
||||
if (!values || !values.length) return 'unknown';
|
||||
|
||||
const n = values.length,
|
||||
m = typeTests.length,
|
||||
a = typeTests.map((_, i) => i + 1);
|
||||
|
||||
for (let i = 0, t = 0, j, value; i < n; ++i) {
|
||||
value = field ? values[i][field] : values[i];
|
||||
for (j = 0; j < m; ++j) {
|
||||
if (a[j] && isValid(value) && !typeTests[j](value)) {
|
||||
a[j] = 0;
|
||||
++t;
|
||||
if (t === typeTests.length) return 'string';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return typeList[
|
||||
a.reduce((u, v) => u === 0 ? v : u, 0) - 1
|
||||
];
|
||||
}
|
||||
|
||||
export function inferTypes(data, fields) {
|
||||
return fields.reduce(function(types, field) {
|
||||
types[field] = inferType(data, field);
|
||||
return types;
|
||||
}, {});
|
||||
}
|
||||
|
||||
// -- Type Checks ----
|
||||
|
||||
function isValid(_) {
|
||||
return _ != null && _ === _;
|
||||
}
|
||||
|
||||
function isBoolean(_) {
|
||||
return _ === 'true' || _ === 'false' || _ === true || _ === false;
|
||||
}
|
||||
|
||||
function isDate(_) {
|
||||
return !Number.isNaN(Date.parse(_));
|
||||
}
|
||||
|
||||
function isNumber(_) {
|
||||
return !Number.isNaN(+_) && !(_ instanceof Date);
|
||||
}
|
||||
|
||||
function isInteger(_) {
|
||||
return isNumber(_) && Number.isInteger(+_);
|
||||
}
|
||||
Reference in New Issue
Block a user