diff --git a/.gitattributes b/.gitattributes index 6828588eaa2fad3843e9e02dc6b26ed4a7c89387..9abc6f2bb8ca7b8b9edfea31531f70e006872e54 100644 --- a/.gitattributes +++ b/.gitattributes @@ -35,3 +35,8 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text *tfevents* filter=lfs diff=lfs merge=lfs -text node_modules/.bin/esbuild filter=lfs diff=lfs merge=lfs -text node_modules/@esbuild/linux-x64/bin/esbuild filter=lfs diff=lfs merge=lfs -text +node_modules/@mapbox/vector-tile/test/fixtures/14-8801-5371.vector.pbf filter=lfs diff=lfs merge=lfs -text +node_modules/@plotly/d3-sankey/img/align-center.png filter=lfs diff=lfs merge=lfs -text +node_modules/@plotly/d3-sankey/img/align-left.png filter=lfs diff=lfs merge=lfs -text +node_modules/@plotly/d3-sankey/img/align-right.png filter=lfs diff=lfs merge=lfs -text +node_modules/@plotly/d3-sankey/img/energy.png filter=lfs diff=lfs merge=lfs -text diff --git a/node_modules/@mapbox/geojson-types/generate-fixtures.js b/node_modules/@mapbox/geojson-types/generate-fixtures.js new file mode 100644 index 0000000000000000000000000000000000000000..24045b2359ec1e0964a7d7540550cbb73f124ff8 --- /dev/null +++ b/node_modules/@mapbox/geojson-types/generate-fixtures.js @@ -0,0 +1,13 @@ +const fs = require('fs'); +const fixtures = require('@mapbox/geojson-fixtures'); + +for (let key in fixtures.geometry) { + fs.writeFileSync(`${__dirname}/fixtures/valid/${key}.js.flow`, `// @flow +// This file was generated by generate-fixtures.js. Do not edit! +import type { + GeoJSONGeometry +} from '../../index'; + +const geojson: GeoJSONGeometry = ${JSON.stringify(fixtures.geometry[key], null, 2)} +`); +} diff --git a/node_modules/@mapbox/geojson-types/index.js b/node_modules/@mapbox/geojson-types/index.js new file mode 100644 index 0000000000000000000000000000000000000000..4fffae8e5291298618664a340a47bfc4574d698d --- /dev/null +++ b/node_modules/@mapbox/geojson-types/index.js @@ -0,0 +1,41 @@ +// @flow strict + +type GeoJSONPosition = [number, number] | [number, number, number]; +type Geometry = { type: T, coordinates: C } + +export type GeoJSONPoint = Geometry< 'Point', GeoJSONPosition>; +export type GeoJSONMultiPoint = Geometry<'MultiPoint', Array>; + +export type GeoJSONLineString = Geometry< 'LineString', Array>; +export type GeoJSONMultiLineString = Geometry<'MultiLineString', Array>>; + +export type GeoJSONPolygon = Geometry< 'Polygon', Array>>; +export type GeoJSONMultiPolygon = Geometry<'MultiPolygon', Array>>>; + +export type GeoJSONGeometry = + | GeoJSONPoint + | GeoJSONMultiPoint + | GeoJSONLineString + | GeoJSONMultiLineString + | GeoJSONPolygon + | GeoJSONMultiPolygon + | GeoJSONGeometryCollection; + +export type GeoJSONGeometryCollection = { + type: 'GeometryCollection', + geometries: Array +}; + +export type GeoJSONFeature = { + type: 'Feature', + geometry: ?GeoJSONGeometry, + properties: ?{}, + id?: number | string +}; + +export type GeoJSONFeatureCollection = { + type: 'FeatureCollection', + features: Array +}; + +export type GeoJSON = GeoJSONGeometry | GeoJSONFeature | GeoJSONFeatureCollection; diff --git a/node_modules/@mapbox/geojson-types/package.json b/node_modules/@mapbox/geojson-types/package.json new file mode 100644 index 0000000000000000000000000000000000000000..86237a4d09a054a7534d023e08e33f3902ca0c2b --- /dev/null +++ b/node_modules/@mapbox/geojson-types/package.json @@ -0,0 +1,17 @@ +{ + "name": "@mapbox/geojson-types", + "version": "1.0.2", + "description": "", + "main": "index.js", + "scripts": { + "test": "tape test.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "@mapbox/geojson-fixtures": "^1.0.0", + "flow-bin": "^0.77.0", + "tape": "^4.9.1" + } +} diff --git a/node_modules/@mapbox/geojson-types/test.js b/node_modules/@mapbox/geojson-types/test.js new file mode 100644 index 0000000000000000000000000000000000000000..09a1298eca338f16cbdebc7612ca9337079c7449 --- /dev/null +++ b/node_modules/@mapbox/geojson-types/test.js @@ -0,0 +1,25 @@ +const fs = require('fs'); +const tape = require('tape'); +const exec = require('child_process').exec; + +tape('valid', (t) => { + exec(`npx flow focus-check ${__dirname}/fixtures/valid/*.js.flow`, (err) => { + t.error(err); + t.end(); + }); +}); + +tape('invalid', (t) => { + const fixtures = fs.readdirSync(`${__dirname}/fixtures/invalid`); + for (const file of fixtures) { + t.test(file, (t) => { + exec(`npx flow focus-check ${__dirname}/fixtures/invalid/${file}`, (err) => { + t.ok(err, 'nonzero exit for invalid fixture'); + t.end(); + }); + }); + } + + t.end(); +}); + diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/.npmignore b/node_modules/@mapbox/jsonlint-lines-primitives/.npmignore new file mode 100644 index 0000000000000000000000000000000000000000..3c3629e647f5ddf82548912e337bea9826b434af --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/.npmignore @@ -0,0 +1 @@ +node_modules diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/Makefile b/node_modules/@mapbox/jsonlint-lines-primitives/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..6660a8ed79d6471b191706ae0adebfb5381859f8 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/Makefile @@ -0,0 +1,17 @@ + +all: build test site + +build: + ./node_modules/jison/lib/cli.js src/jsonlint.y src/jsonlint.l + mv jsonlint.js lib/jsonlint.js + node scripts/bundle.js | ./node_modules/uglify-js/bin/uglifyjs > web/jsonlint.js + +site: + cp web/jsonlint.js ../jsonlint-pages/jsonlint.js + +deploy: site + cd ../jsonlint-pages && git commit -a -m 'deploy site updates' && git push origin gh-pages + +test: lib/jsonlint.js test/all-tests.js + node test/all-tests.js + diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/README.md b/node_modules/@mapbox/jsonlint-lines-primitives/README.md new file mode 100644 index 0000000000000000000000000000000000000000..eb75347cba4ebe7b01411e727897e2d7e39b5f7a --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/README.md @@ -0,0 +1,7 @@ +JSON Lint +========= + +A fork of the `lines-primitive` branch of [tmcw/jsonlint](https://github.com/tmcw/jsonlint), which is a fork of [zaach/jsonlint](https://github.com/zaach/jsonlint) that adds line number annotations to the parsed JSON. + +This fork is used by Mapbox GL JS, specifically for providing helpful error messages when validating Mapbox GL style JSON documents. + diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/lib/formatter.js b/node_modules/@mapbox/jsonlint-lines-primitives/lib/formatter.js new file mode 100644 index 0000000000000000000000000000000000000000..e6e27265acc83936a332942822506c11efb3b8aa --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/lib/formatter.js @@ -0,0 +1,92 @@ +#!/usr/bin/env node + +/** + * Manual formatter taken straight from https://github.com/umbrae/jsonlintdotcom +**/ + +/*jslint white: true, devel: true, onevar: true, browser: true, undef: true, nomen: true, regexp: true, plusplus: false, bitwise: true, newcap: true, maxerr: 50, indent: 4 */ + +/** + * jsl.format - Provide json reformatting in a character-by-character approach, so that even invalid JSON may be reformatted (to the best of its ability). + * +**/ +var formatter = (function () { + + function repeat(s, count) { + return new Array(count + 1).join(s); + } + + function formatJson(json, indentChars) { + var i = 0, + il = 0, + tab = (typeof indentChars !== "undefined") ? indentChars : " ", + newJson = "", + indentLevel = 0, + inString = false, + currentChar = null; + + for (i = 0, il = json.length; i < il; i += 1) { + currentChar = json.charAt(i); + + switch (currentChar) { + case '{': + case '[': + if (!inString) { + newJson += currentChar + "\n" + repeat(tab, indentLevel + 1); + indentLevel += 1; + } else { + newJson += currentChar; + } + break; + case '}': + case ']': + if (!inString) { + indentLevel -= 1; + newJson += "\n" + repeat(tab, indentLevel) + currentChar; + } else { + newJson += currentChar; + } + break; + case ',': + if (!inString) { + newJson += ",\n" + repeat(tab, indentLevel); + } else { + newJson += currentChar; + } + break; + case ':': + if (!inString) { + newJson += ": "; + } else { + newJson += currentChar; + } + break; + case ' ': + case "\n": + case "\t": + if (inString) { + newJson += currentChar; + } + break; + case '"': + if (i > 0 && json.charAt(i - 1) !== '\\') { + inString = !inString; + } + newJson += currentChar; + break; + default: + newJson += currentChar; + break; + } + } + + return newJson; + } + + return { "formatJson": formatJson }; + +}()); + +if (typeof require !== 'undefined' && typeof exports !== 'undefined') { + exports.formatter = formatter; +} \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/lib/jsonlint.js b/node_modules/@mapbox/jsonlint-lines-primitives/lib/jsonlint.js new file mode 100644 index 0000000000000000000000000000000000000000..7800de7580b0b19b129f6837aee363c8ac75d6aa --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/lib/jsonlint.js @@ -0,0 +1,681 @@ +/* parser generated by jison 0.4.15 */ +/* + Returns a Parser object of the following structure: + + Parser: { + yy: {} + } + + Parser.prototype: { + yy: {}, + trace: function(), + symbols_: {associative list: name ==> number}, + terminals_: {associative list: number ==> name}, + productions_: [...], + performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$), + table: [...], + defaultActions: {...}, + parseError: function(str, hash), + parse: function(input), + + lexer: { + EOF: 1, + parseError: function(str, hash), + setInput: function(input), + input: function(), + unput: function(str), + more: function(), + less: function(n), + pastInput: function(), + upcomingInput: function(), + showPosition: function(), + test_match: function(regex_match_array, rule_index), + next: function(), + lex: function(), + begin: function(condition), + popState: function(), + _currentRules: function(), + topState: function(), + pushState: function(condition), + + options: { + ranges: boolean (optional: true ==> token location info will include a .range[] member) + flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match) + backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code) + }, + + performAction: function(yy, yy_, $avoiding_name_collisions, YY_START), + rules: [...], + conditions: {associative list: name ==> set}, + } + } + + + token location info (@$, _$, etc.): { + first_line: n, + last_line: n, + first_column: n, + last_column: n, + range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based) + } + + + the parseError function receives a 'hash' object with these members for lexer and parser errors: { + text: (matched text) + token: (the produced terminal token, if any) + line: (yylineno) + } + while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: { + loc: (yylloc) + expected: (string describing the set of expected tokens) + recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error) + } +*/ +var parser = (function(){ +var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,12],$V1=[1,13],$V2=[1,9],$V3=[1,10],$V4=[1,11],$V5=[1,14],$V6=[1,15],$V7=[14,18,22,24],$V8=[18,22],$V9=[22,24]; +var parser = {trace: function trace() { }, +yy: {}, +symbols_: {"error":2,"JSONString":3,"STRING":4,"JSONNumber":5,"NUMBER":6,"JSONNullLiteral":7,"NULL":8,"JSONBooleanLiteral":9,"TRUE":10,"FALSE":11,"JSONText":12,"JSONValue":13,"EOF":14,"JSONObject":15,"JSONArray":16,"{":17,"}":18,"JSONMemberList":19,"JSONMember":20,":":21,",":22,"[":23,"]":24,"JSONElementList":25,"$accept":0,"$end":1}, +terminals_: {2:"error",4:"STRING",6:"NUMBER",8:"NULL",10:"TRUE",11:"FALSE",14:"EOF",17:"{",18:"}",21:":",22:",",23:"[",24:"]"}, +productions_: [0,[3,1],[5,1],[7,1],[9,1],[9,1],[12,2],[13,1],[13,1],[13,1],[13,1],[13,1],[13,1],[15,2],[15,3],[20,3],[19,1],[19,3],[16,2],[16,3],[25,1],[25,3]], +performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) { +/* this == yyval */ + +var $0 = $$.length - 1; +switch (yystate) { +case 1: + // replace escaped characters with actual character + this.$ = new String(yytext.replace(/\\(\\|")/g, "$"+"1") + .replace(/\\n/g,'\n') + .replace(/\\r/g,'\r') + .replace(/\\t/g,'\t') + .replace(/\\v/g,'\v') + .replace(/\\f/g,'\f') + .replace(/\\b/g,'\b')); + this.$.__line__ = this._$.first_line; + +break; +case 2: + + this.$ = new Number(yytext); + this.$.__line__ = this._$.first_line; + +break; +case 3: + + this.$ = null; + +break; +case 4: + + this.$ = new Boolean(true); + this.$.__line__ = this._$.first_line; + +break; +case 5: + + this.$ = new Boolean(false); + this.$.__line__ = this._$.first_line; + +break; +case 6: +return this.$ = $$[$0-1]; +break; +case 13: +this.$ = {}; Object.defineProperty(this.$, '__line__', { + value: this._$.first_line, + enumerable: false + }) +break; +case 14: case 19: +this.$ = $$[$0-1]; Object.defineProperty(this.$, '__line__', { + value: this._$.first_line, + enumerable: false + }) +break; +case 15: +this.$ = [$$[$0-2], $$[$0]]; +break; +case 16: +this.$ = {}; this.$[$$[$0][0]] = $$[$0][1]; +break; +case 17: +this.$ = $$[$0-2]; $$[$0-2][$$[$0][0]] = $$[$0][1]; +break; +case 18: +this.$ = []; Object.defineProperty(this.$, '__line__', { + value: this._$.first_line, + enumerable: false + }) +break; +case 20: +this.$ = [$$[$0]]; +break; +case 21: +this.$ = $$[$0-2]; $$[$0-2].push($$[$0]); +break; +} +}, +table: [{3:5,4:$V0,5:6,6:$V1,7:3,8:$V2,9:4,10:$V3,11:$V4,12:1,13:2,15:7,16:8,17:$V5,23:$V6},{1:[3]},{14:[1,16]},o($V7,[2,7]),o($V7,[2,8]),o($V7,[2,9]),o($V7,[2,10]),o($V7,[2,11]),o($V7,[2,12]),o($V7,[2,3]),o($V7,[2,4]),o($V7,[2,5]),o([14,18,21,22,24],[2,1]),o($V7,[2,2]),{3:20,4:$V0,18:[1,17],19:18,20:19},{3:5,4:$V0,5:6,6:$V1,7:3,8:$V2,9:4,10:$V3,11:$V4,13:23,15:7,16:8,17:$V5,23:$V6,24:[1,21],25:22},{1:[2,6]},o($V7,[2,13]),{18:[1,24],22:[1,25]},o($V8,[2,16]),{21:[1,26]},o($V7,[2,18]),{22:[1,28],24:[1,27]},o($V9,[2,20]),o($V7,[2,14]),{3:20,4:$V0,20:29},{3:5,4:$V0,5:6,6:$V1,7:3,8:$V2,9:4,10:$V3,11:$V4,13:30,15:7,16:8,17:$V5,23:$V6},o($V7,[2,19]),{3:5,4:$V0,5:6,6:$V1,7:3,8:$V2,9:4,10:$V3,11:$V4,13:31,15:7,16:8,17:$V5,23:$V6},o($V8,[2,17]),o($V8,[2,15]),o($V9,[2,21])], +defaultActions: {16:[2,6]}, +parseError: function parseError(str, hash) { + if (hash.recoverable) { + this.trace(str); + } else { + throw new Error(str); + } +}, +parse: function parse(input) { + var self = this, stack = [0], tstack = [], vstack = [null], lstack = [], table = this.table, yytext = '', yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1; + var args = lstack.slice.call(arguments, 1); + var lexer = Object.create(this.lexer); + var sharedState = { yy: {} }; + for (var k in this.yy) { + if (Object.prototype.hasOwnProperty.call(this.yy, k)) { + sharedState.yy[k] = this.yy[k]; + } + } + lexer.setInput(input, sharedState.yy); + sharedState.yy.lexer = lexer; + sharedState.yy.parser = this; + if (typeof lexer.yylloc == 'undefined') { + lexer.yylloc = {}; + } + var yyloc = lexer.yylloc; + lstack.push(yyloc); + var ranges = lexer.options && lexer.options.ranges; + if (typeof sharedState.yy.parseError === 'function') { + this.parseError = sharedState.yy.parseError; + } else { + this.parseError = Object.getPrototypeOf(this).parseError; + } + function popStack(n) { + stack.length = stack.length - 2 * n; + vstack.length = vstack.length - n; + lstack.length = lstack.length - n; + } + _token_stack: + function lex() { + var token; + token = lexer.lex() || EOF; + if (typeof token !== 'number') { + token = self.symbols_[token] || token; + } + return token; + } + var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected; + while (true) { + state = stack[stack.length - 1]; + if (this.defaultActions[state]) { + action = this.defaultActions[state]; + } else { + if (symbol === null || typeof symbol == 'undefined') { + symbol = lex(); + } + action = table[state] && table[state][symbol]; + } + if (typeof action === 'undefined' || !action.length || !action[0]) { + var errStr = ''; + expected = []; + for (p in table[state]) { + if (this.terminals_[p] && p > TERROR) { + expected.push('\'' + this.terminals_[p] + '\''); + } + } + if (lexer.showPosition) { + errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\''; + } else { + errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\''); + } + this.parseError(errStr, { + text: lexer.match, + token: this.terminals_[symbol] || symbol, + line: lexer.yylineno, + loc: yyloc, + expected: expected + }); + } + if (action[0] instanceof Array && action.length > 1) { + throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol); + } + switch (action[0]) { + case 1: + stack.push(symbol); + vstack.push(lexer.yytext); + lstack.push(lexer.yylloc); + stack.push(action[1]); + symbol = null; + if (!preErrorSymbol) { + yyleng = lexer.yyleng; + yytext = lexer.yytext; + yylineno = lexer.yylineno; + yyloc = lexer.yylloc; + if (recovering > 0) { + recovering--; + } + } else { + symbol = preErrorSymbol; + preErrorSymbol = null; + } + break; + case 2: + len = this.productions_[action[1]][1]; + yyval.$ = vstack[vstack.length - len]; + yyval._$ = { + first_line: lstack[lstack.length - (len || 1)].first_line, + last_line: lstack[lstack.length - 1].last_line, + first_column: lstack[lstack.length - (len || 1)].first_column, + last_column: lstack[lstack.length - 1].last_column + }; + if (ranges) { + yyval._$.range = [ + lstack[lstack.length - (len || 1)].range[0], + lstack[lstack.length - 1].range[1] + ]; + } + r = this.performAction.apply(yyval, [ + yytext, + yyleng, + yylineno, + sharedState.yy, + action[1], + vstack, + lstack + ].concat(args)); + if (typeof r !== 'undefined') { + return r; + } + if (len) { + stack = stack.slice(0, -1 * len * 2); + vstack = vstack.slice(0, -1 * len); + lstack = lstack.slice(0, -1 * len); + } + stack.push(this.productions_[action[1]][0]); + vstack.push(yyval.$); + lstack.push(yyval._$); + newState = table[stack[stack.length - 2]][stack[stack.length - 1]]; + stack.push(newState); + break; + case 3: + return true; + } + } + return true; +}}; +/* generated by jison-lex 0.3.4 */ +var lexer = (function(){ +var lexer = ({ + +EOF:1, + +parseError:function parseError(str, hash) { + if (this.yy.parser) { + this.yy.parser.parseError(str, hash); + } else { + throw new Error(str); + } + }, + +// resets the lexer, sets new input +setInput:function (input, yy) { + this.yy = yy || this.yy || {}; + this._input = input; + this._more = this._backtrack = this.done = false; + this.yylineno = this.yyleng = 0; + this.yytext = this.matched = this.match = ''; + this.conditionStack = ['INITIAL']; + this.yylloc = { + first_line: 1, + first_column: 0, + last_line: 1, + last_column: 0 + }; + if (this.options.ranges) { + this.yylloc.range = [0,0]; + } + this.offset = 0; + return this; + }, + +// consumes and returns one char from the input +input:function () { + var ch = this._input[0]; + this.yytext += ch; + this.yyleng++; + this.offset++; + this.match += ch; + this.matched += ch; + var lines = ch.match(/(?:\r\n?|\n).*/g); + if (lines) { + this.yylineno++; + this.yylloc.last_line++; + } else { + this.yylloc.last_column++; + } + if (this.options.ranges) { + this.yylloc.range[1]++; + } + + this._input = this._input.slice(1); + return ch; + }, + +// unshifts one char (or a string) into the input +unput:function (ch) { + var len = ch.length; + var lines = ch.split(/(?:\r\n?|\n)/g); + + this._input = ch + this._input; + this.yytext = this.yytext.substr(0, this.yytext.length - len); + //this.yyleng -= len; + this.offset -= len; + var oldLines = this.match.split(/(?:\r\n?|\n)/g); + this.match = this.match.substr(0, this.match.length - 1); + this.matched = this.matched.substr(0, this.matched.length - 1); + + if (lines.length - 1) { + this.yylineno -= lines.length - 1; + } + var r = this.yylloc.range; + + this.yylloc = { + first_line: this.yylloc.first_line, + last_line: this.yylineno + 1, + first_column: this.yylloc.first_column, + last_column: lines ? + (lines.length === oldLines.length ? this.yylloc.first_column : 0) + + oldLines[oldLines.length - lines.length].length - lines[0].length : + this.yylloc.first_column - len + }; + + if (this.options.ranges) { + this.yylloc.range = [r[0], r[0] + this.yyleng - len]; + } + this.yyleng = this.yytext.length; + return this; + }, + +// When called from action, caches matched text and appends it on next action +more:function () { + this._more = true; + return this; + }, + +// When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead. +reject:function () { + if (this.options.backtrack_lexer) { + this._backtrack = true; + } else { + return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), { + text: "", + token: null, + line: this.yylineno + }); + + } + return this; + }, + +// retain first n characters of the match +less:function (n) { + this.unput(this.match.slice(n)); + }, + +// displays already matched input, i.e. for error messages +pastInput:function () { + var past = this.matched.substr(0, this.matched.length - this.match.length); + return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, ""); + }, + +// displays upcoming input, i.e. for error messages +upcomingInput:function () { + var next = this.match; + if (next.length < 20) { + next += this._input.substr(0, 20-next.length); + } + return (next.substr(0,20) + (next.length > 20 ? '...' : '')).replace(/\n/g, ""); + }, + +// displays the character position where the lexing error occurred, i.e. for error messages +showPosition:function () { + var pre = this.pastInput(); + var c = new Array(pre.length + 1).join("-"); + return pre + this.upcomingInput() + "\n" + c + "^"; + }, + +// test the lexed token: return FALSE when not a match, otherwise return token +test_match:function (match, indexed_rule) { + var token, + lines, + backup; + + if (this.options.backtrack_lexer) { + // save context + backup = { + yylineno: this.yylineno, + yylloc: { + first_line: this.yylloc.first_line, + last_line: this.last_line, + first_column: this.yylloc.first_column, + last_column: this.yylloc.last_column + }, + yytext: this.yytext, + match: this.match, + matches: this.matches, + matched: this.matched, + yyleng: this.yyleng, + offset: this.offset, + _more: this._more, + _input: this._input, + yy: this.yy, + conditionStack: this.conditionStack.slice(0), + done: this.done + }; + if (this.options.ranges) { + backup.yylloc.range = this.yylloc.range.slice(0); + } + } + + lines = match[0].match(/(?:\r\n?|\n).*/g); + if (lines) { + this.yylineno += lines.length; + } + this.yylloc = { + first_line: this.yylloc.last_line, + last_line: this.yylineno + 1, + first_column: this.yylloc.last_column, + last_column: lines ? + lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : + this.yylloc.last_column + match[0].length + }; + this.yytext += match[0]; + this.match += match[0]; + this.matches = match; + this.yyleng = this.yytext.length; + if (this.options.ranges) { + this.yylloc.range = [this.offset, this.offset += this.yyleng]; + } + this._more = false; + this._backtrack = false; + this._input = this._input.slice(match[0].length); + this.matched += match[0]; + token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]); + if (this.done && this._input) { + this.done = false; + } + if (token) { + return token; + } else if (this._backtrack) { + // recover context + for (var k in backup) { + this[k] = backup[k]; + } + return false; // rule action called reject() implying the next rule should be tested instead. + } + return false; + }, + +// return next match in input +next:function () { + if (this.done) { + return this.EOF; + } + if (!this._input) { + this.done = true; + } + + var token, + match, + tempMatch, + index; + if (!this._more) { + this.yytext = ''; + this.match = ''; + } + var rules = this._currentRules(); + for (var i = 0; i < rules.length; i++) { + tempMatch = this._input.match(this.rules[rules[i]]); + if (tempMatch && (!match || tempMatch[0].length > match[0].length)) { + match = tempMatch; + index = i; + if (this.options.backtrack_lexer) { + token = this.test_match(tempMatch, rules[i]); + if (token !== false) { + return token; + } else if (this._backtrack) { + match = false; + continue; // rule action called reject() implying a rule MISmatch. + } else { + // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace) + return false; + } + } else if (!this.options.flex) { + break; + } + } + } + if (match) { + token = this.test_match(match, rules[index]); + if (token !== false) { + return token; + } + // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace) + return false; + } + if (this._input === "") { + return this.EOF; + } else { + return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), { + text: "", + token: null, + line: this.yylineno + }); + } + }, + +// return next match that has a token +lex:function lex() { + var r = this.next(); + if (r) { + return r; + } else { + return this.lex(); + } + }, + +// activates a new lexer condition state (pushes the new lexer condition state onto the condition stack) +begin:function begin(condition) { + this.conditionStack.push(condition); + }, + +// pop the previously active lexer condition state off the condition stack +popState:function popState() { + var n = this.conditionStack.length - 1; + if (n > 0) { + return this.conditionStack.pop(); + } else { + return this.conditionStack[0]; + } + }, + +// produce the lexer rule set which is active for the currently active lexer condition state +_currentRules:function _currentRules() { + if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) { + return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules; + } else { + return this.conditions["INITIAL"].rules; + } + }, + +// return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available +topState:function topState(n) { + n = this.conditionStack.length - 1 - Math.abs(n || 0); + if (n >= 0) { + return this.conditionStack[n]; + } else { + return "INITIAL"; + } + }, + +// alias for begin(condition) +pushState:function pushState(condition) { + this.begin(condition); + }, + +// return the number of states currently on the stack +stateStackSize:function stateStackSize() { + return this.conditionStack.length; + }, +options: {}, +performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) { +var YYSTATE=YY_START; +switch($avoiding_name_collisions) { +case 0:/* skip whitespace */ +break; +case 1:return 6 +break; +case 2:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2); return 4 +break; +case 3:return 17 +break; +case 4:return 18 +break; +case 5:return 23 +break; +case 6:return 24 +break; +case 7:return 22 +break; +case 8:return 21 +break; +case 9:return 10 +break; +case 10:return 11 +break; +case 11:return 8 +break; +case 12:return 14 +break; +case 13:return 'INVALID' +break; +} +}, +rules: [/^(?:\s+)/,/^(?:(-?([0-9]|[1-9][0-9]+))(\.[0-9]+)?([eE][-+]?[0-9]+)?\b)/,/^(?:"(?:\\[\\"bfnrt/]|\\u[a-fA-F0-9]{4}|[^\\\0-\x09\x0a-\x1f"])*")/,/^(?:\{)/,/^(?:\})/,/^(?:\[)/,/^(?:\])/,/^(?:,)/,/^(?::)/,/^(?:true\b)/,/^(?:false\b)/,/^(?:null\b)/,/^(?:$)/,/^(?:.)/], +conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],"inclusive":true}} +}); +return lexer; +})(); +parser.lexer = lexer; +function Parser () { + this.yy = {}; +} +Parser.prototype = parser;parser.Parser = Parser; +return new Parser; +})(); + + +if (typeof require !== 'undefined' && typeof exports !== 'undefined') { +exports.parser = parser; +exports.Parser = parser.Parser; +exports.parse = function () { return parser.parse.apply(parser, arguments); }; +} diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/package.json b/node_modules/@mapbox/jsonlint-lines-primitives/package.json new file mode 100644 index 0000000000000000000000000000000000000000..4a98576c4aebbb28f710f1a22386d67a42ce1764 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/package.json @@ -0,0 +1,34 @@ +{ + "author": "Zach Carter (http://zaa.ch)", + "name": "@mapbox/jsonlint-lines-primitives", + "description": "Validate JSON", + "keywords": [ + "json", + "validation", + "lint", + "jsonlint" + ], + "version": "2.0.2", + "preferGlobal": true, + "repository": { + "type": "git", + "url": "git://github.com/mapbox/jsonlint.git" + }, + "bugs": { + "url": "http://github.com/mapbox/jsonlint/issues" + }, + "main": "lib/jsonlint.js", + "engines": { + "node": ">= 0.6" + }, + "dependencies": {}, + "devDependencies": { + "test": "*", + "jison": "*", + "uglify-js": "*" + }, + "scripts": { + "test": "node test/all-tests.js" + }, + "optionalDependencies": {} +} diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/scripts/bundle.js b/node_modules/@mapbox/jsonlint-lines-primitives/scripts/bundle.js new file mode 100644 index 0000000000000000000000000000000000000000..c8e542d7e232f350271085b4393f4e7fa88a4b17 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/scripts/bundle.js @@ -0,0 +1,8 @@ +var fs = require('fs'); + +var source = "var jsonlint = (function(){var require=true,module=false;var exports={};" + + fs.readFileSync(__dirname+'/../lib/jsonlint.js', 'utf8') + + "return exports;})()"; + +console.log(source); + diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/src/jsonlint.l b/node_modules/@mapbox/jsonlint-lines-primitives/src/jsonlint.l new file mode 100644 index 0000000000000000000000000000000000000000..35491e11baa13dabdeadef793c18a50275e34eda --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/src/jsonlint.l @@ -0,0 +1,24 @@ +int "-"?([0-9]|[1-9][0-9]+) +exp [eE][-+]?[0-9]+ +frac "."[0-9]+ + +%% +\s+ /* skip whitespace */ + +{int}{frac}?{exp}?\b return 'NUMBER' +\"(?:'\\'[\\"bfnrt/]|'\\u'[a-fA-F0-9]{4}|[^\\\0-\x09\x0a-\x1f"])*\" yytext = yytext.substr(1,yyleng-2); return 'STRING' + +"{" return '{' +"}" return '}' +"[" return '[' +"]" return ']' +"," return ',' +":" return ':' +"true" return 'TRUE' +"false" return 'FALSE' +"null" return 'NULL' +<> return 'EOF' +. return 'INVALID' + +%% + diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/src/jsonlint.y b/node_modules/@mapbox/jsonlint-lines-primitives/src/jsonlint.y new file mode 100644 index 0000000000000000000000000000000000000000..09a171f12efad92ad9436161dd58c378f89e07bd --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/src/jsonlint.y @@ -0,0 +1,110 @@ +%start JSONText + +/* + ECMA-262 5th Edition, 15.12.1 The JSON Grammar. +*/ + + +%% + +JSONString + : STRING + { // replace escaped characters with actual character + $$ = new String(yytext.replace(/\\(\\|")/g, "$"+"1") + .replace(/\\n/g,'\n') + .replace(/\\r/g,'\r') + .replace(/\\t/g,'\t') + .replace(/\\v/g,'\v') + .replace(/\\f/g,'\f') + .replace(/\\b/g,'\b')); + $$.__line__ = @$.first_line; + } + ; + +JSONNumber + : NUMBER + { + $$ = new Number(yytext); + $$.__line__ = @$.first_line; + } + ; + +JSONNullLiteral + : NULL + { + $$ = null; + } + ; + +JSONBooleanLiteral + : TRUE + { + $$ = new Boolean(true); + $$.__line__ = @$.first_line; + } + | FALSE + { + $$ = new Boolean(false); + $$.__line__ = @$.first_line; + } + ; + +JSONText + : JSONValue EOF + {return $$ = $1;} + ; + +JSONValue + : JSONNullLiteral + | JSONBooleanLiteral + | JSONString + | JSONNumber + | JSONObject + | JSONArray + ; + +JSONObject + : '{' '}' + {$$ = {}; Object.defineProperty($$, '__line__', { + value: @$.first_line, + enumerable: false + })} + | '{' JSONMemberList '}' + {$$ = $2; Object.defineProperty($$, '__line__', { + value: @$.first_line, + enumerable: false + })} + ; + +JSONMember + : JSONString ':' JSONValue + {$$ = [$1, $3];} + ; + +JSONMemberList + : JSONMember + {{$$ = {}; $$[$1[0]] = $1[1];}} + | JSONMemberList ',' JSONMember + {$$ = $1; $1[$3[0]] = $3[1];} + ; + +JSONArray + : '[' ']' + {$$ = []; Object.defineProperty($$, '__line__', { + value: @$.first_line, + enumerable: false + })} + | '[' JSONElementList ']' + {$$ = $2; Object.defineProperty($$, '__line__', { + value: @$.first_line, + enumerable: false + })} + ; + +JSONElementList + : JSONValue + {$$ = [$1];} + | JSONElementList ',' JSONValue + {$$ = $1; $1.push($3);} + ; + diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/all-tests.js b/node_modules/@mapbox/jsonlint-lines-primitives/test/all-tests.js new file mode 100644 index 0000000000000000000000000000000000000000..276f372880779336a6321611b46100cf411bfe1e --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/all-tests.js @@ -0,0 +1,210 @@ +var fs = require("fs"), + assert = require("assert"), + parser = require("../lib/jsonlint").parser; + +exports["test string with line break"] = function () { + var json = '{"foo": "bar\nbar"}'; + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test string literal"] = function () { + var json = '"foo"'; + assert.equal(parser.parse(json), "foo"); + assert.equal(parser.parse(json).__line__, 1); +}; + +exports["test number literal"] = function () { + var json = '1234'; + assert.equal(parser.parse(json), 1234); + assert.equal(parser.parse(json).__line__, 1); +}; + +exports["test null literal"] = function () { + var json = 'null'; + assert.equal(parser.parse(json), null); +}; + +exports["test boolean literal"] = function () { + var json = 'true'; + assert.equal(parser.parse(json), true); + assert.equal(parser.parse(json).__line__, 1); +}; + +exports["test unclosed array"] = function () { + var json = fs.readFileSync(__dirname + "/fails/2.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test unquotedkey keys must be quoted"] = function () { + var json = fs.readFileSync(__dirname + "/fails/3.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test extra comma"] = function () { + var json = fs.readFileSync(__dirname + "/fails/4.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test double extra comma"] = function () { + var json = fs.readFileSync(__dirname + "/fails/5.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test missing value"] = function () { + var json = fs.readFileSync(__dirname + "/fails/6.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test comma after the close"] = function () { + var json = fs.readFileSync(__dirname + "/fails/7.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test extra close"] = function () { + var json = fs.readFileSync(__dirname + "/fails/8.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test extra comma after value"] = function () { + var json = fs.readFileSync(__dirname + "/fails/9.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test extra value after close with misplaced quotes"] = function () { + var json = fs.readFileSync(__dirname + "/fails/10.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test illegal expression addition"] = function () { + var json = fs.readFileSync(__dirname + "/fails/11.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test illegal invocation of alert"] = function () { + var json = fs.readFileSync(__dirname + "/fails/12.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test numbers cannot have leading zeroes"] = function () { + var json = fs.readFileSync(__dirname + "/fails/13.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test numbers cannot be hex"] = function () { + var json = fs.readFileSync(__dirname + "/fails/14.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test illegal backslash escape \\0"] = function () { + var json = fs.readFileSync(__dirname + "/fails/15.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test unquoted text"] = function () { + var json = fs.readFileSync(__dirname + "/fails/16.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test illegal backslash escape \\x"] = function () { + var json = fs.readFileSync(__dirname + "/fails/17.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test missing colon"] = function () { + var json = fs.readFileSync(__dirname + "/fails/19.json") + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test double colon"] = function () { + var json = fs.readFileSync(__dirname + "/fails/20.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test comma instead of colon"] = function () { + var json = fs.readFileSync(__dirname + "/fails/21.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test colon instead of comma"] = function () { + var json = fs.readFileSync(__dirname + "/fails/22.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test bad raw value"] = function () { + var json = fs.readFileSync(__dirname + "/fails/23.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test single quotes"] = function () { + var json = fs.readFileSync(__dirname + "/fails/24.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test tab character in string"] = function () { + var json = fs.readFileSync(__dirname + "/fails/25.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test tab character in string 2"] = function () { + var json = fs.readFileSync(__dirname + "/fails/26.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test line break in string"] = function () { + var json = fs.readFileSync(__dirname + "/fails/27.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test line break in string in array"] = function () { + var json = fs.readFileSync(__dirname + "/fails/28.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test 0e"] = function () { + var json = fs.readFileSync(__dirname + "/fails/29.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test 0e+"] = function () { + var json = fs.readFileSync(__dirname + "/fails/30.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test 0e+ 1"] = function () { + var json = fs.readFileSync(__dirname + "/fails/31.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test comma instead of closing brace"] = function () { + var json = fs.readFileSync(__dirname + "/fails/32.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +}; + +exports["test bracket mismatch"] = function () { + var json = fs.readFileSync(__dirname + "/fails/33.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +} + +exports["test extra brace"] = function () { + var json = fs.readFileSync(__dirname + "/fails/34.json").toString(); + assert["throws"](function () {parser.parse(json)}, "should throw error"); +} + +exports["test pass-1"] = function () { + var json = fs.readFileSync(__dirname + "/passes/1.json").toString(); + assert.doesNotThrow(function () {parser.parse(json)}, "should pass"); +} + +exports["test pass-2"] = function () { + var json = fs.readFileSync(__dirname + "/passes/2.json").toString(); + assert.doesNotThrow(function () {parser.parse(json)}, "should pass"); +} + +exports["test pass-3"] = function () { + var json = fs.readFileSync(__dirname + "/passes/3.json").toString(); + assert.doesNotThrow(function () {parser.parse(json)}, "should pass"); +} + +if (require.main === module) { + require("test").run(exports); +} diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/10.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/10.json new file mode 100644 index 0000000000000000000000000000000000000000..5d8c0047bd522dfa9fbc642051ed76bd3162d936 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/10.json @@ -0,0 +1 @@ +{"Extra value after close": true} "misplaced quoted value" \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/11.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/11.json new file mode 100644 index 0000000000000000000000000000000000000000..76eb95b4583c8ee74eee3bdc25e1db69e1aaf4bb --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/11.json @@ -0,0 +1 @@ +{"Illegal expression": 1 + 2} \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/12.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/12.json new file mode 100644 index 0000000000000000000000000000000000000000..77580a4522d8c79245851e72a3644a0709b3d28c --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/12.json @@ -0,0 +1 @@ +{"Illegal invocation": alert()} \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/13.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/13.json new file mode 100644 index 0000000000000000000000000000000000000000..379406b59bdb943f145afea98ff1bbc45d43ff45 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/13.json @@ -0,0 +1 @@ +{"Numbers cannot have leading zeroes": 013} \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/14.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/14.json new file mode 100644 index 0000000000000000000000000000000000000000..0ed366b38a34f551c25735bdcb9282d27beae026 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/14.json @@ -0,0 +1 @@ +{"Numbers cannot be hex": 0x14} \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/15.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/15.json new file mode 100644 index 0000000000000000000000000000000000000000..fc8376b605da69dda23f3fcdd9816dcbf2e736cc --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/15.json @@ -0,0 +1 @@ +["Illegal backslash escape: \x15"] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/16.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/16.json new file mode 100644 index 0000000000000000000000000000000000000000..3fe21d4b532498c8b90872ef571c6867f45e645f --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/16.json @@ -0,0 +1 @@ +[\naked] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/17.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/17.json new file mode 100644 index 0000000000000000000000000000000000000000..62b9214aeda6d74a72ebeceedf0aae3609f1c638 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/17.json @@ -0,0 +1 @@ +["Illegal backslash escape: \017"] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/19.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/19.json new file mode 100644 index 0000000000000000000000000000000000000000..3b9c46fa9a296c9d8c35ce4a6592d8bb7ffe748a --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/19.json @@ -0,0 +1 @@ +{"Missing colon" null} \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/2.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/2.json new file mode 100644 index 0000000000000000000000000000000000000000..6b7c11e5a56537f81e651980359c62e263f7399f --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/2.json @@ -0,0 +1 @@ +["Unclosed array" \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/20.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/20.json new file mode 100644 index 0000000000000000000000000000000000000000..27c1af3e72ee37bbf64ccd7b77c5bad8cdea1557 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/20.json @@ -0,0 +1 @@ +{"Double colon":: null} \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/21.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/21.json new file mode 100644 index 0000000000000000000000000000000000000000..62474573b2160adefc3dc669b39200ea659d6e59 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/21.json @@ -0,0 +1 @@ +{"Comma instead of colon", null} \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/22.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/22.json new file mode 100644 index 0000000000000000000000000000000000000000..a7752581bcf7f3b901aef052a2df541c1285b6c2 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/22.json @@ -0,0 +1 @@ +["Colon instead of comma": false] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/23.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/23.json new file mode 100644 index 0000000000000000000000000000000000000000..494add1ca190e12acd1c8e34ac819a6316c927bc --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/23.json @@ -0,0 +1 @@ +["Bad value", truth] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/24.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/24.json new file mode 100644 index 0000000000000000000000000000000000000000..caff239bfc36297da08828095105bb497b8aef2a --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/24.json @@ -0,0 +1 @@ +['single quote'] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/25.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/25.json new file mode 100644 index 0000000000000000000000000000000000000000..8b7ad23e010314591d914519996c28483b5dadc8 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/25.json @@ -0,0 +1 @@ +[" tab character in string "] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/26.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/26.json new file mode 100644 index 0000000000000000000000000000000000000000..845d26a6a54398c49cd492e6836c0d1987f554e4 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/26.json @@ -0,0 +1 @@ +["tab\ character\ in\ string\ "] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/27.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/27.json new file mode 100644 index 0000000000000000000000000000000000000000..6b01a2ca4a97ec36604771dcc3175bbcda865d85 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/27.json @@ -0,0 +1,2 @@ +["line +break"] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/28.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/28.json new file mode 100644 index 0000000000000000000000000000000000000000..621a0101c664a619457d16f1107a677c911481b4 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/28.json @@ -0,0 +1,2 @@ +["line\ +break"] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/29.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/29.json new file mode 100644 index 0000000000000000000000000000000000000000..47ec421bb6242648e80b2b465049acbae1e6e44a --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/29.json @@ -0,0 +1 @@ +[0e] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/3.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/3.json new file mode 100644 index 0000000000000000000000000000000000000000..168c81eb78537ea4006ea0a46b67851d9995564d --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/3.json @@ -0,0 +1 @@ +{unquoted_key: "keys must be quoted"} \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/30.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/30.json new file mode 100644 index 0000000000000000000000000000000000000000..8ab0bc4b8b2c73b616a45931d05720555a2f7762 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/30.json @@ -0,0 +1 @@ +[0e+] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/31.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/31.json new file mode 100644 index 0000000000000000000000000000000000000000..1cce602b518fc6e7f164a58cc710def27e64b8a5 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/31.json @@ -0,0 +1 @@ +[0e+-1] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/32.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/32.json new file mode 100644 index 0000000000000000000000000000000000000000..45cba7396ff7462dd6de005c32fd2a95c5318e5f --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/32.json @@ -0,0 +1 @@ +{"Comma instead if closing brace": true, \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/33.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/33.json new file mode 100644 index 0000000000000000000000000000000000000000..ca5eb19dc97f5ca363ff33a4c3644ad28e612679 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/33.json @@ -0,0 +1 @@ +["mismatch"} \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/34.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/34.json new file mode 100644 index 0000000000000000000000000000000000000000..11ef16af64c145edb681f27e5934ad601705b228 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/34.json @@ -0,0 +1 @@ +{"extra brace": 1}} diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/4.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/4.json new file mode 100644 index 0000000000000000000000000000000000000000..9de168bf34e2e368d044bccc099d44b02316de66 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/4.json @@ -0,0 +1 @@ +["extra comma",] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/5.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/5.json new file mode 100644 index 0000000000000000000000000000000000000000..ddf3ce3d2409467011ec7545551d5d078bce1bfd --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/5.json @@ -0,0 +1 @@ +["double extra comma",,] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/6.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/6.json new file mode 100644 index 0000000000000000000000000000000000000000..ed91580e1b1c15194a9a758f1b231575074722db --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/6.json @@ -0,0 +1 @@ +[ , "<-- missing value"] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/7.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/7.json new file mode 100644 index 0000000000000000000000000000000000000000..8a96af3e4ee6c7fffd8da641dedcd750a5cc4d9d --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/7.json @@ -0,0 +1 @@ +["Comma after the close"], \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/8.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/8.json new file mode 100644 index 0000000000000000000000000000000000000000..b28479c6ecb21a801d6988b9ea39a4eb00a64702 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/8.json @@ -0,0 +1 @@ +["Extra close"]] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/9.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/9.json new file mode 100644 index 0000000000000000000000000000000000000000..5815574f363e58cf91578e909ef4dabb402a75de --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/fails/9.json @@ -0,0 +1 @@ +{"Extra comma": true,} \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/passes/1.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/passes/1.json new file mode 100644 index 0000000000000000000000000000000000000000..70e26854369282e625e75b302782f581e610f2b3 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/passes/1.json @@ -0,0 +1,58 @@ +[ + "JSON Test Pattern pass1", + {"object with 1 member":["array with 1 element"]}, + {}, + [], + -42, + true, + false, + null, + { + "integer": 1234567890, + "real": -9876.543210, + "e": 0.123456789e-12, + "E": 1.234567890E+34, + "": 23456789012E66, + "zero": 0, + "one": 1, + "space": " ", + "quote": "\"", + "backslash": "\\", + "controls": "\b\f\n\r\t", + "slash": "/ & \/", + "alpha": "abcdefghijklmnopqrstuvwyz", + "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ", + "digit": "0123456789", + "0123456789": "digit", + "special": "`1~!@#$%^&*()_+-={':[,]}|;.?", + "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A", + "true": true, + "false": false, + "null": null, + "array":[ ], + "object":{ }, + "address": "50 St. James Street", + "url": "http://www.JSON.org/", + "comment": "// /* */": " ", + " s p a c e d " :[1,2 , 3 + +, + +4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7], + "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}", + "quotes": "" \u0022 %22 0x22 034 "", + "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?" +: "A key can be any string" + }, + 0.5 ,98.6 +, +99.44 +, + +1066, +1e1, +0.1e1, +1e-1, +1e00,2e+00,2e-00 +,"rosebud"] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/passes/2.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/passes/2.json new file mode 100644 index 0000000000000000000000000000000000000000..d3c63c7ad845e4cedd0c70d13102b38c51ec197a --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/passes/2.json @@ -0,0 +1 @@ +[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]] \ No newline at end of file diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/test/passes/3.json b/node_modules/@mapbox/jsonlint-lines-primitives/test/passes/3.json new file mode 100644 index 0000000000000000000000000000000000000000..4528d51f1ac615e7e11dbb1321dc99187705f0d8 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/test/passes/3.json @@ -0,0 +1,6 @@ +{ + "JSON Test Pattern pass3": { + "The outermost value": "must be an object or array.", + "In this test": "It is an object." + } +} diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/web/json2.js b/node_modules/@mapbox/jsonlint-lines-primitives/web/json2.js new file mode 100644 index 0000000000000000000000000000000000000000..7044c6de7e2e279172ffbb1e6d29d4f950c20806 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/web/json2.js @@ -0,0 +1,334 @@ + +/*jslint evil: true, strict: false */ + +/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply, + call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, + getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, + lastIndex, length, parse, prototype, push, replace, slice, stringify, + test, toJSON, toString, valueOf +*/ + + +// Create a JSON object only if one does not already exist. We create the +// methods in a closure to avoid creating global variables. + +if (!this.JSON) { + this.JSON = {}; +} + +(function () { + + function f(n) { + // Format integers to have at least two digits. + return n < 10 ? '0' + n : n; + } + + if (typeof Date.prototype.toJSON !== 'function') { + + Date.prototype.toJSON = function (key) { + + return isFinite(this.valueOf()) ? + this.getUTCFullYear() + '-' + + f(this.getUTCMonth() + 1) + '-' + + f(this.getUTCDate()) + 'T' + + f(this.getUTCHours()) + ':' + + f(this.getUTCMinutes()) + ':' + + f(this.getUTCSeconds()) + 'Z' : null; + }; + + String.prototype.toJSON = + Number.prototype.toJSON = + Boolean.prototype.toJSON = function (key) { + return this.valueOf(); + }; + } + + var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + gap, + indent, + meta = { // table of character substitutions + '\b': '\\b', + '\t': '\\t', + '\n': '\\n', + '\f': '\\f', + '\r': '\\r', + '"' : '\\"', + '\\': '\\\\' + }, + rep; + + + function quote(string) { + +// If the string contains no control characters, no quote characters, and no +// backslash characters, then we can safely slap some quotes around it. +// Otherwise we must also replace the offending characters with safe escape +// sequences. + + escapable.lastIndex = 0; + return escapable.test(string) ? + '"' + string.replace(escapable, function (a) { + var c = meta[a]; + return typeof c === 'string' ? c : + '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); + }) + '"' : + '"' + string + '"'; + } + + + function str(key, holder) { + +// Produce a string from holder[key]. + + var i, // The loop counter. + k, // The member key. + v, // The member value. + length, + mind = gap, + partial, + value = holder[key]; + +// If the value has a toJSON method, call it to obtain a replacement value. + + if (value && typeof value === 'object' && + typeof value.toJSON === 'function') { + value = value.toJSON(key); + } + +// If we were called with a replacer function, then call the replacer to +// obtain a replacement value. + + if (typeof rep === 'function') { + value = rep.call(holder, key, value); + } + +// What happens next depends on the value's type. + + switch (typeof value) { + case 'string': + return quote(value); + + case 'number': + +// JSON numbers must be finite. Encode non-finite numbers as null. + + return isFinite(value) ? String(value) : 'null'; + + case 'boolean': + case 'null': + +// If the value is a boolean or null, convert it to a string. Note: +// typeof null does not produce 'null'. The case is included here in +// the remote chance that this gets fixed someday. + + return String(value); + +// If the type is 'object', we might be dealing with an object or an array or +// null. + + case 'object': + +// Due to a specification blunder in ECMAScript, typeof null is 'object', +// so watch out for that case. + + if (!value) { + return 'null'; + } + +// Make an array to hold the partial results of stringifying this object value. + + gap += indent; + partial = []; + +// Is the value an array? + + if (Object.prototype.toString.apply(value) === '[object Array]') { + +// The value is an array. Stringify every element. Use null as a placeholder +// for non-JSON values. + + length = value.length; + for (i = 0; i < length; i += 1) { + partial[i] = str(i, value) || 'null'; + } + +// Join all of the elements together, separated with commas, and wrap them in +// brackets. + + v = partial.length === 0 ? '[]' : + gap ? '[\n' + gap + + partial.join(',\n' + gap) + '\n' + + mind + ']' : + '[' + partial.join(',') + ']'; + gap = mind; + return v; + } + +// If the replacer is an array, use it to select the members to be stringified. + + if (rep && typeof rep === 'object') { + length = rep.length; + for (i = 0; i < length; i += 1) { + k = rep[i]; + if (typeof k === 'string') { + v = str(k, value); + if (v) { + partial.push(quote(k) + (gap ? ': ' : ':') + v); + } + } + } + } else { + +// Otherwise, iterate through all of the keys in the object. + + for (k in value) { + if (Object.hasOwnProperty.call(value, k)) { + v = str(k, value); + if (v) { + partial.push(quote(k) + (gap ? ': ' : ':') + v); + } + } + } + } + +// Join all of the member texts together, separated with commas, +// and wrap them in braces. + + v = partial.length === 0 ? '{}' : + gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + + mind + '}' : '{' + partial.join(',') + '}'; + gap = mind; + return v; + } + } + +// If the JSON object does not yet have a stringify method, give it one. + + if (typeof JSON.stringify !== 'function') { + JSON.stringify = function (value, replacer, space) { + +// The stringify method takes a value and an optional replacer, and an optional +// space parameter, and returns a JSON text. The replacer can be a function +// that can replace values, or an array of strings that will select the keys. +// A default replacer method can be provided. Use of the space parameter can +// produce text that is more easily readable. + + var i; + gap = ''; + indent = ''; + +// If the space parameter is a number, make an indent string containing that +// many spaces. + + if (typeof space === 'number') { + for (i = 0; i < space; i += 1) { + indent += ' '; + } + +// If the space parameter is a string, it will be used as the indent string. + + } else if (typeof space === 'string') { + indent = space; + } + +// If there is a replacer, it must be a function or an array. +// Otherwise, throw an error. + + rep = replacer; + if (replacer && typeof replacer !== 'function' && + (typeof replacer !== 'object' || + typeof replacer.length !== 'number')) { + throw new Error('JSON.stringify'); + } + +// Make a fake root object containing our value under the key of ''. +// Return the result of stringifying the value. + + return str('', {'': value}); + }; + } + + +// If the JSON object does not yet have a parse method, give it one. + + if (typeof JSON.parse !== 'function') { + JSON.parse = function (text, reviver) { + +// The parse method takes a text and an optional reviver function, and returns +// a JavaScript value if the text is a valid JSON text. + + var j; + + function walk(holder, key) { + +// The walk method is used to recursively walk the resulting structure so +// that modifications can be made. + + var k, v, value = holder[key]; + if (value && typeof value === 'object') { + for (k in value) { + if (Object.hasOwnProperty.call(value, k)) { + v = walk(value, k); + if (v !== undefined) { + value[k] = v; + } else { + delete value[k]; + } + } + } + } + return reviver.call(holder, key, value); + } + + +// Parsing happens in four stages. In the first stage, we replace certain +// Unicode characters with escape sequences. JavaScript handles many characters +// incorrectly, either silently deleting them, or treating them as line endings. + + cx.lastIndex = 0; + if (cx.test(text)) { + text = text.replace(cx, function (a) { + return '\\u' + + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); + }); + } + +// In the second stage, we run the text against regular expressions that look +// for non-JSON patterns. We are especially concerned with '()' and 'new' +// because they can cause invocation, and '=' because it can cause mutation. +// But just to be safe, we want to reject all unexpected forms. + +// We split the second stage into 4 regexp operations in order to work around +// crippling inefficiencies in IE's and Safari's regexp engines. First we +// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we +// replace all simple value tokens with ']' characters. Third, we delete all +// open brackets that follow a colon or comma or that begin the text. Finally, +// we look to see that the remaining characters are only whitespace or ']' or +// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval. + + if (/^[\],:{}\s]*$/. +test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@'). +replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'). +replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { + +// In the third stage we use the eval function to compile the text into a +// JavaScript structure. The '{' operator is subject to a syntactic ambiguity +// in JavaScript: it can begin a block or an object literal. We wrap the text +// in parens to eliminate the ambiguity. + + j = eval('(' + text + ')'); + +// In the optional fourth stage, we recursively walk the new structure, passing +// each name/value pair to a reviver function for possible transformation. + + return typeof reviver === 'function' ? + walk({'': j}, '') : j; + } + +// If the text is not JSON parseable, then a SyntaxError is thrown. + + throw new SyntaxError('JSON.parse'); + }; + } +}()); diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/web/jsonlint.html b/node_modules/@mapbox/jsonlint-lines-primitives/web/jsonlint.html new file mode 100644 index 0000000000000000000000000000000000000000..b0880660c7384e55b7d7f8c2790cd1939cd16d66 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/web/jsonlint.html @@ -0,0 +1,59 @@ + + + + + JSON Lint + + + + + + +

JSON Lint

+

A pure JavaScript version of the service provided at jsonlint.com.

+ +

+ + +

+

Results

+

+  

project on github

+ + diff --git a/node_modules/@mapbox/jsonlint-lines-primitives/web/jsonlint.js b/node_modules/@mapbox/jsonlint-lines-primitives/web/jsonlint.js new file mode 100644 index 0000000000000000000000000000000000000000..0766e623fd073d3dcd5ffeb0aa1efd2dab134fe2 --- /dev/null +++ b/node_modules/@mapbox/jsonlint-lines-primitives/web/jsonlint.js @@ -0,0 +1 @@ +var jsonlint=function(){var require=true,module=false;var exports={};var parser=function(){var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,12],$V1=[1,13],$V2=[1,9],$V3=[1,10],$V4=[1,11],$V5=[1,14],$V6=[1,15],$V7=[14,18,22,24],$V8=[18,22],$V9=[22,24];var parser={trace:function trace(){},yy:{},symbols_:{error:2,JSONString:3,STRING:4,JSONNumber:5,NUMBER:6,JSONNullLiteral:7,NULL:8,JSONBooleanLiteral:9,TRUE:10,FALSE:11,JSONText:12,JSONValue:13,EOF:14,JSONObject:15,JSONArray:16,"{":17,"}":18,JSONMemberList:19,JSONMember:20,":":21,",":22,"[":23,"]":24,JSONElementList:25,$accept:0,$end:1},terminals_:{2:"error",4:"STRING",6:"NUMBER",8:"NULL",10:"TRUE",11:"FALSE",14:"EOF",17:"{",18:"}",21:":",22:",",23:"[",24:"]"},productions_:[0,[3,1],[5,1],[7,1],[9,1],[9,1],[12,2],[13,1],[13,1],[13,1],[13,1],[13,1],[13,1],[15,2],[15,3],[20,3],[19,1],[19,3],[16,2],[16,3],[25,1],[25,3]],performAction:function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$){var $0=$$.length-1;switch(yystate){case 1:this.$=new String(yytext.replace(/\\(\\|")/g,"$"+"1").replace(/\\n/g,"\n").replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\v/g," ").replace(/\\f/g,"\f").replace(/\\b/g,"\b"));this.$.__line__=this._$.first_line;break;case 2:this.$=new Number(yytext);this.$.__line__=this._$.first_line;break;case 3:this.$=null;break;case 4:this.$=new Boolean(true);this.$.__line__=this._$.first_line;break;case 5:this.$=new Boolean(false);this.$.__line__=this._$.first_line;break;case 6:return this.$=$$[$0-1];break;case 13:this.$={};Object.defineProperty(this.$,"__line__",{value:this._$.first_line,enumerable:false});break;case 14:case 19:this.$=$$[$0-1];Object.defineProperty(this.$,"__line__",{value:this._$.first_line,enumerable:false});break;case 15:this.$=[$$[$0-2],$$[$0]];break;case 16:this.$={};this.$[$$[$0][0]]=$$[$0][1];break;case 17:this.$=$$[$0-2];$$[$0-2][$$[$0][0]]=$$[$0][1];break;case 18:this.$=[];Object.defineProperty(this.$,"__line__",{value:this._$.first_line,enumerable:false});break;case 20:this.$=[$$[$0]];break;case 21:this.$=$$[$0-2];$$[$0-2].push($$[$0]);break}},table:[{3:5,4:$V0,5:6,6:$V1,7:3,8:$V2,9:4,10:$V3,11:$V4,12:1,13:2,15:7,16:8,17:$V5,23:$V6},{1:[3]},{14:[1,16]},o($V7,[2,7]),o($V7,[2,8]),o($V7,[2,9]),o($V7,[2,10]),o($V7,[2,11]),o($V7,[2,12]),o($V7,[2,3]),o($V7,[2,4]),o($V7,[2,5]),o([14,18,21,22,24],[2,1]),o($V7,[2,2]),{3:20,4:$V0,18:[1,17],19:18,20:19},{3:5,4:$V0,5:6,6:$V1,7:3,8:$V2,9:4,10:$V3,11:$V4,13:23,15:7,16:8,17:$V5,23:$V6,24:[1,21],25:22},{1:[2,6]},o($V7,[2,13]),{18:[1,24],22:[1,25]},o($V8,[2,16]),{21:[1,26]},o($V7,[2,18]),{22:[1,28],24:[1,27]},o($V9,[2,20]),o($V7,[2,14]),{3:20,4:$V0,20:29},{3:5,4:$V0,5:6,6:$V1,7:3,8:$V2,9:4,10:$V3,11:$V4,13:30,15:7,16:8,17:$V5,23:$V6},o($V7,[2,19]),{3:5,4:$V0,5:6,6:$V1,7:3,8:$V2,9:4,10:$V3,11:$V4,13:31,15:7,16:8,17:$V5,23:$V6},o($V8,[2,17]),o($V8,[2,15]),o($V9,[2,21])],defaultActions:{16:[2,6]},parseError:function parseError(str,hash){if(hash.recoverable){this.trace(str)}else{throw new Error(str)}},parse:function parse(input){var self=this,stack=[0],tstack=[],vstack=[null],lstack=[],table=this.table,yytext="",yylineno=0,yyleng=0,recovering=0,TERROR=2,EOF=1;var args=lstack.slice.call(arguments,1);var lexer=Object.create(this.lexer);var sharedState={yy:{}};for(var k in this.yy){if(Object.prototype.hasOwnProperty.call(this.yy,k)){sharedState.yy[k]=this.yy[k]}}lexer.setInput(input,sharedState.yy);sharedState.yy.lexer=lexer;sharedState.yy.parser=this;if(typeof lexer.yylloc=="undefined"){lexer.yylloc={}}var yyloc=lexer.yylloc;lstack.push(yyloc);var ranges=lexer.options&&lexer.options.ranges;if(typeof sharedState.yy.parseError==="function"){this.parseError=sharedState.yy.parseError}else{this.parseError=Object.getPrototypeOf(this).parseError}function popStack(n){stack.length=stack.length-2*n;vstack.length=vstack.length-n;lstack.length=lstack.length-n}_token_stack:function lex(){var token;token=lexer.lex()||EOF;if(typeof token!=="number"){token=self.symbols_[token]||token}return token}var symbol,preErrorSymbol,state,action,a,r,yyval={},p,len,newState,expected;while(true){state=stack[stack.length-1];if(this.defaultActions[state]){action=this.defaultActions[state]}else{if(symbol===null||typeof symbol=="undefined"){symbol=lex()}action=table[state]&&table[state][symbol]}if(typeof action==="undefined"||!action.length||!action[0]){var errStr="";expected=[];for(p in table[state]){if(this.terminals_[p]&&p>TERROR){expected.push("'"+this.terminals_[p]+"'")}}if(lexer.showPosition){errStr="Parse error on line "+(yylineno+1)+":\n"+lexer.showPosition()+"\nExpecting "+expected.join(", ")+", got '"+(this.terminals_[symbol]||symbol)+"'"}else{errStr="Parse error on line "+(yylineno+1)+": Unexpected "+(symbol==EOF?"end of input":"'"+(this.terminals_[symbol]||symbol)+"'")}this.parseError(errStr,{text:lexer.match,token:this.terminals_[symbol]||symbol,line:lexer.yylineno,loc:yyloc,expected:expected})}if(action[0]instanceof Array&&action.length>1){throw new Error("Parse Error: multiple actions possible at state: "+state+", token: "+symbol)}switch(action[0]){case 1:stack.push(symbol);vstack.push(lexer.yytext);lstack.push(lexer.yylloc);stack.push(action[1]);symbol=null;if(!preErrorSymbol){yyleng=lexer.yyleng;yytext=lexer.yytext;yylineno=lexer.yylineno;yyloc=lexer.yylloc;if(recovering>0){recovering--}}else{symbol=preErrorSymbol;preErrorSymbol=null}break;case 2:len=this.productions_[action[1]][1];yyval.$=vstack[vstack.length-len];yyval._$={first_line:lstack[lstack.length-(len||1)].first_line,last_line:lstack[lstack.length-1].last_line,first_column:lstack[lstack.length-(len||1)].first_column,last_column:lstack[lstack.length-1].last_column};if(ranges){yyval._$.range=[lstack[lstack.length-(len||1)].range[0],lstack[lstack.length-1].range[1]]}r=this.performAction.apply(yyval,[yytext,yyleng,yylineno,sharedState.yy,action[1],vstack,lstack].concat(args));if(typeof r!=="undefined"){return r}if(len){stack=stack.slice(0,-1*len*2);vstack=vstack.slice(0,-1*len);lstack=lstack.slice(0,-1*len)}stack.push(this.productions_[action[1]][0]);vstack.push(yyval.$);lstack.push(yyval._$);newState=table[stack[stack.length-2]][stack[stack.length-1]];stack.push(newState);break;case 3:return true}}return true}};var lexer=function(){var lexer={EOF:1,parseError:function parseError(str,hash){if(this.yy.parser){this.yy.parser.parseError(str,hash)}else{throw new Error(str)}},setInput:function(input,yy){this.yy=yy||this.yy||{};this._input=input;this._more=this._backtrack=this.done=false;this.yylineno=this.yyleng=0;this.yytext=this.matched=this.match="";this.conditionStack=["INITIAL"];this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0};if(this.options.ranges){this.yylloc.range=[0,0]}this.offset=0;return this},input:function(){var ch=this._input[0];this.yytext+=ch;this.yyleng++;this.offset++;this.match+=ch;this.matched+=ch;var lines=ch.match(/(?:\r\n?|\n).*/g);if(lines){this.yylineno++;this.yylloc.last_line++}else{this.yylloc.last_column++}if(this.options.ranges){this.yylloc.range[1]++}this._input=this._input.slice(1);return ch},unput:function(ch){var len=ch.length;var lines=ch.split(/(?:\r\n?|\n)/g);this._input=ch+this._input;this.yytext=this.yytext.substr(0,this.yytext.length-len);this.offset-=len;var oldLines=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1);this.matched=this.matched.substr(0,this.matched.length-1);if(lines.length-1){this.yylineno-=lines.length-1}var r=this.yylloc.range;this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:lines?(lines.length===oldLines.length?this.yylloc.first_column:0)+oldLines[oldLines.length-lines.length].length-lines[0].length:this.yylloc.first_column-len};if(this.options.ranges){this.yylloc.range=[r[0],r[0]+this.yyleng-len]}this.yyleng=this.yytext.length;return this},more:function(){this._more=true;return this},reject:function(){if(this.options.backtrack_lexer){this._backtrack=true}else{return this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})}return this},less:function(n){this.unput(this.match.slice(n))},pastInput:function(){var past=this.matched.substr(0,this.matched.length-this.match.length);return(past.length>20?"...":"")+past.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var next=this.match;if(next.length<20){next+=this._input.substr(0,20-next.length)}return(next.substr(0,20)+(next.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var pre=this.pastInput();var c=new Array(pre.length+1).join("-");return pre+this.upcomingInput()+"\n"+c+"^"},test_match:function(match,indexed_rule){var token,lines,backup;if(this.options.backtrack_lexer){backup={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done};if(this.options.ranges){backup.yylloc.range=this.yylloc.range.slice(0)}}lines=match[0].match(/(?:\r\n?|\n).*/g);if(lines){this.yylineno+=lines.length}this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:lines?lines[lines.length-1].length-lines[lines.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+match[0].length};this.yytext+=match[0];this.match+=match[0];this.matches=match;this.yyleng=this.yytext.length;if(this.options.ranges){this.yylloc.range=[this.offset,this.offset+=this.yyleng]}this._more=false;this._backtrack=false;this._input=this._input.slice(match[0].length);this.matched+=match[0];token=this.performAction.call(this,this.yy,this,indexed_rule,this.conditionStack[this.conditionStack.length-1]);if(this.done&&this._input){this.done=false}if(token){return token}else if(this._backtrack){for(var k in backup){this[k]=backup[k]}return false}return false},next:function(){if(this.done){return this.EOF}if(!this._input){this.done=true}var token,match,tempMatch,index;if(!this._more){this.yytext="";this.match=""}var rules=this._currentRules();for(var i=0;imatch[0].length)){match=tempMatch;index=i;if(this.options.backtrack_lexer){token=this.test_match(tempMatch,rules[i]);if(token!==false){return token}else if(this._backtrack){match=false;continue}else{return false}}else if(!this.options.flex){break}}}if(match){token=this.test_match(match,rules[index]);if(token!==false){return token}return false}if(this._input===""){return this.EOF}else{return this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})}},lex:function lex(){var r=this.next();if(r){return r}else{return this.lex()}},begin:function begin(condition){this.conditionStack.push(condition)},popState:function popState(){var n=this.conditionStack.length-1;if(n>0){return this.conditionStack.pop()}else{return this.conditionStack[0]}},_currentRules:function _currentRules(){if(this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]){return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules}else{return this.conditions["INITIAL"].rules}},topState:function topState(n){n=this.conditionStack.length-1-Math.abs(n||0);if(n>=0){return this.conditionStack[n]}else{return"INITIAL"}},pushState:function pushState(condition){this.begin(condition)},stateStackSize:function stateStackSize(){return this.conditionStack.length},options:{},performAction:function anonymous(yy,yy_,$avoiding_name_collisions,YY_START){var YYSTATE=YY_START;switch($avoiding_name_collisions){case 0:break;case 1:return 6;break;case 2:yy_.yytext=yy_.yytext.substr(1,yy_.yyleng-2);return 4;break;case 3:return 17;break;case 4:return 18;break;case 5:return 23;break;case 6:return 24;break;case 7:return 22;break;case 8:return 21;break;case 9:return 10;break;case 10:return 11;break;case 11:return 8;break;case 12:return 14;break;case 13:return"INVALID";break}},rules:[/^(?:\s+)/,/^(?:(-?([0-9]|[1-9][0-9]+))(\.[0-9]+)?([eE][-+]?[0-9]+)?\b)/,/^(?:"(?:\\[\\"bfnrt/]|\\u[a-fA-F0-9]{4}|[^\\\0-\x09\x0a-\x1f"])*")/,/^(?:\{)/,/^(?:\})/,/^(?:\[)/,/^(?:\])/,/^(?:,)/,/^(?::)/,/^(?:true\b)/,/^(?:false\b)/,/^(?:null\b)/,/^(?:$)/,/^(?:.)/],conditions:{INITIAL:{rules:[0,1,2,3,4,5,6,7,8,9,10,11,12,13],inclusive:true}}};return lexer}();parser.lexer=lexer;function Parser(){this.yy={}}Parser.prototype=parser;parser.Parser=Parser;return new Parser}();if(typeof require!=="undefined"&&typeof exports!=="undefined"){exports.parser=parser;exports.Parser=parser.Parser;exports.parse=function(){return parser.parse.apply(parser,arguments)};exports.main=function commonjsMain(args){if(!args[1]){console.log("Usage: "+args[0]+" FILE");process.exit(1)}var source=require("fs").readFileSync(require("path").normalize(args[1]),"utf8");return exports.parser.parse(source)};if(typeof module!=="undefined"&&require.main===module){exports.main(process.argv.slice(1))}}return exports}(); \ No newline at end of file diff --git a/node_modules/@mapbox/mapbox-gl-supported/.eslintrc b/node_modules/@mapbox/mapbox-gl-supported/.eslintrc new file mode 100644 index 0000000000000000000000000000000000000000..426351675db21c9615466bdf8d27da91096c139a --- /dev/null +++ b/node_modules/@mapbox/mapbox-gl-supported/.eslintrc @@ -0,0 +1,17 @@ +{ + "extends": "mourner", + "rules": { + "object-curly-spacing": 0, + "key-spacing": 0, + "array-bracket-spacing": 0, + "space-before-function-paren": 0, + "quotes": 0, + "no-eq-null": 0, + "consistent-return": 0, + "global-require": 0, + "block-scoped-var": 2 + }, + "env": { + "browser": true + } +} diff --git a/node_modules/@mapbox/mapbox-gl-supported/CONTRIBUTING.md b/node_modules/@mapbox/mapbox-gl-supported/CONTRIBUTING.md new file mode 100644 index 0000000000000000000000000000000000000000..dd6ad7f1e2608bc8c9a88bd7ed4bed54dbc2499c --- /dev/null +++ b/node_modules/@mapbox/mapbox-gl-supported/CONTRIBUTING.md @@ -0,0 +1,6 @@ +# Deploying a new release + + - `npm test` + - `npm version {patch|minor|major}` + - `git push --follow-tags` + - `aws s3 cp --acl public-read index.js s3://mapbox-gl-js/plugins/mapbox-gl-supported/v$(node --print --eval "require('./package.json').version")/mapbox-gl-supported.js` diff --git a/node_modules/@mapbox/mapbox-gl-supported/LICENSE.txt b/node_modules/@mapbox/mapbox-gl-supported/LICENSE.txt new file mode 100644 index 0000000000000000000000000000000000000000..03483177d84dec658454eb6478bf3f27fe284470 --- /dev/null +++ b/node_modules/@mapbox/mapbox-gl-supported/LICENSE.txt @@ -0,0 +1,30 @@ + +BSD 3-Clause License + +Copyright (c) 2017, Mapbox +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* 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. + +* 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 HOLDER 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. diff --git a/node_modules/@mapbox/mapbox-gl-supported/README.md b/node_modules/@mapbox/mapbox-gl-supported/README.md new file mode 100644 index 0000000000000000000000000000000000000000..7102e35b2b0534c9d8a659a5e27dff84cb430d9f --- /dev/null +++ b/node_modules/@mapbox/mapbox-gl-supported/README.md @@ -0,0 +1,30 @@ +# Mapbox GL JS Supported + +This library determines if a browser supports [Mapbox GL JS](http://github.com/mapbox/mapbox-gl-js). + +## Testing Your Browser + +You may test your browser [here](http://mapbox.github.io/mapbox-gl-supported). + +## Using Mapbox GL JS Supported with a ` + +``` + +## Using Mapbox GL JS Supported with [Browserify](http://browserify.org/) + +```bash +npm install --save @mapbox/mapbox-gl-supported +``` + +```js +var isSupported = require('@mapbox/mapbox-gl-supported')(); +``` diff --git a/node_modules/@mapbox/mapbox-gl-supported/diagnostics.html b/node_modules/@mapbox/mapbox-gl-supported/diagnostics.html new file mode 100644 index 0000000000000000000000000000000000000000..e878f4e7068cec990ae92903f50fb8eac9c9179b --- /dev/null +++ b/node_modules/@mapbox/mapbox-gl-supported/diagnostics.html @@ -0,0 +1,165 @@ + + + + + + + + + + + + +

Map instantiation diagnostics

+
+ + + + + + +

Support detection diagnostics

+ + + + + + + + + +
Detection methodContext typefailIfMajorPerformanceCaveatResultErrors
+ + + + + +

WebGL diagnostics

+ + + + + + + + + diff --git a/node_modules/@mapbox/mapbox-gl-supported/index.html b/node_modules/@mapbox/mapbox-gl-supported/index.html new file mode 100644 index 0000000000000000000000000000000000000000..2486fe17a65741955787b471adfbea4c06c802f1 --- /dev/null +++ b/node_modules/@mapbox/mapbox-gl-supported/index.html @@ -0,0 +1,52 @@ + + + + + + + + + + + +

Mapbox GL JS is

+

...

+

+ + + + + + diff --git a/node_modules/@mapbox/mapbox-gl-supported/index.js b/node_modules/@mapbox/mapbox-gl-supported/index.js new file mode 100644 index 0000000000000000000000000000000000000000..8957b209a629110b78b3d7b0ded58c610092f59d --- /dev/null +++ b/node_modules/@mapbox/mapbox-gl-supported/index.js @@ -0,0 +1,189 @@ +'use strict'; + +if (typeof module !== 'undefined' && module.exports) { + module.exports = isSupported; +} else if (window) { + window.mapboxgl = window.mapboxgl || {}; + window.mapboxgl.supported = isSupported; + window.mapboxgl.notSupportedReason = notSupportedReason; +} + +/** + * Test whether the current browser supports Mapbox GL JS + * @param {Object} options + * @param {boolean} [options.failIfMajorPerformanceCaveat=false] Return `false` + * if the performance of Mapbox GL JS would be dramatically worse than + * expected (i.e. a software renderer is would be used) + * @return {boolean} + */ +function isSupported(options) { + return !notSupportedReason(options); +} + +function notSupportedReason(options) { + if (!isBrowser()) return 'not a browser'; + if (!isArraySupported()) return 'insufficent Array support'; + if (!isFunctionSupported()) return 'insufficient Function support'; + if (!isObjectSupported()) return 'insufficient Object support'; + if (!isJSONSupported()) return 'insufficient JSON support'; + if (!isWorkerSupported()) return 'insufficient worker support'; + if (!isUint8ClampedArraySupported()) return 'insufficient Uint8ClampedArray support'; + if (!isArrayBufferSupported()) return 'insufficient ArrayBuffer support'; + if (!isCanvasGetImageDataSupported()) return 'insufficient Canvas/getImageData support'; + if (!isWebGLSupportedCached(options && options.failIfMajorPerformanceCaveat)) return 'insufficient WebGL support'; +} + +function isBrowser() { + return typeof window !== 'undefined' && typeof document !== 'undefined'; +} + +function isArraySupported() { + return ( + Array.prototype && + Array.prototype.every && + Array.prototype.filter && + Array.prototype.forEach && + Array.prototype.indexOf && + Array.prototype.lastIndexOf && + Array.prototype.map && + Array.prototype.some && + Array.prototype.reduce && + Array.prototype.reduceRight && + Array.isArray + ); +} + +function isFunctionSupported() { + return Function.prototype && Function.prototype.bind; +} + +function isObjectSupported() { + return ( + Object.keys && + Object.create && + Object.getPrototypeOf && + Object.getOwnPropertyNames && + Object.isSealed && + Object.isFrozen && + Object.isExtensible && + Object.getOwnPropertyDescriptor && + Object.defineProperty && + Object.defineProperties && + Object.seal && + Object.freeze && + Object.preventExtensions + ); +} + +function isJSONSupported() { + return 'JSON' in window && 'parse' in JSON && 'stringify' in JSON; +} + +function isWorkerSupported() { + if (!('Worker' in window && 'Blob' in window && 'URL' in window)) { + return false; + } + + var blob = new Blob([''], { type: 'text/javascript' }); + var workerURL = URL.createObjectURL(blob); + var supported; + var worker; + + try { + worker = new Worker(workerURL); + supported = true; + } catch (e) { + supported = false; + } + + if (worker) { + worker.terminate(); + } + URL.revokeObjectURL(workerURL); + + return supported; +} + +// IE11 only supports `Uint8ClampedArray` as of version +// [KB2929437](https://support.microsoft.com/en-us/kb/2929437) +function isUint8ClampedArraySupported() { + return 'Uint8ClampedArray' in window; +} + +// https://github.com/mapbox/mapbox-gl-supported/issues/19 +function isArrayBufferSupported() { + return ArrayBuffer.isView; +} + +// Some browsers or browser extensions block access to canvas data to prevent fingerprinting. +// Mapbox GL uses this API to load sprites and images in general. +function isCanvasGetImageDataSupported() { + const canvas = document.createElement('canvas'); + canvas.width = canvas.height = 1; + const context = canvas.getContext('2d'); + if (!context) { + return false; + } + const imageData = context.getImageData(0, 0, 1, 1); + return imageData && imageData.width === canvas.width; +} + +var isWebGLSupportedCache = {}; +function isWebGLSupportedCached(failIfMajorPerformanceCaveat) { + + if (isWebGLSupportedCache[failIfMajorPerformanceCaveat] === undefined) { + isWebGLSupportedCache[failIfMajorPerformanceCaveat] = isWebGLSupported(failIfMajorPerformanceCaveat); + } + + return isWebGLSupportedCache[failIfMajorPerformanceCaveat]; +} + +isSupported.webGLContextAttributes = { + antialias: false, + alpha: true, + stencil: true, + depth: true +}; + +function getWebGLContext(failIfMajorPerformanceCaveat) { + var canvas = document.createElement('canvas'); + + var attributes = Object.create(isSupported.webGLContextAttributes); + attributes.failIfMajorPerformanceCaveat = failIfMajorPerformanceCaveat; + + if (canvas.probablySupportsContext) { + return ( + canvas.probablySupportsContext('webgl', attributes) || + canvas.probablySupportsContext('experimental-webgl', attributes) + ); + + } else if (canvas.supportsContext) { + return ( + canvas.supportsContext('webgl', attributes) || + canvas.supportsContext('experimental-webgl', attributes) + ); + + } else { + return ( + canvas.getContext('webgl', attributes) || + canvas.getContext('experimental-webgl', attributes) + ); + } +} + +function isWebGLSupported(failIfMajorPerformanceCaveat) { + const gl = getWebGLContext(failIfMajorPerformanceCaveat); + if (!gl) { + return false; + } + + // Try compiling a shader and get its compile status. Some browsers like Brave block this API + // to prevent fingerprinting. Unfortunately, this also means that Mapbox GL won't work. + const shader = gl.createShader(gl.VERTEX_SHADER); + if (!shader || gl.isContextLost()) { + return false; + } + gl.shaderSource(shader, 'void main() {}'); + gl.compileShader(shader); + return gl.getShaderParameter(shader, gl.COMPILE_STATUS) === true; +} diff --git a/node_modules/@mapbox/mapbox-gl-supported/package.json b/node_modules/@mapbox/mapbox-gl-supported/package.json new file mode 100644 index 0000000000000000000000000000000000000000..e48869a2e3b63dc472a37d1449e0f3e7f42dbaf4 --- /dev/null +++ b/node_modules/@mapbox/mapbox-gl-supported/package.json @@ -0,0 +1,28 @@ +{ + "name": "@mapbox/mapbox-gl-supported", + "version": "1.5.0", + "description": "A library to determine if a browser supports Mapbox GL JS", + "main": "index.js", + "scripts": { + "test": "eslint index.js", + "build": "mkdir -p dist && uglifyjs index.js -c -m -o dist/mapbox-gl-supported.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/mapbox/mapbox-gl-supported.git" + }, + "license": "BSD-3-Clause", + "bugs": { + "url": "https://github.com/mapbox/mapbox-gl-supported/issues" + }, + "homepage": "https://github.com/mapbox/mapbox-gl-supported#readme", + "devDependencies": { + "browserify": "^16.2.3", + "eslint": "^2.8.0", + "eslint-config-mourner": "^2.0.1", + "uglify-js": "^2.4.24" + }, + "peerDependencies": { + "mapbox-gl": ">=0.32.1 <2.0.0" + } +} diff --git a/node_modules/@mapbox/point-geometry/.travis.yml b/node_modules/@mapbox/point-geometry/.travis.yml new file mode 100644 index 0000000000000000000000000000000000000000..83c838f0f4f6447d815e25b244deab3c71c8f76c --- /dev/null +++ b/node_modules/@mapbox/point-geometry/.travis.yml @@ -0,0 +1,8 @@ +language: node_js +node_js: + - "0.10" +before_install: + - npm install -g npm@~1.4.6 +script: + - npm test + - npm run cov diff --git a/node_modules/@mapbox/point-geometry/HISTORY.md b/node_modules/@mapbox/point-geometry/HISTORY.md new file mode 100644 index 0000000000000000000000000000000000000000..9e97108ba179f49a8bcf06238be99db01486272d --- /dev/null +++ b/node_modules/@mapbox/point-geometry/HISTORY.md @@ -0,0 +1,5 @@ +## 0.1.0 + +* Adds [rotateAround](https://github.com/mapbox/point-geometry/pull/5) and + [multByPoint](https://github.com/mapbox/point-geometry/pull/7) and divByPoint + methods. diff --git a/node_modules/@mapbox/point-geometry/LICENSE b/node_modules/@mapbox/point-geometry/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..745f3e4dadeea5a9336665f9c756e6f56a0926c9 --- /dev/null +++ b/node_modules/@mapbox/point-geometry/LICENSE @@ -0,0 +1,13 @@ +Copyright (c) 2015, Mapbox <> + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/node_modules/@mapbox/point-geometry/README.md b/node_modules/@mapbox/point-geometry/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e2541b44ebba55832f1453ffbb6395ae3a92bef9 --- /dev/null +++ b/node_modules/@mapbox/point-geometry/README.md @@ -0,0 +1,364 @@ +# point-geometry + +[![build status](https://secure.travis-ci.org/mapbox/point-geometry.png)](http://travis-ci.org/mapbox/point-geometry) [![Coverage Status](https://coveralls.io/repos/mapbox/point-geometry/badge.svg?branch=master)](https://coveralls.io/r/mapbox/point-geometry?branch=master) + +a point geometry with transforms + + +### `Point(x, y)` + +A standalone point geometry with useful accessor, comparison, and +modification methods. + + +### Parameters + +| parameter | type | description | +| --------- | ------ | -------------------------------------------------------------------------------------- | +| `x` | Number | the x-coordinate. this could be longitude or screen pixels, or any other sort of unit. | +| `y` | Number | the y-coordinate. this could be latitude or screen pixels, or any other sort of unit. | + + +### Example + +```js +var point = new Point(-77, 38); +``` + + +### `clone` + +Clone this point, returning a new point that can be modified +without affecting the old one. + + +**Returns** `Point`, the clone + + +### `add(p)` + +Add this point's x & y coordinates to another point, +yielding a new point. + +### Parameters + +| parameter | type | description | +| --------- | ----- | --------------- | +| `p` | Point | the other point | + + + +**Returns** `Point`, output point + + +### `sub(p)` + +Subtract this point's x & y coordinates to from point, +yielding a new point. + +### Parameters + +| parameter | type | description | +| --------- | ----- | --------------- | +| `p` | Point | the other point | + + + +**Returns** `Point`, output point + + +### `multByPoint(p)` + +Multiply this point's x & y coordinates by point, +yielding a new point. + +### Parameters + +| parameter | type | description | +| --------- | ----- | --------------- | +| `p` | Point | the other point | + + + +**Returns** `Point`, output point + + +### `divByPoint(p)` + +Divide this point's x & y coordinates by point, +yielding a new point. + +### Parameters + +| parameter | type | description | +| --------- | ----- | --------------- | +| `p` | Point | the other point | + + + +**Returns** `Point`, output point + + +### `mult(k)` + +Multiply this point's x & y coordinates by a factor, +yielding a new point. + +### Parameters + +| parameter | type | description | +| --------- | ----- | ----------- | +| `k` | Point | factor | + + + +**Returns** `Point`, output point + + +### `div(k)` + +Divide this point's x & y coordinates by a factor, +yielding a new point. + +### Parameters + +| parameter | type | description | +| --------- | ----- | ----------- | +| `k` | Point | factor | + + + +**Returns** `Point`, output point + + +### `rotate(a)` + +Rotate this point around the 0, 0 origin by an angle a, +given in radians + +### Parameters + +| parameter | type | description | +| --------- | ------ | ---------------------------------- | +| `a` | Number | angle to rotate around, in radians | + + + +**Returns** `Point`, output point + + +### `rotateAround(a, p)` + +Rotate this point around p point by an angle a, +given in radians + +### Parameters + +| parameter | type | description | +| --------- | ------ | ---------------------------------- | +| `a` | Number | angle to rotate around, in radians | +| `p` | Point | Point to rotate around | + + + +**Returns** `Point`, output point + + +### `matMult(m)` + +Multiply this point by a 4x1 transformation matrix + +### Parameters + +| parameter | type | description | +| --------- | ----------------- | --------------------- | +| `m` | Array\.\ | transformation matrix | + + + +**Returns** `Point`, output point + + +### `unit` + +Calculate this point but as a unit vector from 0, 0, meaning +that the distance from the resulting point to the 0, 0 +coordinate will be equal to 1 and the angle from the resulting +point to the 0, 0 coordinate will be the same as before. + + +**Returns** `Point`, unit vector point + + +### `perp` + +Compute a perpendicular point, where the new y coordinate +is the old x coordinate and the new x coordinate is the old y +coordinate multiplied by -1 + + +**Returns** `Point`, perpendicular point + + +### `round` + +Return a version of this point with the x & y coordinates +rounded to integers. + + +**Returns** `Point`, rounded point + + +### `mag` + +Return the magitude of this point: this is the Euclidean +distance from the 0, 0 coordinate to this point's x and y +coordinates. + + +**Returns** `Number`, magnitude + + +### `equals(other)` + +Judge whether this point is equal to another point, returning +true or false. + +### Parameters + +| parameter | type | description | +| --------- | ----- | --------------- | +| `other` | Point | the other point | + + + +**Returns** `boolean`, whether the points are equal + + +### `dist(p)` + +Calculate the distance from this point to another point + +### Parameters + +| parameter | type | description | +| --------- | ----- | --------------- | +| `p` | Point | the other point | + + + +**Returns** `Number`, distance + + +### `distSqr(p)` + +Calculate the distance from this point to another point, +without the square root step. Useful if you're comparing +relative distances. + +### Parameters + +| parameter | type | description | +| --------- | ----- | --------------- | +| `p` | Point | the other point | + + + +**Returns** `Number`, distance + + +### `angle` + +Get the angle from the 0, 0 coordinate to this point, in radians +coordinates. + + +**Returns** `Number`, angle + + +### `angleTo(b)` + +Get the angle from this point to another point, in radians + +### Parameters + +| parameter | type | description | +| --------- | ----- | --------------- | +| `b` | Point | the other point | + + + +**Returns** `Number`, angle + + +### `angleWith(b)` + +Get the angle between this point and another point, in radians + +### Parameters + +| parameter | type | description | +| --------- | ----- | --------------- | +| `b` | Point | the other point | + + + +**Returns** `Number`, angle + + +### `angleWithSep(x, y)` + +Find the angle of the two vectors, solving the formula for +the cross product a x b = |a||b|sin(θ) for θ. + +### Parameters + +| parameter | type | description | +| --------- | ------ | ---------------- | +| `x` | Number | the x-coordinate | +| `y` | Number | the y-coordinate | + + + +**Returns** `Number`, the angle in radians + + +### `convert(a)` + +Construct a point from an array if necessary, otherwise if the input +is already a Point, or an unknown type, return it unchanged + +### Parameters + +| parameter | type | description | +| --------- | ------------------------ | ----------------------- | +| `a` | Array\.\\,Point | any kind of input value | + + +### Example + +```js +// this +var point = Point.convert([0, 1]); +// is equivalent to +var point = new Point(0, 1); +``` + + +**Returns** `Point`, constructed point, or passed-through value. + +## Installation + +Requires [nodejs](http://nodejs.org/). + +```sh +$ npm install point-geometry +``` + +## Tests + +```sh +$ npm test +``` + + diff --git a/node_modules/@mapbox/point-geometry/index.js b/node_modules/@mapbox/point-geometry/index.js new file mode 100644 index 0000000000000000000000000000000000000000..5f21f840171deba8d78eaa01643d3d055e0c7ef6 --- /dev/null +++ b/node_modules/@mapbox/point-geometry/index.js @@ -0,0 +1,312 @@ +'use strict'; + +module.exports = Point; + +/** + * A standalone point geometry with useful accessor, comparison, and + * modification methods. + * + * @class Point + * @param {Number} x the x-coordinate. this could be longitude or screen + * pixels, or any other sort of unit. + * @param {Number} y the y-coordinate. this could be latitude or screen + * pixels, or any other sort of unit. + * @example + * var point = new Point(-77, 38); + */ +function Point(x, y) { + this.x = x; + this.y = y; +} + +Point.prototype = { + + /** + * Clone this point, returning a new point that can be modified + * without affecting the old one. + * @return {Point} the clone + */ + clone: function() { return new Point(this.x, this.y); }, + + /** + * Add this point's x & y coordinates to another point, + * yielding a new point. + * @param {Point} p the other point + * @return {Point} output point + */ + add: function(p) { return this.clone()._add(p); }, + + /** + * Subtract this point's x & y coordinates to from point, + * yielding a new point. + * @param {Point} p the other point + * @return {Point} output point + */ + sub: function(p) { return this.clone()._sub(p); }, + + /** + * Multiply this point's x & y coordinates by point, + * yielding a new point. + * @param {Point} p the other point + * @return {Point} output point + */ + multByPoint: function(p) { return this.clone()._multByPoint(p); }, + + /** + * Divide this point's x & y coordinates by point, + * yielding a new point. + * @param {Point} p the other point + * @return {Point} output point + */ + divByPoint: function(p) { return this.clone()._divByPoint(p); }, + + /** + * Multiply this point's x & y coordinates by a factor, + * yielding a new point. + * @param {Point} k factor + * @return {Point} output point + */ + mult: function(k) { return this.clone()._mult(k); }, + + /** + * Divide this point's x & y coordinates by a factor, + * yielding a new point. + * @param {Point} k factor + * @return {Point} output point + */ + div: function(k) { return this.clone()._div(k); }, + + /** + * Rotate this point around the 0, 0 origin by an angle a, + * given in radians + * @param {Number} a angle to rotate around, in radians + * @return {Point} output point + */ + rotate: function(a) { return this.clone()._rotate(a); }, + + /** + * Rotate this point around p point by an angle a, + * given in radians + * @param {Number} a angle to rotate around, in radians + * @param {Point} p Point to rotate around + * @return {Point} output point + */ + rotateAround: function(a,p) { return this.clone()._rotateAround(a,p); }, + + /** + * Multiply this point by a 4x1 transformation matrix + * @param {Array} m transformation matrix + * @return {Point} output point + */ + matMult: function(m) { return this.clone()._matMult(m); }, + + /** + * Calculate this point but as a unit vector from 0, 0, meaning + * that the distance from the resulting point to the 0, 0 + * coordinate will be equal to 1 and the angle from the resulting + * point to the 0, 0 coordinate will be the same as before. + * @return {Point} unit vector point + */ + unit: function() { return this.clone()._unit(); }, + + /** + * Compute a perpendicular point, where the new y coordinate + * is the old x coordinate and the new x coordinate is the old y + * coordinate multiplied by -1 + * @return {Point} perpendicular point + */ + perp: function() { return this.clone()._perp(); }, + + /** + * Return a version of this point with the x & y coordinates + * rounded to integers. + * @return {Point} rounded point + */ + round: function() { return this.clone()._round(); }, + + /** + * Return the magitude of this point: this is the Euclidean + * distance from the 0, 0 coordinate to this point's x and y + * coordinates. + * @return {Number} magnitude + */ + mag: function() { + return Math.sqrt(this.x * this.x + this.y * this.y); + }, + + /** + * Judge whether this point is equal to another point, returning + * true or false. + * @param {Point} other the other point + * @return {boolean} whether the points are equal + */ + equals: function(other) { + return this.x === other.x && + this.y === other.y; + }, + + /** + * Calculate the distance from this point to another point + * @param {Point} p the other point + * @return {Number} distance + */ + dist: function(p) { + return Math.sqrt(this.distSqr(p)); + }, + + /** + * Calculate the distance from this point to another point, + * without the square root step. Useful if you're comparing + * relative distances. + * @param {Point} p the other point + * @return {Number} distance + */ + distSqr: function(p) { + var dx = p.x - this.x, + dy = p.y - this.y; + return dx * dx + dy * dy; + }, + + /** + * Get the angle from the 0, 0 coordinate to this point, in radians + * coordinates. + * @return {Number} angle + */ + angle: function() { + return Math.atan2(this.y, this.x); + }, + + /** + * Get the angle from this point to another point, in radians + * @param {Point} b the other point + * @return {Number} angle + */ + angleTo: function(b) { + return Math.atan2(this.y - b.y, this.x - b.x); + }, + + /** + * Get the angle between this point and another point, in radians + * @param {Point} b the other point + * @return {Number} angle + */ + angleWith: function(b) { + return this.angleWithSep(b.x, b.y); + }, + + /* + * Find the angle of the two vectors, solving the formula for + * the cross product a x b = |a||b|sin(θ) for θ. + * @param {Number} x the x-coordinate + * @param {Number} y the y-coordinate + * @return {Number} the angle in radians + */ + angleWithSep: function(x, y) { + return Math.atan2( + this.x * y - this.y * x, + this.x * x + this.y * y); + }, + + _matMult: function(m) { + var x = m[0] * this.x + m[1] * this.y, + y = m[2] * this.x + m[3] * this.y; + this.x = x; + this.y = y; + return this; + }, + + _add: function(p) { + this.x += p.x; + this.y += p.y; + return this; + }, + + _sub: function(p) { + this.x -= p.x; + this.y -= p.y; + return this; + }, + + _mult: function(k) { + this.x *= k; + this.y *= k; + return this; + }, + + _div: function(k) { + this.x /= k; + this.y /= k; + return this; + }, + + _multByPoint: function(p) { + this.x *= p.x; + this.y *= p.y; + return this; + }, + + _divByPoint: function(p) { + this.x /= p.x; + this.y /= p.y; + return this; + }, + + _unit: function() { + this._div(this.mag()); + return this; + }, + + _perp: function() { + var y = this.y; + this.y = this.x; + this.x = -y; + return this; + }, + + _rotate: function(angle) { + var cos = Math.cos(angle), + sin = Math.sin(angle), + x = cos * this.x - sin * this.y, + y = sin * this.x + cos * this.y; + this.x = x; + this.y = y; + return this; + }, + + _rotateAround: function(angle, p) { + var cos = Math.cos(angle), + sin = Math.sin(angle), + x = p.x + cos * (this.x - p.x) - sin * (this.y - p.y), + y = p.y + sin * (this.x - p.x) + cos * (this.y - p.y); + this.x = x; + this.y = y; + return this; + }, + + _round: function() { + this.x = Math.round(this.x); + this.y = Math.round(this.y); + return this; + } +}; + +/** + * Construct a point from an array if necessary, otherwise if the input + * is already a Point, or an unknown type, return it unchanged + * @param {Array|Point|*} a any kind of input value + * @return {Point} constructed point, or passed-through value. + * @example + * // this + * var point = Point.convert([0, 1]); + * // is equivalent to + * var point = new Point(0, 1); + */ +Point.convert = function (a) { + if (a instanceof Point) { + return a; + } + if (Array.isArray(a)) { + return new Point(a[0], a[1]); + } + return a; +}; diff --git a/node_modules/@mapbox/point-geometry/package.json b/node_modules/@mapbox/point-geometry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..6872312070d5fb212937b3427b838631d538b58d --- /dev/null +++ b/node_modules/@mapbox/point-geometry/package.json @@ -0,0 +1,33 @@ +{ + "name": "@mapbox/point-geometry", + "version": "0.1.0", + "description": "a point geometry with transforms", + "main": "index.js", + "scripts": { + "test": "tape test.js", + "doc": "dox -r < index.js | doxme --readme > README.md", + "cov": "istanbul cover test.js && coveralls < ./coverage/lcov.info" + }, + "repository": { + "type": "git", + "url": "git@github.com:mapbox/point-geometry.git" + }, + "keywords": [ + "point", + "geometry", + "primitive" + ], + "author": "Tom MacWright", + "license": "ISC", + "bugs": { + "url": "https://github.com/mapbox/point-geometry/issues" + }, + "homepage": "https://github.com/mapbox/point-geometry", + "devDependencies": { + "coveralls": "~2.10.1", + "dox": "^0.6.1", + "doxme": "^1.8.2", + "istanbul": "~0.2.11", + "tape": "~2.13.3" + } +} diff --git a/node_modules/@mapbox/point-geometry/test.js b/node_modules/@mapbox/point-geometry/test.js new file mode 100644 index 0000000000000000000000000000000000000000..90cefc79913463ef8a6a7d3530f7965d19f2b118 --- /dev/null +++ b/node_modules/@mapbox/point-geometry/test.js @@ -0,0 +1,139 @@ +'use strict'; +var test = require('tape').test; + +var Point = require('./'); + +test('Point', function(t) { + t.test('.convert', function(t) { + t.equal(Point.convert(new Point(20, 30)).equals(new Point(20, 30)), true); + t.equal(Point.convert([20, 30]).equals(new Point(20, 30)), true); + t.equal(Point.convert('somestring'), 'somestring'); + t.end(); + }); + t.test('vector operations', function(t) { + t.test('#mag', function(t) { + t.test('gets the magnitude of a vector', function() { + t.equal(new Point(0, 2).mag(), 2); + t.equal(new Point(0, 0).mag(), 0); + t.equal(new Point(10, 0).mag(), 10); + t.end(); + }); + }); + t.test('#unit', function(t) { + t.test('calculates the unit vector', function() { + t.deepEqual(new Point(0, 1000).unit(), new Point(0, 1)); + t.end(); + }); + }); + t.test('#equals', function(t) { + t.equals((new Point(0, 0).equals(new Point(0, 0))), true, 'equal'); + t.equals((new Point(0, 0).equals(new Point(0, 10))), false, 'not equal'); + t.end(); + }); + t.test('#dist', function(t) { + t.equals((new Point(0, 10).dist(new Point(0, 0))), 10); + t.equals((new Point(Math.sqrt(2), Math.sqrt(2)).dist(new Point(0, 0))), 2); + t.equals((new Point(0, 0).dist(new Point(0, 0))), 0); + t.end(); + }); + t.test('#mult', function(t) { + t.equals((new Point(0, 0).mult(5)).equals(new Point(0, 0)), true); + t.equals((new Point(0, 1).mult(5)).equals(new Point(0, 5)), true); + t.equals((new Point(1, 1).mult(5)).equals(new Point(5, 5)), true); + t.end(); + }); + t.test('#div', function(t) { + t.equals((new Point(0, 0).div(5)).equals(new Point(0, 0)), true); + t.equals((new Point(0, 1).div(5)).equals(new Point(0, 1/5)), true); + t.equals((new Point(1, 1).div(5)).equals(new Point(1/5, 1/5)), true); + t.end(); + }); + t.test('#multByPoint', function(t) { + t.equals((new Point(0, 0).multByPoint(new Point(5,5))).equals(new Point(0, 0)), true); + t.equals((new Point(0, 1).multByPoint(new Point(5,5))).equals(new Point(0, 5)), true); + t.equals((new Point(1, 1).multByPoint(new Point(4,5))).equals(new Point(4, 5)), true); + t.end(); + }); + t.test('#divByPoint', function(t) { + t.equals((new Point(0, 0).divByPoint(new Point(5,5))).equals(new Point(0, 0)), true); + t.equals((new Point(0, 1).divByPoint(new Point(5,5))).equals(new Point(0, 1/5)), true); + t.equals((new Point(1, 1).divByPoint(new Point(4,5))).equals(new Point(1/4, 1/5)), true); + t.end(); + }); + t.test('#rotate', function(t) { + t.equals((new Point(0, 0).rotate(0)).equals(new Point(0, 0)), true); + t.deepEquals((new Point(0, 1).rotate(Math.PI/2)).round(), new Point(-1, 0)); + t.deepEquals((new Point(0, 1).rotate(Math.PI)).round(), new Point(0, -1)); + t.end(); + }); + t.test('#rotateAround', function(t) { + t.deepEquals((new Point(2, 3).rotateAround(Math.PI/2, new Point(2,2))).round(), new Point(1, 2)); + t.deepEquals((new Point(2, 3).rotateAround(Math.PI, new Point(2,2))).round(), new Point(2, 1)); + t.end(); + }); + t.test('#round', function(t) { + t.equals((new Point(0, 0).round()).equals(new Point(0, 0)), true); + t.equals((new Point(0, 0.5).round()).equals(new Point(0, 1)), true); + t.equals((new Point(0.2, 0.2).round()).equals(new Point(0, 0)), true); + t.end(); + }); + t.test('#angle', function(t) { + t.equals((new Point(0, 0).angle()), 0); + t.equals((new Point(10, 10).angle()), Math.PI / 4); + t.equals((new Point(0, 10).angle()), Math.PI / 2); + t.equals((new Point(10, 0).angle()), 0); + t.end(); + }); + t.test('#angleTo', function(t) { + var b = new Point(0, 0); + t.equals((new Point(0, 0).angleTo(b)), 0); + t.equals((new Point(10, 10).angleTo(b)), Math.PI / 4); + t.equals((new Point(0, 10).angleTo(b)), Math.PI / 2); + t.equals((new Point(10, 0).angleTo(b)), 0); + t.end(); + }); + t.test('#angleWith', function(t) { + var b = new Point(0, 0); + t.equals((new Point(0, 0).angleWith(b)), 0); + t.equals((new Point(10, 10).angleWith(b)), 0); + t.equals((new Point(0, 10).angleWith(b)), 0); + t.equals((new Point(10, 0).angleWith(b)), 0); + t.end(); + }); + t.test('#angleWithSep', function(t) { + t.equals((new Point(0, 0).angleWithSep(0, 0)), 0); + t.equals((new Point(10, 10).angleWithSep(0, 0)), 0); + t.equals((new Point(0, 10).angleWithSep(0, 0)), 0); + t.equals((new Point(10, 0).angleWithSep(0, 0)), 0); + t.end(); + }); + t.test('#matMult', function(t) { + t.equals((new Point(0, 0).matMult([0, 0, 0, 0])).equals(new Point(0, 0)), true); + t.deepEquals((new Point(1, 1).matMult([0, 0, 0, 0])), new Point(0, 0)); + t.deepEquals((new Point(1, 1).matMult([1, 0, 1, 0])), new Point(1, 1)); + t.deepEquals((new Point(1, 1).matMult([1, 0, 0, 0])), new Point(1, 0)); + t.deepEquals((new Point(1, 1).matMult([0, 0, 1, 0])), new Point(0, 1)); + t.deepEquals((new Point(1, 1).matMult([0, 0, 1, 2])), new Point(0, 3)); + t.deepEquals((new Point(1, 1).matMult([1, 1, 1, 1])), new Point(2, 2)); + t.end(); + }); + t.test('#perp', function(t) { + t.test('calculates a vector perpendicular to the given vector', function() { + t.deepEqual(new Point(0, 1000).perp(), new Point(-1000, 0)); + t.end(); + }); + }); + t.test('#add', function(t) { + t.test('adds two vectors', function() { + t.deepEqual(new Point(0, 0).add(new Point(10, 10)), new Point(10, 10)); + t.end(); + }); + }); + t.test('#sub', function(t) { + t.test('adds subtracts a vector from another', function() { + t.deepEqual(new Point(0, 0).sub(new Point(10, 10)), new Point(-10, -10)); + t.end(); + }); + }); + }); +}); diff --git a/node_modules/@mapbox/tiny-sdf/LICENSE.txt b/node_modules/@mapbox/tiny-sdf/LICENSE.txt new file mode 100644 index 0000000000000000000000000000000000000000..94c832c064c2e8aaadaafbb03c4e632f027d1045 --- /dev/null +++ b/node_modules/@mapbox/tiny-sdf/LICENSE.txt @@ -0,0 +1,7 @@ +Copyright © 2016-2021 Mapbox, Inc. +This code available under the terms of the BSD 2-Clause license. + +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. +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 HOLDER 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. diff --git a/node_modules/@mapbox/tiny-sdf/README.md b/node_modules/@mapbox/tiny-sdf/README.md new file mode 100644 index 0000000000000000000000000000000000000000..3abbd39ff64ecea96890d0fe894722f106d4f4e5 --- /dev/null +++ b/node_modules/@mapbox/tiny-sdf/README.md @@ -0,0 +1,40 @@ +# TinySDF + +TinySDF is a tiny and fast JavaScript library for generating SDF (signed distance field) +from system fonts on the browser using Canvas 2D and +[Felzenszwalb/Huttenlocher distance transform](https://cs.brown.edu/~pff/papers/dt-final.pdf). +This is very useful for [rendering text with WebGL](https://www.mapbox.com/blog/text-signed-distance-fields/). + +This implementation is based directly on the algorithm published in the Felzenszwalb/Huttenlocher paper, and is not a port of the existing C++ implementation provided by the paper's authors. + +Demo: http://mapbox.github.io/tiny-sdf/ + +## Usage +Create a TinySDF for drawing SDFs based on font parameters: + +```js +var fontsize = 24; // Font size in pixels +var buffer = 3; // Whitespace buffer around a glyph in pixels +var radius = 8; // How many pixels around the glyph shape to use for encoding distance +var cutoff = 0.25 // How much of the radius (relative) is used for the inside part the glyph + +var fontFamily = 'sans-serif'; // css font-family +var fontWeight = 'normal'; // css font-weight +var tinySDFGenerator = new TinySDF(fontsize, buffer, radius, cutoff, fontFamily, fontWeight); + +var oneSDF = tinySDFGenerator.draw('泽'); +// returns a Uint8ClampedArray array of alpha values (0–255) for a size x size square grid + +// To generate glyphs with variable advances (e.g. non-ideographic glyphs), +// use `drawWithMetrics` +var sdfWithMetrics = tinySDFGenerator.drawWithMetrics('A'); +// sdfWithMetrics.data is the same as in `draw`, except the size may be clipped to fit the glyph +// sdfWithMetrics.metrics contains: +// top: Maximum ascent of glyph from alphabetic baseline +// left: Currently hardwired to 0 (actual glyph differences are encoded in the rasterization) +// width: Width of rasterized portion of glyph +// height +// advance: Layout advance +// sdfWidth: Width of the returned bitmap, usually but not always width + 2 * buffer +// sdfHeight +``` diff --git a/node_modules/@mapbox/tiny-sdf/debug.html b/node_modules/@mapbox/tiny-sdf/debug.html new file mode 100644 index 0000000000000000000000000000000000000000..342ac41573114107a21e9b5e9bcf1854b2871560 --- /dev/null +++ b/node_modules/@mapbox/tiny-sdf/debug.html @@ -0,0 +1,99 @@ + + + +SDF test + + + + + + + + + diff --git a/node_modules/@mapbox/tiny-sdf/index.html b/node_modules/@mapbox/tiny-sdf/index.html new file mode 100644 index 0000000000000000000000000000000000000000..aab394e1b11c0acc615597d39d21b860ea927b80 --- /dev/null +++ b/node_modules/@mapbox/tiny-sdf/index.html @@ -0,0 +1,315 @@ + + + +SDF test + + + + + +
+

TinySDF demo

+

+ + +

+ +

+

+ + + + +

+ +
+ + + + + + + + + + + diff --git a/node_modules/@mapbox/tiny-sdf/index.js b/node_modules/@mapbox/tiny-sdf/index.js new file mode 100644 index 0000000000000000000000000000000000000000..8ba4a569a60cb4da44a4de6a03f3faf9948153ab --- /dev/null +++ b/node_modules/@mapbox/tiny-sdf/index.js @@ -0,0 +1,192 @@ +'use strict'; + +module.exports = TinySDF; +module.exports.default = TinySDF; + +var INF = 1e20; + +function TinySDF(fontSize, buffer, radius, cutoff, fontFamily, fontWeight) { + this.fontSize = fontSize || 24; + this.buffer = buffer === undefined ? 3 : buffer; + this.cutoff = cutoff || 0.25; + this.fontFamily = fontFamily || 'sans-serif'; + this.fontWeight = fontWeight || 'normal'; + this.radius = radius || 8; + + // For backwards compatibility, we honor the implicit contract that the + // size of the returned bitmap will be fontSize + buffer * 2 + var size = this.size = this.fontSize + this.buffer * 2; + // Glyphs may be slightly larger than their fontSize. The canvas already + // has buffer space, but create extra buffer space in the output grid for the + // "halo" to extend into (if metric extraction is enabled) + var gridSize = size + this.buffer * 2; + + this.canvas = document.createElement('canvas'); + this.canvas.width = this.canvas.height = size; + + this.ctx = this.canvas.getContext('2d'); + this.ctx.font = this.fontWeight + ' ' + this.fontSize + 'px ' + this.fontFamily; + + this.ctx.textAlign = 'left'; // Necessary so that RTL text doesn't have different alignment + this.ctx.fillStyle = 'black'; + + // temporary arrays for the distance transform + this.gridOuter = new Float64Array(gridSize * gridSize); + this.gridInner = new Float64Array(gridSize * gridSize); + this.f = new Float64Array(gridSize); + this.z = new Float64Array(gridSize + 1); + this.v = new Uint16Array(gridSize); + + this.useMetrics = this.ctx.measureText('A').actualBoundingBoxLeft !== undefined; + + // hack around https://bugzilla.mozilla.org/show_bug.cgi?id=737852 + this.middle = Math.round((size / 2) * (navigator.userAgent.indexOf('Gecko/') >= 0 ? 1.2 : 1)); +} + +function prepareGrids(imgData, width, height, glyphWidth, glyphHeight, gridOuter, gridInner) { + // Initialize grids outside the glyph range to alpha 0 + gridOuter.fill(INF, 0, width * height); + gridInner.fill(0, 0, width * height); + + var offset = (width - glyphWidth) / 2; // This is zero if we're not extracting metrics + + for (var y = 0; y < glyphHeight; y++) { + for (var x = 0; x < glyphWidth; x++) { + var j = (y + offset) * width + x + offset; + var a = imgData.data[4 * (y * glyphWidth + x) + 3] / 255; // alpha value + if (a === 1) { + gridOuter[j] = 0; + gridInner[j] = INF; + } else if (a === 0) { + gridOuter[j] = INF; + gridInner[j] = 0; + } else { + var b = Math.max(0, 0.5 - a); + var c = Math.max(0, a - 0.5); + gridOuter[j] = b * b; + gridInner[j] = c * c; + } + } + } +} + +function extractAlpha(alphaChannel, width, height, gridOuter, gridInner, radius, cutoff) { + for (var i = 0; i < width * height; i++) { + var d = Math.sqrt(gridOuter[i]) - Math.sqrt(gridInner[i]); + alphaChannel[i] = Math.round(255 - 255 * (d / radius + cutoff)); + } +} + +TinySDF.prototype._draw = function (char, getMetrics) { + var textMetrics = this.ctx.measureText(char); + // Older browsers only expose the glyph width + // This is enough for basic layout with all glyphs using the same fixed size + var advance = textMetrics.width; + + var doubleBuffer = 2 * this.buffer; + var width, glyphWidth, height, glyphHeight, top; + + var imgTop, imgLeft, baselinePosition; + // If the browser supports bounding box metrics, we can generate a smaller + // SDF. This is a significant performance win. + if (getMetrics && this.useMetrics) { + // The integer/pixel part of the top alignment is encoded in metrics.top + // The remainder is implicitly encoded in the rasterization + top = Math.floor(textMetrics.actualBoundingBoxAscent); + baselinePosition = this.buffer + Math.ceil(textMetrics.actualBoundingBoxAscent); + imgTop = this.buffer; + imgLeft = this.buffer; + + // If the glyph overflows the canvas size, it will be clipped at the + // bottom/right + glyphWidth = Math.min(this.size, + Math.ceil(textMetrics.actualBoundingBoxRight - textMetrics.actualBoundingBoxLeft)); + glyphHeight = Math.min(this.size - imgTop, + Math.ceil(textMetrics.actualBoundingBoxAscent + textMetrics.actualBoundingBoxDescent)); + + width = glyphWidth + doubleBuffer; + height = glyphHeight + doubleBuffer; + this.ctx.textBaseline = 'alphabetic'; + } else { + width = glyphWidth = this.size; + height = glyphHeight = this.size; + // 19 points is an approximation of the "cap height" ascent from alphabetic + // baseline (even though actual drawing is from middle baseline, we can + // use the approximation because every glyph fills the em box) + top = 19 * this.fontSize / 24; + imgTop = imgLeft = 0; + baselinePosition = this.middle; + this.ctx.textBaseline = 'middle'; + } + + var imgData; + if (glyphWidth && glyphHeight) { + this.ctx.clearRect(imgLeft, imgTop, glyphWidth, glyphHeight); + this.ctx.fillText(char, this.buffer, baselinePosition); + imgData = this.ctx.getImageData(imgLeft, imgTop, glyphWidth, glyphHeight); + } + + var alphaChannel = new Uint8ClampedArray(width * height); + + prepareGrids(imgData, width, height, glyphWidth, glyphHeight, this.gridOuter, this.gridInner); + + edt(this.gridOuter, width, height, this.f, this.v, this.z); + edt(this.gridInner, width, height, this.f, this.v, this.z); + + extractAlpha(alphaChannel, width, height, this.gridOuter, this.gridInner, this.radius, this.cutoff); + + return { + data: alphaChannel, + metrics: { + width: glyphWidth, + height: glyphHeight, + sdfWidth: width, + sdfHeight: height, + top: top, + left: 0, + advance: advance + } + }; +}; + +TinySDF.prototype.draw = function (char) { + return this._draw(char, false).data; +}; + +TinySDF.prototype.drawWithMetrics = function (char) { + return this._draw(char, true); +}; + +// 2D Euclidean squared distance transform by Felzenszwalb & Huttenlocher https://cs.brown.edu/~pff/papers/dt-final.pdf +function edt(data, width, height, f, v, z) { + for (var x = 0; x < width; x++) edt1d(data, x, width, height, f, v, z); + for (var y = 0; y < height; y++) edt1d(data, y * width, 1, width, f, v, z); +} + +// 1D squared distance transform +function edt1d(grid, offset, stride, length, f, v, z) { + var q, k, s, r; + v[0] = 0; + z[0] = -INF; + z[1] = INF; + + for (q = 0; q < length; q++) f[q] = grid[offset + q * stride]; + + for (q = 1, k = 0, s = 0; q < length; q++) { + do { + r = v[k]; + s = (f[q] - f[r] + q * q - r * r) / (q - r) / 2; + } while (s <= z[k] && --k > -1); + + k++; + v[k] = q; + z[k] = s; + z[k + 1] = INF; + } + + for (q = 0, k = 0; q < length; q++) { + while (z[k + 1] < q) k++; + r = v[k]; + grid[offset + q * stride] = f[r] + (q - r) * (q - r); + } +} diff --git a/node_modules/@mapbox/tiny-sdf/package.json b/node_modules/@mapbox/tiny-sdf/package.json new file mode 100644 index 0000000000000000000000000000000000000000..dda6e2569086bce00231c44f732fbe75142689ff --- /dev/null +++ b/node_modules/@mapbox/tiny-sdf/package.json @@ -0,0 +1,34 @@ +{ + "name": "@mapbox/tiny-sdf", + "version": "1.2.5", + "description": "Browser-side SDF font generator", + "main": "index.js", + "scripts": { + "test": "eslint index.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/mapbox/tiny-sdf.git" + }, + "keywords": [ + "sdf", + "signed distance fields", + "font", + "canvas", + "text", + "distance transform" + ], + "author": "Vladimir Agafonkin", + "license": "BSD-2-Clause", + "bugs": { + "url": "https://github.com/mapbox/tiny-sdf/issues" + }, + "homepage": "https://github.com/mapbox/tiny-sdf#readme", + "devDependencies": { + "eslint": "^7.0.0", + "eslint-config-mourner": "^2.0.1" + }, + "eslintConfig": { + "extends": "mourner" + } +} diff --git a/node_modules/@mapbox/unitbezier/.travis.yml b/node_modules/@mapbox/unitbezier/.travis.yml new file mode 100644 index 0000000000000000000000000000000000000000..20fd86b6a5bee335c75b4efea34312ff7f3a039e --- /dev/null +++ b/node_modules/@mapbox/unitbezier/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - 0.10 diff --git a/node_modules/@mapbox/unitbezier/README.md b/node_modules/@mapbox/unitbezier/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9a3bb4e92b3c133ee35bb56318f6d394c5f18e40 --- /dev/null +++ b/node_modules/@mapbox/unitbezier/README.md @@ -0,0 +1,23 @@ +[![Build Status](https://travis-ci.org/mapbox/unitbezier.svg)](https://travis-ci.org/mapbox/unitbezier) + +# unitbezier + +Unit bezier interpolation function: a port to JavaScript from Webkit: + +http://svn.webkit.org/repository/webkit/trunk/Source/WebCore/platform/graphics/UnitBezier.h + +## api + +### new UnitBezier(p1x, p1y, p2x, p2y) + +Initialize a new bezier curve given the points + +### bezier.sampleCurveX(t) + +### bezier.sampleCurveY(t) + +### bezier.sampleCurveDerivativeX(t) + +### bezier.solveCurveX(t) + +### bezier.solve(x, epsilon) diff --git a/node_modules/@mapbox/unitbezier/index.js b/node_modules/@mapbox/unitbezier/index.js new file mode 100644 index 0000000000000000000000000000000000000000..ecdbce023a60668ca6b92079f96e744a28ac5e92 --- /dev/null +++ b/node_modules/@mapbox/unitbezier/index.js @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2008 Apple Inc. 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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 APPLE INC. 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. + * + * Ported from Webkit + * http://svn.webkit.org/repository/webkit/trunk/Source/WebCore/platform/graphics/UnitBezier.h + */ + +module.exports = UnitBezier; + +function UnitBezier(p1x, p1y, p2x, p2y) { + // Calculate the polynomial coefficients, implicit first and last control points are (0,0) and (1,1). + this.cx = 3.0 * p1x; + this.bx = 3.0 * (p2x - p1x) - this.cx; + this.ax = 1.0 - this.cx - this.bx; + + this.cy = 3.0 * p1y; + this.by = 3.0 * (p2y - p1y) - this.cy; + this.ay = 1.0 - this.cy - this.by; + + this.p1x = p1x; + this.p1y = p2y; + this.p2x = p2x; + this.p2y = p2y; +} + +UnitBezier.prototype.sampleCurveX = function(t) { + // `ax t^3 + bx t^2 + cx t' expanded using Horner's rule. + return ((this.ax * t + this.bx) * t + this.cx) * t; +}; + +UnitBezier.prototype.sampleCurveY = function(t) { + return ((this.ay * t + this.by) * t + this.cy) * t; +}; + +UnitBezier.prototype.sampleCurveDerivativeX = function(t) { + return (3.0 * this.ax * t + 2.0 * this.bx) * t + this.cx; +}; + +UnitBezier.prototype.solveCurveX = function(x, epsilon) { + if (typeof epsilon === 'undefined') epsilon = 1e-6; + + var t0, t1, t2, x2, i; + + // First try a few iterations of Newton's method -- normally very fast. + for (t2 = x, i = 0; i < 8; i++) { + + x2 = this.sampleCurveX(t2) - x; + if (Math.abs(x2) < epsilon) return t2; + + var d2 = this.sampleCurveDerivativeX(t2); + if (Math.abs(d2) < 1e-6) break; + + t2 = t2 - x2 / d2; + } + + // Fall back to the bisection method for reliability. + t0 = 0.0; + t1 = 1.0; + t2 = x; + + if (t2 < t0) return t0; + if (t2 > t1) return t1; + + while (t0 < t1) { + + x2 = this.sampleCurveX(t2); + if (Math.abs(x2 - x) < epsilon) return t2; + + if (x > x2) { + t0 = t2; + } else { + t1 = t2; + } + + t2 = (t1 - t0) * 0.5 + t0; + } + + // Failure. + return t2; +}; + +UnitBezier.prototype.solve = function(x, epsilon) { + return this.sampleCurveY(this.solveCurveX(x, epsilon)); +}; diff --git a/node_modules/@mapbox/unitbezier/package.json b/node_modules/@mapbox/unitbezier/package.json new file mode 100644 index 0000000000000000000000000000000000000000..3028103f1a7fd6ca7410c373e1aadb41b7979a9f --- /dev/null +++ b/node_modules/@mapbox/unitbezier/package.json @@ -0,0 +1,34 @@ +{ + "name": "@mapbox/unitbezier", + "version": "0.0.0", + "description": "unit bezier curve interpolation", + "main": "index.js", + "scripts": { + "test": "tap --coverage test/*.js" + }, + "repository": { + "type": "git", + "url": "git@github.com:mapbox/unitbezier.git" + }, + "keywords": [ + "unit", + "bezier", + "interpolation", + "webkit" + ], + "author": "", + "license": "BSD-2-Clause", + "bugs": { + "url": "https://github.com/mapbox/unitbezier/issues" + }, + "homepage": "https://github.com/mapbox/unitbezier", + "devDependencies": { + "cz-conventional-changelog": "1.2.0", + "tap": "~9.0.3" + }, + "config": { + "commitizen": { + "path": "./node_modules/cz-conventional-changelog" + } + } +} diff --git a/node_modules/@mapbox/unitbezier/test/unitbezier.js b/node_modules/@mapbox/unitbezier/test/unitbezier.js new file mode 100644 index 0000000000000000000000000000000000000000..75db049ac733333290b0e9d675ec70c40aa22e00 --- /dev/null +++ b/node_modules/@mapbox/unitbezier/test/unitbezier.js @@ -0,0 +1,16 @@ +var test = require('tap').test, + UnitBezier = require('../'); + +test('unit bezier', function(t) { + var u = new UnitBezier(0, 0, 1, 1); + t.equal(u.sampleCurveY(1), 1, 'sampleCurveY'); + t.equal(u.sampleCurveX(1), 1, 'sampleCurveX'); + t.equal(u.sampleCurveDerivativeX(0.1), 0.54, 'sampleCurveDerivativeX'); + t.equal(u.solveCurveX(0), 0, 'solveCurveX'); + t.equal(u.solveCurveX(1), 1, 'solveCurveX'); + t.equal(u.solveCurveX(1.25552, 1.e-8), 1, 'solveCurveX'); + t.equal(u.solveCurveX(1, 1e-8), 1, 'solveCurveX'); + t.equal(u.solveCurveX(0.5), 0.5, 'solveCurveX'); + t.equal(u.solve(0.5), 0.5, 'solve'); + t.end(); +}); diff --git a/node_modules/@mapbox/vector-tile/.eslintrc b/node_modules/@mapbox/vector-tile/.eslintrc new file mode 100644 index 0000000000000000000000000000000000000000..2ede22687d4ce4408aa846aa7f1986ea92a59ca8 --- /dev/null +++ b/node_modules/@mapbox/vector-tile/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": "eslint-config-unstyled" +} \ No newline at end of file diff --git a/node_modules/@mapbox/vector-tile/.travis.yml b/node_modules/@mapbox/vector-tile/.travis.yml new file mode 100644 index 0000000000000000000000000000000000000000..f5627428f8648024e9846fa26ce0d9ab8cfc4647 --- /dev/null +++ b/node_modules/@mapbox/vector-tile/.travis.yml @@ -0,0 +1,7 @@ +language: node_js +sudo: false +node_js: + - 4 +script: + - npm test + - npm run cov diff --git a/node_modules/@mapbox/vector-tile/CHANGELOG.md b/node_modules/@mapbox/vector-tile/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..0ac071ba72b240bd82faa3e1de3ad61303242beb --- /dev/null +++ b/node_modules/@mapbox/vector-tile/CHANGELOG.md @@ -0,0 +1,41 @@ +## vector-tile-js changelog + +### 1.3.1 (2017-03-02) + +- Fix bug causing infinite loop when parsing ClosePath command (#61) h/t @sanjin-saric +- Pin node-mapnik dependency to `~3.6.0` (#62, see also https://github.com/mapnik/node-mapnik/issues/848) + +### 1.3.0 (2016-07-18) + +- Added "id" property to VectorTileFeature (#43) + +### 1.2.1 (2016-05-18) + +- Fixed geometry structure of MultiPoints, Polygons, and MultiPolygons in toGeoJSON() + +### 1.2.0 (2015-12-10) + +- Added "id" property to toGeoJSON() output + +### 1.1.3 (2015-06-15) + +- Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90 + +### 1.1.2 (2015-03-05) + +- Fixed decoding of negative values in feature properties + +### 1.1.1 (2015-02-25) + +- Remove sphericalmercator dependency +- Correctly handle MultiPoint and MultiLineString features in toGeoJSON() + +### 1.1.0 (2015-02-21) + +- Added VectorTileFeature#toGeoJSON() + +### 1.0.0 (2014-12-26) + +### 0.0.1 (2014-04-13) + +- Initial release diff --git a/node_modules/@mapbox/vector-tile/LICENSE.txt b/node_modules/@mapbox/vector-tile/LICENSE.txt new file mode 100644 index 0000000000000000000000000000000000000000..a3473509bd7f7b8d39d992ff4731db245ebc0cbc --- /dev/null +++ b/node_modules/@mapbox/vector-tile/LICENSE.txt @@ -0,0 +1,28 @@ +Copyright (c) 2014, Mapbox + + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * 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. + * Neither the name of Mapbox 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. diff --git a/node_modules/@mapbox/vector-tile/README.md b/node_modules/@mapbox/vector-tile/README.md new file mode 100644 index 0000000000000000000000000000000000000000..66b897d57c8d96e0a82c8a935e85eba343d37383 --- /dev/null +++ b/node_modules/@mapbox/vector-tile/README.md @@ -0,0 +1,104 @@ +# vector-tile + +[![build status](https://secure.travis-ci.org/mapbox/vector-tile-js.svg)](http://travis-ci.org/mapbox/vector-tile-js) [![Coverage Status](https://coveralls.io/repos/mapbox/vector-tile-js/badge.svg)](https://coveralls.io/r/mapbox/vector-tile-js) + +This library reads [Mapbox Vector Tiles](https://github.com/mapbox/vector-tile-spec) and allows access to the layers and features. + +## Example + +```js +var VectorTile = require('@mapbox/vector-tile').VectorTile; +var Protobuf = require('pbf'); + +var tile = new VectorTile(new Protobuf(data)); + +// Contains a map of all layers +tile.layers; + +var landuse = tile.layers.landuse; + +// Amount of features in this layer +landuse.length; + +// Returns the first feature +landuse.feature(0); +``` + +Vector tiles contained in [serialtiles-spec](https://github.com/mapbox/serialtiles-spec) +are gzip-encoded, so a complete example of parsing them with the native +zlib module would be: + +```js +var VectorTile = require('vector-tile').VectorTile; +var Protobuf = require('pbf'); +var zlib = require('zlib'); + +zlib.gunzip(data, function(err, buffer) { + var tile = new VectorTile(new Protobuf(buffer)); +}); +``` + +## Depends + + - Node.js v0.10.x or v0.8.x + + +## Install + +To install: + + npm install @mapbox/vector-tile + + +## API Reference + + +### VectorTile + +An object that parses vector tile data and makes it readable. + +#### Constructor + +- **new VectorTile(protobuf[, end])** — + parses the vector tile data contained in the given [Protobuf](https://github.com/mapbox/pbf) object, + saving resulting layers in the created object as a `layers` property. Optionally accepts end index. + +#### Properties + +- **layers** (Object) — an object containing parsed layers in the form of `{: , ...}`, +where each layer is a `VectorTileLayer` object. + + +### VectorTileLayer + +An object that contains the data for a single vector tile layer. + +#### Properties + +- **version** (`Number`, default: `1`) +- **name** (`String) `— layer name +- **extent** (`Number`, default: `4096`) — tile extent size +- **length** (`Number`) — number of features in the layer + +#### Methods + +- **feature(i)** — get a feature (`VectorTileFeature`) by the given index from the layer. + + +### VectorTileFeature + +An object that contains the data for a single feature. + +#### Properties + +- **type** (`Number`) — type of the feature (also see `VectorTileFeature.types`) +- **extent** (`Number`) — feature extent size +- **id** (`Number`) — feature identifier, if present +- **properties** (`Object`) — object literal with feature properties + +#### Methods + +- **loadGeometry()** — parses feature geometry and returns an array of + [Point](https://github.com/mapbox/point-geometry) arrays (with each point having `x` and `y` properties) +- **bbox()** — calculates and returns the bounding box of the feature in the form `[x1, y1, x2, y2]` +- **toGeoJSON(x, y, z)** — returns a GeoJSON representation of the feature. (`x`, `y`, and `z` refer to the containing tile's index.) diff --git a/node_modules/@mapbox/vector-tile/fixtures.js b/node_modules/@mapbox/vector-tile/fixtures.js new file mode 100644 index 0000000000000000000000000000000000000000..a14d4f59a2a388a15f84537749e32dfe33877ae2 --- /dev/null +++ b/node_modules/@mapbox/vector-tile/fixtures.js @@ -0,0 +1,157 @@ +var mapnik = require('mapnik'); +var path = require('path'); +var fs = require('fs'); + +mapnik.register_datasource(path.join(mapnik.settings.paths.input_plugins, 'geojson.input')); + +var fixtures = { + "zero-point": { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "MultiPoint", + "coordinates": [] + }, + "properties": {} + } + ] + }, + "zero-line": { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "MultiLineString", + "coordinates": [] + }, + "properties": {} + } + ] + }, + "zero-polygon": { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "MultiPolygon", + "coordinates": [] + }, + "properties": {} + } + ] + }, + "singleton-multi-point": { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "MultiPoint", + "coordinates": [[1, 2]] + }, + "properties": {} + } + ] + }, + "singleton-multi-line": { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "MultiLineString", + "coordinates": [[[1, 2], [3, 4]]] + }, + "properties": {} + } + ] + }, + "singleton-multi-polygon": { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "MultiPolygon", + "coordinates": [[[[0, 0], [1, 0], [1, 1], [0, 0]]]] + }, + "properties": {} + } + ] + }, + "multi-point": { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "MultiPoint", + "coordinates": [[1, 2], [3, 4]] + }, + "properties": {} + } + ] + }, + "multi-line": { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "MultiLineString", + "coordinates": [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] + }, + "properties": {} + } + ] + }, + "multi-polygon": { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "MultiPolygon", + "coordinates": [[[[0, 0], [1, 0], [1, 1], [0, 0]]], [[[0, 0], [-1, 0], [-1, -1], [0, 0]]]] + }, + "properties": {} + } + ] + }, + "polygon-with-inner": { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [[[-2, 2], [2, 2], [2, -2], [-2, -2], [-2, 2]], [[-1, 1], [1, 1], [1, -1], [-1, -1], [-1, 1]]] + }, + "properties": {} + } + ] + }, + "stacked-multipolygon": { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "MultiPolygon", + "coordinates": [[[[-2, 2], [2, 2], [2, -2], [-2, -2], [-2, 2]]], [[[-1, 1], [1, 1], [1, -1], [-1, -1], [-1, 1]]]] + }, + "properties": {} + } + ] + } +} + +for (var fixture in fixtures) { + var vtile = new mapnik.VectorTile(0, 0, 0); + vtile.addGeoJSON(JSON.stringify(fixtures[fixture]), "geojson"); + fs.writeFileSync('./test/fixtures/' + fixture + '.pbf', vtile.getData()); +} diff --git a/node_modules/@mapbox/vector-tile/index.js b/node_modules/@mapbox/vector-tile/index.js new file mode 100644 index 0000000000000000000000000000000000000000..8938a55f5125b38c06c00c909af18977f9fd518c --- /dev/null +++ b/node_modules/@mapbox/vector-tile/index.js @@ -0,0 +1,3 @@ +module.exports.VectorTile = require('./lib/vectortile.js'); +module.exports.VectorTileFeature = require('./lib/vectortilefeature.js'); +module.exports.VectorTileLayer = require('./lib/vectortilelayer.js'); diff --git a/node_modules/@mapbox/vector-tile/lib/vectortile.js b/node_modules/@mapbox/vector-tile/lib/vectortile.js new file mode 100644 index 0000000000000000000000000000000000000000..360a5698d7ed8314ceebe235b49e66d0b84e479d --- /dev/null +++ b/node_modules/@mapbox/vector-tile/lib/vectortile.js @@ -0,0 +1,17 @@ +'use strict'; + +var VectorTileLayer = require('./vectortilelayer'); + +module.exports = VectorTile; + +function VectorTile(pbf, end) { + this.layers = pbf.readFields(readTile, {}, end); +} + +function readTile(tag, layers, pbf) { + if (tag === 3) { + var layer = new VectorTileLayer(pbf, pbf.readVarint() + pbf.pos); + if (layer.length) layers[layer.name] = layer; + } +} + diff --git a/node_modules/@mapbox/vector-tile/lib/vectortilefeature.js b/node_modules/@mapbox/vector-tile/lib/vectortilefeature.js new file mode 100644 index 0000000000000000000000000000000000000000..b9880a1386a6f664e1ac0ce3d9d195ce1f67381d --- /dev/null +++ b/node_modules/@mapbox/vector-tile/lib/vectortilefeature.js @@ -0,0 +1,233 @@ +'use strict'; + +var Point = require('@mapbox/point-geometry'); + +module.exports = VectorTileFeature; + +function VectorTileFeature(pbf, end, extent, keys, values) { + // Public + this.properties = {}; + this.extent = extent; + this.type = 0; + + // Private + this._pbf = pbf; + this._geometry = -1; + this._keys = keys; + this._values = values; + + pbf.readFields(readFeature, this, end); +} + +function readFeature(tag, feature, pbf) { + if (tag == 1) feature.id = pbf.readVarint(); + else if (tag == 2) readTag(pbf, feature); + else if (tag == 3) feature.type = pbf.readVarint(); + else if (tag == 4) feature._geometry = pbf.pos; +} + +function readTag(pbf, feature) { + var end = pbf.readVarint() + pbf.pos; + + while (pbf.pos < end) { + var key = feature._keys[pbf.readVarint()], + value = feature._values[pbf.readVarint()]; + feature.properties[key] = value; + } +} + +VectorTileFeature.types = ['Unknown', 'Point', 'LineString', 'Polygon']; + +VectorTileFeature.prototype.loadGeometry = function() { + var pbf = this._pbf; + pbf.pos = this._geometry; + + var end = pbf.readVarint() + pbf.pos, + cmd = 1, + length = 0, + x = 0, + y = 0, + lines = [], + line; + + while (pbf.pos < end) { + if (length <= 0) { + var cmdLen = pbf.readVarint(); + cmd = cmdLen & 0x7; + length = cmdLen >> 3; + } + + length--; + + if (cmd === 1 || cmd === 2) { + x += pbf.readSVarint(); + y += pbf.readSVarint(); + + if (cmd === 1) { // moveTo + if (line) lines.push(line); + line = []; + } + + line.push(new Point(x, y)); + + } else if (cmd === 7) { + + // Workaround for https://github.com/mapbox/mapnik-vector-tile/issues/90 + if (line) { + line.push(line[0].clone()); // closePolygon + } + + } else { + throw new Error('unknown command ' + cmd); + } + } + + if (line) lines.push(line); + + return lines; +}; + +VectorTileFeature.prototype.bbox = function() { + var pbf = this._pbf; + pbf.pos = this._geometry; + + var end = pbf.readVarint() + pbf.pos, + cmd = 1, + length = 0, + x = 0, + y = 0, + x1 = Infinity, + x2 = -Infinity, + y1 = Infinity, + y2 = -Infinity; + + while (pbf.pos < end) { + if (length <= 0) { + var cmdLen = pbf.readVarint(); + cmd = cmdLen & 0x7; + length = cmdLen >> 3; + } + + length--; + + if (cmd === 1 || cmd === 2) { + x += pbf.readSVarint(); + y += pbf.readSVarint(); + if (x < x1) x1 = x; + if (x > x2) x2 = x; + if (y < y1) y1 = y; + if (y > y2) y2 = y; + + } else if (cmd !== 7) { + throw new Error('unknown command ' + cmd); + } + } + + return [x1, y1, x2, y2]; +}; + +VectorTileFeature.prototype.toGeoJSON = function(x, y, z) { + var size = this.extent * Math.pow(2, z), + x0 = this.extent * x, + y0 = this.extent * y, + coords = this.loadGeometry(), + type = VectorTileFeature.types[this.type], + i, j; + + function project(line) { + for (var j = 0; j < line.length; j++) { + var p = line[j], y2 = 180 - (p.y + y0) * 360 / size; + line[j] = [ + (p.x + x0) * 360 / size - 180, + 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90 + ]; + } + } + + switch (this.type) { + case 1: + var points = []; + for (i = 0; i < coords.length; i++) { + points[i] = coords[i][0]; + } + coords = points; + project(coords); + break; + + case 2: + for (i = 0; i < coords.length; i++) { + project(coords[i]); + } + break; + + case 3: + coords = classifyRings(coords); + for (i = 0; i < coords.length; i++) { + for (j = 0; j < coords[i].length; j++) { + project(coords[i][j]); + } + } + break; + } + + if (coords.length === 1) { + coords = coords[0]; + } else { + type = 'Multi' + type; + } + + var result = { + type: "Feature", + geometry: { + type: type, + coordinates: coords + }, + properties: this.properties + }; + + if ('id' in this) { + result.id = this.id; + } + + return result; +}; + +// classifies an array of rings into polygons with outer rings and holes + +function classifyRings(rings) { + var len = rings.length; + + if (len <= 1) return [rings]; + + var polygons = [], + polygon, + ccw; + + for (var i = 0; i < len; i++) { + var area = signedArea(rings[i]); + if (area === 0) continue; + + if (ccw === undefined) ccw = area < 0; + + if (ccw === area < 0) { + if (polygon) polygons.push(polygon); + polygon = [rings[i]]; + + } else { + polygon.push(rings[i]); + } + } + if (polygon) polygons.push(polygon); + + return polygons; +} + +function signedArea(ring) { + var sum = 0; + for (var i = 0, len = ring.length, j = len - 1, p1, p2; i < len; j = i++) { + p1 = ring[i]; + p2 = ring[j]; + sum += (p2.x - p1.x) * (p1.y + p2.y); + } + return sum; +} diff --git a/node_modules/@mapbox/vector-tile/lib/vectortilelayer.js b/node_modules/@mapbox/vector-tile/lib/vectortilelayer.js new file mode 100644 index 0000000000000000000000000000000000000000..07a9e418511e8bf48fd0c8abd13826a5d28b81e9 --- /dev/null +++ b/node_modules/@mapbox/vector-tile/lib/vectortilelayer.js @@ -0,0 +1,61 @@ +'use strict'; + +var VectorTileFeature = require('./vectortilefeature.js'); + +module.exports = VectorTileLayer; + +function VectorTileLayer(pbf, end) { + // Public + this.version = 1; + this.name = null; + this.extent = 4096; + this.length = 0; + + // Private + this._pbf = pbf; + this._keys = []; + this._values = []; + this._features = []; + + pbf.readFields(readLayer, this, end); + + this.length = this._features.length; +} + +function readLayer(tag, layer, pbf) { + if (tag === 15) layer.version = pbf.readVarint(); + else if (tag === 1) layer.name = pbf.readString(); + else if (tag === 5) layer.extent = pbf.readVarint(); + else if (tag === 2) layer._features.push(pbf.pos); + else if (tag === 3) layer._keys.push(pbf.readString()); + else if (tag === 4) layer._values.push(readValueMessage(pbf)); +} + +function readValueMessage(pbf) { + var value = null, + end = pbf.readVarint() + pbf.pos; + + while (pbf.pos < end) { + var tag = pbf.readVarint() >> 3; + + value = tag === 1 ? pbf.readString() : + tag === 2 ? pbf.readFloat() : + tag === 3 ? pbf.readDouble() : + tag === 4 ? pbf.readVarint64() : + tag === 5 ? pbf.readVarint() : + tag === 6 ? pbf.readSVarint() : + tag === 7 ? pbf.readBoolean() : null; + } + + return value; +} + +// return feature `i` from this layer as a `VectorTileFeature` +VectorTileLayer.prototype.feature = function(i) { + if (i < 0 || i >= this._features.length) throw new Error('feature index out of bounds'); + + this._pbf.pos = this._features[i]; + + var end = this._pbf.readVarint() + this._pbf.pos; + return new VectorTileFeature(this._pbf, end, this.extent, this._keys, this._values); +}; diff --git a/node_modules/@mapbox/vector-tile/package.json b/node_modules/@mapbox/vector-tile/package.json new file mode 100644 index 0000000000000000000000000000000000000000..9f0f370fefecc6c64170be344e3203136aeadab7 --- /dev/null +++ b/node_modules/@mapbox/vector-tile/package.json @@ -0,0 +1,33 @@ +{ + "name": "@mapbox/vector-tile", + "description": "Parses vector tiles", + "repository": "https://github.com/mapbox/vector-tile-js.git", + "version": "1.3.1", + "license": "BSD-3-Clause", + "main": "index.js", + "dependencies": { + "@mapbox/point-geometry": "~0.1.0" + }, + "devDependencies": { + "benchmark": "^1.0.0", + "coveralls": "~2.11.2", + "istanbul": "~0.3.6", + "mapnik": "~3.6.0", + "jshint": "^2.6.3", + "pbf": "^1.3.2", + "tape": "~3.5.0", + "eslint": "~1.00.0", + "eslint-config-unstyled": "^1.1.0" + }, + "jshintConfig": { + "trailing": true, + "undef": true, + "unused": true, + "indent": 4, + "node": true + }, + "scripts": { + "test": "eslint lib index.js && jshint lib && tape test/parse.test.js", + "cov": "istanbul cover ./node_modules/.bin/tape test/parse.test.js && coveralls < ./coverage/lcov.info" + } +} diff --git a/node_modules/@mapbox/vector-tile/proto/vector_tile.proto b/node_modules/@mapbox/vector-tile/proto/vector_tile.proto new file mode 100644 index 0000000000000000000000000000000000000000..3a489c38574dbf8000ce41f08764670a5127d100 --- /dev/null +++ b/node_modules/@mapbox/vector-tile/proto/vector_tile.proto @@ -0,0 +1,88 @@ +// Protocol Version 1 + +message tile { + enum GeomType { + Unknown = 0; + Point = 1; + LineString = 2; + Polygon = 3; + } + + // Variant type encoding + message value { + // Exactly one of these values may be present in a valid message + optional string string_value = 1; + optional float float_value = 2; + optional double double_value = 3; + optional int64 int_value = 4; + optional uint64 uint_value = 5; + optional sint64 sint_value = 6; + optional bool bool_value = 7; + + extensions 8 to max; + } + + message feature { + optional uint64 id = 1; + + // Tags of this feature. Even numbered values refer to the nth + // value in the keys list on the tile message, odd numbered + // values refer to the nth value in the values list on the tile + // message. + repeated uint32 tags = 2 [ packed = true ]; + + // The type of geometry stored in this feature. + optional GeomType type = 3 [ default = Unknown ]; + + // Contains a stream of commands and parameters (vertices). The + // repeat count is shifted to the left by 3 bits. This means + // that the command has 3 bits (0-7). The repeat count + // indicates how often this command is to be repeated. Defined + // commands are: + // - MoveTo: 1 (2 parameters follow) + // - LineTo: 2 (2 parameters follow) + // - ClosePath: 7 (no parameters follow) + // + // Ex.: MoveTo(3, 6), LineTo(8, 12), LineTo(20, 34), ClosePath + // Encoded as: [ 9 3 6 18 5 6 12 22 15 ] + // == command type 7 (ClosePath), length 1 + // ===== relative LineTo(+12, +22) == LineTo(20, 34) + // === relative LineTo(+5, +6) == LineTo(8, 12) + // == [00010 010] = command type 2 (LineTo), length 2 + // === relative MoveTo(+3, +6) + // == [00001 001] = command type 1 (MoveTo), length 1 + // Commands are encoded as uint32 varints, vertex parameters are + // encoded as sint32 varints (zigzag). Vertex parameters are + // also encoded as deltas to the previous position. The original + // position is (0,0) + repeated uint32 geometry = 4 [ packed = true ]; + } + + message layer { + // Any compliant implementation must first read the version + // number encoded in this message and choose the correct + // implementation for this version number before proceeding to + // decode other parts of this message. + required uint32 version = 15 [ default = 1 ]; + + required string name = 1; + + // The actual features in this tile. + repeated feature features = 2; + + // Dictionary encoding for keys + repeated string keys = 3; + + // Dictionary encoding for values + repeated value values = 4; + + // The bounding box in this tile spans from 0..4095 units + optional uint32 extent = 5 [ default = 4096 ]; + + extensions 16 to max; + } + + repeated layer layers = 3; + + extensions 16 to 8191; +} diff --git a/node_modules/@mapbox/vector-tile/test/bench.js b/node_modules/@mapbox/vector-tile/test/bench.js new file mode 100644 index 0000000000000000000000000000000000000000..f7e593be9ce445b8ebb39beda1d89897e590f27c --- /dev/null +++ b/node_modules/@mapbox/vector-tile/test/bench.js @@ -0,0 +1,36 @@ +var Pbf = require('pbf'), + VectorTile = require('..').VectorTile, + Benchmark = require('benchmark'), + fs = require('fs'); + +var suite = new Benchmark.Suite(), + data = fs.readFileSync(__dirname + '/fixtures/14-8801-5371.vector.Pbf'); + +readTile(); // output any errors before running the suite +readTile(true); + +suite +.add('read tile with geometries', function() { + readTile(true); +}) +.add('read tile without geometries', function() { + readTile(); +}) +.on('cycle', function(event) { + console.log(String(event.target)); +}) +.run(); + + +function readTile(loadGeom, loadPacked) { + var buf = new Pbf(data), + vt = new VectorTile(buf); + + for (var id in vt.layers) { + var layer = vt.layers[id]; + for (var i = 0; i < layer.length; i++) { + var feature = layer.feature(i); + if (loadGeom) feature.loadGeometry(); + } + } +} diff --git a/node_modules/@mapbox/vector-tile/test/fixtures/12-1143-1497.vector.pbf b/node_modules/@mapbox/vector-tile/test/fixtures/12-1143-1497.vector.pbf new file mode 100644 index 0000000000000000000000000000000000000000..80bbb2780e20ca0fc80ff05288656f5427219f0b Binary files /dev/null and b/node_modules/@mapbox/vector-tile/test/fixtures/12-1143-1497.vector.pbf differ diff --git a/node_modules/@mapbox/vector-tile/test/fixtures/14-8801-5371.vector.pbf b/node_modules/@mapbox/vector-tile/test/fixtures/14-8801-5371.vector.pbf new file mode 100644 index 0000000000000000000000000000000000000000..87811b07ba89ae0db391cc372c273476ad150bd9 --- /dev/null +++ b/node_modules/@mapbox/vector-tile/test/fixtures/14-8801-5371.vector.pbf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:02cf1d0154ff59d8c559d041e3b41297f5e260d925fc5e49ad00743478a12d60 +size 182636 diff --git a/node_modules/@mapbox/vector-tile/test/fixtures/lots-of-tags.vector.pbf b/node_modules/@mapbox/vector-tile/test/fixtures/lots-of-tags.vector.pbf new file mode 100644 index 0000000000000000000000000000000000000000..281b8624bf466e53bad6a46d15f6e25ff0829ccc Binary files /dev/null and b/node_modules/@mapbox/vector-tile/test/fixtures/lots-of-tags.vector.pbf differ diff --git a/node_modules/@mapbox/vector-tile/test/fixtures/multi-line.pbf b/node_modules/@mapbox/vector-tile/test/fixtures/multi-line.pbf new file mode 100644 index 0000000000000000000000000000000000000000..a00081602db6e01da14d82203e21bdf92f6f9891 --- /dev/null +++ b/node_modules/@mapbox/vector-tile/test/fixtures/multi-line.pbf @@ -0,0 +1,4 @@ +$x +geojson(€ " – Ò +.- .+ +.- \ No newline at end of file diff --git a/node_modules/@mapbox/vector-tile/test/fixtures/multi-point.pbf b/node_modules/@mapbox/vector-tile/test/fixtures/multi-point.pbf new file mode 100644 index 0000000000000000000000000000000000000000..f49d513b06278637c9fd7068a16bf1ad9d1664ed --- /dev/null +++ b/node_modules/@mapbox/vector-tile/test/fixtures/multi-point.pbf @@ -0,0 +1,2 @@ +x +geojson(€  "– Ò.- \ No newline at end of file diff --git a/node_modules/@mapbox/vector-tile/test/fixtures/multi-polygon.pbf b/node_modules/@mapbox/vector-tile/test/fixtures/multi-polygon.pbf new file mode 100644 index 0000000000000000000000000000000000000000..0d81bd6bc93eda42b44d369cd2c5e79ae476f04a Binary files /dev/null and b/node_modules/@mapbox/vector-tile/test/fixtures/multi-polygon.pbf differ diff --git a/node_modules/@mapbox/vector-tile/test/fixtures/multipolygon-with-closepath.pbf b/node_modules/@mapbox/vector-tile/test/fixtures/multipolygon-with-closepath.pbf new file mode 100644 index 0000000000000000000000000000000000000000..40bb2dceeb5f4780063421011874ca48e55f36db Binary files /dev/null and b/node_modules/@mapbox/vector-tile/test/fixtures/multipolygon-with-closepath.pbf differ diff --git a/node_modules/@mapbox/vector-tile/test/fixtures/multipolygon.pbf b/node_modules/@mapbox/vector-tile/test/fixtures/multipolygon.pbf new file mode 100644 index 0000000000000000000000000000000000000000..171c073b1da39d4f83079e9de804ba1c60e468fb Binary files /dev/null and b/node_modules/@mapbox/vector-tile/test/fixtures/multipolygon.pbf differ diff --git a/node_modules/@mapbox/vector-tile/test/fixtures/polygon-with-inner.pbf b/node_modules/@mapbox/vector-tile/test/fixtures/polygon-with-inner.pbf new file mode 100644 index 0000000000000000000000000000000000000000..5550fd82465e9cf274df0eb6cd532cd2ee685cea Binary files /dev/null and b/node_modules/@mapbox/vector-tile/test/fixtures/polygon-with-inner.pbf differ diff --git a/node_modules/@mapbox/vector-tile/test/fixtures/singleton-multi-line.pbf b/node_modules/@mapbox/vector-tile/test/fixtures/singleton-multi-line.pbf new file mode 100644 index 0000000000000000000000000000000000000000..86235274999f4d003e1380932d96cc2f8bedc6a8 --- /dev/null +++ b/node_modules/@mapbox/vector-tile/test/fixtures/singleton-multi-line.pbf @@ -0,0 +1,3 @@ +x +geojson(€ " – Ò +.- \ No newline at end of file diff --git a/node_modules/@mapbox/vector-tile/test/fixtures/singleton-multi-point.pbf b/node_modules/@mapbox/vector-tile/test/fixtures/singleton-multi-point.pbf new file mode 100644 index 0000000000000000000000000000000000000000..1e08de9610ffcd892c46ef1fb87290ce2f24193e --- /dev/null +++ b/node_modules/@mapbox/vector-tile/test/fixtures/singleton-multi-point.pbf @@ -0,0 +1,2 @@ +x +geojson(€  " – Ò \ No newline at end of file diff --git a/node_modules/@mapbox/vector-tile/test/fixtures/singleton-multi-polygon.pbf b/node_modules/@mapbox/vector-tile/test/fixtures/singleton-multi-polygon.pbf new file mode 100644 index 0000000000000000000000000000000000000000..a48ff0c7c267ed3de1c40b537382a794d9398165 Binary files /dev/null and b/node_modules/@mapbox/vector-tile/test/fixtures/singleton-multi-polygon.pbf differ diff --git a/node_modules/@mapbox/vector-tile/test/fixtures/stacked-multipolygon.pbf b/node_modules/@mapbox/vector-tile/test/fixtures/stacked-multipolygon.pbf new file mode 100644 index 0000000000000000000000000000000000000000..e039c4cbbb938fd4e771eb2f98dff659273e6561 Binary files /dev/null and b/node_modules/@mapbox/vector-tile/test/fixtures/stacked-multipolygon.pbf differ diff --git a/node_modules/@mapbox/vector-tile/test/fixtures/zero-line.pbf b/node_modules/@mapbox/vector-tile/test/fixtures/zero-line.pbf new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/node_modules/@mapbox/vector-tile/test/fixtures/zero-point.pbf b/node_modules/@mapbox/vector-tile/test/fixtures/zero-point.pbf new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/node_modules/@mapbox/vector-tile/test/fixtures/zero-polygon.pbf b/node_modules/@mapbox/vector-tile/test/fixtures/zero-polygon.pbf new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/node_modules/@mapbox/vector-tile/test/parse.test.js b/node_modules/@mapbox/vector-tile/test/parse.test.js new file mode 100644 index 0000000000000000000000000000000000000000..156bedbe5d484107ce63c834118ec617196ba4db --- /dev/null +++ b/node_modules/@mapbox/vector-tile/test/parse.test.js @@ -0,0 +1,225 @@ +var test = require('tape'), + fs = require('fs'), + Protobuf = require('pbf'), + VectorTile = require('..').VectorTile, + VectorTileLayer = require('..').VectorTileLayer, + VectorTileFeature = require('..').VectorTileFeature; + +function approximateDeepEqual(a, b, epsilon) { + epsilon = epsilon || 1e-6; + + if (typeof a !== typeof b) + return false; + if (typeof a === 'number') + return Math.abs(a - b) < epsilon; + if (a === null || typeof a !== 'object') + return a === b; + + var ka = Object.keys(a); + var kb = Object.keys(b); + + if (ka.length != kb.length) + return false; + + ka.sort(); + kb.sort(); + + for (var i = 0; i < ka.length; i++) + if (ka[i] != kb[i] || !approximateDeepEqual(a[ka[i]], b[ka[i]], epsilon)) + return false; + + return true; +} + +test('parsing vector tiles', function(t) { + var data = fs.readFileSync(__dirname + '/fixtures/14-8801-5371.vector.pbf'); + + t.test('should have all layers', function(t) { + var tile = new VectorTile(new Protobuf(data)); + + t.deepEqual(Object.keys(tile.layers), [ + 'landuse', 'waterway', 'water', 'barrier_line', 'building', + 'landuse_overlay', 'tunnel', 'road', 'bridge', 'place_label', + 'water_label', 'poi_label', 'road_label', 'waterway_label' ]); + + t.end(); + }); + + t.test('should extract the tags of a feature', function(t) { + var tile = new VectorTile(new Protobuf(data)); + + t.equal(tile.layers.poi_label.length, 558); + + var park = tile.layers.poi_label.feature(11); + + t.deepEqual(park.bbox(), [ 3898, 1731, 3898, 1731 ]); + + t.throws(function() { + var park = tile.layers.poi_label.feature(1e9); + }, 'throws on reading a feature out of bounds'); + + t.equal(park.id, 3000003150561); + + t.equal(park.properties.name, 'Mauerpark'); + t.equal(park.properties.type, 'Park'); + + // Check point geometry + t.deepEqual(park.loadGeometry(), [ [ { x: 3898, y: 1731 } ] ]); + + // Check line geometry + t.deepEqual(tile.layers.road.feature(656).loadGeometry(), [ [ { x: 1988, y: 306 }, { x: 1808, y: 321 }, { x: 1506, y: 347 } ] ]); + t.end(); + }); + + t.test('changing first point of a polygon should not change last point', function(t) { + var tile = new VectorTile(new Protobuf(data)); + + var building = tile.layers.building.feature(0).loadGeometry(); + t.deepEqual(building, [ [ { x: 2039, y: -32 }, { x: 2035, y: -31 }, { x: 2032, y: -31 }, { x: 2032, y: -32 }, { x: 2039, y: -32 } ] ]); + building[0][0].x = 1; + building[0][0].y = 2; + building[0][1].x = 3; + building[0][1].y = 4; + t.deepEqual(building, [ [ { x: 1, y: 2 }, { x: 3, y: 4 }, { x: 2032, y: -31 }, { x: 2032, y: -32 }, { x: 2039, y: -32 } ] ]); + t.end(); + }); + + t.test('toGeoJSON', function(t) { + var tile = new VectorTile(new Protobuf(data)); + + t.ok(approximateDeepEqual(tile.layers.poi_label.feature(11).toGeoJSON(8801, 5371, 14), { + type: 'Feature', + id: 3000003150561, + properties: { + localrank: 1, + maki: 'park', + name: 'Mauerpark', + name_de: 'Mauerpark', + name_en: 'Mauerpark', + name_es: 'Mauerpark', + name_fr: 'Mauerpark', + osm_id: 3000003150561, + ref: '', + scalerank: 2, + type: 'Park' + }, + geometry: { + type: 'Point', + coordinates: [13.402258157730103, 52.54398925380624] + } + })); + + t.ok(approximateDeepEqual(tile.layers.bridge.feature(0).toGeoJSON(8801, 5371, 14), { + type: 'Feature', + id: 238162948, + properties: { + class: 'service', + oneway: 0, + osm_id: 238162948, + type: 'service' + }, + geometry: { + type: 'LineString', + coordinates: [[13.399457931518555, 52.546334844036416], [13.399441838264465, 52.546504478525016]] + } + })); + + t.ok(approximateDeepEqual(tile.layers.building.feature(0).toGeoJSON(8801, 5371, 14), { + type: 'Feature', + id: 1000267229912, + properties: { + osm_id: 1000267229912 + }, + geometry: { + type: 'Polygon', + coordinates: [[[13.392285704612732, 52.54974045706258], [13.392264246940613, 52.549737195107554], + [13.392248153686523, 52.549737195107554], [13.392248153686523, 52.54974045706258], + [13.392285704612732, 52.54974045706258]]] + } + })); + + function geoJSONFromFixture(name) { + var tile = new VectorTile(new Protobuf(fs.readFileSync(__dirname + '/fixtures/' + name + '.pbf'))); + return tile.layers.geojson.feature(0).toGeoJSON(0, 0, 0); + } + + // https://github.com/mapbox/vector-tile-spec/issues/30 + t.ok(approximateDeepEqual(geoJSONFromFixture("singleton-multi-point").geometry, { + type: 'Point', + coordinates: [1, 2] + }, 1e-1)); + t.ok(approximateDeepEqual(geoJSONFromFixture("singleton-multi-line").geometry, { + type: 'LineString', + coordinates: [[1, 2], [3, 4]] + }, 1e-1)); + t.ok(approximateDeepEqual(geoJSONFromFixture("singleton-multi-polygon").geometry, { + type: 'Polygon', + coordinates: [[[1, 0], [0, 0], [1, 1], [1, 0]]] + }, 1e-1)); + + t.ok(approximateDeepEqual(geoJSONFromFixture("multi-point").geometry, { + type: 'MultiPoint', + coordinates: [[1, 2], [3, 4]] + }, 1e-1)); + t.ok(approximateDeepEqual(geoJSONFromFixture("multi-line").geometry, { + type: 'MultiLineString', + coordinates: [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] + }, 1e-1)); + t.ok(approximateDeepEqual(geoJSONFromFixture("multi-polygon").geometry, { + type: 'MultiPolygon', + coordinates: [[[[1, 0], [0, 0], [1, 1], [1, 0]]], [[[-1, -1], [-1, 0], [0, 0], [-1, -1]]]] + }, 1e-1)); + + // https://github.com/mapbox/vector-tile-js/issues/32 + t.ok(approximateDeepEqual(geoJSONFromFixture("polygon-with-inner").geometry, { + type: 'Polygon', + coordinates: [[[2, -2], [-2, -2], [-2, 2], [2, 2], [2, -2]], [[-1, 1], [-1, -1], [1, -1], [1, 1], [-1, 1]]] + }, 1e-1)); + t.ok(approximateDeepEqual(geoJSONFromFixture("stacked-multipolygon").geometry, { + type: 'MultiPolygon', + coordinates: [[[[2, -2], [-2, -2], [-2, 2], [2, 2], [2, -2]]], [[[1, -1], [-1, -1], [-1, 1], [1, 1], [1, -1]]]] + }, 1e-1)); + + t.end(); + }) +}); + +test('VectorTileLayer', function(t) { + var emptyLayer = new VectorTileLayer(new Protobuf(new Buffer([]))); + t.ok(emptyLayer, 'can be created with no values'); + t.end(); +}); + +test('VectorTileFeature', function(t) { + var emptyFeature = new VectorTileFeature(new Protobuf(new Buffer([]))); + t.ok(emptyFeature, 'can be created with no values'); + t.ok(Array.isArray(VectorTileFeature.types)); + t.deepEqual(VectorTileFeature.types, ['Unknown', 'Point', 'LineString', 'Polygon']); + t.end(); +}); + +test('https://github.com/mapbox/vector-tile-js/issues/15', function(t) { + var data = fs.readFileSync(__dirname + '/fixtures/lots-of-tags.vector.pbf'); + var tile = new VectorTile(new Protobuf(data)); + t.ok(tile.layers["stuttgart-rails"].feature(0)); + t.end(); +}); + +test('https://github.com/mapbox/mapbox-gl-js/issues/1019', function(t) { + var data = fs.readFileSync(__dirname + '/fixtures/12-1143-1497.vector.pbf'); + var tile = new VectorTile(new Protobuf(data)); + t.ok(tile.layers["water"].feature(1).loadGeometry()); + t.end(); +}); + +test('https://github.com/mapbox/vector-tile-js/issues/60', function(t) { + var data = fs.readFileSync(__dirname + '/fixtures/multipolygon-with-closepath.pbf'); + var tile = new VectorTile(new Protobuf(data)); + for (var id in tile.layers) { + var layer = tile.layers[id]; + for (var i = 0; i < layer.length; i++) { + layer.feature(i).loadGeometry(); + } + } + t.end(); +}); diff --git a/node_modules/@mapbox/whoots-js/CHANGELOG.md b/node_modules/@mapbox/whoots-js/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..9e422a711bf074433aac5351f55ceab306e4f73f --- /dev/null +++ b/node_modules/@mapbox/whoots-js/CHANGELOG.md @@ -0,0 +1,28 @@ +_Breaking changes, which may affect downstream projects are marked with a_ :warning: + +## 3.1.0 +##### 2018-Jul-12 +* Replace legacy Rollup `jsnext:main` with now standard `module` ([#74]) +* :warning: Drop support for Node 4 + +[#74]: https://github.com/mapbox/whoots-js/issues/74 + +## 3.0.0 +##### 2017-Feb-13 +* :warning: whoots-js is now a scoped package under the @mapbox namespace + +## 2.1.0 +##### Jul 15, 2016 +* Release as ES6 module alongside UMD build, add `jsnext:main` to `package.json` + +## 2.0.0 +##### Jun 1, 2016 +* :warning: Refactor for a classless API + +## 1.1.0 +##### May 23, 2016 +* Make getTileBbox and getMercCoords public + +## 1.0.0 +##### May 23, 2016 +* Initial release diff --git a/node_modules/@mapbox/whoots-js/LICENSE.md b/node_modules/@mapbox/whoots-js/LICENSE.md new file mode 100644 index 0000000000000000000000000000000000000000..6f4f868bbc92108cca26dcb3ba22f46b568a2090 --- /dev/null +++ b/node_modules/@mapbox/whoots-js/LICENSE.md @@ -0,0 +1,15 @@ +ISC License + +Copyright (c) 2017, Mapbox + +Permission to use, copy, modify, and/or distribute this software for any purpose +with or without fee is hereby granted, provided that the above copyright notice +and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. diff --git a/node_modules/@mapbox/whoots-js/README.md b/node_modules/@mapbox/whoots-js/README.md new file mode 100644 index 0000000000000000000000000000000000000000..cc600398d2edf78c762cfa280aa1d7da71dcffca --- /dev/null +++ b/node_modules/@mapbox/whoots-js/README.md @@ -0,0 +1,53 @@ +[![npm version](https://badge.fury.io/js/%40mapbox%2Fwhoots-js.svg)](https://badge.fury.io/js/%40mapbox%2Fwhoots-js) +[![Build Status](https://secure.travis-ci.org/mapbox/whoots-js.svg)](http://travis-ci.org/mapbox/whoots-js) +[![Coverage Status](https://coveralls.io/repos/github/mapbox/whoots-js/badge.svg?branch=master)](https://coveralls.io/github/mapbox/whoots-js?branch=master) + + +## whoots-js + +Request tiles from WMS servers that support EPSG:3857. + +This project is a JavaScript port of https://github.com/timwaters/whoots by Tim Waters. + + +### What is it? + +Given a `z/x/y` tile coordinate like `19/154308/197167`, `whoots-js` can request imagery from an EPSG:3857 supporting WMS server like this: + +``` +http://geodata.state.nj.us/imagerywms/Natural2015? + bbox=-8242663.382160267,4966572.349857613,-8242586.945131982,4966648.786885899 + &format=image/png&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:3857 + &width=256&height=256&layers=Natural2015 +``` + + +### Usage + +```js +var WhooTS = require('@mapbox/whoots-js'); + +// Get an image url for a given tile coordinate +var baseUrl = 'http://geodata.state.nj.us/imagerywms/Natural2015'; +var layer = 'Natural2015'; +var url = WhooTS.getURL(baseUrl, layer, 154308, 197167, 19); +``` + + +### Server + +This project includes a sample redirecting wms proxy server in `server.js`. + +`npm run server` will start a local server on port 8080 that redirects tile requests. + +Valid tile requests look like: + +``` +http://localhost:8080/tms/{z}/{x}/{y}/{layer}/{endpoint} +http://localhost:8080/tms/19/154308/197167/Natural2015/http://geodata.state.nj.us/imagerywms/Natural2015 +``` + + +### Documentation + +Complete API documentation is here: http://mapbox.github.io/whoots-js/ diff --git a/node_modules/@mapbox/whoots-js/index.js b/node_modules/@mapbox/whoots-js/index.js new file mode 100644 index 0000000000000000000000000000000000000000..c8e3dd2d46bc334aa8abed94c03298819fd50b3d --- /dev/null +++ b/node_modules/@mapbox/whoots-js/index.js @@ -0,0 +1,88 @@ +(function (global, factory) { +typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : +typeof define === 'function' && define.amd ? define(['exports'], factory) : +(factory((global.WhooTS = {}))); +}(this, (function (exports) { +/** + * getURL + * + * @param {String} baseUrl Base url of the WMS server + * @param {String} layer Layer name + * @param {Number} x Tile coordinate x + * @param {Number} y Tile coordinate y + * @param {Number} z Tile zoom + * @param {Object} [options] + * @param {String} [options.format='image/png'] + * @param {String} [options.service='WMS'] + * @param {String} [options.version='1.1.1'] + * @param {String} [options.request='GetMap'] + * @param {String} [options.srs='EPSG:3857'] + * @param {Number} [options.width='256'] + * @param {Number} [options.height='256'] + * @returns {String} url + * @example + * var baseUrl = 'http://geodata.state.nj.us/imagerywms/Natural2015'; + * var layer = 'Natural2015'; + * var url = whoots.getURL(baseUrl, layer, 154308, 197167, 19); + */ +function getURL(baseUrl, layer, x, y, z, options) { + options = options || {}; + + var url = baseUrl + '?' + [ + 'bbox=' + getTileBBox(x, y, z), + 'format=' + (options.format || 'image/png'), + 'service=' + (options.service || 'WMS'), + 'version=' + (options.version || '1.1.1'), + 'request=' + (options.request || 'GetMap'), + 'srs=' + (options.srs || 'EPSG:3857'), + 'width=' + (options.width || 256), + 'height=' + (options.height || 256), + 'layers=' + layer + ].join('&'); + + return url; +} + + +/** + * getTileBBox + * + * @param {Number} x Tile coordinate x + * @param {Number} y Tile coordinate y + * @param {Number} z Tile zoom + * @returns {String} String of the bounding box + */ +function getTileBBox(x, y, z) { + // for Google/OSM tile scheme we need to alter the y + y = (Math.pow(2, z) - y - 1); + + var min = getMercCoords(x * 256, y * 256, z), + max = getMercCoords((x + 1) * 256, (y + 1) * 256, z); + + return min[0] + ',' + min[1] + ',' + max[0] + ',' + max[1]; +} + + +/** + * getMercCoords + * + * @param {Number} x Pixel coordinate x + * @param {Number} y Pixel coordinate y + * @param {Number} z Tile zoom + * @returns {Array} [x, y] + */ +function getMercCoords(x, y, z) { + var resolution = (2 * Math.PI * 6378137 / 256) / Math.pow(2, z), + merc_x = (x * resolution - 2 * Math.PI * 6378137 / 2.0), + merc_y = (y * resolution - 2 * Math.PI * 6378137 / 2.0); + + return [merc_x, merc_y]; +} + +exports.getURL = getURL; +exports.getTileBBox = getTileBBox; +exports.getMercCoords = getMercCoords; + +Object.defineProperty(exports, '__esModule', { value: true }); + +}))); diff --git a/node_modules/@mapbox/whoots-js/index.mjs b/node_modules/@mapbox/whoots-js/index.mjs new file mode 100644 index 0000000000000000000000000000000000000000..b2a5c755503ce5db13a1c5b3f36cdb9e667e43fa --- /dev/null +++ b/node_modules/@mapbox/whoots-js/index.mjs @@ -0,0 +1,78 @@ +export { getURL, getTileBBox, getMercCoords }; + + +/** + * getURL + * + * @param {String} baseUrl Base url of the WMS server + * @param {String} layer Layer name + * @param {Number} x Tile coordinate x + * @param {Number} y Tile coordinate y + * @param {Number} z Tile zoom + * @param {Object} [options] + * @param {String} [options.format='image/png'] + * @param {String} [options.service='WMS'] + * @param {String} [options.version='1.1.1'] + * @param {String} [options.request='GetMap'] + * @param {String} [options.srs='EPSG:3857'] + * @param {Number} [options.width='256'] + * @param {Number} [options.height='256'] + * @returns {String} url + * @example + * var baseUrl = 'http://geodata.state.nj.us/imagerywms/Natural2015'; + * var layer = 'Natural2015'; + * var url = whoots.getURL(baseUrl, layer, 154308, 197167, 19); + */ +function getURL(baseUrl, layer, x, y, z, options) { + options = options || {}; + + var url = baseUrl + '?' + [ + 'bbox=' + getTileBBox(x, y, z), + 'format=' + (options.format || 'image/png'), + 'service=' + (options.service || 'WMS'), + 'version=' + (options.version || '1.1.1'), + 'request=' + (options.request || 'GetMap'), + 'srs=' + (options.srs || 'EPSG:3857'), + 'width=' + (options.width || 256), + 'height=' + (options.height || 256), + 'layers=' + layer + ].join('&'); + + return url; +} + + +/** + * getTileBBox + * + * @param {Number} x Tile coordinate x + * @param {Number} y Tile coordinate y + * @param {Number} z Tile zoom + * @returns {String} String of the bounding box + */ +function getTileBBox(x, y, z) { + // for Google/OSM tile scheme we need to alter the y + y = (Math.pow(2, z) - y - 1); + + var min = getMercCoords(x * 256, y * 256, z), + max = getMercCoords((x + 1) * 256, (y + 1) * 256, z); + + return min[0] + ',' + min[1] + ',' + max[0] + ',' + max[1]; +} + + +/** + * getMercCoords + * + * @param {Number} x Pixel coordinate x + * @param {Number} y Pixel coordinate y + * @param {Number} z Tile zoom + * @returns {Array} [x, y] + */ +function getMercCoords(x, y, z) { + var resolution = (2 * Math.PI * 6378137 / 256) / Math.pow(2, z), + merc_x = (x * resolution - 2 * Math.PI * 6378137 / 2.0), + merc_y = (y * resolution - 2 * Math.PI * 6378137 / 2.0); + + return [merc_x, merc_y]; +} diff --git a/node_modules/@mapbox/whoots-js/package.json b/node_modules/@mapbox/whoots-js/package.json new file mode 100644 index 0000000000000000000000000000000000000000..385b67cba6357d2e4de5503eb7185200af6db500 --- /dev/null +++ b/node_modules/@mapbox/whoots-js/package.json @@ -0,0 +1,33 @@ +{ + "name": "@mapbox/whoots-js", + "description": "Request tiles from WMS servers that support EPSG:3857", + "version": "3.1.0", + "main": "index.js", + "module": "index.mjs", + "license": "ISC", + "author": "Bryan Housel ", + "repository": "mapbox/whoots-js", + "keywords": [ + "WMS", + "tiles", + "EPSG:3857" + ], + "dependencies": {}, + "devDependencies": { + "coveralls": "^3.0.0", + "documentation": "4.0.0-beta5", + "eslint": "^5.0.0", + "rollup": "0.60.0", + "tap": "^12.0.0" + }, + "engines": { + "node": ">=6.0.0" + }, + "scripts": { + "build": "rollup -f umd -n WhooTS index.mjs --no-indent --no-strict -o index.js", + "docs": "documentation build index.mjs --lint --github --format html --output docs/", + "lint": "eslint index.mjs server.js test", + "start": "node server.js", + "test": "npm run lint && npm run build && tap --cov test/*.js" + } +} diff --git a/node_modules/@mapbox/whoots-js/server.js b/node_modules/@mapbox/whoots-js/server.js new file mode 100644 index 0000000000000000000000000000000000000000..3fe4cd002578e813448eab829ec7c823729ebe21 --- /dev/null +++ b/node_modules/@mapbox/whoots-js/server.js @@ -0,0 +1,40 @@ +'use strict'; + +var WhooTS = require('./'); +var http = require('http'); +var url = require('url'); + +var PORT = 8080; + +// valid requests look like: +// http://localhost:8080/tms/{z}/{x}/{y}/{layer}/{baseUrl} +// http://localhost:8080/tms/19/154308/197167/Natural2015/http://geodata.state.nj.us/imagerywms/Natural2015 +function handleRequest(request, response) { + var pathname = url.parse(request.url, true).pathname; + var params = pathname.split('/'); + + if (params.length > 6 && params[1].toLowerCase() === 'tms') { + var z = +params[2], + x = +params[3], + y = +params[4], + layer = params[5], + baseUrl = pathname.replace(params.slice(0,6).join('/') + '/', ''); + + if (!isNaN(z) && !isNaN(x) && !isNaN(y) && layer && url.parse(baseUrl).protocol) { + response.writeHead(302, { 'Location': WhooTS.getURL(baseUrl, layer, x, y, z) }); + response.end('Redirect'); + return; + } + } + + response.statusCode = '404'; + response.end('Not Found'); +} + + +var server = http.createServer(handleRequest); +server.listen(PORT, function() { + /* eslint-disable no-console */ + console.log('Server listening on: http://localhost:%s', PORT); + /* eslint-enable no-console */ +}); diff --git a/node_modules/@playwright/test/LICENSE b/node_modules/@playwright/test/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..df112373eb2e23e459bf93ec412be1764dc5a38b --- /dev/null +++ b/node_modules/@playwright/test/LICENSE @@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Portions Copyright (c) Microsoft Corporation. + Portions Copyright 2017 Google Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/node_modules/@playwright/test/NOTICE b/node_modules/@playwright/test/NOTICE new file mode 100644 index 0000000000000000000000000000000000000000..814ec1696f7ad36c1b524fb6adeef14b4b367fec --- /dev/null +++ b/node_modules/@playwright/test/NOTICE @@ -0,0 +1,5 @@ +Playwright +Copyright (c) Microsoft Corporation + +This software contains code derived from the Puppeteer project (https://github.com/puppeteer/puppeteer), +available under the Apache 2.0 license (https://github.com/puppeteer/puppeteer/blob/master/LICENSE). diff --git a/node_modules/@playwright/test/README.md b/node_modules/@playwright/test/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8b6bd945d0767e2895821cbbe40240f9fc1e857a --- /dev/null +++ b/node_modules/@playwright/test/README.md @@ -0,0 +1,168 @@ +# 🎭 Playwright + +[![npm version](https://img.shields.io/npm/v/playwright.svg)](https://www.npmjs.com/package/playwright) [![Chromium version](https://img.shields.io/badge/chromium-145.0.7632.6-blue.svg?logo=google-chrome)](https://www.chromium.org/Home) [![Firefox version](https://img.shields.io/badge/firefox-146.0.1-blue.svg?logo=firefoxbrowser)](https://www.mozilla.org/en-US/firefox/new/) [![WebKit version](https://img.shields.io/badge/webkit-26.0-blue.svg?logo=safari)](https://webkit.org/) [![Join Discord](https://img.shields.io/badge/join-discord-informational)](https://aka.ms/playwright/discord) + +## [Documentation](https://playwright.dev) | [API reference](https://playwright.dev/docs/api/class-playwright) + +Playwright is a framework for Web Testing and Automation. It allows testing [Chromium](https://www.chromium.org/Home), [Firefox](https://www.mozilla.org/en-US/firefox/new/) and [WebKit](https://webkit.org/) with a single API. Playwright is built to enable cross-browser web automation that is **ever-green**, **capable**, **reliable**, and **fast**. + +| | Linux | macOS | Windows | +| :--- | :---: | :---: | :---: | +| Chromium 145.0.7632.6 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| WebKit 26.0 | :white_check_mark: | :white_check_mark: | :white_check_mark: | +| Firefox 146.0.1 | :white_check_mark: | :white_check_mark: | :white_check_mark: | + +Headless execution is supported for all browsers on all platforms. Check out [system requirements](https://playwright.dev/docs/intro#system-requirements) for details. + +Looking for Playwright for [Python](https://playwright.dev/python/docs/intro), [.NET](https://playwright.dev/dotnet/docs/intro), or [Java](https://playwright.dev/java/docs/intro)? + +## Installation + +Playwright has its own test runner for end-to-end tests, we call it Playwright Test. + +### Using init command + +The easiest way to get started with Playwright Test is to run the init command. + +```Shell +# Run from your project's root directory +npm init playwright@latest +# Or create a new project +npm init playwright@latest new-project +``` + +This will create a configuration file, optionally add examples, a GitHub Action workflow and a first test example.spec.ts. You can now jump directly to writing assertions section. + +### Manually + +Add dependency and install browsers. + +```Shell +npm i -D @playwright/test +# install supported browsers +npx playwright install +``` + +You can optionally install only selected browsers, see [install browsers](https://playwright.dev/docs/cli#install-browsers) for more details. Or you can install no browsers at all and use existing [browser channels](https://playwright.dev/docs/browsers). + +* [Getting started](https://playwright.dev/docs/intro) +* [API reference](https://playwright.dev/docs/api/class-playwright) + +## Capabilities + +### Resilient • No flaky tests + +**Auto-wait**. Playwright waits for elements to be actionable prior to performing actions. It also has a rich set of introspection events. The combination of the two eliminates the need for artificial timeouts - a primary cause of flaky tests. + +**Web-first assertions**. Playwright assertions are created specifically for the dynamic web. Checks are automatically retried until the necessary conditions are met. + +**Tracing**. Configure test retry strategy, capture execution trace, videos and screenshots to eliminate flakes. + +### No trade-offs • No limits + +Browsers run web content belonging to different origins in different processes. Playwright is aligned with the architecture of the modern browsers and runs tests out-of-process. This makes Playwright free of the typical in-process test runner limitations. + +**Multiple everything**. Test scenarios that span multiple tabs, multiple origins and multiple users. Create scenarios with different contexts for different users and run them against your server, all in one test. + +**Trusted events**. Hover elements, interact with dynamic controls and produce trusted events. Playwright uses real browser input pipeline indistinguishable from the real user. + +Test frames, pierce Shadow DOM. Playwright selectors pierce shadow DOM and allow entering frames seamlessly. + +### Full isolation • Fast execution + +**Browser contexts**. Playwright creates a browser context for each test. Browser context is equivalent to a brand new browser profile. This delivers full test isolation with zero overhead. Creating a new browser context only takes a handful of milliseconds. + +**Log in once**. Save the authentication state of the context and reuse it in all the tests. This bypasses repetitive log-in operations in each test, yet delivers full isolation of independent tests. + +### Powerful Tooling + +**[Codegen](https://playwright.dev/docs/codegen)**. Generate tests by recording your actions. Save them into any language. + +**[Playwright inspector](https://playwright.dev/docs/inspector)**. Inspect page, generate selectors, step through the test execution, see click points and explore execution logs. + +**[Trace Viewer](https://playwright.dev/docs/trace-viewer)**. Capture all the information to investigate the test failure. Playwright trace contains test execution screencast, live DOM snapshots, action explorer, test source and many more. + +Looking for Playwright for [TypeScript](https://playwright.dev/docs/intro), [JavaScript](https://playwright.dev/docs/intro), [Python](https://playwright.dev/python/docs/intro), [.NET](https://playwright.dev/dotnet/docs/intro), or [Java](https://playwright.dev/java/docs/intro)? + +## Examples + +To learn how to run these Playwright Test examples, check out our [getting started docs](https://playwright.dev/docs/intro). + +#### Page screenshot + +This code snippet navigates to Playwright homepage and saves a screenshot. + +```TypeScript +import { test } from '@playwright/test'; + +test('Page Screenshot', async ({ page }) => { + await page.goto('https://playwright.dev/'); + await page.screenshot({ path: `example.png` }); +}); +``` + +#### Mobile and geolocation + +This snippet emulates Mobile Safari on a device at given geolocation, navigates to maps.google.com, performs the action and takes a screenshot. + +```TypeScript +import { test, devices } from '@playwright/test'; + +test.use({ + ...devices['iPhone 13 Pro'], + locale: 'en-US', + geolocation: { longitude: 12.492507, latitude: 41.889938 }, + permissions: ['geolocation'], +}) + +test('Mobile and geolocation', async ({ page }) => { + await page.goto('https://maps.google.com'); + await page.getByText('Your location').click(); + await page.waitForRequest(/.*preview\/pwa/); + await page.screenshot({ path: 'colosseum-iphone.png' }); +}); +``` + +#### Evaluate in browser context + +This code snippet navigates to example.com, and executes a script in the page context. + +```TypeScript +import { test } from '@playwright/test'; + +test('Evaluate in browser context', async ({ page }) => { + await page.goto('https://www.example.com/'); + const dimensions = await page.evaluate(() => { + return { + width: document.documentElement.clientWidth, + height: document.documentElement.clientHeight, + deviceScaleFactor: window.devicePixelRatio + } + }); + console.log(dimensions); +}); +``` + +#### Intercept network requests + +This code snippet sets up request routing for a page to log all network requests. + +```TypeScript +import { test } from '@playwright/test'; + +test('Intercept network requests', async ({ page }) => { + // Log and continue all network requests + await page.route('**', route => { + console.log(route.request().url()); + route.continue(); + }); + await page.goto('http://todomvc.com'); +}); +``` + +## Resources + +* [Documentation](https://playwright.dev) +* [API reference](https://playwright.dev/docs/api/class-playwright/) +* [Contribution guide](CONTRIBUTING.md) +* [Changelog](https://github.com/microsoft/playwright/releases) diff --git a/node_modules/@playwright/test/cli.js b/node_modules/@playwright/test/cli.js new file mode 100644 index 0000000000000000000000000000000000000000..e42facb076f4b05f009186346d05d39c2d9b784d --- /dev/null +++ b/node_modules/@playwright/test/cli.js @@ -0,0 +1,19 @@ +#!/usr/bin/env node +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const { program } = require('playwright/lib/program'); +program.parse(process.argv); diff --git a/node_modules/@playwright/test/index.d.ts b/node_modules/@playwright/test/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..8d99c91500c65b4b9d762b900dedf5e6000cf257 --- /dev/null +++ b/node_modules/@playwright/test/index.d.ts @@ -0,0 +1,18 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from 'playwright/test'; +export { default } from 'playwright/test'; diff --git a/node_modules/@playwright/test/index.js b/node_modules/@playwright/test/index.js new file mode 100644 index 0000000000000000000000000000000000000000..8536f063904ffa04a91240061ce1cf2c4c855b79 --- /dev/null +++ b/node_modules/@playwright/test/index.js @@ -0,0 +1,17 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +module.exports = require('playwright/test'); diff --git a/node_modules/@playwright/test/index.mjs b/node_modules/@playwright/test/index.mjs new file mode 100644 index 0000000000000000000000000000000000000000..8d99c91500c65b4b9d762b900dedf5e6000cf257 --- /dev/null +++ b/node_modules/@playwright/test/index.mjs @@ -0,0 +1,18 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from 'playwright/test'; +export { default } from 'playwright/test'; diff --git a/node_modules/@playwright/test/package.json b/node_modules/@playwright/test/package.json new file mode 100644 index 0000000000000000000000000000000000000000..56748d924bbe4c363c8b2620a086edf321cf8ddc --- /dev/null +++ b/node_modules/@playwright/test/package.json @@ -0,0 +1,35 @@ +{ + "name": "@playwright/test", + "version": "1.58.2", + "description": "A high-level API to automate web browsers", + "repository": { + "type": "git", + "url": "git+https://github.com/microsoft/playwright.git" + }, + "homepage": "https://playwright.dev", + "engines": { + "node": ">=18" + }, + "author": { + "name": "Microsoft Corporation" + }, + "license": "Apache-2.0", + "exports": { + ".": { + "types": "./index.d.ts", + "import": "./index.mjs", + "require": "./index.js", + "default": "./index.js" + }, + "./cli": "./cli.js", + "./package.json": "./package.json", + "./reporter": "./reporter.js" + }, + "bin": { + "playwright": "cli.js" + }, + "scripts": {}, + "dependencies": { + "playwright": "1.58.2" + } +} diff --git a/node_modules/@playwright/test/reporter.d.ts b/node_modules/@playwright/test/reporter.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..806d13fb09e73f0dc1f4e129a2889b9e6bac3a8d --- /dev/null +++ b/node_modules/@playwright/test/reporter.d.ts @@ -0,0 +1,17 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export * from 'playwright/types/testReporter'; diff --git a/node_modules/@playwright/test/reporter.js b/node_modules/@playwright/test/reporter.js new file mode 100644 index 0000000000000000000000000000000000000000..485e880a66229eb7290fd274e35b8acf4a4a8ecd --- /dev/null +++ b/node_modules/@playwright/test/reporter.js @@ -0,0 +1,17 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// We only export types in reporter.d.ts. diff --git a/node_modules/@playwright/test/reporter.mjs b/node_modules/@playwright/test/reporter.mjs new file mode 100644 index 0000000000000000000000000000000000000000..485e880a66229eb7290fd274e35b8acf4a4a8ecd --- /dev/null +++ b/node_modules/@playwright/test/reporter.mjs @@ -0,0 +1,17 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// We only export types in reporter.d.ts. diff --git a/node_modules/@plotly/d3-sankey-circular/LICENSE b/node_modules/@plotly/d3-sankey-circular/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..90df63b3b5385bbbbd551811b5aaee7c543b5af1 --- /dev/null +++ b/node_modules/@plotly/d3-sankey-circular/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Tom Shanley + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/node_modules/@plotly/d3-sankey-circular/README.md b/node_modules/@plotly/d3-sankey-circular/README.md new file mode 100644 index 0000000000000000000000000000000000000000..6b9c8d66321484441d125f82ae0e1c276d73c9f9 --- /dev/null +++ b/node_modules/@plotly/d3-sankey-circular/README.md @@ -0,0 +1,235 @@ +# d3-sankey-circular + +A fork of the d3-sankey library (https://github.com/d3/d3-sankey) to allow circular links (ie cyclic graphs, like in [this example](https://bl.ocks.org/tomshanley/6f3fcf68c0dbc401548733dd0c64e3c3)). + +The library contains a portion of code from Colin Fergus' bl.ock https://gist.github.com/cfergus/3956043 to detect circular links. + +## Install + +If you use NPM, `npm install d3-sankey-circular`. + +Else, use the d3-sankey-circular.js file from the compiled folder. + +## Usage + +var sankey = d3.sankeyCircular(); + +## API Reference + +*The API follows the original d3-sankey library, with additional options to allow the circular links to be laid out and drawn.* + +# d3.sankeyCircular() [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L52 "Source") + +Constructs a new Sankey generator with the default settings. + +# sankey(arguments…) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L62 "Source") + +Computes the node and link positions for the given *arguments*, returning a *graph* representing the Sankey layout. The returned *graph* has the following properties: + +* *graph*.nodes - the array of [nodes](#sankey_nodes) +* *graph*.links - the array of [links](#sankey_links) + +# sankey.update(graph) + +Recomputes the specified *graph*’s links’ positions, updating the following properties of each *link*: + +* *link*.y0 - the link’s vertical starting position (at source node) +* *link*.y1 - the link’s vertical end position (at target node) +* *link*.circularLinkType - the link's circularLinkType either *top* or *bottom*, depending on whether the center of the connected nodes is above or below the vertical midpoint of the figure. + +This method is intended to be called after computing the initial [Sankey layout](#_sankey), for example when the diagram is repositioned interactively. + +# sankey.nodes([nodes]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L93 "Source") + +If *nodes* is specified, sets the Sankey generator’s nodes accessor to the specified function or array and returns this Sankey generator. If *nodes* is not specified, returns the current nodes accessor, which defaults to: + +```js +function nodes(graph) { + return graph.nodes; +} +``` + +If *nodes* is specified as a function, the function is invoked when the Sankey layout is [generated](#_sankey), being passed any arguments passed to the Sankey generator. This function must return an array of nodes. If *nodes* is not a function, it must be a constant array of *nodes*. + +Each *node* must be an object. The following properties are assigned by the [Sankey generator](#_sankey): + +* *node*.sourceLinks - the array of outgoing [links](#sankey_links) which have this node as their source +* *node*.targetLinks - the array of incoming [links](#sankey_links) which have this node as their target +* *node*.value - the node’s value; the sum of *link*.value for the node’s incoming [links](#sankey_links) +* *node*.index - the node’s zero-based index within the array of nodes +* *node*.depth - the node’s zero-based graph depth, derived from the graph topology +* *node*.column - the node’s zero-based depth, as drawn, going from left to right. Column is derived from *node*.depth and the [*sankey*.nodeAlign](#sankey_nodeAlign) setting. +* *node*.height - the node’s zero-based graph height, derived from the graph topology +* *node*.x0 - the node’s minimum horizontal position, derived from *node*.column +* *node*.x1 - the node’s maximum horizontal position (*node*.x0 + [*sankey*.nodeWidth](#sankey_nodeWidth)) +* *node*.y0 - the node’s minimum vertical position +* *node*.y1 - the node’s maximum vertical position (*node*.y1 - *node*.y0 is proportional to *node*.value) +* *node*.partOfCycle - set to *true* if the node has incoming or outgoing links that are circular +* *node*.circularLinkType - set to either *top* or *bottom*, if *node.partOfCycle* is *true*, which relates to whether circular links are drawn above or below the main part of the graph + +See also [*sankey*.links](#sankey_links). + +# sankey.links([links]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L97 "Source") + +If *links* is specified, sets the Sankey generator’s links accessor to the specified function or array and returns this Sankey generator. If *links* is not specified, returns the current links accessor, which defaults to: + +```js +function links(graph) { + return graph.links; +} +``` + +If *links* is specified as a function, the function is invoked when the Sankey layout is [generated](#_sankey), being passed any arguments passed to the Sankey generator. This function must return an array of links. If *links* is not a function, it must be a constant array of *links*. + +Each *link* must be an object with the following properties: + +* *link*.source - the link’s source [node](#sankey_nodes) +* *link*.target - the link’s target [node](#sankey_nodes) +* *link*.value - the link’s numeric value + +For convenience, a link’s source and target may be initialized using numeric or string identifiers rather than object references; ; see [*sankey*.nodeId](#sankey_nodeId). The following properties are assigned to each link by the [Sankey generator](#_sankey): + +* *link*.y0 - the link’s vertical starting position (at source node) +* *link*.y1 - the link’s vertical end position (at target node) +* *link*.width - the link’s width (proportional to *link*.value) +* *link*.index - the zero-based index of *link* within the array of links +* *link*.circular - set to *true* if the link is circular + +For any links that circular (*link*.circular = *true*), the following properties are assigned + +* *link*.circularLinkID - the zero-based index of *link* within the array of circular links +* *link*.circularLinkType - set to either *top* or *bottom*, which relates to whether the link is drawn above or below the main part of the graph +* *link*.circularLinkPathData - an object containing the properties used to draw the SVG path, including *link*.circularLinkPathData.path, which is the string used for the *d* property. + +# sankey.nodeId([id]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L77 "Source") + +If *id* is specified, sets the node id accessor to the specified function and returns this Sankey generator. If *id* is not specified, returns the current node id accessor, which defaults to the numeric *node*.index: + +```js +function id(d) { + return d.index; +} +``` + +The default id accessor allows each link’s source and target to be specified as a zero-based index into the [nodes](#sankey_nodes) array. For example: + +```js +var nodes = [ + {"id": "Alice"}, + {"id": "Bob"}, + {"id": "Carol"} +]; + +var links = [ + {"source": 0, "target": 1}, // Alice → Bob + {"source": 1, "target": 2} // Bob → Carol +]; +``` + +Now consider a different id accessor that returns a string: + +```js +function id(d) { + return d.id; +} +``` + +With this accessor, you can use named sources and targets: + +```js +var nodes = [ + {"id": "Alice"}, + {"id": "Bob"}, + {"id": "Carol"} +]; + +var links = [ + {"source": "Alice", "target": "Bob"}, + {"source": "Bob", "target": "Carol"} +]; +``` + +# sankey.nodeAlign([align]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L81 "Source") + +If *align* is specified, sets the node [alignment method](#alignments) the specified function and returns this Sankey generator. If *align* is not specified, returns the current node alignment method, which defaults to [d3.sankeyJustify](#sankeyJustify). The specified function is evaluated for each input *node* in order, being passed the current *node* and the total depth *n* of the graph (one plus the maximum *node*.depth), and must return an integer between 0 and *n* - 1 that indicates the desired horizontal position of the node in the generated Sankey diagram. + +# sankey.nodeWidth([width]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L85 "Source") + +If *width* is specified, sets the node width to the specified number and returns this Sankey generator. If *width* is not specified, returns the current node width, which defaults to 24. + +# sankey.nodePadding([padding]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L89 "Source") + +If *padding* is specified, sets the vertical separation between nodes at each column to the specified number and returns this Sankey generator. If *padding* is not specified, returns the current node padding, which defaults to 8. + +# sankey.nodePaddingRatio([proportion]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L89 "Source") + +If *proportion* is specified (from 0 to 1), sets the vertical separation between nodes at each column to the specified number and returns this Sankey generator. The proportion is applied to the most dense column of nodes, and calculates a minimum padding that will be used across the chart. + +If a nodePaddingRatio is not specified, then defaults to the *padding* setting in pixels. + +# sankey.extent([extent]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L105 "Source") + +If *extent* is specified, sets the extent of the Sankey layout to the specified bounds and returns the layout. The *extent* bounds are specified as an array \[\[x0, y0\], \[x1, y1\]\], where *x0* is the left side of the extent, *y0* is the top, *x1* is the right and *y1* is the bottom. If *extent* is not specified, returns the current extent which defaults to [[0, 0], [1, 1]]. + +# sankey.size([size]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L101 "Source") + +An alias for [*sankey*.extent](#sankey_extent) where the minimum *x* and *y* of the extent are ⟨0,0⟩. Equivalent to: + +```js +sankey.extent([[0, 0], size]); +``` + +# sankey.iterations([iterations]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L109 "Source") + +If *iterations* is specified, sets the number of relaxation iterations when [generating the layout](#_sankey) and returns this Sankey generator. If *iterations* is not specified, returns the current number of relaxation iterations, which defaults to 32. + +# sankey.circularLinkGap([circularLinkGap]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L109 "Source") + +If *circularLinkGap* is specified, sets the gap (in pixels) between circular links that travel next to each other. If *circularLinkGap*, it defaults to 2. + +### Alignments + +See [*sankey*.nodeAlign](#sankey_nodeAlign). + +# d3.sankeyLeft(node, n) + +Returns *node*.depth. + +# d3.sankeyRight(node, n) + +Returns *n* - 1 - *node*.height. + +# d3.sankeyCenter(node, n) + +Like [d3.sankeyLeft](#sankeyLeft), except that nodes without any incoming links are moved as right as possible. + +# d3.sankeyJustify(node, n) + +Like [d3.sankeyLeft](#sankeyLeft), except that nodes without any outgoing links are moved to the far right. + +### Links + +# link.path[<>](https://github.com/d3/d3-sankey/blob/master/src/sankeyLinkHorizontal.js "Source") + +Each link has a .path property which stores the svg path **d** string, which can be accessed to draw the path, for example + +```js + +svg.append("g") + .attr("class", "links") + .attr("fill", "none") + .attr("stroke-opacity", 0.2) + .selectAll("path"); + .data(sankey.links) + .enter() + .append("path") + .attr("d", function(d){ + return d.path; + }) + .style("stroke-width", function (link) { link.width; }) + .style("stroke", function (link, i) { + return link.circular ? "red" : "black" + }) +``` + +For normal paths, the path string is created by the d3-shape linkHorizontal function. For circular paths, the path string is calculated to reduced overlaps with other nodes and paths. diff --git a/node_modules/@plotly/d3-sankey-circular/dist/d3-sankey-circular.es.js b/node_modules/@plotly/d3-sankey-circular/dist/d3-sankey-circular.es.js new file mode 100644 index 0000000000000000000000000000000000000000..fe5fde32d3b2159de075e8552ed3a9fc8fab0a3c --- /dev/null +++ b/node_modules/@plotly/d3-sankey-circular/dist/d3-sankey-circular.es.js @@ -0,0 +1,1490 @@ +import { min, ascending, max, mean, sum } from 'd3-array'; +import { map, nest } from 'd3-collection'; +import { linkHorizontal } from 'd3-shape'; +import findCircuits from 'elementary-circuits-directed-graph'; + +// For a given link, return the target node's depth +function targetDepth(d) { + return d.target.depth; +} + +// The depth of a node when the nodeAlign (align) is set to 'left' +function left(node) { + return node.depth; +} + +// The depth of a node when the nodeAlign (align) is set to 'right' +function right(node, n) { + return n - 1 - node.height; +} + +// The depth of a node when the nodeAlign (align) is set to 'justify' +function justify(node, n) { + return node.sourceLinks.length ? node.depth : n - 1; +} + +// The depth of a node when the nodeAlign (align) is set to 'center' +function center(node) { + return node.targetLinks.length ? node.depth : node.sourceLinks.length ? min(node.sourceLinks, targetDepth) - 1 : 0; +} + +// returns a function, using the parameter given to the sankey setting +function constant(x) { + return function () { + return x; + }; +} + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { + return typeof obj; +} : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; +}; + +/// https://github.com/tomshanley/d3-sankeyCircular-circular + +// sort links' breadth (ie top to bottom in a column), based on their source nodes' breadths +function ascendingSourceBreadth(a, b) { + return ascendingBreadth(a.source, b.source) || a.index - b.index; +} + +// sort links' breadth (ie top to bottom in a column), based on their target nodes' breadths +function ascendingTargetBreadth(a, b) { + return ascendingBreadth(a.target, b.target) || a.index - b.index; +} + +// sort nodes' breadth (ie top to bottom in a column) +// if both nodes have circular links, or both don't have circular links, then sort by the top (y0) of the node +// else push nodes that have top circular links to the top, and nodes that have bottom circular links to the bottom +function ascendingBreadth(a, b) { + if (a.partOfCycle === b.partOfCycle) { + return a.y0 - b.y0; + } else { + if (a.circularLinkType === 'top' || b.circularLinkType === 'bottom') { + return -1; + } else { + return 1; + } + } +} + +// return the value of a node or link +function value(d) { + return d.value; +} + +// return the vertical center of a node +function nodeCenter(node) { + return (node.y0 + node.y1) / 2; +} + +// return the vertical center of a link's source node +function linkSourceCenter(link) { + return nodeCenter(link.source); +} + +// return the vertical center of a link's target node +function linkTargetCenter(link) { + return nodeCenter(link.target); +} + +// Return the default value for ID for node, d.index +function defaultId(d) { + return d.index; +} + +// Return the default object the graph's nodes, graph.nodes +function defaultNodes(graph) { + return graph.nodes; +} + +// Return the default object the graph's nodes, graph.links +function defaultLinks(graph) { + return graph.links; +} + +// Return the node from the collection that matches the provided ID, or throw an error if no match +function find(nodeById, id) { + var node = nodeById.get(id); + if (!node) throw new Error('missing: ' + id); + return node; +} + +function getNodeID(node, id) { + return id(node); +} + +// The main sankeyCircular functions + +// Some constants for circular link calculations +var verticalMargin = 25; +var baseRadius = 10; +var scale = 0.3; //Possibly let user control this, although anything over 0.5 starts to get too cramped + +function sankeyCircular () { + // Set the default values + var x0 = 0, + y0 = 0, + x1 = 1, + y1 = 1, + // extent + dx = 24, + // nodeWidth + py, + // nodePadding, for vertical postioning + id = defaultId, + align = justify, + nodes = defaultNodes, + links = defaultLinks, + iterations = 32, + circularLinkGap = 2, + paddingRatio, + sortNodes = null; + + function sankeyCircular() { + var graph = { + nodes: nodes.apply(null, arguments), + links: links.apply(null, arguments) + + // Process the graph's nodes and links, setting their positions + + // 1. Associate the nodes with their respective links, and vice versa + };computeNodeLinks(graph); + + // 2. Determine which links result in a circular path in the graph + identifyCircles(graph, id, sortNodes); + + // 4. Calculate the nodes' values, based on the values of the incoming and outgoing links + computeNodeValues(graph); + + // 5. Calculate the nodes' depth based on the incoming and outgoing links + // Sets the nodes': + // - depth: the depth in the graph + // - column: the depth (0, 1, 2, etc), as is relates to visual position from left to right + // - x0, x1: the x coordinates, as is relates to visual position from left to right + computeNodeDepths(graph); + + // 3. Determine how the circular links will be drawn, + // either travelling back above the main chart ("top") + // or below the main chart ("bottom") + selectCircularLinkTypes(graph, id); + + // 6. Calculate the nodes' and links' vertical position within their respective column + // Also readjusts sankeyCircular size if circular links are needed, and node x's + computeNodeBreadths(graph, iterations, id); + computeLinkBreadths(graph); + + // 7. Sort links per node, based on the links' source/target nodes' breadths + // 8. Adjust nodes that overlap links that span 2+ columns + var linkSortingIterations = 4; //Possibly let user control this number, like the iterations over node placement + for (var iteration = 0; iteration < linkSortingIterations; iteration++) { + + sortSourceLinks(graph, y1, id); + sortTargetLinks(graph, y1, id); + resolveNodeLinkOverlaps(graph, y0, y1, id); + sortSourceLinks(graph, y1, id); + sortTargetLinks(graph, y1, id); + } + + // 8.1 Adjust node and link positions back to fill height of chart area if compressed + fillHeight(graph, y0, y1); + + // 9. Calculate visually appealling path for the circular paths, and create the "d" string + addCircularPathData(graph, circularLinkGap, y1, id); + + return graph; + } // end of sankeyCircular function + + + // Set the sankeyCircular parameters + // nodeID, nodeAlign, nodeWidth, nodePadding, nodes, links, size, extent, iterations, nodePaddingRatio, circularLinkGap + sankeyCircular.nodeId = function (_) { + return arguments.length ? (id = typeof _ === 'function' ? _ : constant(_), sankeyCircular) : id; + }; + + sankeyCircular.nodeAlign = function (_) { + return arguments.length ? (align = typeof _ === 'function' ? _ : constant(_), sankeyCircular) : align; + }; + + sankeyCircular.nodeWidth = function (_) { + return arguments.length ? (dx = +_, sankeyCircular) : dx; + }; + + sankeyCircular.nodePadding = function (_) { + return arguments.length ? (py = +_, sankeyCircular) : py; + }; + + sankeyCircular.nodes = function (_) { + return arguments.length ? (nodes = typeof _ === 'function' ? _ : constant(_), sankeyCircular) : nodes; + }; + + sankeyCircular.links = function (_) { + return arguments.length ? (links = typeof _ === 'function' ? _ : constant(_), sankeyCircular) : links; + }; + + sankeyCircular.size = function (_) { + return arguments.length ? (x0 = y0 = 0, x1 = +_[0], y1 = +_[1], sankeyCircular) : [x1 - x0, y1 - y0]; + }; + + sankeyCircular.extent = function (_) { + return arguments.length ? (x0 = +_[0][0], x1 = +_[1][0], y0 = +_[0][1], y1 = +_[1][1], sankeyCircular) : [[x0, y0], [x1, y1]]; + }; + + sankeyCircular.iterations = function (_) { + return arguments.length ? (iterations = +_, sankeyCircular) : iterations; + }; + + sankeyCircular.circularLinkGap = function (_) { + return arguments.length ? (circularLinkGap = +_, sankeyCircular) : circularLinkGap; + }; + + sankeyCircular.nodePaddingRatio = function (_) { + return arguments.length ? (paddingRatio = +_, sankeyCircular) : paddingRatio; + }; + + sankeyCircular.sortNodes = function (_) { + return arguments.length ? (sortNodes = _, sankeyCircular) : sortNodes; + }; + + sankeyCircular.update = function (graph) { + // 5. Calculate the nodes' depth based on the incoming and outgoing links + // Sets the nodes': + // - depth: the depth in the graph + // - column: the depth (0, 1, 2, etc), as is relates to visual position from left to right + // - x0, x1: the x coordinates, as is relates to visual position from left to right + // computeNodeDepths(graph) + + // 3. Determine how the circular links will be drawn, + // either travelling back above the main chart ("top") + // or below the main chart ("bottom") + selectCircularLinkTypes(graph, id); + + // 6. Calculate the nodes' and links' vertical position within their respective column + // Also readjusts sankeyCircular size if circular links are needed, and node x's + // computeNodeBreadths(graph, iterations, id) + computeLinkBreadths(graph); + + // Force position of circular link type based on position + graph.links.forEach(function (link) { + if (link.circular) { + link.circularLinkType = link.y0 + link.y1 < y1 ? 'top' : 'bottom'; + + link.source.circularLinkType = link.circularLinkType; + link.target.circularLinkType = link.circularLinkType; + } + }); + + sortSourceLinks(graph, y1, id, false); // Sort links but do not move nodes + sortTargetLinks(graph, y1, id); + + // 7. Sort links per node, based on the links' source/target nodes' breadths + // 8. Adjust nodes that overlap links that span 2+ columns + // var linkSortingIterations = 4; //Possibly let user control this number, like the iterations over node placement + // for (var iteration = 0; iteration < linkSortingIterations; iteration++) { + // + // sortSourceLinks(graph, y1, id) + // sortTargetLinks(graph, y1, id) + // resolveNodeLinkOverlaps(graph, y0, y1, id) + // sortSourceLinks(graph, y1, id) + // sortTargetLinks(graph, y1, id) + // + // } + + // 8.1 Adjust node and link positions back to fill height of chart area if compressed + // fillHeight(graph, y0, y1) + + // 9. Calculate visually appealling path for the circular paths, and create the "d" string + addCircularPathData(graph, circularLinkGap, y1, id); + return graph; + }; + + // Populate the sourceLinks and targetLinks for each node. + // Also, if the source and target are not objects, assume they are indices. + function computeNodeLinks(graph) { + graph.nodes.forEach(function (node, i) { + node.index = i; + node.sourceLinks = []; + node.targetLinks = []; + }); + var nodeById = map(graph.nodes, id); + graph.links.forEach(function (link, i) { + link.index = i; + var source = link.source; + var target = link.target; + if ((typeof source === "undefined" ? "undefined" : _typeof(source)) !== 'object') { + source = link.source = find(nodeById, source); + } + if ((typeof target === "undefined" ? "undefined" : _typeof(target)) !== 'object') { + target = link.target = find(nodeById, target); + } + source.sourceLinks.push(link); + target.targetLinks.push(link); + }); + return graph; + } + + // Compute the value (size) and cycleness of each node by summing the associated links. + function computeNodeValues(graph) { + graph.nodes.forEach(function (node) { + node.partOfCycle = false; + node.value = Math.max(sum(node.sourceLinks, value), sum(node.targetLinks, value)); + node.sourceLinks.forEach(function (link) { + if (link.circular) { + node.partOfCycle = true; + node.circularLinkType = link.circularLinkType; + } + }); + node.targetLinks.forEach(function (link) { + if (link.circular) { + node.partOfCycle = true; + node.circularLinkType = link.circularLinkType; + } + }); + }); + } + + function getCircleMargins(graph) { + var totalTopLinksWidth = 0, + totalBottomLinksWidth = 0, + totalRightLinksWidth = 0, + totalLeftLinksWidth = 0; + + var maxColumn = max(graph.nodes, function (node) { + return node.column; + }); + + graph.links.forEach(function (link) { + if (link.circular) { + if (link.circularLinkType == 'top') { + totalTopLinksWidth = totalTopLinksWidth + link.width; + } else { + totalBottomLinksWidth = totalBottomLinksWidth + link.width; + } + + if (link.target.column == 0) { + totalLeftLinksWidth = totalLeftLinksWidth + link.width; + } + + if (link.source.column == maxColumn) { + totalRightLinksWidth = totalRightLinksWidth + link.width; + } + } + }); + + //account for radius of curves and padding between links + totalTopLinksWidth = totalTopLinksWidth > 0 ? totalTopLinksWidth + verticalMargin + baseRadius : totalTopLinksWidth; + totalBottomLinksWidth = totalBottomLinksWidth > 0 ? totalBottomLinksWidth + verticalMargin + baseRadius : totalBottomLinksWidth; + totalRightLinksWidth = totalRightLinksWidth > 0 ? totalRightLinksWidth + verticalMargin + baseRadius : totalRightLinksWidth; + totalLeftLinksWidth = totalLeftLinksWidth > 0 ? totalLeftLinksWidth + verticalMargin + baseRadius : totalLeftLinksWidth; + + return { "top": totalTopLinksWidth, "bottom": totalBottomLinksWidth, "left": totalLeftLinksWidth, "right": totalRightLinksWidth }; + } + + // Update the x0, y0, x1 and y1 for the sankeyCircular, to allow space for any circular links + function scaleSankeySize(graph, margin) { + + var maxColumn = max(graph.nodes, function (node) { + return node.column; + }); + + var currentWidth = x1 - x0; + var currentHeight = y1 - y0; + + var newWidth = currentWidth + margin.right + margin.left; + var newHeight = currentHeight + margin.top + margin.bottom; + + var scaleX = currentWidth / newWidth; + var scaleY = currentHeight / newHeight; + + x0 = x0 * scaleX + margin.left; + x1 = margin.right == 0 ? x1 : x1 * scaleX; + y0 = y0 * scaleY + margin.top; + y1 = y1 * scaleY; + + graph.nodes.forEach(function (node) { + node.x0 = x0 + node.column * ((x1 - x0 - dx) / maxColumn); + node.x1 = node.x0 + dx; + }); + + return scaleY; + } + + // Iteratively assign the depth for each node. + // Nodes are assigned the maximum depth of incoming neighbors plus one; + // nodes with no incoming links are assigned depth zero, while + // nodes with no outgoing links are assigned the maximum depth. + function computeNodeDepths(graph) { + var nodes, next, x; + + for (nodes = graph.nodes, next = [], x = 0; nodes.length; ++x, nodes = next, next = []) { + nodes.forEach(function (node) { + node.depth = x; + node.sourceLinks.forEach(function (link) { + if (next.indexOf(link.target) < 0 && !link.circular) { + next.push(link.target); + } + }); + }); + } + + for (nodes = graph.nodes, next = [], x = 0; nodes.length; ++x, nodes = next, next = []) { + nodes.forEach(function (node) { + node.height = x; + node.targetLinks.forEach(function (link) { + if (next.indexOf(link.source) < 0 && !link.circular) { + next.push(link.source); + } + }); + }); + } + + // assign column numbers, and get max value + graph.nodes.forEach(function (node) { + node.column = Math.floor(align.call(null, node, x)); + }); + } + + // Assign nodes' breadths, and then shift nodes that overlap (resolveCollisions) + function computeNodeBreadths(graph, iterations, id) { + var columns = nest().key(function (d) { + return d.column; + }).sortKeys(ascending).entries(graph.nodes).map(function (d) { + return d.values; + }); + + initializeNodeBreadth(id); + resolveCollisions(); + + for (var alpha = 1, n = iterations; n > 0; --n) { + relaxLeftAndRight(alpha *= 0.99, id); + resolveCollisions(); + } + + function initializeNodeBreadth(id) { + + //override py if nodePadding has been set + if (paddingRatio) { + var padding = Infinity; + columns.forEach(function (nodes) { + var thisPadding = y1 * paddingRatio / (nodes.length + 1); + padding = thisPadding < padding ? thisPadding : padding; + }); + py = padding; + } + + var ky = min(columns, function (nodes) { + return (y1 - y0 - (nodes.length - 1) * py) / sum(nodes, value); + }); + + //calculate the widths of the links + ky = ky * scale; + + graph.links.forEach(function (link) { + link.width = link.value * ky; + }); + + //determine how much to scale down the chart, based on circular links + var margin = getCircleMargins(graph); + var ratio = scaleSankeySize(graph, margin); + + //re-calculate widths + ky = ky * ratio; + + graph.links.forEach(function (link) { + link.width = link.value * ky; + }); + + columns.forEach(function (nodes) { + var nodesLength = nodes.length; + nodes.forEach(function (node, i) { + if (node.depth == columns.length - 1 && nodesLength == 1) { + node.y0 = y1 / 2 - node.value * ky; + node.y1 = node.y0 + node.value * ky; + } else if (node.depth == 0 && nodesLength == 1) { + node.y0 = y1 / 2 - node.value * ky; + node.y1 = node.y0 + node.value * ky; + } else if (node.partOfCycle) { + if (numberOfNonSelfLinkingCycles(node, id) == 0) { + node.y0 = y1 / 2 + i; + node.y1 = node.y0 + node.value * ky; + } else if (node.circularLinkType == 'top') { + node.y0 = y0 + i; + node.y1 = node.y0 + node.value * ky; + } else { + node.y0 = y1 - node.value * ky - i; + node.y1 = node.y0 + node.value * ky; + } + } else { + if (margin.top == 0 || margin.bottom == 0) { + node.y0 = (y1 - y0) / nodesLength * i; + node.y1 = node.y0 + node.value * ky; + } else { + node.y0 = (y1 - y0) / 2 - nodesLength / 2 + i; + node.y1 = node.y0 + node.value * ky; + } + } + }); + }); + } + + // For each node in each column, check the node's vertical position in relation to its targets and sources vertical position + // and shift up/down to be closer to the vertical middle of those targets and sources + function relaxLeftAndRight(alpha, id) { + var columnsLength = columns.length; + + columns.forEach(function (nodes) { + var n = nodes.length; + var depth = nodes[0].depth; + + nodes.forEach(function (node) { + // check the node is not an orphan + var nodeHeight; + if (node.sourceLinks.length || node.targetLinks.length) { + if (node.partOfCycle && numberOfNonSelfLinkingCycles(node, id) > 0) ; else if (depth == 0 && n == 1) { + nodeHeight = node.y1 - node.y0; + + node.y0 = y1 / 2 - nodeHeight / 2; + node.y1 = y1 / 2 + nodeHeight / 2; + } else if (depth == columnsLength - 1 && n == 1) { + nodeHeight = node.y1 - node.y0; + + node.y0 = y1 / 2 - nodeHeight / 2; + node.y1 = y1 / 2 + nodeHeight / 2; + } else { + var avg = 0; + + var avgTargetY = mean(node.sourceLinks, linkTargetCenter); + var avgSourceY = mean(node.targetLinks, linkSourceCenter); + + if (avgTargetY && avgSourceY) { + avg = (avgTargetY + avgSourceY) / 2; + } else { + avg = avgTargetY || avgSourceY; + } + + var dy = (avg - nodeCenter(node)) * alpha; + // positive if it node needs to move down + node.y0 += dy; + node.y1 += dy; + } + } + }); + }); + } + + // For each column, check if nodes are overlapping, and if so, shift up/down + function resolveCollisions() { + columns.forEach(function (nodes) { + var node, + dy, + y = y0, + n = nodes.length, + i; + + // Push any overlapping nodes down. + nodes.sort(ascendingBreadth); + + for (i = 0; i < n; ++i) { + node = nodes[i]; + dy = y - node.y0; + + if (dy > 0) { + node.y0 += dy; + node.y1 += dy; + } + y = node.y1 + py; + } + + // If the bottommost node goes outside the bounds, push it back up. + dy = y - py - y1; + if (dy > 0) { + y = node.y0 -= dy, node.y1 -= dy; + + // Push any overlapping nodes back up. + for (i = n - 2; i >= 0; --i) { + node = nodes[i]; + dy = node.y1 + py - y; + if (dy > 0) node.y0 -= dy, node.y1 -= dy; + y = node.y0; + } + } + }); + } + } + + // Assign the links y0 and y1 based on source/target nodes position, + // plus the link's relative position to other links to the same node + function computeLinkBreadths(graph) { + graph.nodes.forEach(function (node) { + node.sourceLinks.sort(ascendingTargetBreadth); + node.targetLinks.sort(ascendingSourceBreadth); + }); + graph.nodes.forEach(function (node) { + var y0 = node.y0; + var y1 = y0; + + // start from the bottom of the node for cycle links + var y0cycle = node.y1; + var y1cycle = y0cycle; + + node.sourceLinks.forEach(function (link) { + if (link.circular) { + link.y0 = y0cycle - link.width / 2; + y0cycle = y0cycle - link.width; + } else { + link.y0 = y0 + link.width / 2; + y0 += link.width; + } + }); + node.targetLinks.forEach(function (link) { + if (link.circular) { + link.y1 = y1cycle - link.width / 2; + y1cycle = y1cycle - link.width; + } else { + link.y1 = y1 + link.width / 2; + y1 += link.width; + } + }); + }); + } + + return sankeyCircular; +} + +/// ///////////////////////////////////////////////////////////////////////////////// +// Cycle functions +// portion of code to detect circular links based on Colin Fergus' bl.ock https://gist.github.com/cfergus/3956043 + +// Identify circles in the link objects +function identifyCircles(graph, id, sortNodes) { + var circularLinkID = 0; + if (sortNodes === null) { + + // Building adjacency graph + var adjList = []; + for (var i = 0; i < graph.links.length; i++) { + var link = graph.links[i]; + var source = link.source.index; + var target = link.target.index; + if (!adjList[source]) adjList[source] = []; + if (!adjList[target]) adjList[target] = []; + + // Add links if not already in set + if (adjList[source].indexOf(target) === -1) adjList[source].push(target); + } + + // Find all elementary circuits + var cycles = findCircuits(adjList); + + // Sort by circuits length + cycles.sort(function (a, b) { + return a.length - b.length; + }); + + var circularLinks = {}; + for (i = 0; i < cycles.length; i++) { + var cycle = cycles[i]; + var last = cycle.slice(-2); + if (!circularLinks[last[0]]) circularLinks[last[0]] = {}; + circularLinks[last[0]][last[1]] = true; + } + + graph.links.forEach(function (link) { + var target = link.target.index; + var source = link.source.index; + // If self-linking or a back-edge + if (target === source || circularLinks[source] && circularLinks[source][target]) { + link.circular = true; + link.circularLinkID = circularLinkID; + circularLinkID = circularLinkID + 1; + } else { + link.circular = false; + } + }); + } else { + graph.links.forEach(function (link) { + if (link.source[sortNodes] < link.target[sortNodes]) { + link.circular = false; + } else { + link.circular = true; + link.circularLinkID = circularLinkID; + circularLinkID = circularLinkID + 1; + } + }); + } +} + +// Assign a circular link type (top or bottom), based on: +// - if the source/target node already has circular links, then use the same type +// - if not, choose the type with fewer links +function selectCircularLinkTypes(graph, id) { + var numberOfTops = 0; + var numberOfBottoms = 0; + graph.links.forEach(function (link) { + if (link.circular) { + // if either souce or target has type already use that + if (link.source.circularLinkType || link.target.circularLinkType) { + // default to source type if available + link.circularLinkType = link.source.circularLinkType ? link.source.circularLinkType : link.target.circularLinkType; + } else { + link.circularLinkType = numberOfTops < numberOfBottoms ? 'top' : 'bottom'; + } + + if (link.circularLinkType == 'top') { + numberOfTops = numberOfTops + 1; + } else { + numberOfBottoms = numberOfBottoms + 1; + } + + graph.nodes.forEach(function (node) { + if (getNodeID(node, id) == getNodeID(link.source, id) || getNodeID(node, id) == getNodeID(link.target, id)) { + node.circularLinkType = link.circularLinkType; + } + }); + } + }); + + //correct self-linking links to be same direction as node + graph.links.forEach(function (link) { + if (link.circular) { + //if both source and target node are same type, then link should have same type + if (link.source.circularLinkType == link.target.circularLinkType) { + link.circularLinkType = link.source.circularLinkType; + } + //if link is selflinking, then link should have same type as node + if (selfLinking(link, id)) { + link.circularLinkType = link.source.circularLinkType; + } + } + }); +} + +// Return the angle between a straight line between the source and target of the link, and the vertical plane of the node +function linkAngle(link) { + var adjacent = Math.abs(link.y1 - link.y0); + var opposite = Math.abs(link.target.x0 - link.source.x1); + + return Math.atan(opposite / adjacent); +} + +// Check if two circular links potentially overlap +function circularLinksCross(link1, link2) { + if (link1.source.column < link2.target.column) { + return false; + } else if (link1.target.column > link2.source.column) { + return false; + } else { + return true; + } +} + +// Return the number of circular links for node, not including self linking links +function numberOfNonSelfLinkingCycles(node, id) { + var sourceCount = 0; + node.sourceLinks.forEach(function (l) { + sourceCount = l.circular && !selfLinking(l, id) ? sourceCount + 1 : sourceCount; + }); + + var targetCount = 0; + node.targetLinks.forEach(function (l) { + targetCount = l.circular && !selfLinking(l, id) ? targetCount + 1 : targetCount; + }); + + return sourceCount + targetCount; +} + +// Check if a circular link is the only circular link for both its source and target node +function onlyCircularLink(link) { + var nodeSourceLinks = link.source.sourceLinks; + var sourceCount = 0; + nodeSourceLinks.forEach(function (l) { + sourceCount = l.circular ? sourceCount + 1 : sourceCount; + }); + + var nodeTargetLinks = link.target.targetLinks; + var targetCount = 0; + nodeTargetLinks.forEach(function (l) { + targetCount = l.circular ? targetCount + 1 : targetCount; + }); + + if (sourceCount > 1 || targetCount > 1) { + return false; + } else { + return true; + } +} + +// creates vertical buffer values per set of top/bottom links +function calcVerticalBuffer(links, circularLinkGap, id) { + links.sort(sortLinkColumnAscending); + links.forEach(function (link, i) { + var buffer = 0; + + if (selfLinking(link, id) && onlyCircularLink(link)) { + link.circularPathData.verticalBuffer = buffer + link.width / 2; + } else { + var j = 0; + for (j; j < i; j++) { + if (circularLinksCross(links[i], links[j])) { + var bufferOverThisLink = links[j].circularPathData.verticalBuffer + links[j].width / 2 + circularLinkGap; + buffer = bufferOverThisLink > buffer ? bufferOverThisLink : buffer; + } + } + + link.circularPathData.verticalBuffer = buffer + link.width / 2; + } + }); + + return links; +} + +// calculate the optimum path for a link to reduce overlaps +function addCircularPathData(graph, circularLinkGap, y1, id) { + //var baseRadius = 10 + var buffer = 5; + //var verticalMargin = 25 + + var minY = min(graph.links, function (link) { + return link.source.y0; + }); + + // create object for circular Path Data + graph.links.forEach(function (link) { + if (link.circular) { + link.circularPathData = {}; + } + }); + + // calc vertical offsets per top/bottom links + var topLinks = graph.links.filter(function (l) { + return l.circularLinkType == 'top'; + }); + /* topLinks = */calcVerticalBuffer(topLinks, circularLinkGap, id); + + var bottomLinks = graph.links.filter(function (l) { + return l.circularLinkType == 'bottom'; + }); + /* bottomLinks = */calcVerticalBuffer(bottomLinks, circularLinkGap, id); + + // add the base data for each link + graph.links.forEach(function (link) { + if (link.circular) { + link.circularPathData.arcRadius = link.width + baseRadius; + link.circularPathData.leftNodeBuffer = buffer; + link.circularPathData.rightNodeBuffer = buffer; + link.circularPathData.sourceWidth = link.source.x1 - link.source.x0; + link.circularPathData.sourceX = link.source.x0 + link.circularPathData.sourceWidth; + link.circularPathData.targetX = link.target.x0; + link.circularPathData.sourceY = link.y0; + link.circularPathData.targetY = link.y1; + + // for self linking paths, and that the only circular link in/out of that node + if (selfLinking(link, id) && onlyCircularLink(link)) { + link.circularPathData.leftSmallArcRadius = baseRadius + link.width / 2; + link.circularPathData.leftLargeArcRadius = baseRadius + link.width / 2; + link.circularPathData.rightSmallArcRadius = baseRadius + link.width / 2; + link.circularPathData.rightLargeArcRadius = baseRadius + link.width / 2; + + if (link.circularLinkType == 'bottom') { + link.circularPathData.verticalFullExtent = link.source.y1 + verticalMargin + link.circularPathData.verticalBuffer; + link.circularPathData.verticalLeftInnerExtent = link.circularPathData.verticalFullExtent - link.circularPathData.leftLargeArcRadius; + link.circularPathData.verticalRightInnerExtent = link.circularPathData.verticalFullExtent - link.circularPathData.rightLargeArcRadius; + } else { + // top links + link.circularPathData.verticalFullExtent = link.source.y0 - verticalMargin - link.circularPathData.verticalBuffer; + link.circularPathData.verticalLeftInnerExtent = link.circularPathData.verticalFullExtent + link.circularPathData.leftLargeArcRadius; + link.circularPathData.verticalRightInnerExtent = link.circularPathData.verticalFullExtent + link.circularPathData.rightLargeArcRadius; + } + } else { + // else calculate normally + // add left extent coordinates, based on links with same source column and circularLink type + var thisColumn = link.source.column; + var thisCircularLinkType = link.circularLinkType; + var sameColumnLinks = graph.links.filter(function (l) { + return l.source.column == thisColumn && l.circularLinkType == thisCircularLinkType; + }); + + if (link.circularLinkType == 'bottom') { + sameColumnLinks.sort(sortLinkSourceYDescending); + } else { + sameColumnLinks.sort(sortLinkSourceYAscending); + } + + var radiusOffset = 0; + sameColumnLinks.forEach(function (l, i) { + if (l.circularLinkID == link.circularLinkID) { + link.circularPathData.leftSmallArcRadius = baseRadius + link.width / 2 + radiusOffset; + link.circularPathData.leftLargeArcRadius = baseRadius + link.width / 2 + i * circularLinkGap + radiusOffset; + } + radiusOffset = radiusOffset + l.width; + }); + + // add right extent coordinates, based on links with same target column and circularLink type + thisColumn = link.target.column; + sameColumnLinks = graph.links.filter(function (l) { + return l.target.column == thisColumn && l.circularLinkType == thisCircularLinkType; + }); + if (link.circularLinkType == 'bottom') { + sameColumnLinks.sort(sortLinkTargetYDescending); + } else { + sameColumnLinks.sort(sortLinkTargetYAscending); + } + + radiusOffset = 0; + sameColumnLinks.forEach(function (l, i) { + if (l.circularLinkID == link.circularLinkID) { + link.circularPathData.rightSmallArcRadius = baseRadius + link.width / 2 + radiusOffset; + link.circularPathData.rightLargeArcRadius = baseRadius + link.width / 2 + i * circularLinkGap + radiusOffset; + } + radiusOffset = radiusOffset + l.width; + }); + + // bottom links + if (link.circularLinkType == 'bottom') { + link.circularPathData.verticalFullExtent = Math.max(y1, link.source.y1, link.target.y1) + verticalMargin + link.circularPathData.verticalBuffer; + link.circularPathData.verticalLeftInnerExtent = link.circularPathData.verticalFullExtent - link.circularPathData.leftLargeArcRadius; + link.circularPathData.verticalRightInnerExtent = link.circularPathData.verticalFullExtent - link.circularPathData.rightLargeArcRadius; + } else { + // top links + link.circularPathData.verticalFullExtent = minY - verticalMargin - link.circularPathData.verticalBuffer; + link.circularPathData.verticalLeftInnerExtent = link.circularPathData.verticalFullExtent + link.circularPathData.leftLargeArcRadius; + link.circularPathData.verticalRightInnerExtent = link.circularPathData.verticalFullExtent + link.circularPathData.rightLargeArcRadius; + } + } + + // all links + link.circularPathData.leftInnerExtent = link.circularPathData.sourceX + link.circularPathData.leftNodeBuffer; + link.circularPathData.rightInnerExtent = link.circularPathData.targetX - link.circularPathData.rightNodeBuffer; + link.circularPathData.leftFullExtent = link.circularPathData.sourceX + link.circularPathData.leftLargeArcRadius + link.circularPathData.leftNodeBuffer; + link.circularPathData.rightFullExtent = link.circularPathData.targetX - link.circularPathData.rightLargeArcRadius - link.circularPathData.rightNodeBuffer; + } + + if (link.circular) { + link.path = createCircularPathString(link); + } else { + var normalPath = linkHorizontal().source(function (d) { + var x = d.source.x0 + (d.source.x1 - d.source.x0); + var y = d.y0; + return [x, y]; + }).target(function (d) { + var x = d.target.x0; + var y = d.y1; + return [x, y]; + }); + link.path = normalPath(link); + } + }); +} + +// create a d path using the addCircularPathData +function createCircularPathString(link) { + var pathString = ''; + // 'pathData' is assigned a value but never used + // var pathData = {} + + if (link.circularLinkType == 'top') { + pathString = + // start at the right of the source node + 'M' + link.circularPathData.sourceX + ' ' + link.circularPathData.sourceY + ' ' + + // line right to buffer point + 'L' + link.circularPathData.leftInnerExtent + ' ' + link.circularPathData.sourceY + ' ' + + // Arc around: Centre of arc X and //Centre of arc Y + 'A' + link.circularPathData.leftLargeArcRadius + ' ' + link.circularPathData.leftSmallArcRadius + ' 0 0 0 ' + + // End of arc X //End of arc Y + link.circularPathData.leftFullExtent + ' ' + (link.circularPathData.sourceY - link.circularPathData.leftSmallArcRadius) + ' ' + // End of arc X + // line up to buffer point + 'L' + link.circularPathData.leftFullExtent + ' ' + link.circularPathData.verticalLeftInnerExtent + ' ' + + // Arc around: Centre of arc X and //Centre of arc Y + 'A' + link.circularPathData.leftLargeArcRadius + ' ' + link.circularPathData.leftLargeArcRadius + ' 0 0 0 ' + + // End of arc X //End of arc Y + link.circularPathData.leftInnerExtent + ' ' + link.circularPathData.verticalFullExtent + ' ' + // End of arc X + // line left to buffer point + 'L' + link.circularPathData.rightInnerExtent + ' ' + link.circularPathData.verticalFullExtent + ' ' + + // Arc around: Centre of arc X and //Centre of arc Y + 'A' + link.circularPathData.rightLargeArcRadius + ' ' + link.circularPathData.rightLargeArcRadius + ' 0 0 0 ' + + // End of arc X //End of arc Y + link.circularPathData.rightFullExtent + ' ' + link.circularPathData.verticalRightInnerExtent + ' ' + // End of arc X + // line down + 'L' + link.circularPathData.rightFullExtent + ' ' + (link.circularPathData.targetY - link.circularPathData.rightSmallArcRadius) + ' ' + + // Arc around: Centre of arc X and //Centre of arc Y + 'A' + link.circularPathData.rightLargeArcRadius + ' ' + link.circularPathData.rightSmallArcRadius + ' 0 0 0 ' + + // End of arc X //End of arc Y + link.circularPathData.rightInnerExtent + ' ' + link.circularPathData.targetY + ' ' + // End of arc X + // line to end + 'L' + link.circularPathData.targetX + ' ' + link.circularPathData.targetY; + } else { + // bottom path + pathString = + // start at the right of the source node + 'M' + link.circularPathData.sourceX + ' ' + link.circularPathData.sourceY + ' ' + + // line right to buffer point + 'L' + link.circularPathData.leftInnerExtent + ' ' + link.circularPathData.sourceY + ' ' + + // Arc around: Centre of arc X and //Centre of arc Y + 'A' + link.circularPathData.leftLargeArcRadius + ' ' + link.circularPathData.leftSmallArcRadius + ' 0 0 1 ' + + // End of arc X //End of arc Y + link.circularPathData.leftFullExtent + ' ' + (link.circularPathData.sourceY + link.circularPathData.leftSmallArcRadius) + ' ' + // End of arc X + // line down to buffer point + 'L' + link.circularPathData.leftFullExtent + ' ' + link.circularPathData.verticalLeftInnerExtent + ' ' + + // Arc around: Centre of arc X and //Centre of arc Y + 'A' + link.circularPathData.leftLargeArcRadius + ' ' + link.circularPathData.leftLargeArcRadius + ' 0 0 1 ' + + // End of arc X //End of arc Y + link.circularPathData.leftInnerExtent + ' ' + link.circularPathData.verticalFullExtent + ' ' + // End of arc X + // line left to buffer point + 'L' + link.circularPathData.rightInnerExtent + ' ' + link.circularPathData.verticalFullExtent + ' ' + + // Arc around: Centre of arc X and //Centre of arc Y + 'A' + link.circularPathData.rightLargeArcRadius + ' ' + link.circularPathData.rightLargeArcRadius + ' 0 0 1 ' + + // End of arc X //End of arc Y + link.circularPathData.rightFullExtent + ' ' + link.circularPathData.verticalRightInnerExtent + ' ' + // End of arc X + // line up + 'L' + link.circularPathData.rightFullExtent + ' ' + (link.circularPathData.targetY + link.circularPathData.rightSmallArcRadius) + ' ' + + // Arc around: Centre of arc X and //Centre of arc Y + 'A' + link.circularPathData.rightLargeArcRadius + ' ' + link.circularPathData.rightSmallArcRadius + ' 0 0 1 ' + + // End of arc X //End of arc Y + link.circularPathData.rightInnerExtent + ' ' + link.circularPathData.targetY + ' ' + // End of arc X + // line to end + 'L' + link.circularPathData.targetX + ' ' + link.circularPathData.targetY; + } + + return pathString; +} + +// sort links based on the distance between the source and tartget node columns +// if the same, then use Y position of the source node +function sortLinkColumnAscending(link1, link2) { + if (linkColumnDistance(link1) == linkColumnDistance(link2)) { + return link1.circularLinkType == 'bottom' ? sortLinkSourceYDescending(link1, link2) : sortLinkSourceYAscending(link1, link2); + } else { + return linkColumnDistance(link2) - linkColumnDistance(link1); + } +} + +// sort ascending links by their source vertical position, y0 +function sortLinkSourceYAscending(link1, link2) { + return link1.y0 - link2.y0; +} + +// sort descending links by their source vertical position, y0 +function sortLinkSourceYDescending(link1, link2) { + return link2.y0 - link1.y0; +} + +// sort ascending links by their target vertical position, y1 +function sortLinkTargetYAscending(link1, link2) { + return link1.y1 - link2.y1; +} + +// sort descending links by their target vertical position, y1 +function sortLinkTargetYDescending(link1, link2) { + return link2.y1 - link1.y1; +} + +// return the distance between the link's target and source node, in terms of the nodes' column +function linkColumnDistance(link) { + return link.target.column - link.source.column; +} + +// return the distance between the link's target and source node, in terms of the nodes' X coordinate +function linkXLength(link) { + return link.target.x0 - link.source.x1; +} + +// Return the Y coordinate on the longerLink path * which is perpendicular shorterLink's source. +// * approx, based on a straight line from target to source, when in fact the path is a bezier +function linkPerpendicularYToLinkSource(longerLink, shorterLink) { + // get the angle for the longer link + var angle = linkAngle(longerLink); + + // get the adjacent length to the other link's x position + var heightFromY1ToPependicular = linkXLength(shorterLink) / Math.tan(angle); + + // add or subtract from longer link1's original y1, depending on the slope + var yPerpendicular = incline(longerLink) == 'up' ? longerLink.y1 + heightFromY1ToPependicular : longerLink.y1 - heightFromY1ToPependicular; + + return yPerpendicular; +} + +// Return the Y coordinate on the longerLink path * which is perpendicular shorterLink's source. +// * approx, based on a straight line from target to source, when in fact the path is a bezier +function linkPerpendicularYToLinkTarget(longerLink, shorterLink) { + // get the angle for the longer link + var angle = linkAngle(longerLink); + + // get the adjacent length to the other link's x position + var heightFromY1ToPependicular = linkXLength(shorterLink) / Math.tan(angle); + + // add or subtract from longer link's original y1, depending on the slope + var yPerpendicular = incline(longerLink) == 'up' ? longerLink.y1 - heightFromY1ToPependicular : longerLink.y1 + heightFromY1ToPependicular; + + return yPerpendicular; +} + +// Move any nodes that overlap links which span 2+ columns +function resolveNodeLinkOverlaps(graph, y0, y1, id) { + + graph.links.forEach(function (link) { + if (link.circular) { + return; + } + + if (link.target.column - link.source.column > 1) { + var columnToTest = link.source.column + 1; + var maxColumnToTest = link.target.column - 1; + + var i = 1; + var numberOfColumnsToTest = maxColumnToTest - columnToTest + 1; + + for (i = 1; columnToTest <= maxColumnToTest; columnToTest++, i++) { + graph.nodes.forEach(function (node) { + if (node.column == columnToTest) { + var t = i / (numberOfColumnsToTest + 1); + + // Find all the points of a cubic bezier curve in javascript + // https://stackoverflow.com/questions/15397596/find-all-the-points-of-a-cubic-bezier-curve-in-javascript + + var B0_t = Math.pow(1 - t, 3); + var B1_t = 3 * t * Math.pow(1 - t, 2); + var B2_t = 3 * Math.pow(t, 2) * (1 - t); + var B3_t = Math.pow(t, 3); + + var py_t = B0_t * link.y0 + B1_t * link.y0 + B2_t * link.y1 + B3_t * link.y1; + + var linkY0AtColumn = py_t - link.width / 2; + var linkY1AtColumn = py_t + link.width / 2; + var dy; + + // If top of link overlaps node, push node up + if (linkY0AtColumn > node.y0 && linkY0AtColumn < node.y1) { + + dy = node.y1 - linkY0AtColumn + 10; + dy = node.circularLinkType == 'bottom' ? dy : -dy; + + node = adjustNodeHeight(node, dy, y0, y1); + + // check if other nodes need to move up too + graph.nodes.forEach(function (otherNode) { + // don't need to check itself or nodes at different columns + if (getNodeID(otherNode, id) == getNodeID(node, id) || otherNode.column != node.column) { + return; + } + if (nodesOverlap(node, otherNode)) { + adjustNodeHeight(otherNode, dy, y0, y1); + } + }); + } else if (linkY1AtColumn > node.y0 && linkY1AtColumn < node.y1) { + // If bottom of link overlaps node, push node down + dy = linkY1AtColumn - node.y0 + 10; + + node = adjustNodeHeight(node, dy, y0, y1); + + // check if other nodes need to move down too + graph.nodes.forEach(function (otherNode) { + // don't need to check itself or nodes at different columns + if (getNodeID(otherNode, id) == getNodeID(node, id) || otherNode.column != node.column) { + return; + } + if (otherNode.y0 < node.y1 && otherNode.y1 > node.y1) { + adjustNodeHeight(otherNode, dy, y0, y1); + } + }); + } else if (linkY0AtColumn < node.y0 && linkY1AtColumn > node.y1) { + // if link completely overlaps node + dy = linkY1AtColumn - node.y0 + 10; + + node = adjustNodeHeight(node, dy, y0, y1); + + graph.nodes.forEach(function (otherNode) { + // don't need to check itself or nodes at different columns + if (getNodeID(otherNode, id) == getNodeID(node, id) || otherNode.column != node.column) { + return; + } + if (otherNode.y0 < node.y1 && otherNode.y1 > node.y1) { + adjustNodeHeight(otherNode, dy, y0, y1); + } + }); + } + } + }); + } + } + }); +} + +// check if two nodes overlap +function nodesOverlap(nodeA, nodeB) { + // test if nodeA top partially overlaps nodeB + if (nodeA.y0 > nodeB.y0 && nodeA.y0 < nodeB.y1) { + return true; + } else if (nodeA.y1 > nodeB.y0 && nodeA.y1 < nodeB.y1) { + // test if nodeA bottom partially overlaps nodeB + return true; + } else if (nodeA.y0 < nodeB.y0 && nodeA.y1 > nodeB.y1) { + // test if nodeA covers nodeB + return true; + } else { + return false; + } +} + +// update a node, and its associated links, vertical positions (y0, y1) +function adjustNodeHeight(node, dy, sankeyY0, sankeyY1) { + if (node.y0 + dy >= sankeyY0 && node.y1 + dy <= sankeyY1) { + node.y0 = node.y0 + dy; + node.y1 = node.y1 + dy; + + node.targetLinks.forEach(function (l) { + l.y1 = l.y1 + dy; + }); + + node.sourceLinks.forEach(function (l) { + l.y0 = l.y0 + dy; + }); + } + return node; +} + +// sort and set the links' y0 for each node +function sortSourceLinks(graph, y1, id, moveNodes) { + graph.nodes.forEach(function (node) { + // move any nodes up which are off the bottom + if (moveNodes && node.y + (node.y1 - node.y0) > y1) { + node.y = node.y - (node.y + (node.y1 - node.y0) - y1); + } + + var nodesSourceLinks = graph.links.filter(function (l) { + return getNodeID(l.source, id) == getNodeID(node, id); + }); + + var nodeSourceLinksLength = nodesSourceLinks.length; + + // if more than 1 link then sort + if (nodeSourceLinksLength > 1) { + nodesSourceLinks.sort(function (link1, link2) { + // if both are not circular... + if (!link1.circular && !link2.circular) { + // if the target nodes are the same column, then sort by the link's target y + if (link1.target.column == link2.target.column) { + return link1.y1 - link2.y1; + } else if (!sameInclines(link1, link2)) { + // if the links slope in different directions, then sort by the link's target y + return link1.y1 - link2.y1; + + // if the links slope in same directions, then sort by any overlap + } else { + if (link1.target.column > link2.target.column) { + var link2Adj = linkPerpendicularYToLinkTarget(link2, link1); + return link1.y1 - link2Adj; + } + if (link2.target.column > link1.target.column) { + var link1Adj = linkPerpendicularYToLinkTarget(link1, link2); + return link1Adj - link2.y1; + } + } + } + + // if only one is circular, the move top links up, or bottom links down + if (link1.circular && !link2.circular) { + return link1.circularLinkType == 'top' ? -1 : 1; + } else if (link2.circular && !link1.circular) { + return link2.circularLinkType == 'top' ? 1 : -1; + } + + // if both links are circular... + if (link1.circular && link2.circular) { + // ...and they both loop the same way (both top) + if (link1.circularLinkType === link2.circularLinkType && link1.circularLinkType == 'top') { + // ...and they both connect to a target with same column, then sort by the target's y + if (link1.target.column === link2.target.column) { + return link1.target.y1 - link2.target.y1; + } else { + // ...and they connect to different column targets, then sort by how far back they + return link2.target.column - link1.target.column; + } + } else if (link1.circularLinkType === link2.circularLinkType && link1.circularLinkType == 'bottom') { + // ...and they both loop the same way (both bottom) + // ...and they both connect to a target with same column, then sort by the target's y + if (link1.target.column === link2.target.column) { + return link2.target.y1 - link1.target.y1; + } else { + // ...and they connect to different column targets, then sort by how far back they + return link1.target.column - link2.target.column; + } + } else { + // ...and they loop around different ways, the move top up and bottom down + return link1.circularLinkType == 'top' ? -1 : 1; + } + } + }); + } + + // update y0 for links + var ySourceOffset = node.y0; + + nodesSourceLinks.forEach(function (link) { + link.y0 = ySourceOffset + link.width / 2; + ySourceOffset = ySourceOffset + link.width; + }); + + // correct any circular bottom links so they are at the bottom of the node + nodesSourceLinks.forEach(function (link, i) { + if (link.circularLinkType == 'bottom') { + var j = i + 1; + var offsetFromBottom = 0; + // sum the widths of any links that are below this link + for (j; j < nodeSourceLinksLength; j++) { + offsetFromBottom = offsetFromBottom + nodesSourceLinks[j].width; + } + link.y0 = node.y1 - offsetFromBottom - link.width / 2; + } + }); + }); +} + +// sort and set the links' y1 for each node +function sortTargetLinks(graph, y1, id) { + graph.nodes.forEach(function (node) { + var nodesTargetLinks = graph.links.filter(function (l) { + return getNodeID(l.target, id) == getNodeID(node, id); + }); + + var nodesTargetLinksLength = nodesTargetLinks.length; + + if (nodesTargetLinksLength > 1) { + nodesTargetLinks.sort(function (link1, link2) { + // if both are not circular, the base on the source y position + if (!link1.circular && !link2.circular) { + if (link1.source.column == link2.source.column) { + return link1.y0 - link2.y0; + } else if (!sameInclines(link1, link2)) { + return link1.y0 - link2.y0; + } else { + // get the angle of the link to the further source node (ie the smaller column) + if (link2.source.column < link1.source.column) { + var link2Adj = linkPerpendicularYToLinkSource(link2, link1); + + return link1.y0 - link2Adj; + } + if (link1.source.column < link2.source.column) { + var link1Adj = linkPerpendicularYToLinkSource(link1, link2); + + return link1Adj - link2.y0; + } + } + } + + // if only one is circular, the move top links up, or bottom links down + if (link1.circular && !link2.circular) { + return link1.circularLinkType == 'top' ? -1 : 1; + } else if (link2.circular && !link1.circular) { + return link2.circularLinkType == 'top' ? 1 : -1; + } + + // if both links are circular... + if (link1.circular && link2.circular) { + // ...and they both loop the same way (both top) + if (link1.circularLinkType === link2.circularLinkType && link1.circularLinkType == 'top') { + // ...and they both connect to a target with same column, then sort by the target's y + if (link1.source.column === link2.source.column) { + return link1.source.y1 - link2.source.y1; + } else { + // ...and they connect to different column targets, then sort by how far back they + return link1.source.column - link2.source.column; + } + } else if (link1.circularLinkType === link2.circularLinkType && link1.circularLinkType == 'bottom') { + // ...and they both loop the same way (both bottom) + // ...and they both connect to a target with same column, then sort by the target's y + if (link1.source.column === link2.source.column) { + return link1.source.y1 - link2.source.y1; + } else { + // ...and they connect to different column targets, then sort by how far back they + return link2.source.column - link1.source.column; + } + } else { + // ...and they loop around different ways, the move top up and bottom down + return link1.circularLinkType == 'top' ? -1 : 1; + } + } + }); + } + + // update y1 for links + var yTargetOffset = node.y0; + + nodesTargetLinks.forEach(function (link) { + link.y1 = yTargetOffset + link.width / 2; + yTargetOffset = yTargetOffset + link.width; + }); + + // correct any circular bottom links so they are at the bottom of the node + nodesTargetLinks.forEach(function (link, i) { + if (link.circularLinkType == 'bottom') { + var j = i + 1; + var offsetFromBottom = 0; + // sum the widths of any links that are below this link + for (j; j < nodesTargetLinksLength; j++) { + offsetFromBottom = offsetFromBottom + nodesTargetLinks[j].width; + } + link.y1 = node.y1 - offsetFromBottom - link.width / 2; + } + }); + }); +} + +// test if links both slope up, or both slope down +function sameInclines(link1, link2) { + return incline(link1) == incline(link2); +} + +// returns the slope of a link, from source to target +// up => slopes up from source to target +// down => slopes down from source to target +function incline(link) { + return link.y0 - link.y1 > 0 ? 'up' : 'down'; +} + +// check if link is self linking, ie links a node to the same node +function selfLinking(link, id) { + return getNodeID(link.source, id) == getNodeID(link.target, id); +} + +function fillHeight(graph, y0, y1) { + + var nodes = graph.nodes; + var links = graph.links; + + var top = false; + var bottom = false; + + links.forEach(function (link) { + if (link.circularLinkType == "top") { + top = true; + } else if (link.circularLinkType == "bottom") { + bottom = true; + } + }); + + if (top == false || bottom == false) { + var minY0 = min(nodes, function (node) { + return node.y0; + }); + var maxY1 = max(nodes, function (node) { + return node.y1; + }); + var currentHeight = maxY1 - minY0; + var chartHeight = y1 - y0; + var ratio = chartHeight / currentHeight; + + nodes.forEach(function (node) { + var nodeHeight = (node.y1 - node.y0) * ratio; + node.y0 = (node.y0 - minY0) * ratio; + node.y1 = node.y0 + nodeHeight; + }); + + links.forEach(function (link) { + link.y0 = (link.y0 - minY0) * ratio; + link.y1 = (link.y1 - minY0) * ratio; + link.width = link.width * ratio; + }); + } +} + +export { sankeyCircular, center as sankeyCenter, left as sankeyLeft, right as sankeyRight, justify as sankeyJustify }; diff --git a/node_modules/@plotly/d3-sankey-circular/dist/d3-sankey-circular.js b/node_modules/@plotly/d3-sankey-circular/dist/d3-sankey-circular.js new file mode 100644 index 0000000000000000000000000000000000000000..5ec08f5a22b5eb3f2867e097809207d606941cda --- /dev/null +++ b/node_modules/@plotly/d3-sankey-circular/dist/d3-sankey-circular.js @@ -0,0 +1,1501 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-array'), require('d3-collection'), require('d3-shape'), require('elementary-circuits-directed-graph')) : + typeof define === 'function' && define.amd ? define(['exports', 'd3-array', 'd3-collection', 'd3-shape', 'elementary-circuits-directed-graph'], factory) : + (factory((global.d3 = global.d3 || {}),global.d3,global.d3,global.d3,null)); +}(this, (function (exports,d3Array,d3Collection,d3Shape,findCircuits) { 'use strict'; + + findCircuits = findCircuits && findCircuits.hasOwnProperty('default') ? findCircuits['default'] : findCircuits; + + // For a given link, return the target node's depth + function targetDepth(d) { + return d.target.depth; + } + + // The depth of a node when the nodeAlign (align) is set to 'left' + function left(node) { + return node.depth; + } + + // The depth of a node when the nodeAlign (align) is set to 'right' + function right(node, n) { + return n - 1 - node.height; + } + + // The depth of a node when the nodeAlign (align) is set to 'justify' + function justify(node, n) { + return node.sourceLinks.length ? node.depth : n - 1; + } + + // The depth of a node when the nodeAlign (align) is set to 'center' + function center(node) { + return node.targetLinks.length ? node.depth : node.sourceLinks.length ? d3Array.min(node.sourceLinks, targetDepth) - 1 : 0; + } + + // returns a function, using the parameter given to the sankey setting + function constant(x) { + return function () { + return x; + }; + } + + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + + /// https://github.com/tomshanley/d3-sankeyCircular-circular + + // sort links' breadth (ie top to bottom in a column), based on their source nodes' breadths + function ascendingSourceBreadth(a, b) { + return ascendingBreadth(a.source, b.source) || a.index - b.index; + } + + // sort links' breadth (ie top to bottom in a column), based on their target nodes' breadths + function ascendingTargetBreadth(a, b) { + return ascendingBreadth(a.target, b.target) || a.index - b.index; + } + + // sort nodes' breadth (ie top to bottom in a column) + // if both nodes have circular links, or both don't have circular links, then sort by the top (y0) of the node + // else push nodes that have top circular links to the top, and nodes that have bottom circular links to the bottom + function ascendingBreadth(a, b) { + if (a.partOfCycle === b.partOfCycle) { + return a.y0 - b.y0; + } else { + if (a.circularLinkType === 'top' || b.circularLinkType === 'bottom') { + return -1; + } else { + return 1; + } + } + } + + // return the value of a node or link + function value(d) { + return d.value; + } + + // return the vertical center of a node + function nodeCenter(node) { + return (node.y0 + node.y1) / 2; + } + + // return the vertical center of a link's source node + function linkSourceCenter(link) { + return nodeCenter(link.source); + } + + // return the vertical center of a link's target node + function linkTargetCenter(link) { + return nodeCenter(link.target); + } + + // Return the default value for ID for node, d.index + function defaultId(d) { + return d.index; + } + + // Return the default object the graph's nodes, graph.nodes + function defaultNodes(graph) { + return graph.nodes; + } + + // Return the default object the graph's nodes, graph.links + function defaultLinks(graph) { + return graph.links; + } + + // Return the node from the collection that matches the provided ID, or throw an error if no match + function find(nodeById, id) { + var node = nodeById.get(id); + if (!node) throw new Error('missing: ' + id); + return node; + } + + function getNodeID(node, id) { + return id(node); + } + + // The main sankeyCircular functions + + // Some constants for circular link calculations + var verticalMargin = 25; + var baseRadius = 10; + var scale = 0.3; //Possibly let user control this, although anything over 0.5 starts to get too cramped + + function sankeyCircular () { + // Set the default values + var x0 = 0, + y0 = 0, + x1 = 1, + y1 = 1, + // extent + dx = 24, + // nodeWidth + py, + // nodePadding, for vertical postioning + id = defaultId, + align = justify, + nodes = defaultNodes, + links = defaultLinks, + iterations = 32, + circularLinkGap = 2, + paddingRatio, + sortNodes = null; + + function sankeyCircular() { + var graph = { + nodes: nodes.apply(null, arguments), + links: links.apply(null, arguments) + + // Process the graph's nodes and links, setting their positions + + // 1. Associate the nodes with their respective links, and vice versa + };computeNodeLinks(graph); + + // 2. Determine which links result in a circular path in the graph + identifyCircles(graph, id, sortNodes); + + // 4. Calculate the nodes' values, based on the values of the incoming and outgoing links + computeNodeValues(graph); + + // 5. Calculate the nodes' depth based on the incoming and outgoing links + // Sets the nodes': + // - depth: the depth in the graph + // - column: the depth (0, 1, 2, etc), as is relates to visual position from left to right + // - x0, x1: the x coordinates, as is relates to visual position from left to right + computeNodeDepths(graph); + + // 3. Determine how the circular links will be drawn, + // either travelling back above the main chart ("top") + // or below the main chart ("bottom") + selectCircularLinkTypes(graph, id); + + // 6. Calculate the nodes' and links' vertical position within their respective column + // Also readjusts sankeyCircular size if circular links are needed, and node x's + computeNodeBreadths(graph, iterations, id); + computeLinkBreadths(graph); + + // 7. Sort links per node, based on the links' source/target nodes' breadths + // 8. Adjust nodes that overlap links that span 2+ columns + var linkSortingIterations = 4; //Possibly let user control this number, like the iterations over node placement + for (var iteration = 0; iteration < linkSortingIterations; iteration++) { + + sortSourceLinks(graph, y1, id); + sortTargetLinks(graph, y1, id); + resolveNodeLinkOverlaps(graph, y0, y1, id); + sortSourceLinks(graph, y1, id); + sortTargetLinks(graph, y1, id); + } + + // 8.1 Adjust node and link positions back to fill height of chart area if compressed + fillHeight(graph, y0, y1); + + // 9. Calculate visually appealling path for the circular paths, and create the "d" string + addCircularPathData(graph, circularLinkGap, y1, id); + + return graph; + } // end of sankeyCircular function + + + // Set the sankeyCircular parameters + // nodeID, nodeAlign, nodeWidth, nodePadding, nodes, links, size, extent, iterations, nodePaddingRatio, circularLinkGap + sankeyCircular.nodeId = function (_) { + return arguments.length ? (id = typeof _ === 'function' ? _ : constant(_), sankeyCircular) : id; + }; + + sankeyCircular.nodeAlign = function (_) { + return arguments.length ? (align = typeof _ === 'function' ? _ : constant(_), sankeyCircular) : align; + }; + + sankeyCircular.nodeWidth = function (_) { + return arguments.length ? (dx = +_, sankeyCircular) : dx; + }; + + sankeyCircular.nodePadding = function (_) { + return arguments.length ? (py = +_, sankeyCircular) : py; + }; + + sankeyCircular.nodes = function (_) { + return arguments.length ? (nodes = typeof _ === 'function' ? _ : constant(_), sankeyCircular) : nodes; + }; + + sankeyCircular.links = function (_) { + return arguments.length ? (links = typeof _ === 'function' ? _ : constant(_), sankeyCircular) : links; + }; + + sankeyCircular.size = function (_) { + return arguments.length ? (x0 = y0 = 0, x1 = +_[0], y1 = +_[1], sankeyCircular) : [x1 - x0, y1 - y0]; + }; + + sankeyCircular.extent = function (_) { + return arguments.length ? (x0 = +_[0][0], x1 = +_[1][0], y0 = +_[0][1], y1 = +_[1][1], sankeyCircular) : [[x0, y0], [x1, y1]]; + }; + + sankeyCircular.iterations = function (_) { + return arguments.length ? (iterations = +_, sankeyCircular) : iterations; + }; + + sankeyCircular.circularLinkGap = function (_) { + return arguments.length ? (circularLinkGap = +_, sankeyCircular) : circularLinkGap; + }; + + sankeyCircular.nodePaddingRatio = function (_) { + return arguments.length ? (paddingRatio = +_, sankeyCircular) : paddingRatio; + }; + + sankeyCircular.sortNodes = function (_) { + return arguments.length ? (sortNodes = _, sankeyCircular) : sortNodes; + }; + + sankeyCircular.update = function (graph) { + // 5. Calculate the nodes' depth based on the incoming and outgoing links + // Sets the nodes': + // - depth: the depth in the graph + // - column: the depth (0, 1, 2, etc), as is relates to visual position from left to right + // - x0, x1: the x coordinates, as is relates to visual position from left to right + // computeNodeDepths(graph) + + // 3. Determine how the circular links will be drawn, + // either travelling back above the main chart ("top") + // or below the main chart ("bottom") + selectCircularLinkTypes(graph, id); + + // 6. Calculate the nodes' and links' vertical position within their respective column + // Also readjusts sankeyCircular size if circular links are needed, and node x's + // computeNodeBreadths(graph, iterations, id) + computeLinkBreadths(graph); + + // Force position of circular link type based on position + graph.links.forEach(function (link) { + if (link.circular) { + link.circularLinkType = link.y0 + link.y1 < y1 ? 'top' : 'bottom'; + + link.source.circularLinkType = link.circularLinkType; + link.target.circularLinkType = link.circularLinkType; + } + }); + + sortSourceLinks(graph, y1, id, false); // Sort links but do not move nodes + sortTargetLinks(graph, y1, id); + + // 7. Sort links per node, based on the links' source/target nodes' breadths + // 8. Adjust nodes that overlap links that span 2+ columns + // var linkSortingIterations = 4; //Possibly let user control this number, like the iterations over node placement + // for (var iteration = 0; iteration < linkSortingIterations; iteration++) { + // + // sortSourceLinks(graph, y1, id) + // sortTargetLinks(graph, y1, id) + // resolveNodeLinkOverlaps(graph, y0, y1, id) + // sortSourceLinks(graph, y1, id) + // sortTargetLinks(graph, y1, id) + // + // } + + // 8.1 Adjust node and link positions back to fill height of chart area if compressed + // fillHeight(graph, y0, y1) + + // 9. Calculate visually appealling path for the circular paths, and create the "d" string + addCircularPathData(graph, circularLinkGap, y1, id); + return graph; + }; + + // Populate the sourceLinks and targetLinks for each node. + // Also, if the source and target are not objects, assume they are indices. + function computeNodeLinks(graph) { + graph.nodes.forEach(function (node, i) { + node.index = i; + node.sourceLinks = []; + node.targetLinks = []; + }); + var nodeById = d3Collection.map(graph.nodes, id); + graph.links.forEach(function (link, i) { + link.index = i; + var source = link.source; + var target = link.target; + if ((typeof source === "undefined" ? "undefined" : _typeof(source)) !== 'object') { + source = link.source = find(nodeById, source); + } + if ((typeof target === "undefined" ? "undefined" : _typeof(target)) !== 'object') { + target = link.target = find(nodeById, target); + } + source.sourceLinks.push(link); + target.targetLinks.push(link); + }); + return graph; + } + + // Compute the value (size) and cycleness of each node by summing the associated links. + function computeNodeValues(graph) { + graph.nodes.forEach(function (node) { + node.partOfCycle = false; + node.value = Math.max(d3Array.sum(node.sourceLinks, value), d3Array.sum(node.targetLinks, value)); + node.sourceLinks.forEach(function (link) { + if (link.circular) { + node.partOfCycle = true; + node.circularLinkType = link.circularLinkType; + } + }); + node.targetLinks.forEach(function (link) { + if (link.circular) { + node.partOfCycle = true; + node.circularLinkType = link.circularLinkType; + } + }); + }); + } + + function getCircleMargins(graph) { + var totalTopLinksWidth = 0, + totalBottomLinksWidth = 0, + totalRightLinksWidth = 0, + totalLeftLinksWidth = 0; + + var maxColumn = d3Array.max(graph.nodes, function (node) { + return node.column; + }); + + graph.links.forEach(function (link) { + if (link.circular) { + if (link.circularLinkType == 'top') { + totalTopLinksWidth = totalTopLinksWidth + link.width; + } else { + totalBottomLinksWidth = totalBottomLinksWidth + link.width; + } + + if (link.target.column == 0) { + totalLeftLinksWidth = totalLeftLinksWidth + link.width; + } + + if (link.source.column == maxColumn) { + totalRightLinksWidth = totalRightLinksWidth + link.width; + } + } + }); + + //account for radius of curves and padding between links + totalTopLinksWidth = totalTopLinksWidth > 0 ? totalTopLinksWidth + verticalMargin + baseRadius : totalTopLinksWidth; + totalBottomLinksWidth = totalBottomLinksWidth > 0 ? totalBottomLinksWidth + verticalMargin + baseRadius : totalBottomLinksWidth; + totalRightLinksWidth = totalRightLinksWidth > 0 ? totalRightLinksWidth + verticalMargin + baseRadius : totalRightLinksWidth; + totalLeftLinksWidth = totalLeftLinksWidth > 0 ? totalLeftLinksWidth + verticalMargin + baseRadius : totalLeftLinksWidth; + + return { "top": totalTopLinksWidth, "bottom": totalBottomLinksWidth, "left": totalLeftLinksWidth, "right": totalRightLinksWidth }; + } + + // Update the x0, y0, x1 and y1 for the sankeyCircular, to allow space for any circular links + function scaleSankeySize(graph, margin) { + + var maxColumn = d3Array.max(graph.nodes, function (node) { + return node.column; + }); + + var currentWidth = x1 - x0; + var currentHeight = y1 - y0; + + var newWidth = currentWidth + margin.right + margin.left; + var newHeight = currentHeight + margin.top + margin.bottom; + + var scaleX = currentWidth / newWidth; + var scaleY = currentHeight / newHeight; + + x0 = x0 * scaleX + margin.left; + x1 = margin.right == 0 ? x1 : x1 * scaleX; + y0 = y0 * scaleY + margin.top; + y1 = y1 * scaleY; + + graph.nodes.forEach(function (node) { + node.x0 = x0 + node.column * ((x1 - x0 - dx) / maxColumn); + node.x1 = node.x0 + dx; + }); + + return scaleY; + } + + // Iteratively assign the depth for each node. + // Nodes are assigned the maximum depth of incoming neighbors plus one; + // nodes with no incoming links are assigned depth zero, while + // nodes with no outgoing links are assigned the maximum depth. + function computeNodeDepths(graph) { + var nodes, next, x; + + for (nodes = graph.nodes, next = [], x = 0; nodes.length; ++x, nodes = next, next = []) { + nodes.forEach(function (node) { + node.depth = x; + node.sourceLinks.forEach(function (link) { + if (next.indexOf(link.target) < 0 && !link.circular) { + next.push(link.target); + } + }); + }); + } + + for (nodes = graph.nodes, next = [], x = 0; nodes.length; ++x, nodes = next, next = []) { + nodes.forEach(function (node) { + node.height = x; + node.targetLinks.forEach(function (link) { + if (next.indexOf(link.source) < 0 && !link.circular) { + next.push(link.source); + } + }); + }); + } + + // assign column numbers, and get max value + graph.nodes.forEach(function (node) { + node.column = Math.floor(align.call(null, node, x)); + }); + } + + // Assign nodes' breadths, and then shift nodes that overlap (resolveCollisions) + function computeNodeBreadths(graph, iterations, id) { + var columns = d3Collection.nest().key(function (d) { + return d.column; + }).sortKeys(d3Array.ascending).entries(graph.nodes).map(function (d) { + return d.values; + }); + + initializeNodeBreadth(id); + resolveCollisions(); + + for (var alpha = 1, n = iterations; n > 0; --n) { + relaxLeftAndRight(alpha *= 0.99, id); + resolveCollisions(); + } + + function initializeNodeBreadth(id) { + + //override py if nodePadding has been set + if (paddingRatio) { + var padding = Infinity; + columns.forEach(function (nodes) { + var thisPadding = y1 * paddingRatio / (nodes.length + 1); + padding = thisPadding < padding ? thisPadding : padding; + }); + py = padding; + } + + var ky = d3Array.min(columns, function (nodes) { + return (y1 - y0 - (nodes.length - 1) * py) / d3Array.sum(nodes, value); + }); + + //calculate the widths of the links + ky = ky * scale; + + graph.links.forEach(function (link) { + link.width = link.value * ky; + }); + + //determine how much to scale down the chart, based on circular links + var margin = getCircleMargins(graph); + var ratio = scaleSankeySize(graph, margin); + + //re-calculate widths + ky = ky * ratio; + + graph.links.forEach(function (link) { + link.width = link.value * ky; + }); + + columns.forEach(function (nodes) { + var nodesLength = nodes.length; + nodes.forEach(function (node, i) { + if (node.depth == columns.length - 1 && nodesLength == 1) { + node.y0 = y1 / 2 - node.value * ky; + node.y1 = node.y0 + node.value * ky; + } else if (node.depth == 0 && nodesLength == 1) { + node.y0 = y1 / 2 - node.value * ky; + node.y1 = node.y0 + node.value * ky; + } else if (node.partOfCycle) { + if (numberOfNonSelfLinkingCycles(node, id) == 0) { + node.y0 = y1 / 2 + i; + node.y1 = node.y0 + node.value * ky; + } else if (node.circularLinkType == 'top') { + node.y0 = y0 + i; + node.y1 = node.y0 + node.value * ky; + } else { + node.y0 = y1 - node.value * ky - i; + node.y1 = node.y0 + node.value * ky; + } + } else { + if (margin.top == 0 || margin.bottom == 0) { + node.y0 = (y1 - y0) / nodesLength * i; + node.y1 = node.y0 + node.value * ky; + } else { + node.y0 = (y1 - y0) / 2 - nodesLength / 2 + i; + node.y1 = node.y0 + node.value * ky; + } + } + }); + }); + } + + // For each node in each column, check the node's vertical position in relation to its targets and sources vertical position + // and shift up/down to be closer to the vertical middle of those targets and sources + function relaxLeftAndRight(alpha, id) { + var columnsLength = columns.length; + + columns.forEach(function (nodes) { + var n = nodes.length; + var depth = nodes[0].depth; + + nodes.forEach(function (node) { + // check the node is not an orphan + var nodeHeight; + if (node.sourceLinks.length || node.targetLinks.length) { + if (node.partOfCycle && numberOfNonSelfLinkingCycles(node, id) > 0) ; else if (depth == 0 && n == 1) { + nodeHeight = node.y1 - node.y0; + + node.y0 = y1 / 2 - nodeHeight / 2; + node.y1 = y1 / 2 + nodeHeight / 2; + } else if (depth == columnsLength - 1 && n == 1) { + nodeHeight = node.y1 - node.y0; + + node.y0 = y1 / 2 - nodeHeight / 2; + node.y1 = y1 / 2 + nodeHeight / 2; + } else { + var avg = 0; + + var avgTargetY = d3Array.mean(node.sourceLinks, linkTargetCenter); + var avgSourceY = d3Array.mean(node.targetLinks, linkSourceCenter); + + if (avgTargetY && avgSourceY) { + avg = (avgTargetY + avgSourceY) / 2; + } else { + avg = avgTargetY || avgSourceY; + } + + var dy = (avg - nodeCenter(node)) * alpha; + // positive if it node needs to move down + node.y0 += dy; + node.y1 += dy; + } + } + }); + }); + } + + // For each column, check if nodes are overlapping, and if so, shift up/down + function resolveCollisions() { + columns.forEach(function (nodes) { + var node, + dy, + y = y0, + n = nodes.length, + i; + + // Push any overlapping nodes down. + nodes.sort(ascendingBreadth); + + for (i = 0; i < n; ++i) { + node = nodes[i]; + dy = y - node.y0; + + if (dy > 0) { + node.y0 += dy; + node.y1 += dy; + } + y = node.y1 + py; + } + + // If the bottommost node goes outside the bounds, push it back up. + dy = y - py - y1; + if (dy > 0) { + y = node.y0 -= dy, node.y1 -= dy; + + // Push any overlapping nodes back up. + for (i = n - 2; i >= 0; --i) { + node = nodes[i]; + dy = node.y1 + py - y; + if (dy > 0) node.y0 -= dy, node.y1 -= dy; + y = node.y0; + } + } + }); + } + } + + // Assign the links y0 and y1 based on source/target nodes position, + // plus the link's relative position to other links to the same node + function computeLinkBreadths(graph) { + graph.nodes.forEach(function (node) { + node.sourceLinks.sort(ascendingTargetBreadth); + node.targetLinks.sort(ascendingSourceBreadth); + }); + graph.nodes.forEach(function (node) { + var y0 = node.y0; + var y1 = y0; + + // start from the bottom of the node for cycle links + var y0cycle = node.y1; + var y1cycle = y0cycle; + + node.sourceLinks.forEach(function (link) { + if (link.circular) { + link.y0 = y0cycle - link.width / 2; + y0cycle = y0cycle - link.width; + } else { + link.y0 = y0 + link.width / 2; + y0 += link.width; + } + }); + node.targetLinks.forEach(function (link) { + if (link.circular) { + link.y1 = y1cycle - link.width / 2; + y1cycle = y1cycle - link.width; + } else { + link.y1 = y1 + link.width / 2; + y1 += link.width; + } + }); + }); + } + + return sankeyCircular; + } + + /// ///////////////////////////////////////////////////////////////////////////////// + // Cycle functions + // portion of code to detect circular links based on Colin Fergus' bl.ock https://gist.github.com/cfergus/3956043 + + // Identify circles in the link objects + function identifyCircles(graph, id, sortNodes) { + var circularLinkID = 0; + if (sortNodes === null) { + + // Building adjacency graph + var adjList = []; + for (var i = 0; i < graph.links.length; i++) { + var link = graph.links[i]; + var source = link.source.index; + var target = link.target.index; + if (!adjList[source]) adjList[source] = []; + if (!adjList[target]) adjList[target] = []; + + // Add links if not already in set + if (adjList[source].indexOf(target) === -1) adjList[source].push(target); + } + + // Find all elementary circuits + var cycles = findCircuits(adjList); + + // Sort by circuits length + cycles.sort(function (a, b) { + return a.length - b.length; + }); + + var circularLinks = {}; + for (i = 0; i < cycles.length; i++) { + var cycle = cycles[i]; + var last = cycle.slice(-2); + if (!circularLinks[last[0]]) circularLinks[last[0]] = {}; + circularLinks[last[0]][last[1]] = true; + } + + graph.links.forEach(function (link) { + var target = link.target.index; + var source = link.source.index; + // If self-linking or a back-edge + if (target === source || circularLinks[source] && circularLinks[source][target]) { + link.circular = true; + link.circularLinkID = circularLinkID; + circularLinkID = circularLinkID + 1; + } else { + link.circular = false; + } + }); + } else { + graph.links.forEach(function (link) { + if (link.source[sortNodes] < link.target[sortNodes]) { + link.circular = false; + } else { + link.circular = true; + link.circularLinkID = circularLinkID; + circularLinkID = circularLinkID + 1; + } + }); + } + } + + // Assign a circular link type (top or bottom), based on: + // - if the source/target node already has circular links, then use the same type + // - if not, choose the type with fewer links + function selectCircularLinkTypes(graph, id) { + var numberOfTops = 0; + var numberOfBottoms = 0; + graph.links.forEach(function (link) { + if (link.circular) { + // if either souce or target has type already use that + if (link.source.circularLinkType || link.target.circularLinkType) { + // default to source type if available + link.circularLinkType = link.source.circularLinkType ? link.source.circularLinkType : link.target.circularLinkType; + } else { + link.circularLinkType = numberOfTops < numberOfBottoms ? 'top' : 'bottom'; + } + + if (link.circularLinkType == 'top') { + numberOfTops = numberOfTops + 1; + } else { + numberOfBottoms = numberOfBottoms + 1; + } + + graph.nodes.forEach(function (node) { + if (getNodeID(node, id) == getNodeID(link.source, id) || getNodeID(node, id) == getNodeID(link.target, id)) { + node.circularLinkType = link.circularLinkType; + } + }); + } + }); + + //correct self-linking links to be same direction as node + graph.links.forEach(function (link) { + if (link.circular) { + //if both source and target node are same type, then link should have same type + if (link.source.circularLinkType == link.target.circularLinkType) { + link.circularLinkType = link.source.circularLinkType; + } + //if link is selflinking, then link should have same type as node + if (selfLinking(link, id)) { + link.circularLinkType = link.source.circularLinkType; + } + } + }); + } + + // Return the angle between a straight line between the source and target of the link, and the vertical plane of the node + function linkAngle(link) { + var adjacent = Math.abs(link.y1 - link.y0); + var opposite = Math.abs(link.target.x0 - link.source.x1); + + return Math.atan(opposite / adjacent); + } + + // Check if two circular links potentially overlap + function circularLinksCross(link1, link2) { + if (link1.source.column < link2.target.column) { + return false; + } else if (link1.target.column > link2.source.column) { + return false; + } else { + return true; + } + } + + // Return the number of circular links for node, not including self linking links + function numberOfNonSelfLinkingCycles(node, id) { + var sourceCount = 0; + node.sourceLinks.forEach(function (l) { + sourceCount = l.circular && !selfLinking(l, id) ? sourceCount + 1 : sourceCount; + }); + + var targetCount = 0; + node.targetLinks.forEach(function (l) { + targetCount = l.circular && !selfLinking(l, id) ? targetCount + 1 : targetCount; + }); + + return sourceCount + targetCount; + } + + // Check if a circular link is the only circular link for both its source and target node + function onlyCircularLink(link) { + var nodeSourceLinks = link.source.sourceLinks; + var sourceCount = 0; + nodeSourceLinks.forEach(function (l) { + sourceCount = l.circular ? sourceCount + 1 : sourceCount; + }); + + var nodeTargetLinks = link.target.targetLinks; + var targetCount = 0; + nodeTargetLinks.forEach(function (l) { + targetCount = l.circular ? targetCount + 1 : targetCount; + }); + + if (sourceCount > 1 || targetCount > 1) { + return false; + } else { + return true; + } + } + + // creates vertical buffer values per set of top/bottom links + function calcVerticalBuffer(links, circularLinkGap, id) { + links.sort(sortLinkColumnAscending); + links.forEach(function (link, i) { + var buffer = 0; + + if (selfLinking(link, id) && onlyCircularLink(link)) { + link.circularPathData.verticalBuffer = buffer + link.width / 2; + } else { + var j = 0; + for (j; j < i; j++) { + if (circularLinksCross(links[i], links[j])) { + var bufferOverThisLink = links[j].circularPathData.verticalBuffer + links[j].width / 2 + circularLinkGap; + buffer = bufferOverThisLink > buffer ? bufferOverThisLink : buffer; + } + } + + link.circularPathData.verticalBuffer = buffer + link.width / 2; + } + }); + + return links; + } + + // calculate the optimum path for a link to reduce overlaps + function addCircularPathData(graph, circularLinkGap, y1, id) { + //var baseRadius = 10 + var buffer = 5; + //var verticalMargin = 25 + + var minY = d3Array.min(graph.links, function (link) { + return link.source.y0; + }); + + // create object for circular Path Data + graph.links.forEach(function (link) { + if (link.circular) { + link.circularPathData = {}; + } + }); + + // calc vertical offsets per top/bottom links + var topLinks = graph.links.filter(function (l) { + return l.circularLinkType == 'top'; + }); + /* topLinks = */calcVerticalBuffer(topLinks, circularLinkGap, id); + + var bottomLinks = graph.links.filter(function (l) { + return l.circularLinkType == 'bottom'; + }); + /* bottomLinks = */calcVerticalBuffer(bottomLinks, circularLinkGap, id); + + // add the base data for each link + graph.links.forEach(function (link) { + if (link.circular) { + link.circularPathData.arcRadius = link.width + baseRadius; + link.circularPathData.leftNodeBuffer = buffer; + link.circularPathData.rightNodeBuffer = buffer; + link.circularPathData.sourceWidth = link.source.x1 - link.source.x0; + link.circularPathData.sourceX = link.source.x0 + link.circularPathData.sourceWidth; + link.circularPathData.targetX = link.target.x0; + link.circularPathData.sourceY = link.y0; + link.circularPathData.targetY = link.y1; + + // for self linking paths, and that the only circular link in/out of that node + if (selfLinking(link, id) && onlyCircularLink(link)) { + link.circularPathData.leftSmallArcRadius = baseRadius + link.width / 2; + link.circularPathData.leftLargeArcRadius = baseRadius + link.width / 2; + link.circularPathData.rightSmallArcRadius = baseRadius + link.width / 2; + link.circularPathData.rightLargeArcRadius = baseRadius + link.width / 2; + + if (link.circularLinkType == 'bottom') { + link.circularPathData.verticalFullExtent = link.source.y1 + verticalMargin + link.circularPathData.verticalBuffer; + link.circularPathData.verticalLeftInnerExtent = link.circularPathData.verticalFullExtent - link.circularPathData.leftLargeArcRadius; + link.circularPathData.verticalRightInnerExtent = link.circularPathData.verticalFullExtent - link.circularPathData.rightLargeArcRadius; + } else { + // top links + link.circularPathData.verticalFullExtent = link.source.y0 - verticalMargin - link.circularPathData.verticalBuffer; + link.circularPathData.verticalLeftInnerExtent = link.circularPathData.verticalFullExtent + link.circularPathData.leftLargeArcRadius; + link.circularPathData.verticalRightInnerExtent = link.circularPathData.verticalFullExtent + link.circularPathData.rightLargeArcRadius; + } + } else { + // else calculate normally + // add left extent coordinates, based on links with same source column and circularLink type + var thisColumn = link.source.column; + var thisCircularLinkType = link.circularLinkType; + var sameColumnLinks = graph.links.filter(function (l) { + return l.source.column == thisColumn && l.circularLinkType == thisCircularLinkType; + }); + + if (link.circularLinkType == 'bottom') { + sameColumnLinks.sort(sortLinkSourceYDescending); + } else { + sameColumnLinks.sort(sortLinkSourceYAscending); + } + + var radiusOffset = 0; + sameColumnLinks.forEach(function (l, i) { + if (l.circularLinkID == link.circularLinkID) { + link.circularPathData.leftSmallArcRadius = baseRadius + link.width / 2 + radiusOffset; + link.circularPathData.leftLargeArcRadius = baseRadius + link.width / 2 + i * circularLinkGap + radiusOffset; + } + radiusOffset = radiusOffset + l.width; + }); + + // add right extent coordinates, based on links with same target column and circularLink type + thisColumn = link.target.column; + sameColumnLinks = graph.links.filter(function (l) { + return l.target.column == thisColumn && l.circularLinkType == thisCircularLinkType; + }); + if (link.circularLinkType == 'bottom') { + sameColumnLinks.sort(sortLinkTargetYDescending); + } else { + sameColumnLinks.sort(sortLinkTargetYAscending); + } + + radiusOffset = 0; + sameColumnLinks.forEach(function (l, i) { + if (l.circularLinkID == link.circularLinkID) { + link.circularPathData.rightSmallArcRadius = baseRadius + link.width / 2 + radiusOffset; + link.circularPathData.rightLargeArcRadius = baseRadius + link.width / 2 + i * circularLinkGap + radiusOffset; + } + radiusOffset = radiusOffset + l.width; + }); + + // bottom links + if (link.circularLinkType == 'bottom') { + link.circularPathData.verticalFullExtent = Math.max(y1, link.source.y1, link.target.y1) + verticalMargin + link.circularPathData.verticalBuffer; + link.circularPathData.verticalLeftInnerExtent = link.circularPathData.verticalFullExtent - link.circularPathData.leftLargeArcRadius; + link.circularPathData.verticalRightInnerExtent = link.circularPathData.verticalFullExtent - link.circularPathData.rightLargeArcRadius; + } else { + // top links + link.circularPathData.verticalFullExtent = minY - verticalMargin - link.circularPathData.verticalBuffer; + link.circularPathData.verticalLeftInnerExtent = link.circularPathData.verticalFullExtent + link.circularPathData.leftLargeArcRadius; + link.circularPathData.verticalRightInnerExtent = link.circularPathData.verticalFullExtent + link.circularPathData.rightLargeArcRadius; + } + } + + // all links + link.circularPathData.leftInnerExtent = link.circularPathData.sourceX + link.circularPathData.leftNodeBuffer; + link.circularPathData.rightInnerExtent = link.circularPathData.targetX - link.circularPathData.rightNodeBuffer; + link.circularPathData.leftFullExtent = link.circularPathData.sourceX + link.circularPathData.leftLargeArcRadius + link.circularPathData.leftNodeBuffer; + link.circularPathData.rightFullExtent = link.circularPathData.targetX - link.circularPathData.rightLargeArcRadius - link.circularPathData.rightNodeBuffer; + } + + if (link.circular) { + link.path = createCircularPathString(link); + } else { + var normalPath = d3Shape.linkHorizontal().source(function (d) { + var x = d.source.x0 + (d.source.x1 - d.source.x0); + var y = d.y0; + return [x, y]; + }).target(function (d) { + var x = d.target.x0; + var y = d.y1; + return [x, y]; + }); + link.path = normalPath(link); + } + }); + } + + // create a d path using the addCircularPathData + function createCircularPathString(link) { + var pathString = ''; + // 'pathData' is assigned a value but never used + // var pathData = {} + + if (link.circularLinkType == 'top') { + pathString = + // start at the right of the source node + 'M' + link.circularPathData.sourceX + ' ' + link.circularPathData.sourceY + ' ' + + // line right to buffer point + 'L' + link.circularPathData.leftInnerExtent + ' ' + link.circularPathData.sourceY + ' ' + + // Arc around: Centre of arc X and //Centre of arc Y + 'A' + link.circularPathData.leftLargeArcRadius + ' ' + link.circularPathData.leftSmallArcRadius + ' 0 0 0 ' + + // End of arc X //End of arc Y + link.circularPathData.leftFullExtent + ' ' + (link.circularPathData.sourceY - link.circularPathData.leftSmallArcRadius) + ' ' + // End of arc X + // line up to buffer point + 'L' + link.circularPathData.leftFullExtent + ' ' + link.circularPathData.verticalLeftInnerExtent + ' ' + + // Arc around: Centre of arc X and //Centre of arc Y + 'A' + link.circularPathData.leftLargeArcRadius + ' ' + link.circularPathData.leftLargeArcRadius + ' 0 0 0 ' + + // End of arc X //End of arc Y + link.circularPathData.leftInnerExtent + ' ' + link.circularPathData.verticalFullExtent + ' ' + // End of arc X + // line left to buffer point + 'L' + link.circularPathData.rightInnerExtent + ' ' + link.circularPathData.verticalFullExtent + ' ' + + // Arc around: Centre of arc X and //Centre of arc Y + 'A' + link.circularPathData.rightLargeArcRadius + ' ' + link.circularPathData.rightLargeArcRadius + ' 0 0 0 ' + + // End of arc X //End of arc Y + link.circularPathData.rightFullExtent + ' ' + link.circularPathData.verticalRightInnerExtent + ' ' + // End of arc X + // line down + 'L' + link.circularPathData.rightFullExtent + ' ' + (link.circularPathData.targetY - link.circularPathData.rightSmallArcRadius) + ' ' + + // Arc around: Centre of arc X and //Centre of arc Y + 'A' + link.circularPathData.rightLargeArcRadius + ' ' + link.circularPathData.rightSmallArcRadius + ' 0 0 0 ' + + // End of arc X //End of arc Y + link.circularPathData.rightInnerExtent + ' ' + link.circularPathData.targetY + ' ' + // End of arc X + // line to end + 'L' + link.circularPathData.targetX + ' ' + link.circularPathData.targetY; + } else { + // bottom path + pathString = + // start at the right of the source node + 'M' + link.circularPathData.sourceX + ' ' + link.circularPathData.sourceY + ' ' + + // line right to buffer point + 'L' + link.circularPathData.leftInnerExtent + ' ' + link.circularPathData.sourceY + ' ' + + // Arc around: Centre of arc X and //Centre of arc Y + 'A' + link.circularPathData.leftLargeArcRadius + ' ' + link.circularPathData.leftSmallArcRadius + ' 0 0 1 ' + + // End of arc X //End of arc Y + link.circularPathData.leftFullExtent + ' ' + (link.circularPathData.sourceY + link.circularPathData.leftSmallArcRadius) + ' ' + // End of arc X + // line down to buffer point + 'L' + link.circularPathData.leftFullExtent + ' ' + link.circularPathData.verticalLeftInnerExtent + ' ' + + // Arc around: Centre of arc X and //Centre of arc Y + 'A' + link.circularPathData.leftLargeArcRadius + ' ' + link.circularPathData.leftLargeArcRadius + ' 0 0 1 ' + + // End of arc X //End of arc Y + link.circularPathData.leftInnerExtent + ' ' + link.circularPathData.verticalFullExtent + ' ' + // End of arc X + // line left to buffer point + 'L' + link.circularPathData.rightInnerExtent + ' ' + link.circularPathData.verticalFullExtent + ' ' + + // Arc around: Centre of arc X and //Centre of arc Y + 'A' + link.circularPathData.rightLargeArcRadius + ' ' + link.circularPathData.rightLargeArcRadius + ' 0 0 1 ' + + // End of arc X //End of arc Y + link.circularPathData.rightFullExtent + ' ' + link.circularPathData.verticalRightInnerExtent + ' ' + // End of arc X + // line up + 'L' + link.circularPathData.rightFullExtent + ' ' + (link.circularPathData.targetY + link.circularPathData.rightSmallArcRadius) + ' ' + + // Arc around: Centre of arc X and //Centre of arc Y + 'A' + link.circularPathData.rightLargeArcRadius + ' ' + link.circularPathData.rightSmallArcRadius + ' 0 0 1 ' + + // End of arc X //End of arc Y + link.circularPathData.rightInnerExtent + ' ' + link.circularPathData.targetY + ' ' + // End of arc X + // line to end + 'L' + link.circularPathData.targetX + ' ' + link.circularPathData.targetY; + } + + return pathString; + } + + // sort links based on the distance between the source and tartget node columns + // if the same, then use Y position of the source node + function sortLinkColumnAscending(link1, link2) { + if (linkColumnDistance(link1) == linkColumnDistance(link2)) { + return link1.circularLinkType == 'bottom' ? sortLinkSourceYDescending(link1, link2) : sortLinkSourceYAscending(link1, link2); + } else { + return linkColumnDistance(link2) - linkColumnDistance(link1); + } + } + + // sort ascending links by their source vertical position, y0 + function sortLinkSourceYAscending(link1, link2) { + return link1.y0 - link2.y0; + } + + // sort descending links by their source vertical position, y0 + function sortLinkSourceYDescending(link1, link2) { + return link2.y0 - link1.y0; + } + + // sort ascending links by their target vertical position, y1 + function sortLinkTargetYAscending(link1, link2) { + return link1.y1 - link2.y1; + } + + // sort descending links by their target vertical position, y1 + function sortLinkTargetYDescending(link1, link2) { + return link2.y1 - link1.y1; + } + + // return the distance between the link's target and source node, in terms of the nodes' column + function linkColumnDistance(link) { + return link.target.column - link.source.column; + } + + // return the distance between the link's target and source node, in terms of the nodes' X coordinate + function linkXLength(link) { + return link.target.x0 - link.source.x1; + } + + // Return the Y coordinate on the longerLink path * which is perpendicular shorterLink's source. + // * approx, based on a straight line from target to source, when in fact the path is a bezier + function linkPerpendicularYToLinkSource(longerLink, shorterLink) { + // get the angle for the longer link + var angle = linkAngle(longerLink); + + // get the adjacent length to the other link's x position + var heightFromY1ToPependicular = linkXLength(shorterLink) / Math.tan(angle); + + // add or subtract from longer link1's original y1, depending on the slope + var yPerpendicular = incline(longerLink) == 'up' ? longerLink.y1 + heightFromY1ToPependicular : longerLink.y1 - heightFromY1ToPependicular; + + return yPerpendicular; + } + + // Return the Y coordinate on the longerLink path * which is perpendicular shorterLink's source. + // * approx, based on a straight line from target to source, when in fact the path is a bezier + function linkPerpendicularYToLinkTarget(longerLink, shorterLink) { + // get the angle for the longer link + var angle = linkAngle(longerLink); + + // get the adjacent length to the other link's x position + var heightFromY1ToPependicular = linkXLength(shorterLink) / Math.tan(angle); + + // add or subtract from longer link's original y1, depending on the slope + var yPerpendicular = incline(longerLink) == 'up' ? longerLink.y1 - heightFromY1ToPependicular : longerLink.y1 + heightFromY1ToPependicular; + + return yPerpendicular; + } + + // Move any nodes that overlap links which span 2+ columns + function resolveNodeLinkOverlaps(graph, y0, y1, id) { + + graph.links.forEach(function (link) { + if (link.circular) { + return; + } + + if (link.target.column - link.source.column > 1) { + var columnToTest = link.source.column + 1; + var maxColumnToTest = link.target.column - 1; + + var i = 1; + var numberOfColumnsToTest = maxColumnToTest - columnToTest + 1; + + for (i = 1; columnToTest <= maxColumnToTest; columnToTest++, i++) { + graph.nodes.forEach(function (node) { + if (node.column == columnToTest) { + var t = i / (numberOfColumnsToTest + 1); + + // Find all the points of a cubic bezier curve in javascript + // https://stackoverflow.com/questions/15397596/find-all-the-points-of-a-cubic-bezier-curve-in-javascript + + var B0_t = Math.pow(1 - t, 3); + var B1_t = 3 * t * Math.pow(1 - t, 2); + var B2_t = 3 * Math.pow(t, 2) * (1 - t); + var B3_t = Math.pow(t, 3); + + var py_t = B0_t * link.y0 + B1_t * link.y0 + B2_t * link.y1 + B3_t * link.y1; + + var linkY0AtColumn = py_t - link.width / 2; + var linkY1AtColumn = py_t + link.width / 2; + var dy; + + // If top of link overlaps node, push node up + if (linkY0AtColumn > node.y0 && linkY0AtColumn < node.y1) { + + dy = node.y1 - linkY0AtColumn + 10; + dy = node.circularLinkType == 'bottom' ? dy : -dy; + + node = adjustNodeHeight(node, dy, y0, y1); + + // check if other nodes need to move up too + graph.nodes.forEach(function (otherNode) { + // don't need to check itself or nodes at different columns + if (getNodeID(otherNode, id) == getNodeID(node, id) || otherNode.column != node.column) { + return; + } + if (nodesOverlap(node, otherNode)) { + adjustNodeHeight(otherNode, dy, y0, y1); + } + }); + } else if (linkY1AtColumn > node.y0 && linkY1AtColumn < node.y1) { + // If bottom of link overlaps node, push node down + dy = linkY1AtColumn - node.y0 + 10; + + node = adjustNodeHeight(node, dy, y0, y1); + + // check if other nodes need to move down too + graph.nodes.forEach(function (otherNode) { + // don't need to check itself or nodes at different columns + if (getNodeID(otherNode, id) == getNodeID(node, id) || otherNode.column != node.column) { + return; + } + if (otherNode.y0 < node.y1 && otherNode.y1 > node.y1) { + adjustNodeHeight(otherNode, dy, y0, y1); + } + }); + } else if (linkY0AtColumn < node.y0 && linkY1AtColumn > node.y1) { + // if link completely overlaps node + dy = linkY1AtColumn - node.y0 + 10; + + node = adjustNodeHeight(node, dy, y0, y1); + + graph.nodes.forEach(function (otherNode) { + // don't need to check itself or nodes at different columns + if (getNodeID(otherNode, id) == getNodeID(node, id) || otherNode.column != node.column) { + return; + } + if (otherNode.y0 < node.y1 && otherNode.y1 > node.y1) { + adjustNodeHeight(otherNode, dy, y0, y1); + } + }); + } + } + }); + } + } + }); + } + + // check if two nodes overlap + function nodesOverlap(nodeA, nodeB) { + // test if nodeA top partially overlaps nodeB + if (nodeA.y0 > nodeB.y0 && nodeA.y0 < nodeB.y1) { + return true; + } else if (nodeA.y1 > nodeB.y0 && nodeA.y1 < nodeB.y1) { + // test if nodeA bottom partially overlaps nodeB + return true; + } else if (nodeA.y0 < nodeB.y0 && nodeA.y1 > nodeB.y1) { + // test if nodeA covers nodeB + return true; + } else { + return false; + } + } + + // update a node, and its associated links, vertical positions (y0, y1) + function adjustNodeHeight(node, dy, sankeyY0, sankeyY1) { + if (node.y0 + dy >= sankeyY0 && node.y1 + dy <= sankeyY1) { + node.y0 = node.y0 + dy; + node.y1 = node.y1 + dy; + + node.targetLinks.forEach(function (l) { + l.y1 = l.y1 + dy; + }); + + node.sourceLinks.forEach(function (l) { + l.y0 = l.y0 + dy; + }); + } + return node; + } + + // sort and set the links' y0 for each node + function sortSourceLinks(graph, y1, id, moveNodes) { + graph.nodes.forEach(function (node) { + // move any nodes up which are off the bottom + if (moveNodes && node.y + (node.y1 - node.y0) > y1) { + node.y = node.y - (node.y + (node.y1 - node.y0) - y1); + } + + var nodesSourceLinks = graph.links.filter(function (l) { + return getNodeID(l.source, id) == getNodeID(node, id); + }); + + var nodeSourceLinksLength = nodesSourceLinks.length; + + // if more than 1 link then sort + if (nodeSourceLinksLength > 1) { + nodesSourceLinks.sort(function (link1, link2) { + // if both are not circular... + if (!link1.circular && !link2.circular) { + // if the target nodes are the same column, then sort by the link's target y + if (link1.target.column == link2.target.column) { + return link1.y1 - link2.y1; + } else if (!sameInclines(link1, link2)) { + // if the links slope in different directions, then sort by the link's target y + return link1.y1 - link2.y1; + + // if the links slope in same directions, then sort by any overlap + } else { + if (link1.target.column > link2.target.column) { + var link2Adj = linkPerpendicularYToLinkTarget(link2, link1); + return link1.y1 - link2Adj; + } + if (link2.target.column > link1.target.column) { + var link1Adj = linkPerpendicularYToLinkTarget(link1, link2); + return link1Adj - link2.y1; + } + } + } + + // if only one is circular, the move top links up, or bottom links down + if (link1.circular && !link2.circular) { + return link1.circularLinkType == 'top' ? -1 : 1; + } else if (link2.circular && !link1.circular) { + return link2.circularLinkType == 'top' ? 1 : -1; + } + + // if both links are circular... + if (link1.circular && link2.circular) { + // ...and they both loop the same way (both top) + if (link1.circularLinkType === link2.circularLinkType && link1.circularLinkType == 'top') { + // ...and they both connect to a target with same column, then sort by the target's y + if (link1.target.column === link2.target.column) { + return link1.target.y1 - link2.target.y1; + } else { + // ...and they connect to different column targets, then sort by how far back they + return link2.target.column - link1.target.column; + } + } else if (link1.circularLinkType === link2.circularLinkType && link1.circularLinkType == 'bottom') { + // ...and they both loop the same way (both bottom) + // ...and they both connect to a target with same column, then sort by the target's y + if (link1.target.column === link2.target.column) { + return link2.target.y1 - link1.target.y1; + } else { + // ...and they connect to different column targets, then sort by how far back they + return link1.target.column - link2.target.column; + } + } else { + // ...and they loop around different ways, the move top up and bottom down + return link1.circularLinkType == 'top' ? -1 : 1; + } + } + }); + } + + // update y0 for links + var ySourceOffset = node.y0; + + nodesSourceLinks.forEach(function (link) { + link.y0 = ySourceOffset + link.width / 2; + ySourceOffset = ySourceOffset + link.width; + }); + + // correct any circular bottom links so they are at the bottom of the node + nodesSourceLinks.forEach(function (link, i) { + if (link.circularLinkType == 'bottom') { + var j = i + 1; + var offsetFromBottom = 0; + // sum the widths of any links that are below this link + for (j; j < nodeSourceLinksLength; j++) { + offsetFromBottom = offsetFromBottom + nodesSourceLinks[j].width; + } + link.y0 = node.y1 - offsetFromBottom - link.width / 2; + } + }); + }); + } + + // sort and set the links' y1 for each node + function sortTargetLinks(graph, y1, id) { + graph.nodes.forEach(function (node) { + var nodesTargetLinks = graph.links.filter(function (l) { + return getNodeID(l.target, id) == getNodeID(node, id); + }); + + var nodesTargetLinksLength = nodesTargetLinks.length; + + if (nodesTargetLinksLength > 1) { + nodesTargetLinks.sort(function (link1, link2) { + // if both are not circular, the base on the source y position + if (!link1.circular && !link2.circular) { + if (link1.source.column == link2.source.column) { + return link1.y0 - link2.y0; + } else if (!sameInclines(link1, link2)) { + return link1.y0 - link2.y0; + } else { + // get the angle of the link to the further source node (ie the smaller column) + if (link2.source.column < link1.source.column) { + var link2Adj = linkPerpendicularYToLinkSource(link2, link1); + + return link1.y0 - link2Adj; + } + if (link1.source.column < link2.source.column) { + var link1Adj = linkPerpendicularYToLinkSource(link1, link2); + + return link1Adj - link2.y0; + } + } + } + + // if only one is circular, the move top links up, or bottom links down + if (link1.circular && !link2.circular) { + return link1.circularLinkType == 'top' ? -1 : 1; + } else if (link2.circular && !link1.circular) { + return link2.circularLinkType == 'top' ? 1 : -1; + } + + // if both links are circular... + if (link1.circular && link2.circular) { + // ...and they both loop the same way (both top) + if (link1.circularLinkType === link2.circularLinkType && link1.circularLinkType == 'top') { + // ...and they both connect to a target with same column, then sort by the target's y + if (link1.source.column === link2.source.column) { + return link1.source.y1 - link2.source.y1; + } else { + // ...and they connect to different column targets, then sort by how far back they + return link1.source.column - link2.source.column; + } + } else if (link1.circularLinkType === link2.circularLinkType && link1.circularLinkType == 'bottom') { + // ...and they both loop the same way (both bottom) + // ...and they both connect to a target with same column, then sort by the target's y + if (link1.source.column === link2.source.column) { + return link1.source.y1 - link2.source.y1; + } else { + // ...and they connect to different column targets, then sort by how far back they + return link2.source.column - link1.source.column; + } + } else { + // ...and they loop around different ways, the move top up and bottom down + return link1.circularLinkType == 'top' ? -1 : 1; + } + } + }); + } + + // update y1 for links + var yTargetOffset = node.y0; + + nodesTargetLinks.forEach(function (link) { + link.y1 = yTargetOffset + link.width / 2; + yTargetOffset = yTargetOffset + link.width; + }); + + // correct any circular bottom links so they are at the bottom of the node + nodesTargetLinks.forEach(function (link, i) { + if (link.circularLinkType == 'bottom') { + var j = i + 1; + var offsetFromBottom = 0; + // sum the widths of any links that are below this link + for (j; j < nodesTargetLinksLength; j++) { + offsetFromBottom = offsetFromBottom + nodesTargetLinks[j].width; + } + link.y1 = node.y1 - offsetFromBottom - link.width / 2; + } + }); + }); + } + + // test if links both slope up, or both slope down + function sameInclines(link1, link2) { + return incline(link1) == incline(link2); + } + + // returns the slope of a link, from source to target + // up => slopes up from source to target + // down => slopes down from source to target + function incline(link) { + return link.y0 - link.y1 > 0 ? 'up' : 'down'; + } + + // check if link is self linking, ie links a node to the same node + function selfLinking(link, id) { + return getNodeID(link.source, id) == getNodeID(link.target, id); + } + + function fillHeight(graph, y0, y1) { + + var nodes = graph.nodes; + var links = graph.links; + + var top = false; + var bottom = false; + + links.forEach(function (link) { + if (link.circularLinkType == "top") { + top = true; + } else if (link.circularLinkType == "bottom") { + bottom = true; + } + }); + + if (top == false || bottom == false) { + var minY0 = d3Array.min(nodes, function (node) { + return node.y0; + }); + var maxY1 = d3Array.max(nodes, function (node) { + return node.y1; + }); + var currentHeight = maxY1 - minY0; + var chartHeight = y1 - y0; + var ratio = chartHeight / currentHeight; + + nodes.forEach(function (node) { + var nodeHeight = (node.y1 - node.y0) * ratio; + node.y0 = (node.y0 - minY0) * ratio; + node.y1 = node.y0 + nodeHeight; + }); + + links.forEach(function (link) { + link.y0 = (link.y0 - minY0) * ratio; + link.y1 = (link.y1 - minY0) * ratio; + link.width = link.width * ratio; + }); + } + } + + exports.sankeyCircular = sankeyCircular; + exports.sankeyCenter = center; + exports.sankeyLeft = left; + exports.sankeyRight = right; + exports.sankeyJustify = justify; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}))); diff --git a/node_modules/@plotly/d3-sankey-circular/package.json b/node_modules/@plotly/d3-sankey-circular/package.json new file mode 100644 index 0000000000000000000000000000000000000000..7270f88a6049197f450ccdb289383e134ddc94e1 --- /dev/null +++ b/node_modules/@plotly/d3-sankey-circular/package.json @@ -0,0 +1,65 @@ +{ + "name": "@plotly/d3-sankey-circular", + "version": "0.33.1", + "description": "D3 sankey with circular links", + "author": "Tom Shanley", + "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/plotly/d3-sankey-circular.git" + }, + "main": "dist/d3-sankey-circular.js", + "module": "dist/d3-sankey-circular.es.js", + "dependencies": { + "d3-array": "^1.2.1", + "d3-collection": "^1.0.4", + "d3-shape": "^1.2.0", + "elementary-circuits-directed-graph": "^1.0.4" + }, + "devDependencies": { + "babel-cli": "^6.26.0", + "babel-plugin-external-helpers": "^6.22.0", + "babel-preset-env": "^1.7.0", + "babelrc-rollup": "^3.0.0", + "derequire": "^2.0.6", + "eslint": "^4.19.1", + "mkdirp": "^0.5.1", + "rimraf": "^2.6.2", + "rollup": "^0.59.4", + "rollup-plugin-babel": "^3.0.4", + "rollup-plugin-commonjs": "^9.1.3", + "rollup-plugin-node-resolve": "^3.3.0", + "uglify-js": "^3.1.3" + }, + "babel": { + "presets": [ + [ + "env", + { + "targets": { + "node": "current" + } + } + ] + ] + }, + "scripts": { + "clean": "rimraf dist && mkdirp dist", + "build": "rollup -c", + "build:watch": "rollup -c -w", + "build:clean": "npm run clean && npm run build", + "prepare": "npm run build:clean", + "lint": "./node_modules/.bin/eslint src/", + "lint:fix": "./node_modules/.bin/eslint src/ --fix" + }, + "files": [ + "dist" + ], + "keywords": [ + "d3" + ], + "bugs": { + "url": "https://github.com/tomshanley/d3-sankey-circular/issues" + }, + "homepage": "https://github.com/tomshanley/d3-sankey-circular#readme" +} diff --git a/node_modules/@plotly/d3-sankey/.eslintrc b/node_modules/@plotly/d3-sankey/.eslintrc new file mode 100644 index 0000000000000000000000000000000000000000..affd3f68ab1e3077bbcc59024b46a56e7415d0c7 --- /dev/null +++ b/node_modules/@plotly/d3-sankey/.eslintrc @@ -0,0 +1,5 @@ +parserOptions: + sourceType: "module" + +extends: + "eslint:recommended" diff --git a/node_modules/@plotly/d3-sankey/LICENSE b/node_modules/@plotly/d3-sankey/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..77d73f7ca8c435096f0d73b874d73d02a9763b16 --- /dev/null +++ b/node_modules/@plotly/d3-sankey/LICENSE @@ -0,0 +1,27 @@ +Copyright 2015, Mike Bostock +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* 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. + +* Neither the name of the author nor the names of 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. diff --git a/node_modules/@plotly/d3-sankey/README.md b/node_modules/@plotly/d3-sankey/README.md new file mode 100644 index 0000000000000000000000000000000000000000..3ea3f26d68f7042290256e2c13266b821a3afe38 --- /dev/null +++ b/node_modules/@plotly/d3-sankey/README.md @@ -0,0 +1,238 @@ +# d3-sankey + +Sankey diagrams visualize the directed flow between nodes in an acyclic network. For example, this diagram shows a possible scenario of UK energy production and consumption in 2050: + +[Sankey diagram](https://bl.ocks.org/mbostock/ca9a0bb7ba204d12974bca90acc507c0) + +Source: Department of Energy & Climate Change, Tom Counsell. + +## Installing + +If you use NPM, `npm install d3-sankey`. Otherwise, download the [latest release](https://github.com/d3/d3-sankey/releases/latest). You can also load directly from [unpkg.com](https://unpkg.com/d3-sankey/). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported: + +```html + + + + + + +``` + +## API Reference + +# d3.sankey() [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L52 "Source") + +Constructs a new Sankey generator with the default settings. + +# sankey(arguments…) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L62 "Source") + +Computes the node and link positions for the given *arguments*, returning a *graph* representing the Sankey layout. The returned *graph* has the following properties: + +* *graph*.nodes - the array of [nodes](#sankey_nodes) +* *graph*.links - the array of [links](#sankey_links) + +# sankey.update(graph) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L72 "Source") + +Recomputes the specified *graph*’s links’ positions, updating the following properties of each *link*: + +* *link*.y0 - the link’s vertical starting position (at source node) +* *link*.y1 - the link’s vertical end position (at target node) + +This method is intended to be called after computing the initial [Sankey layout](#_sankey), for example when the diagram is repositioned interactively. + +# sankey.nodes([nodes]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L93 "Source") + +If *nodes* is specified, sets the Sankey generator’s nodes accessor to the specified function or array and returns this Sankey generator. If *nodes* is not specified, returns the current nodes accessor, which defaults to: + +```js +function nodes(graph) { + return graph.nodes; +} +``` + +If *nodes* is specified as a function, the function is invoked when the Sankey layout is [generated](#_sankey), being passed any arguments passed to the Sankey generator. This function must return an array of nodes. If *nodes* is not a function, it must be a constant array of *nodes*. + +Each *node* must be an object. The following properties are assigned by the [Sankey generator](#_sankey): + +* *node*.sourceLinks - the array of outgoing [links](#sankey_links) which have this node as their source +* *node*.targetLinks - the array of incoming [links](#sankey_links) which have this node as their target +* *node*.value - the node’s value; the sum of *link*.value for the node’s incoming [links](#sankey_links) +* *node*.index - the node’s zero-based index within the array of nodes +* *node*.depth - the node’s zero-based graph depth, derived from the graph topology +* *node*.height - the node’s zero-based graph height, derived from the graph topology +* *node*.x0 - the node’s minimum horizontal position, derived from *node*.depth +* *node*.x1 - the node’s maximum horizontal position (*node*.x0 + [*sankey*.nodeWidth](#sankey_nodeWidth)) +* *node*.y0 - the node’s minimum vertical position +* *node*.y1 - the node’s maximum vertical position (*node*.y1 - *node*.y0 is proportional to *node*.value) + +See also [*sankey*.links](#sankey_links). + +# sankey.links([links]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L97 "Source") + +If *links* is specified, sets the Sankey generator’s links accessor to the specified function or array and returns this Sankey generator. If *links* is not specified, returns the current links accessor, which defaults to: + +```js +function links(graph) { + return graph.links; +} +``` + +If *links* is specified as a function, the function is invoked when the Sankey layout is [generated](#_sankey), being passed any arguments passed to the Sankey generator. This function must return an array of links. If *links* is not a function, it must be a constant array of *links*. + +Each *link* must be an object with the following properties: + +* *link*.source - the link’s source [node](#sankey_nodes) +* *link*.target - the link’s target [node](#sankey_nodes) +* *link*.value - the link’s numeric value + +For convenience, a link’s source and target may be initialized using numeric or string identifiers rather than object references; see [*sankey*.nodeId](#sankey_nodeId). The following properties are assigned to each link by the [Sankey generator](#_sankey): + +* *link*.y0 - the link’s vertical starting position (at source node) +* *link*.y1 - the link’s vertical end position (at target node) +* *link*.width - the link’s width (proportional to *link*.value) +* *link*.index - the zero-based index of *link* within the array of links + +# sankey.nodeId([id]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L77 "Source") + +If *id* is specified, sets the node id accessor to the specified function and returns this Sankey generator. If *id* is not specified, returns the current node id accessor, which defaults to the numeric *node*.index: + +```js +function id(d) { + return d.index; +} +``` + +The default id accessor allows each link’s source and target to be specified as a zero-based index into the [nodes](#sankey_nodes) array. For example: + +```js +var nodes = [ + {"id": "Alice"}, + {"id": "Bob"}, + {"id": "Carol"} +]; + +var links = [ + {"source": 0, "target": 1}, // Alice → Bob + {"source": 1, "target": 2} // Bob → Carol +]; +``` + +Now consider a different id accessor that returns a string: + +```js +function id(d) { + return d.id; +} +``` + +With this accessor, you can use named sources and targets: + +```js +var nodes = [ + {"id": "Alice"}, + {"id": "Bob"}, + {"id": "Carol"} +]; + +var links = [ + {"source": "Alice", "target": "Bob"}, + {"source": "Bob", "target": "Carol"} +]; +``` + +This is particularly useful when representing graphs in JSON, as JSON does not allow references. See [this example](https://bl.ocks.org/mbostock/f584aa36df54c451c94a9d0798caed35). + +# sankey.nodeAlign([align]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L81 "Source") + +If *align* is specified, sets the node [alignment method](#alignments) the specified function and returns this Sankey generator. If *align* is not specified, returns the current node alignment method, which defaults to [d3.sankeyJustify](#sankeyJustify). The specified function is evaluated for each input *node* in order, being passed the current *node* and the total depth *n* of the graph (one plus the maximum *node*.depth), and must return an integer between 0 and *n* - 1 that indicates the desired horizontal position of the node in the generated Sankey diagram. + +# sankey.nodeWidth([width]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L85 "Source") + +If *width* is specified, sets the node width to the specified number and returns this Sankey generator. If *width* is not specified, returns the current node width, which defaults to 24. + +# sankey.nodePadding([padding]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L89 "Source") + +If *padding* is specified, sets the vertical separation between nodes at each column to the specified number and returns this Sankey generator. If *padding* is not specified, returns the current node padding, which defaults to 8. + +# sankey.extent([extent]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L105 "Source") + +If *extent* is specified, sets the extent of the Sankey layout to the specified bounds and returns the layout. The *extent* bounds are specified as an array \[\[x0, y0\], \[x1, y1\]\], where *x0* is the left side of the extent, *y0* is the top, *x1* is the right and *y1* is the bottom. If *extent* is not specified, returns the current extent which defaults to [[0, 0], [1, 1]]. + +# sankey.size([size]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L101 "Source") + +An alias for [*sankey*.extent](#sankey_extent) where the minimum *x* and *y* of the extent are ⟨0,0⟩. Equivalent to: + +```js +sankey.extent([[0, 0], size]); +``` + +# sankey.iterations([iterations]) [<>](https://github.com/d3/d3-sankey/blob/master/src/sankey.js#L109 "Source") + +If *iterations* is specified, sets the number of relaxation iterations when [generating the layout](#_sankey) and returns this Sankey generator. If *iterations* is not specified, returns the current number of relaxation iterations, which defaults to 32. + +### Alignments + +See [*sankey*.nodeAlign](#sankey_nodeAlign). + +# d3.sankeyLeft(node, n) [<>](https://github.com/d3/d3-sankey/blob/master/src/align.js#L7 "Source") + +left + +Returns *node*.depth. + +# d3.sankeyRight(node, n) [<>](https://github.com/d3/d3-sankey/blob/master/src/align.js#L11 "Source") + +right + +Returns *n* - 1 - *node*.height. + +# d3.sankeyCenter(node, n) [<>](https://github.com/d3/d3-sankey/blob/master/src/align.js#L19 "Source") + +center + +Like [d3.sankeyLeft](#sankeyLeft), except that nodes without any incoming links are moved as right as possible. + +# d3.sankeyJustify(node, n) [<>](https://github.com/d3/d3-sankey/blob/master/src/align.js#L15 "Source") + +justify + +Like [d3.sankeyLeft](#sankeyLeft), except that nodes without any outgoing links are moved to the far right. + +### Links + +# d3.sankeyLinkHorizontal() [<>](https://github.com/d3/d3-sankey/blob/master/src/sankeyLinkHorizontal.js "Source") + +Returns a [horizontal link shape](https://github.com/d3/d3-shape/blob/master/README.md#linkHorizontal) suitable for a Sankey diagram. The [source accessor](https://github.com/d3/d3-shape/blob/master/README.md#link_source) is defined as: + +```js +function source(d) { + return [d.source.x1, d.y0]; +} +``` + +The [target accessor](https://github.com/d3/d3-shape/blob/master/README.md#link_target) is defined as: + +```js +function target(d) { + return [d.target.x0, d.y1]; +} +``` + +For example, to render the links of a Sankey diagram in SVG, you might say: + +```js +svg.append("g") + .attr("fill", "none") + .attr("stroke", "#000") + .attr("stroke-opacity", 0.2) + .selectAll("path") + .data(graph.links) + .enter().append("path") + .attr("d", d3.sankeyLinkHorizontal()) + .attr("stroke-width", function(d) { return d.width; }); +``` diff --git a/node_modules/@plotly/d3-sankey/build/d3-sankey.js b/node_modules/@plotly/d3-sankey/build/d3-sankey.js new file mode 100644 index 0000000000000000000000000000000000000000..f65f5786be1b73d47cd2942cd4d22f0b26113a50 --- /dev/null +++ b/node_modules/@plotly/d3-sankey/build/d3-sankey.js @@ -0,0 +1,345 @@ +// https://github.com/d3/d3-sankey Version 0.7.2. Copyright 2019 Mike Bostock. +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-array'), require('d3-collection'), require('d3-shape')) : + typeof define === 'function' && define.amd ? define(['exports', 'd3-array', 'd3-collection', 'd3-shape'], factory) : + (factory((global.d3 = global.d3 || {}),global.d3,global.d3,global.d3)); +}(this, (function (exports,d3Array,d3Collection,d3Shape) { 'use strict'; + +function targetDepth(d) { + return d.target.depth; +} + +function left(node) { + return node.depth; +} + +function right(node, n) { + return n - 1 - node.height; +} + +function justify(node, n) { + return node.sourceLinks.length ? node.depth : n - 1; +} + +function center(node) { + return node.targetLinks.length ? node.depth + : node.sourceLinks.length ? d3Array.min(node.sourceLinks, targetDepth) - 1 + : 0; +} + +function constant(x) { + return function() { + return x; + }; +} + +function ascendingSourceBreadth(a, b) { + return ascendingBreadth(a.source, b.source) || a.index - b.index; +} + +function ascendingTargetBreadth(a, b) { + return ascendingBreadth(a.target, b.target) || a.index - b.index; +} + +function ascendingBreadth(a, b) { + return a.y0 - b.y0; +} + +function value(d) { + return d.value; +} + +function nodeCenter(node) { + return (node.y0 + node.y1) / 2; +} + +function weightedSource(link) { + return nodeCenter(link.source) * link.value; +} + +function weightedTarget(link) { + return nodeCenter(link.target) * link.value; +} + +function defaultId(d) { + return d.index; +} + +function defaultNodes(graph) { + return graph.nodes; +} + +function defaultLinks(graph) { + return graph.links; +} + +function find(nodeById, id) { + var node = nodeById.get(id); + if (!node) throw new Error("missing: " + id); + return node; +} + +var sankey = function() { + var x0 = 0, y0 = 0, x1 = 1, y1 = 1, // extent + dx = 24, // nodeWidth + py = 8, // nodePadding + id = defaultId, + align = justify, + nodes = defaultNodes, + links = defaultLinks, + iterations = 32, + maxPaddedSpace = 2 / 3; // Defined as a fraction of the total available space + + function sankey() { + var graph = {nodes: nodes.apply(null, arguments), links: links.apply(null, arguments)}; + computeNodeLinks(graph); + computeNodeValues(graph); + computeNodeDepths(graph); + computeNodeBreadths(graph, iterations); + computeLinkBreadths(graph); + return graph; + } + + sankey.update = function(graph) { + computeLinkBreadths(graph); + return graph; + }; + + sankey.nodeId = function(_) { + return arguments.length ? (id = typeof _ === "function" ? _ : constant(_), sankey) : id; + }; + + sankey.nodeAlign = function(_) { + return arguments.length ? (align = typeof _ === "function" ? _ : constant(_), sankey) : align; + }; + + sankey.nodeWidth = function(_) { + return arguments.length ? (dx = +_, sankey) : dx; + }; + + sankey.nodePadding = function(_) { + return arguments.length ? (py = +_, sankey) : py; + }; + + sankey.nodes = function(_) { + return arguments.length ? (nodes = typeof _ === "function" ? _ : constant(_), sankey) : nodes; + }; + + sankey.links = function(_) { + return arguments.length ? (links = typeof _ === "function" ? _ : constant(_), sankey) : links; + }; + + sankey.size = function(_) { + return arguments.length ? (x0 = y0 = 0, x1 = +_[0], y1 = +_[1], sankey) : [x1 - x0, y1 - y0]; + }; + + sankey.extent = function(_) { + return arguments.length ? (x0 = +_[0][0], x1 = +_[1][0], y0 = +_[0][1], y1 = +_[1][1], sankey) : [[x0, y0], [x1, y1]]; + }; + + sankey.iterations = function(_) { + return arguments.length ? (iterations = +_, sankey) : iterations; + }; + + // Populate the sourceLinks and targetLinks for each node. + // Also, if the source and target are not objects, assume they are indices. + function computeNodeLinks(graph) { + graph.nodes.forEach(function(node, i) { + node.index = i; + node.sourceLinks = []; + node.targetLinks = []; + }); + + var nodeById = d3Collection.map(graph.nodes, id); + graph.links.forEach(function(link, i) { + link.index = i; + var source = link.source, target = link.target; + if (typeof source !== "object") source = link.source = find(nodeById, source); + if (typeof target !== "object") target = link.target = find(nodeById, target); + source.sourceLinks.push(link); + target.targetLinks.push(link); + }); + } + + // Compute the value (size) of each node by summing the associated links. + function computeNodeValues(graph) { + graph.nodes.forEach(function(node) { + node.value = Math.max( + d3Array.sum(node.sourceLinks, value), + d3Array.sum(node.targetLinks, value) + ); + }); + } + + // Iteratively assign the depth (x-position) for each node. + // Nodes are assigned the maximum depth of incoming neighbors plus one; + // nodes with no incoming links are assigned depth zero, while + // nodes with no outgoing links are assigned the maximum depth. + function computeNodeDepths(graph) { + var nodes, next, x; + + for (nodes = graph.nodes, next = [], x = 0; nodes.length; ++x, nodes = next, next = []) { + nodes.forEach(function(node) { + node.depth = x; + node.sourceLinks.forEach(function(link) { + if (next.indexOf(link.target) < 0) { + next.push(link.target); + } + }); + }); + } + + for (nodes = graph.nodes, next = [], x = 0; nodes.length; ++x, nodes = next, next = []) { + nodes.forEach(function(node) { + node.height = x; + node.targetLinks.forEach(function(link) { + if (next.indexOf(link.source) < 0) { + next.push(link.source); + } + }); + }); + } + + var kx = (x1 - x0 - dx) / (x - 1); + graph.nodes.forEach(function(node) { + node.x1 = (node.x0 = x0 + Math.max(0, Math.min(x - 1, Math.floor(align.call(null, node, x)))) * kx) + dx; + }); + } + + function computeNodeBreadths(graph) { + var columns = d3Collection.nest() + .key(function(d) { return d.x0; }) + .sortKeys(d3Array.ascending) + .entries(graph.nodes) + .map(function(d) { return d.values; }); + + // + initializeNodeBreadth(); + resolveCollisions(); + for (var alpha = 1, n = iterations; n > 0; --n) { + relaxRightToLeft(alpha *= 0.99); + resolveCollisions(); + relaxLeftToRight(alpha); + resolveCollisions(); + } + + function initializeNodeBreadth() { + var L = d3Array.max(columns, function(nodes) { + return nodes.length; + }); + var maxNodePadding = maxPaddedSpace * (y1 - y0) / (L - 1); + if(py > maxNodePadding) py = maxNodePadding; + var ky = d3Array.min(columns, function(nodes) { + return (y1 - y0 - (nodes.length - 1) * py) / d3Array.sum(nodes, value); + }); + + columns.forEach(function(nodes) { + nodes.forEach(function(node, i) { + node.y1 = (node.y0 = i) + node.value * ky; + }); + }); + + graph.links.forEach(function(link) { + link.width = link.value * ky; + }); + } + + function relaxLeftToRight(alpha) { + columns.forEach(function(nodes) { + nodes.forEach(function(node) { + if (node.targetLinks.length) { + var dy = (d3Array.sum(node.targetLinks, weightedSource) / d3Array.sum(node.targetLinks, value) - nodeCenter(node)) * alpha; + node.y0 += dy, node.y1 += dy; + } + }); + }); + } + + function relaxRightToLeft(alpha) { + columns.slice().reverse().forEach(function(nodes) { + nodes.forEach(function(node) { + if (node.sourceLinks.length) { + var dy = (d3Array.sum(node.sourceLinks, weightedTarget) / d3Array.sum(node.sourceLinks, value) - nodeCenter(node)) * alpha; + node.y0 += dy, node.y1 += dy; + } + }); + }); + } + + function resolveCollisions() { + columns.forEach(function(nodes) { + var node, + dy, + y = y0, + n = nodes.length, + i; + + // Push any overlapping nodes down. + nodes.sort(ascendingBreadth); + for (i = 0; i < n; ++i) { + node = nodes[i]; + dy = y - node.y0; + if (dy > 0) node.y0 += dy, node.y1 += dy; + y = node.y1 + py; + } + + // If the bottommost node goes outside the bounds, push it back up. + dy = y - py - y1; + if (dy > 0) { + y = (node.y0 -= dy), node.y1 -= dy; + + // Push any overlapping nodes back up. + for (i = n - 2; i >= 0; --i) { + node = nodes[i]; + dy = node.y1 + py - y; + if (dy > 0) node.y0 -= dy, node.y1 -= dy; + y = node.y0; + } + } + }); + } + } + + function computeLinkBreadths(graph) { + graph.nodes.forEach(function(node) { + node.sourceLinks.sort(ascendingTargetBreadth); + node.targetLinks.sort(ascendingSourceBreadth); + }); + graph.nodes.forEach(function(node) { + var y0 = node.y0, y1 = y0; + node.sourceLinks.forEach(function(link) { + link.y0 = y0 + link.width / 2, y0 += link.width; + }); + node.targetLinks.forEach(function(link) { + link.y1 = y1 + link.width / 2, y1 += link.width; + }); + }); + } + + return sankey; +}; + +function horizontalSource(d) { + return [d.source.x1, d.y0]; +} + +function horizontalTarget(d) { + return [d.target.x0, d.y1]; +} + +var sankeyLinkHorizontal = function() { + return d3Shape.linkHorizontal() + .source(horizontalSource) + .target(horizontalTarget); +}; + +exports.sankey = sankey; +exports.sankeyCenter = center; +exports.sankeyLeft = left; +exports.sankeyRight = right; +exports.sankeyJustify = justify; +exports.sankeyLinkHorizontal = sankeyLinkHorizontal; + +Object.defineProperty(exports, '__esModule', { value: true }); + +}))); diff --git a/node_modules/@plotly/d3-sankey/build/d3-sankey.min.js b/node_modules/@plotly/d3-sankey/build/d3-sankey.min.js new file mode 100644 index 0000000000000000000000000000000000000000..aae0637a5c355bf659aa66ab9e9f3cbb2e728595 --- /dev/null +++ b/node_modules/@plotly/d3-sankey/build/d3-sankey.min.js @@ -0,0 +1,2 @@ +// https://github.com/d3/d3-sankey Version 0.7.2. Copyright 2019 Mike Bostock. +!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3-array"),require("d3-collection"),require("d3-shape")):"function"==typeof define&&define.amd?define(["exports","d3-array","d3-collection","d3-shape"],t):t(n.d3=n.d3||{},n.d3,n.d3,n.d3)}(this,function(n,g,k,t){"use strict";function e(n){return n.target.depth}function p(n,t){return n.sourceLinks.length?n.depth:t-1}function v(n){return function(){return n}}function L(n,t){return E(n.source,t.source)||n.index-t.index}function x(n,t){return E(n.target,t.target)||n.index-t.index}function E(n,t){return n.y0-t.y0}function m(n){return n.value}function w(n){return(n.y0+n.y1)/2}function M(n){return w(n.source)*n.value}function b(n){return w(n.target)*n.value}function j(n){return n.index}function q(n){return n.nodes}function z(n){return n.links}function O(n,t){var e=n.get(t);if(!e)throw new Error("missing: "+t);return e}function r(n){return[n.source.x1,n.y0]}function o(n){return[n.target.x0,n.y1]}n.sankey=function(){var u=0,c=0,i=1,f=1,s=24,a=8,t=j,h=p,e=q,r=z,d=32,l=2/3;function o(){var n={nodes:e.apply(null,arguments),links:r.apply(null,arguments)};return function(n){n.nodes.forEach(function(n,t){n.index=t,n.sourceLinks=[],n.targetLinks=[]});var o=k.map(n.nodes,t);n.links.forEach(function(n,t){n.index=t;var e=n.source,r=n.target;"object"!=typeof e&&(e=n.source=O(o,e)),"object"!=typeof r&&(r=n.target=O(o,r)),e.sourceLinks.push(n),r.targetLinks.push(n)})}(n),n.nodes.forEach(function(n){n.value=Math.max(g.sum(n.sourceLinks,m),g.sum(n.targetLinks,m))}),function(n){var t,e,r;for(t=n.nodes,e=[],r=0;t.length;++r,t=e,e=[])t.forEach(function(n){n.depth=r,n.sourceLinks.forEach(function(n){e.indexOf(n.target)<0&&e.push(n.target)})});for(t=n.nodes,e=[],r=0;t.length;++r,t=e,e=[])t.forEach(function(n){n.height=r,n.targetLinks.forEach(function(n){e.indexOf(n.source)<0&&e.push(n.source)})});var o=(i-u-s)/(r-1);n.nodes.forEach(function(n){n.x1=(n.x0=u+Math.max(0,Math.min(r-1,Math.floor(h.call(null,n,r))))*o)+s})}(n),function(r){var o=k.nest().key(function(n){return n.x0}).sortKeys(g.ascending).entries(r.nodes).map(function(n){return n.values});(function(){var n=g.max(o,function(n){return n.length}),t=l*(f-c)/(n-1);t 0; --n) { + relaxRightToLeft(alpha *= 0.99); + resolveCollisions(); + relaxLeftToRight(alpha); + resolveCollisions(); + } + + function initializeNodeBreadth() { + var L = max(columns, function(nodes) { + return nodes.length; + }); + var maxNodePadding = maxPaddedSpace * (y1 - y0) / (L - 1); + if(py > maxNodePadding) py = maxNodePadding; + var ky = min(columns, function(nodes) { + return (y1 - y0 - (nodes.length - 1) * py) / sum(nodes, value); + }); + + columns.forEach(function(nodes) { + nodes.forEach(function(node, i) { + node.y1 = (node.y0 = i) + node.value * ky; + }); + }); + + graph.links.forEach(function(link) { + link.width = link.value * ky; + }); + } + + function relaxLeftToRight(alpha) { + columns.forEach(function(nodes) { + nodes.forEach(function(node) { + if (node.targetLinks.length) { + var dy = (sum(node.targetLinks, weightedSource) / sum(node.targetLinks, value) - nodeCenter(node)) * alpha; + node.y0 += dy, node.y1 += dy; + } + }); + }); + } + + function relaxRightToLeft(alpha) { + columns.slice().reverse().forEach(function(nodes) { + nodes.forEach(function(node) { + if (node.sourceLinks.length) { + var dy = (sum(node.sourceLinks, weightedTarget) / sum(node.sourceLinks, value) - nodeCenter(node)) * alpha; + node.y0 += dy, node.y1 += dy; + } + }); + }); + } + + function resolveCollisions() { + columns.forEach(function(nodes) { + var node, + dy, + y = y0, + n = nodes.length, + i; + + // Push any overlapping nodes down. + nodes.sort(ascendingBreadth); + for (i = 0; i < n; ++i) { + node = nodes[i]; + dy = y - node.y0; + if (dy > 0) node.y0 += dy, node.y1 += dy; + y = node.y1 + py; + } + + // If the bottommost node goes outside the bounds, push it back up. + dy = y - py - y1; + if (dy > 0) { + y = (node.y0 -= dy), node.y1 -= dy; + + // Push any overlapping nodes back up. + for (i = n - 2; i >= 0; --i) { + node = nodes[i]; + dy = node.y1 + py - y; + if (dy > 0) node.y0 -= dy, node.y1 -= dy; + y = node.y0; + } + } + }); + } + } + + function computeLinkBreadths(graph) { + graph.nodes.forEach(function(node) { + node.sourceLinks.sort(ascendingTargetBreadth); + node.targetLinks.sort(ascendingSourceBreadth); + }); + graph.nodes.forEach(function(node) { + var y0 = node.y0, y1 = y0; + node.sourceLinks.forEach(function(link) { + link.y0 = y0 + link.width / 2, y0 += link.width; + }); + node.targetLinks.forEach(function(link) { + link.y1 = y1 + link.width / 2, y1 += link.width; + }); + }); + } + + return sankey; +} diff --git a/node_modules/@plotly/d3-sankey/src/sankeyLinkHorizontal.js b/node_modules/@plotly/d3-sankey/src/sankeyLinkHorizontal.js new file mode 100644 index 0000000000000000000000000000000000000000..785bb7b45a794fbad197491569ff558b9f32ec93 --- /dev/null +++ b/node_modules/@plotly/d3-sankey/src/sankeyLinkHorizontal.js @@ -0,0 +1,15 @@ +import {linkHorizontal} from "d3-shape"; + +function horizontalSource(d) { + return [d.source.x1, d.y0]; +} + +function horizontalTarget(d) { + return [d.target.x0, d.y1]; +} + +export default function() { + return linkHorizontal() + .source(horizontalSource) + .target(horizontalTarget); +} diff --git a/node_modules/@plotly/d3/.gitattributes b/node_modules/@plotly/d3/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..eab783da7bee07c25483e21746d6b9a076b82474 --- /dev/null +++ b/node_modules/@plotly/d3/.gitattributes @@ -0,0 +1 @@ +d3.js -diff merge=ours diff --git a/node_modules/@plotly/d3/.npmignore b/node_modules/@plotly/d3/.npmignore new file mode 100644 index 0000000000000000000000000000000000000000..23b0df14ba38fd2028e1ff54b3f8b784ad9def7b --- /dev/null +++ b/node_modules/@plotly/d3/.npmignore @@ -0,0 +1,6 @@ +examples/ +test/ +lib/ +.DS_Store +_site +d3.zip diff --git a/node_modules/@plotly/d3/.spmignore b/node_modules/@plotly/d3/.spmignore new file mode 100644 index 0000000000000000000000000000000000000000..0a67304196fed93b0e5c0109319971bd0c6b34b8 --- /dev/null +++ b/node_modules/@plotly/d3/.spmignore @@ -0,0 +1,4 @@ +bin +lib +src +test diff --git a/node_modules/@plotly/d3/CONTRIBUTING.md b/node_modules/@plotly/d3/CONTRIBUTING.md new file mode 100644 index 0000000000000000000000000000000000000000..89a33e2da0b92672db460ea4ae032a9a5be77dad --- /dev/null +++ b/node_modules/@plotly/d3/CONTRIBUTING.md @@ -0,0 +1,27 @@ +# Contributing + +**Important:** these GitHub issues are for *bug reports and feature requests only*. Please use [StackOverflow](http://stackoverflow.com/questions/tagged/d3.js) or the [d3-js Google group](https://groups.google.com/d/forum/d3-js) for general help. + +If you’re looking for ways to contribute, please [peruse open issues](https://github.com/mbostock/d3/issues?milestone=&page=1&state=open). The icebox is a good place to find ideas that are not currently in development. If you already have an idea, please check past issues to see whether your idea or a similar one was previously discussed. + +Before submitting a pull request, consider implementing a live example first, say using [bl.ocks.org](http://bl.ocks.org). Real-world use cases go a long way to demonstrating the usefulness of a proposed feature. The more complex a feature’s implementation, the more usefulness it should provide. Share your demo using the #d3js tag on Twitter or by sending it to the [d3-js Google group](https://groups.google.com/d/forum/d3-js). + +If your proposed feature does not involve changing core functionality, consider submitting it instead as a [D3 plugin](https://github.com/d3/d3-plugins). New core features should be for general use, whereas plugins are suitable for more specialized use cases. When in doubt, it’s easier to start with a plugin before “graduating” to core. + +To contribute new documentation or add examples to the gallery, just [edit the Wiki](https://github.com/mbostock/d3/wiki)! + +## How to Submit a Pull Request + +1. Click the “Fork” button to create your personal fork of the D3 repository. + +2. After cloning your fork of the D3 repository in the terminal, run `npm install` to install D3’s dependencies. + +3. Create a new branch for your new feature. For example: `git checkout -b my-awesome-feature`. A dedicated branch for your pull request means you can develop multiple features at the same time, and ensures that your pull request is stable even if you later decide to develop an unrelated feature. + +4. The `d3.js` file is built from source files in the `src` directory. _Do not edit `d3.js` directly._ Instead, edit the source files, and then run `make` to build the generated files. + +5. Use `make test` to run tests and verify your changes. If you are adding a new feature, you should add new tests! If you are changing existing functionality, make sure the existing tests run, or update them as appropriate. + +6. Sign D3’s [Individual Contributor License Agreement](https://docs.google.com/forms/d/1CzjdBKtDuA8WeuFJinadx956xLQ4Xriv7-oDvXnZMaI/viewform). Unless you are submitting a trivial patch (such as fixing a typo), this form is needed to verify that you are able to contribute. + +7. Submit your pull request, and good luck! diff --git a/node_modules/@plotly/d3/LICENSE b/node_modules/@plotly/d3/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..ff3f2e5419a8598122736e5b6d88245795fe439b --- /dev/null +++ b/node_modules/@plotly/d3/LICENSE @@ -0,0 +1,26 @@ +Copyright (c) 2010-2016, Michael Bostock +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* 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. + +* The name Michael Bostock may not 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 MICHAEL BOSTOCK 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. diff --git a/node_modules/@plotly/d3/README.md b/node_modules/@plotly/d3/README.md new file mode 100644 index 0000000000000000000000000000000000000000..33e97bf18e041f6a8b0c374a53ea25606717e1f7 --- /dev/null +++ b/node_modules/@plotly/d3/README.md @@ -0,0 +1,13 @@ +# Data-Driven Documents + + + +**D3.js** is a JavaScript library for manipulating documents based on data. **D3** helps you bring data to life using HTML, SVG, and CSS. **D3** emphasizes web standards and combines powerful visualization components with a data-driven approach to DOM manipulation, giving you the full capabilities of modern browsers without tying yourself to a proprietary framework. + +Want to learn more? [See the wiki.](https://github.com/mbostock/d3/wiki) + +For examples, [see the gallery](https://github.com/mbostock/d3/wiki/Gallery) and [mbostock’s bl.ocks](http://bl.ocks.org/mbostock). + +## Good News, Everyone! + +The next major release of D3, 4.0, is coming! See the [4.0 development branch](https://github.com/mbostock/d3/tree/4) and read the [new API reference](https://github.com/mbostock/d3/blob/4/README.md) to get ready. diff --git a/node_modules/@plotly/d3/bin/meteor b/node_modules/@plotly/d3/bin/meteor new file mode 100644 index 0000000000000000000000000000000000000000..478705160dbe43f36872a1a5b67e672bcb8cf000 --- /dev/null +++ b/node_modules/@plotly/d3/bin/meteor @@ -0,0 +1,20 @@ +#!/usr/bin/env node + +var fs = require("fs"), + package = require("../package.json"); + +console.log( + "// Package metadata for Meteor.js.\n" + + "\n" + + "Package.describe({\n" + + " name: \"d3js:d3\", // http://atmospherejs.com/d3js/d3\n" + + " summary: \"D3 (official): " + package.description + "\",\n" + + " version: \"" + package.version + "\",\n" + + " git: \"https://github.com/mbostock/d3.git\"\n" + + "});\n" + + "\n" + + "Package.onUse(function(api) {\n" + + " api.versionsFrom([\"METEOR@1.0\"]);\n" + + " api.addFiles(\"d3.js\", \"client\");\n" + + "});" +); diff --git a/node_modules/@plotly/d3/bin/start b/node_modules/@plotly/d3/bin/start new file mode 100644 index 0000000000000000000000000000000000000000..9b046fc937f8f481c35fdd42317d7088d48f18b3 --- /dev/null +++ b/node_modules/@plotly/d3/bin/start @@ -0,0 +1,3 @@ +#!/usr/bin/env node + +console.log("!function(){\n var d3 = {version: " + JSON.stringify(require("../package.json").version) + "}; // semver"); diff --git a/node_modules/@plotly/d3/bin/uglify b/node_modules/@plotly/d3/bin/uglify new file mode 100644 index 0000000000000000000000000000000000000000..6defe2f5b1734593ee0d80494262a8598f9cbc63 --- /dev/null +++ b/node_modules/@plotly/d3/bin/uglify @@ -0,0 +1,34 @@ +#!/usr/bin/env node + +var fs = require("fs"), + uglify = require("uglify-js"); + +var filename = process.argv[2], + toplevel = uglify.parse(fs.readFileSync(filename, "utf8"), {filename: filename}), + output = uglify.OutputStream({ascii_only: true}), + compressor = uglify.Compressor(true), + warn = uglify.AST_Node.warn; + +uglify.AST_Node.warn = function(s, o) { + if (o.msg === "Accidental global?" && o.name === "d3" && o.line === 1 && !o.col) return; + warn.apply(this, arguments); +}; + +toplevel.figure_out_scope(); +toplevel.scope_warnings({ + undeclared: false, + unreferenced: false, + assign_to_global: true, + func_arguments: false, + nested_defuns: false, + eval: false +}); + +toplevel = toplevel.transform(compressor); + +toplevel.figure_out_scope(); +toplevel.compute_char_frequency(true); +toplevel.mangle_names(true); +toplevel.print(output); + +process.stdout.write(output.get()); diff --git a/node_modules/@plotly/d3/composer.json b/node_modules/@plotly/d3/composer.json new file mode 100644 index 0000000000000000000000000000000000000000..c5a50f219ee37428c12ab9f14b3cd3266eb39989 --- /dev/null +++ b/node_modules/@plotly/d3/composer.json @@ -0,0 +1,26 @@ +{ + "name": "mbostock/d3", + "description": "A JavaScript visualization library for HTML and SVG.", + "keywords": [ + "dom", + "w3c", + "visualization", + "svg", + "animation", + "canvas" + ], + "homepage": "http://d3js.org/", + "license": "BSD-3-Clause", + "authors": [ + { + "name": "Mike Bostock", + "homepage": "http://bost.ocks.org/mike" + } + ], + "support": { + "issues": "https://github.com/mbostock/d3/issues", + "wiki": "https://github.com/mbostock/d3/wiki", + "API": "https://github.com/mbostock/d3/wiki/API-Reference", + "source": "https://github.com/mbostock/d3" + } +} diff --git a/node_modules/@plotly/d3/d3.js b/node_modules/@plotly/d3/d3.js new file mode 100644 index 0000000000000000000000000000000000000000..204e9349566ba5baafc5c48c618c1dd055f1b46f Binary files /dev/null and b/node_modules/@plotly/d3/d3.js differ diff --git a/node_modules/@plotly/d3/package.js b/node_modules/@plotly/d3/package.js new file mode 100644 index 0000000000000000000000000000000000000000..1f8566bff0523616d526ae9aeefc06fe2ead480a --- /dev/null +++ b/node_modules/@plotly/d3/package.js @@ -0,0 +1,13 @@ +// Package metadata for Meteor.js. + +Package.describe({ + name: "d3js:d3", // http://atmospherejs.com/d3js/d3 + summary: "D3 (official): A JavaScript visualization library for HTML and SVG.", + version: "3.8.0", + git: "https://github.com/mbostock/d3.git" +}); + +Package.onUse(function(api) { + api.versionsFrom(["METEOR@1.0"]); + api.addFiles("d3.js", "client"); +}); diff --git a/node_modules/@plotly/d3/package.json b/node_modules/@plotly/d3/package.json new file mode 100644 index 0000000000000000000000000000000000000000..5a8c256a469f05cb8cf700a7e846f1021248e0d7 --- /dev/null +++ b/node_modules/@plotly/d3/package.json @@ -0,0 +1,65 @@ +{ + "name": "@plotly/d3", + "version": "3.8.1", + "description": "A JavaScript visualization library for HTML and SVG.", + "keywords": [ + "dom", + "w3c", + "visualization", + "svg", + "animation", + "canvas" + ], + "homepage": "http://d3js.org", + "author": { + "name": "Mike Bostock", + "url": "http://bost.ocks.org/mike" + }, + "contributors": [ + { + "name": "Jason Davies", + "url": "http://jasondavies.com" + } + ], + "repository": { + "type": "git", + "url": "https://github.com/plotly/d3.git" + }, + "main": "d3.js", + "browser": "d3.js", + "jspm": { + "main": "d3", + "shim": { + "d3": { + "exports": "d3" + } + }, + "files": [ + "d3.js" + ], + "buildConfig": { + "uglify": true + } + }, + "jam": { + "main": "d3.js", + "shim": { + "exports": "d3" + } + }, + "spm": { + "main": "d3.js" + }, + "devDependencies": { + "jsdom": "3", + "seedrandom": "2", + "smash": "0.0", + "uglify-js": "2.6.2", + "vows": "0.8" + }, + "scripts": { + "test": "vows && echo", + "build": "rm -f package.js src/start.js d3.js d3.zip && bin/start > src/start.js && bin/meteor > package.js && smash src/d3.js | uglifyjs - -b indent-level=2 -o d3.js && chmod a-w d3.js package.js && zip d3.zip LICENSE d3.js" + }, + "license": "BSD-3-Clause" +} diff --git a/node_modules/@plotly/d3/src/arrays/ascending.js b/node_modules/@plotly/d3/src/arrays/ascending.js new file mode 100644 index 0000000000000000000000000000000000000000..067c17aa60c0d873e1605711d45d3bd4916a2b93 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/ascending.js @@ -0,0 +1,5 @@ +d3.ascending = d3_ascending; + +function d3_ascending(a, b) { + return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN; +} diff --git a/node_modules/@plotly/d3/src/arrays/bisect.js b/node_modules/@plotly/d3/src/arrays/bisect.js new file mode 100644 index 0000000000000000000000000000000000000000..fbe3a737e9815b5c706d2d30c406df03768388a5 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/bisect.js @@ -0,0 +1,36 @@ +import "ascending"; + +function d3_bisector(compare) { + return { + left: function(a, x, lo, hi) { + if (arguments.length < 3) lo = 0; + if (arguments.length < 4) hi = a.length; + while (lo < hi) { + var mid = lo + hi >>> 1; + if (compare(a[mid], x) < 0) lo = mid + 1; + else hi = mid; + } + return lo; + }, + right: function(a, x, lo, hi) { + if (arguments.length < 3) lo = 0; + if (arguments.length < 4) hi = a.length; + while (lo < hi) { + var mid = lo + hi >>> 1; + if (compare(a[mid], x) > 0) hi = mid; + else lo = mid + 1; + } + return lo; + } + }; +} + +var d3_bisect = d3_bisector(d3_ascending); +d3.bisectLeft = d3_bisect.left; +d3.bisect = d3.bisectRight = d3_bisect.right; + +d3.bisector = function(f) { + return d3_bisector(f.length === 1 + ? function(d, x) { return d3_ascending(f(d), x); } + : f); +}; diff --git a/node_modules/@plotly/d3/src/arrays/descending.js b/node_modules/@plotly/d3/src/arrays/descending.js new file mode 100644 index 0000000000000000000000000000000000000000..05034586ffe6ffe3516364500d616d13a13c4a27 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/descending.js @@ -0,0 +1,3 @@ +d3.descending = function(a, b) { + return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN; +}; diff --git a/node_modules/@plotly/d3/src/arrays/deviation.js b/node_modules/@plotly/d3/src/arrays/deviation.js new file mode 100644 index 0000000000000000000000000000000000000000..16663e3f19fb60f182a288726961c52394e3e328 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/deviation.js @@ -0,0 +1,6 @@ +import "variance"; + +d3.deviation = function() { + var v = d3.variance.apply(this, arguments); + return v ? Math.sqrt(v) : v; +}; diff --git a/node_modules/@plotly/d3/src/arrays/entries.js b/node_modules/@plotly/d3/src/arrays/entries.js new file mode 100644 index 0000000000000000000000000000000000000000..4ce014b82bae228e0b27562f93ecc328bd0d10c7 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/entries.js @@ -0,0 +1,5 @@ +d3.entries = function(map) { + var entries = []; + for (var key in map) entries.push({key: key, value: map[key]}); + return entries; +}; diff --git a/node_modules/@plotly/d3/src/arrays/extent.js b/node_modules/@plotly/d3/src/arrays/extent.js new file mode 100644 index 0000000000000000000000000000000000000000..7584658331af70fa15f8cfaf6e397a878dac35c0 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/extent.js @@ -0,0 +1,21 @@ +d3.extent = function(array, f) { + var i = -1, + n = array.length, + a, + b, + c; + if (arguments.length === 1) { + while (++i < n) if ((b = array[i]) != null && b >= b) { a = c = b; break; } + while (++i < n) if ((b = array[i]) != null) { + if (a > b) a = b; + if (c < b) c = b; + } + } else { + while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) { a = c = b; break; } + while (++i < n) if ((b = f.call(array, array[i], i)) != null) { + if (a > b) a = b; + if (c < b) c = b; + } + } + return [a, c]; +}; diff --git a/node_modules/@plotly/d3/src/arrays/index.js b/node_modules/@plotly/d3/src/arrays/index.js new file mode 100644 index 0000000000000000000000000000000000000000..c29fb24b7e45dfabeeca33d1b3fb43d6d834bad4 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/index.js @@ -0,0 +1,25 @@ +import "ascending"; +import "descending"; +import "min"; +import "max"; +import "extent"; +import "sum"; +import "mean"; +import "median"; +import "quantile"; +import "variance"; +import "deviation"; +import "bisect"; +import "shuffle"; +import "permute"; +import "pairs"; +import "zip"; +import "transpose"; +import "keys"; +import "values"; +import "entries"; +import "merge"; +import "range"; +import "nest"; +import "map"; +import "set"; diff --git a/node_modules/@plotly/d3/src/arrays/keys.js b/node_modules/@plotly/d3/src/arrays/keys.js new file mode 100644 index 0000000000000000000000000000000000000000..c83ec8e15688b090ec03ae70545e32226c31997c --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/keys.js @@ -0,0 +1,5 @@ +d3.keys = function(map) { + var keys = []; + for (var key in map) keys.push(key); + return keys; +}; diff --git a/node_modules/@plotly/d3/src/arrays/map.js b/node_modules/@plotly/d3/src/arrays/map.js new file mode 100644 index 0000000000000000000000000000000000000000..4ba7f3d151e26590ad20182daea1aa472bbb50e8 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/map.js @@ -0,0 +1,84 @@ +import "../core/class"; + +d3.map = function(object, f) { + var map = new d3_Map; + if (object instanceof d3_Map) { + object.forEach(function(key, value) { map.set(key, value); }); + } else if (Array.isArray(object)) { + var i = -1, + n = object.length, + o; + if (arguments.length === 1) while (++i < n) map.set(i, object[i]); + else while (++i < n) map.set(f.call(object, o = object[i], i), o); + } else { + for (var key in object) map.set(key, object[key]); + } + return map; +}; + +function d3_Map() { + this._ = Object.create(null); +} + +var d3_map_proto = "__proto__", + d3_map_zero = "\0"; + +d3_class(d3_Map, { + has: d3_map_has, + get: function(key) { + return this._[d3_map_escape(key)]; + }, + set: function(key, value) { + return this._[d3_map_escape(key)] = value; + }, + remove: d3_map_remove, + keys: d3_map_keys, + values: function() { + var values = []; + for (var key in this._) values.push(this._[key]); + return values; + }, + entries: function() { + var entries = []; + for (var key in this._) entries.push({key: d3_map_unescape(key), value: this._[key]}); + return entries; + }, + size: d3_map_size, + empty: d3_map_empty, + forEach: function(f) { + for (var key in this._) f.call(this, d3_map_unescape(key), this._[key]); + } +}); + +function d3_map_escape(key) { + return (key += "") === d3_map_proto || key[0] === d3_map_zero ? d3_map_zero + key : key; +} + +function d3_map_unescape(key) { + return (key += "")[0] === d3_map_zero ? key.slice(1) : key; +} + +function d3_map_has(key) { + return d3_map_escape(key) in this._; +} + +function d3_map_remove(key) { + return (key = d3_map_escape(key)) in this._ && delete this._[key]; +} + +function d3_map_keys() { + var keys = []; + for (var key in this._) keys.push(d3_map_unescape(key)); + return keys; +} + +function d3_map_size() { + var size = 0; + for (var key in this._) ++size; + return size; +} + +function d3_map_empty() { + for (var key in this._) return false; + return true; +} diff --git a/node_modules/@plotly/d3/src/arrays/max.js b/node_modules/@plotly/d3/src/arrays/max.js new file mode 100644 index 0000000000000000000000000000000000000000..5aec78d42a1406160e9a4362dc9fb64b495d3178 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/max.js @@ -0,0 +1,14 @@ +d3.max = function(array, f) { + var i = -1, + n = array.length, + a, + b; + if (arguments.length === 1) { + while (++i < n) if ((b = array[i]) != null && b >= b) { a = b; break; } + while (++i < n) if ((b = array[i]) != null && b > a) a = b; + } else { + while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) { a = b; break; } + while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b; + } + return a; +}; diff --git a/node_modules/@plotly/d3/src/arrays/mean.js b/node_modules/@plotly/d3/src/arrays/mean.js new file mode 100644 index 0000000000000000000000000000000000000000..ab91ae8cfe3701f9c7b6a32430a44240816f70a7 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/mean.js @@ -0,0 +1,15 @@ +import "../math/number"; + +d3.mean = function(array, f) { + var s = 0, + n = array.length, + a, + i = -1, + j = n; + if (arguments.length === 1) { + while (++i < n) if (d3_numeric(a = d3_number(array[i]))) s += a; else --j; + } else { + while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a; else --j; + } + if (j) return s / j; +}; diff --git a/node_modules/@plotly/d3/src/arrays/median.js b/node_modules/@plotly/d3/src/arrays/median.js new file mode 100644 index 0000000000000000000000000000000000000000..9f0308b267ca88d8947f8a932f384e32674b70c9 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/median.js @@ -0,0 +1,16 @@ +import "../math/number"; +import "ascending"; +import "quantile"; + +d3.median = function(array, f) { + var numbers = [], + n = array.length, + a, + i = -1; + if (arguments.length === 1) { + while (++i < n) if (d3_numeric(a = d3_number(array[i]))) numbers.push(a); + } else { + while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) numbers.push(a); + } + if (numbers.length) return d3.quantile(numbers.sort(d3_ascending), 0.5); +}; diff --git a/node_modules/@plotly/d3/src/arrays/merge.js b/node_modules/@plotly/d3/src/arrays/merge.js new file mode 100644 index 0000000000000000000000000000000000000000..53c992dc48768a280e9f2fc4b7a685fd32775438 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/merge.js @@ -0,0 +1,21 @@ +d3.merge = function(arrays) { + var n = arrays.length, + m, + i = -1, + j = 0, + merged, + array; + + while (++i < n) j += arrays[i].length; + merged = new Array(j); + + while (--n >= 0) { + array = arrays[n]; + m = array.length; + while (--m >= 0) { + merged[--j] = array[m]; + } + } + + return merged; +}; diff --git a/node_modules/@plotly/d3/src/arrays/min.js b/node_modules/@plotly/d3/src/arrays/min.js new file mode 100644 index 0000000000000000000000000000000000000000..c48a49d0c6b012ec5d932d6c622bdc94d9abb823 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/min.js @@ -0,0 +1,14 @@ +d3.min = function(array, f) { + var i = -1, + n = array.length, + a, + b; + if (arguments.length === 1) { + while (++i < n) if ((b = array[i]) != null && b >= b) { a = b; break; } + while (++i < n) if ((b = array[i]) != null && a > b) a = b; + } else { + while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) { a = b; break; } + while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b; + } + return a; +}; diff --git a/node_modules/@plotly/d3/src/arrays/nest.js b/node_modules/@plotly/d3/src/arrays/nest.js new file mode 100644 index 0000000000000000000000000000000000000000..859add7be3349c477423584f3e48ff2efee0c0dd --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/nest.js @@ -0,0 +1,97 @@ +import "map"; + +d3.nest = function() { + var nest = {}, + keys = [], + sortKeys = [], + sortValues, + rollup; + + function map(mapType, array, depth) { + if (depth >= keys.length) return rollup + ? rollup.call(nest, array) : (sortValues + ? array.sort(sortValues) + : array); + + var i = -1, + n = array.length, + key = keys[depth++], + keyValue, + object, + setter, + valuesByKey = new d3_Map, + values; + + while (++i < n) { + if (values = valuesByKey.get(keyValue = key(object = array[i]))) { + values.push(object); + } else { + valuesByKey.set(keyValue, [object]); + } + } + + if (mapType) { + object = mapType(); + setter = function(keyValue, values) { + object.set(keyValue, map(mapType, values, depth)); + }; + } else { + object = {}; + setter = function(keyValue, values) { + object[keyValue] = map(mapType, values, depth); + }; + } + + valuesByKey.forEach(setter); + return object; + } + + function entries(map, depth) { + if (depth >= keys.length) return map; + + var array = [], + sortKey = sortKeys[depth++]; + + map.forEach(function(key, keyMap) { + array.push({key: key, values: entries(keyMap, depth)}); + }); + + return sortKey + ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) + : array; + } + + nest.map = function(array, mapType) { + return map(mapType, array, 0); + }; + + nest.entries = function(array) { + return entries(map(d3.map, array, 0), 0); + }; + + nest.key = function(d) { + keys.push(d); + return nest; + }; + + // Specifies the order for the most-recently specified key. + // Note: only applies to entries. Map keys are unordered! + nest.sortKeys = function(order) { + sortKeys[keys.length - 1] = order; + return nest; + }; + + // Specifies the order for leaf values. + // Applies to both maps and entries array. + nest.sortValues = function(order) { + sortValues = order; + return nest; + }; + + nest.rollup = function(f) { + rollup = f; + return nest; + }; + + return nest; +}; diff --git a/node_modules/@plotly/d3/src/arrays/pairs.js b/node_modules/@plotly/d3/src/arrays/pairs.js new file mode 100644 index 0000000000000000000000000000000000000000..e270f957cda3453fcd168cee0baba944f4a6c574 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/pairs.js @@ -0,0 +1,5 @@ +d3.pairs = function(array) { + var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n); + while (i < n) pairs[i] = [p0 = p1, p1 = array[++i]]; + return pairs; +}; diff --git a/node_modules/@plotly/d3/src/arrays/permute.js b/node_modules/@plotly/d3/src/arrays/permute.js new file mode 100644 index 0000000000000000000000000000000000000000..f27d2c9d261fa659d853cfe27fe15c2b35fa7aa2 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/permute.js @@ -0,0 +1,5 @@ +d3.permute = function(array, indexes) { + var i = indexes.length, permutes = new Array(i); + while (i--) permutes[i] = array[indexes[i]]; + return permutes; +}; diff --git a/node_modules/@plotly/d3/src/arrays/quantile.js b/node_modules/@plotly/d3/src/arrays/quantile.js new file mode 100644 index 0000000000000000000000000000000000000000..67fe9fd71cd314ee64a28eb1e4fbb2c7a9bd59ec --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/quantile.js @@ -0,0 +1,8 @@ +// R-7 per +d3.quantile = function(values, p) { + var H = (values.length - 1) * p + 1, + h = Math.floor(H), + v = +values[h - 1], + e = H - h; + return e ? v + e * (values[h] - v) : v; +}; diff --git a/node_modules/@plotly/d3/src/arrays/range.js b/node_modules/@plotly/d3/src/arrays/range.js new file mode 100644 index 0000000000000000000000000000000000000000..2fd6a1e6bfc3c325ffe8f63527665308800e5112 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/range.js @@ -0,0 +1,26 @@ +import "../math/abs"; + +d3.range = function(start, stop, step) { + if (arguments.length < 3) { + step = 1; + if (arguments.length < 2) { + stop = start; + start = 0; + } + } + if ((stop - start) / step === Infinity) throw new Error("infinite range"); + var range = [], + k = d3_range_integerScale(abs(step)), + i = -1, + j; + start *= k, stop *= k, step *= k; + if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); + else while ((j = start + step * ++i) < stop) range.push(j / k); + return range; +}; + +function d3_range_integerScale(x) { + var k = 1; + while (x * k % 1) k *= 10; + return k; +} diff --git a/node_modules/@plotly/d3/src/arrays/set.js b/node_modules/@plotly/d3/src/arrays/set.js new file mode 100644 index 0000000000000000000000000000000000000000..de4dbd426140bd83e46ff0e1833e6e600a75d814 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/set.js @@ -0,0 +1,27 @@ +import "../core/class"; +import "map"; + +d3.set = function(array) { + var set = new d3_Set; + if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]); + return set; +}; + +function d3_Set() { + this._ = Object.create(null); +} + +d3_class(d3_Set, { + has: d3_map_has, + add: function(key) { + this._[d3_map_escape(key += "")] = true; + return key; + }, + remove: d3_map_remove, + values: d3_map_keys, + size: d3_map_size, + empty: d3_map_empty, + forEach: function(f) { + for (var key in this._) f.call(this, d3_map_unescape(key)); + } +}); diff --git a/node_modules/@plotly/d3/src/arrays/shuffle.js b/node_modules/@plotly/d3/src/arrays/shuffle.js new file mode 100644 index 0000000000000000000000000000000000000000..dbe36bdd72d92c12b113656c4390bd47748fbf53 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/shuffle.js @@ -0,0 +1,9 @@ +d3.shuffle = function(array, i0, i1) { + if ((m = arguments.length) < 3) { i1 = array.length; if (m < 2) i0 = 0; } + var m = i1 - i0, t, i; + while (m) { + i = Math.random() * m-- | 0; + t = array[m + i0], array[m + i0] = array[i + i0], array[i + i0] = t; + } + return array; +}; diff --git a/node_modules/@plotly/d3/src/arrays/sum.js b/node_modules/@plotly/d3/src/arrays/sum.js new file mode 100644 index 0000000000000000000000000000000000000000..1e179bc855859b7ac36fdc71994a17b8120dd203 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/sum.js @@ -0,0 +1,14 @@ +import "../math/number"; + +d3.sum = function(array, f) { + var s = 0, + n = array.length, + a, + i = -1; + if (arguments.length === 1) { + while (++i < n) if (d3_numeric(a = +array[i])) s += a; // zero and null are equivalent + } else { + while (++i < n) if (d3_numeric(a = +f.call(array, array[i], i))) s += a; + } + return s; +}; diff --git a/node_modules/@plotly/d3/src/arrays/transpose.js b/node_modules/@plotly/d3/src/arrays/transpose.js new file mode 100644 index 0000000000000000000000000000000000000000..c41e8e59287b30ece9fe9c0eee4cfe22151f5a20 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/transpose.js @@ -0,0 +1,15 @@ +import "min"; + +d3.transpose = function(matrix) { + if (!(n = matrix.length)) return []; + for (var i = -1, m = d3.min(matrix, d3_transposeLength), transpose = new Array(m); ++i < m;) { + for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) { + row[j] = matrix[j][i]; + } + } + return transpose; +}; + +function d3_transposeLength(d) { + return d.length; +} diff --git a/node_modules/@plotly/d3/src/arrays/values.js b/node_modules/@plotly/d3/src/arrays/values.js new file mode 100644 index 0000000000000000000000000000000000000000..299d30433caa314f96d5ff835973fc751d5b4af6 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/values.js @@ -0,0 +1,5 @@ +d3.values = function(map) { + var values = []; + for (var key in map) values.push(map[key]); + return values; +}; diff --git a/node_modules/@plotly/d3/src/arrays/variance.js b/node_modules/@plotly/d3/src/arrays/variance.js new file mode 100644 index 0000000000000000000000000000000000000000..70da168061ee6d92e7a4282aa9cfd0baced2b2d4 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/variance.js @@ -0,0 +1,29 @@ +import "../math/number"; + +d3.variance = function(array, f) { + var n = array.length, + m = 0, + a, + d, + s = 0, + i = -1, + j = 0; + if (arguments.length === 1) { + while (++i < n) { + if (d3_numeric(a = d3_number(array[i]))) { + d = a - m; + m += d / ++j; + s += d * (a - m); + } + } + } else { + while (++i < n) { + if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) { + d = a - m; + m += d / ++j; + s += d * (a - m); + } + } + } + if (j > 1) return s / (j - 1); +}; diff --git a/node_modules/@plotly/d3/src/arrays/zip.js b/node_modules/@plotly/d3/src/arrays/zip.js new file mode 100644 index 0000000000000000000000000000000000000000..502916d162a750ed18f0425675cf4af42710adc7 --- /dev/null +++ b/node_modules/@plotly/d3/src/arrays/zip.js @@ -0,0 +1,5 @@ +import "transpose"; + +d3.zip = function() { + return d3.transpose(arguments); +}; diff --git a/node_modules/@plotly/d3/src/behavior/behavior.js b/node_modules/@plotly/d3/src/behavior/behavior.js new file mode 100644 index 0000000000000000000000000000000000000000..39633b10599fa4652d68ae2505a68ad01b21c6ed --- /dev/null +++ b/node_modules/@plotly/d3/src/behavior/behavior.js @@ -0,0 +1 @@ +d3.behavior = {}; diff --git a/node_modules/@plotly/d3/src/behavior/drag.js b/node_modules/@plotly/d3/src/behavior/drag.js new file mode 100644 index 0000000000000000000000000000000000000000..93e25fbae6f7b9fbc20e0ed6dcbee9df99900ff1 --- /dev/null +++ b/node_modules/@plotly/d3/src/behavior/drag.js @@ -0,0 +1,88 @@ +import "../core/document"; +import "../core/identity"; +import "../core/rebind"; +import "../event/drag"; +import "../event/event"; +import "../event/mouse"; +import "../event/touch"; +import "behavior"; + +d3.behavior.drag = function() { + var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), + origin = null, + mousedown = dragstart(d3_noop, d3.mouse, d3_window, "mousemove", "mouseup"), + touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_identity, "touchmove", "touchend"); + + function drag() { + this.on("mousedown.drag", mousedown) + .on("touchstart.drag", touchstart); + } + + function dragstart(id, position, subject, move, end) { + return function() { + var that = this, + target = d3.event.target.correspondingElement || d3.event.target, + parent = that.parentNode, + dispatch = event.of(that, arguments), + dragged = 0, + dragId = id(), + dragName = ".drag" + (dragId == null ? "" : "-" + dragId), + dragOffset, + dragSubject = d3.select(subject(target)).on(move + dragName, moved).on(end + dragName, ended), + dragRestore = d3_event_dragSuppress(target), + position0 = position(parent, dragId); + + if (origin) { + dragOffset = origin.apply(that, arguments); + dragOffset = [dragOffset.x - position0[0], dragOffset.y - position0[1]]; + } else { + dragOffset = [0, 0]; + } + + dispatch({type: "dragstart"}); + + function moved() { + var position1 = position(parent, dragId), dx, dy; + if (!position1) return; // this touch didn’t move + + dx = position1[0] - position0[0]; + dy = position1[1] - position0[1]; + dragged |= dx | dy; + position0 = position1; + + dispatch({ + type: "drag", + x: position1[0] + dragOffset[0], + y: position1[1] + dragOffset[1], + dx: dx, + dy: dy + }); + } + + function ended() { + if (!position(parent, dragId)) return; // this touch didn’t end + dragSubject.on(move + dragName, null).on(end + dragName, null); + dragRestore(dragged); + dispatch({type: "dragend"}); + } + }; + } + + drag.origin = function(x) { + if (!arguments.length) return origin; + origin = x; + return drag; + }; + + return d3.rebind(drag, event, "on"); +}; + +// While it is possible to receive a touchstart event with more than one changed +// touch, the event is only shared by touches on the same target; for new +// touches targetting different elements, multiple touchstart events are +// received even when the touches start simultaneously. Since multiple touches +// cannot move the same target to different locations concurrently without +// tearing the fabric of spacetime, we allow the first touch to win. +function d3_behavior_dragTouchId() { + return d3.event.changedTouches[0].identifier; +} diff --git a/node_modules/@plotly/d3/src/behavior/index.js b/node_modules/@plotly/d3/src/behavior/index.js new file mode 100644 index 0000000000000000000000000000000000000000..5ce09321d28f75385590be3e6ace2e229c462956 --- /dev/null +++ b/node_modules/@plotly/d3/src/behavior/index.js @@ -0,0 +1,3 @@ +import "behavior"; +import "drag"; +import "zoom"; diff --git a/node_modules/@plotly/d3/src/behavior/zoom.js b/node_modules/@plotly/d3/src/behavior/zoom.js new file mode 100644 index 0000000000000000000000000000000000000000..2169e03e34e73453e4d9cd46ea92abaebd1fc8cc --- /dev/null +++ b/node_modules/@plotly/d3/src/behavior/zoom.js @@ -0,0 +1,348 @@ +import "../core/document"; +import "../core/rebind"; +import "../event/drag"; +import "../event/event"; +import "../event/mouse"; +import "../event/touches"; +import "../selection/selection"; +import "../interpolate/zoom"; +import "behavior"; + +d3.behavior.zoom = function() { + var view = {x: 0, y: 0, k: 1}, + translate0, // translate when we started zooming (to avoid drift) + center0, // implicit desired position of translate0 after zooming + center, // explicit desired position of translate0 after zooming + size = [960, 500], // viewport size; required for zoom interpolation + scaleExtent = d3_behavior_zoomInfinity, + duration = 250, + zooming = 0, + mousedown = "mousedown.zoom", + mousemove = "mousemove.zoom", + mouseup = "mouseup.zoom", + mousewheelTimer, + touchstart = "touchstart.zoom", + touchtime, // time of last touchstart (to detect double-tap) + event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"), + x0, + x1, + y0, + y1; + + // Lazily determine the DOM’s support for Wheel events. + // https://developer.mozilla.org/en-US/docs/Mozilla_event_reference/wheel + if (!d3_behavior_zoomWheel) { + d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() { return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1); }, "wheel") + : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() { return d3.event.wheelDelta; }, "mousewheel") + : (d3_behavior_zoomDelta = function() { return -d3.event.detail; }, "MozMousePixelScroll"); + } + + function zoom(g) { + g .on(mousedown, mousedowned) + .on(d3_behavior_zoomWheel + ".zoom", mousewheeled) + .on("dblclick.zoom", dblclicked) + .on(touchstart, touchstarted); + } + + zoom.event = function(g) { + g.each(function() { + var dispatch = event.of(this, arguments), + view1 = view; + if (d3_transitionInheritId) { + d3.select(this).transition() + .each("start.zoom", function() { + view = this.__chart__ || {x: 0, y: 0, k: 1}; // pre-transition state + zoomstarted(dispatch); + }) + .tween("zoom:zoom", function() { + var dx = size[0], + dy = size[1], + cx = center0 ? center0[0] : dx / 2, + cy = center0 ? center0[1] : dy / 2, + i = d3.interpolateZoom( + [(cx - view.x) / view.k, (cy - view.y) / view.k, dx / view.k], + [(cx - view1.x) / view1.k, (cy - view1.y) / view1.k, dx / view1.k] + ); + return function(t) { + var l = i(t), k = dx / l[2]; + this.__chart__ = view = {x: cx - l[0] * k, y: cy - l[1] * k, k: k}; + zoomed(dispatch); + }; + }) + .each("interrupt.zoom", function() { + zoomended(dispatch); + }) + .each("end.zoom", function() { + zoomended(dispatch); + }); + } else { + this.__chart__ = view; + zoomstarted(dispatch); + zoomed(dispatch); + zoomended(dispatch); + } + }); + } + + zoom.translate = function(_) { + if (!arguments.length) return [view.x, view.y]; + view = {x: +_[0], y: +_[1], k: view.k}; // copy-on-write + rescale(); + return zoom; + }; + + zoom.scale = function(_) { + if (!arguments.length) return view.k; + view = {x: view.x, y: view.y, k: null}; // copy-on-write + scaleTo(+_); + rescale(); + return zoom; + }; + + zoom.scaleExtent = function(_) { + if (!arguments.length) return scaleExtent; + scaleExtent = _ == null ? d3_behavior_zoomInfinity : [+_[0], +_[1]]; + return zoom; + }; + + zoom.center = function(_) { + if (!arguments.length) return center; + center = _ && [+_[0], +_[1]]; + return zoom; + }; + + zoom.size = function(_) { + if (!arguments.length) return size; + size = _ && [+_[0], +_[1]]; + return zoom; + }; + + zoom.duration = function(_) { + if (!arguments.length) return duration; + duration = +_; // TODO function based on interpolateZoom distance? + return zoom; + }; + + zoom.x = function(z) { + if (!arguments.length) return x1; + x1 = z; + x0 = z.copy(); + view = {x: 0, y: 0, k: 1}; // copy-on-write + return zoom; + }; + + zoom.y = function(z) { + if (!arguments.length) return y1; + y1 = z; + y0 = z.copy(); + view = {x: 0, y: 0, k: 1}; // copy-on-write + return zoom; + }; + + function location(p) { + return [(p[0] - view.x) / view.k, (p[1] - view.y) / view.k]; + } + + function point(l) { + return [l[0] * view.k + view.x, l[1] * view.k + view.y]; + } + + function scaleTo(s) { + view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s)); + } + + function translateTo(p, l) { + l = point(l); + view.x += p[0] - l[0]; + view.y += p[1] - l[1]; + } + + function zoomTo(that, p, l, k) { + that.__chart__ = {x: view.x, y: view.y, k: view.k}; + + scaleTo(Math.pow(2, k)); + translateTo(center0 = p, l); + + that = d3.select(that); + if (duration > 0) that = that.transition().duration(duration); + that.call(zoom.event); + } + + function rescale() { + if (x1) x1.domain(x0.range().map(function(x) { return (x - view.x) / view.k; }).map(x0.invert)); + if (y1) y1.domain(y0.range().map(function(y) { return (y - view.y) / view.k; }).map(y0.invert)); + } + + function zoomstarted(dispatch) { + if (!zooming++) dispatch({type: "zoomstart"}); + } + + function zoomed(dispatch) { + rescale(); + dispatch({type: "zoom", scale: view.k, translate: [view.x, view.y]}); + } + + function zoomended(dispatch) { + if (!--zooming) dispatch({type: "zoomend"}), center0 = null; + } + + function mousedowned() { + var that = this, + dispatch = event.of(that, arguments), + dragged = 0, + subject = d3.select(d3_window(that)).on(mousemove, moved).on(mouseup, ended), + location0 = location(d3.mouse(that)), + dragRestore = d3_event_dragSuppress(that); + + d3_selection_interrupt.call(that); + zoomstarted(dispatch); + + function moved() { + dragged = 1; + translateTo(d3.mouse(that), location0); + zoomed(dispatch); + } + + function ended() { + subject.on(mousemove, null).on(mouseup, null); + dragRestore(dragged); + zoomended(dispatch); + } + } + + // These closures persist for as long as at least one touch is active. + function touchstarted() { + var that = this, + dispatch = event.of(that, arguments), + locations0 = {}, // touchstart locations + distance0 = 0, // distance² between initial touches + scale0, // scale when we started touching + zoomName = ".zoom-" + d3.event.changedTouches[0].identifier, + touchmove = "touchmove" + zoomName, + touchend = "touchend" + zoomName, + targets = [], + subject = d3.select(that), + dragRestore = d3_event_dragSuppress(that); + + started(); + zoomstarted(dispatch); + + // Workaround for Chrome issue 412723: the touchstart listener must be set + // after the touchmove listener. + subject.on(mousedown, null).on(touchstart, started); // prevent duplicate events + + // Updates locations of any touches in locations0. + function relocate() { + var touches = d3.touches(that); + scale0 = view.k; + touches.forEach(function(t) { + if (t.identifier in locations0) locations0[t.identifier] = location(t); + }); + return touches; + } + + // Temporarily override touchstart while gesture is active. + function started() { + + // Listen for touchmove and touchend on the target of touchstart. + var target = d3.event.target; + d3.select(target).on(touchmove, moved).on(touchend, ended); + targets.push(target); + + // Only track touches started on the same subject element. + var changed = d3.event.changedTouches; + for (var i = 0, n = changed.length; i < n; ++i) { + locations0[changed[i].identifier] = null; + } + + var touches = relocate(), + now = Date.now(); + + if (touches.length === 1) { + if (now - touchtime < 500) { // dbltap + var p = touches[0]; + zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1); + d3_eventPreventDefault(); + } + touchtime = now; + } else if (touches.length > 1) { + var p = touches[0], q = touches[1], + dx = p[0] - q[0], dy = p[1] - q[1]; + distance0 = dx * dx + dy * dy; + } + } + + function moved() { + var touches = d3.touches(that), + p0, l0, + p1, l1; + + d3_selection_interrupt.call(that); + + for (var i = 0, n = touches.length; i < n; ++i, l1 = null) { + p1 = touches[i]; + if (l1 = locations0[p1.identifier]) { + if (l0) break; + p0 = p1, l0 = l1; + } + } + + if (l1) { + var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, + scale1 = distance0 && Math.sqrt(distance1 / distance0); + p0 = [(p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2]; + l0 = [(l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2]; + scaleTo(scale1 * scale0); + } + + touchtime = null; + translateTo(p0, l0); + zoomed(dispatch); + } + + function ended() { + // If there are any globally-active touches remaining, remove the ended + // touches from locations0. + if (d3.event.touches.length) { + var changed = d3.event.changedTouches; + for (var i = 0, n = changed.length; i < n; ++i) { + delete locations0[changed[i].identifier]; + } + // If locations0 is not empty, then relocate and continue listening for + // touchmove and touchend. + for (var identifier in locations0) { + return void relocate(); // locations may have detached due to rotation + } + } + // Otherwise, remove touchmove and touchend listeners. + d3.selectAll(targets).on(zoomName, null); + subject.on(mousedown, mousedowned).on(touchstart, touchstarted); + dragRestore(); + zoomended(dispatch); + } + } + + function mousewheeled() { + var dispatch = event.of(this, arguments); + if (mousewheelTimer) clearTimeout(mousewheelTimer); + else d3_selection_interrupt.call(this), translate0 = location(center0 = center || d3.mouse(this)), zoomstarted(dispatch); + mousewheelTimer = setTimeout(function() { mousewheelTimer = null; zoomended(dispatch); }, 50); + d3_eventPreventDefault(); + scaleTo(Math.pow(2, d3_behavior_zoomDelta() * 0.002) * view.k); + translateTo(center0, translate0); + zoomed(dispatch); + } + + function dblclicked() { + var p = d3.mouse(this), + k = Math.log(view.k) / Math.LN2; + + zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1); + } + + return d3.rebind(zoom, event, "on"); +}; + +var d3_behavior_zoomInfinity = [0, Infinity], // default scale extent + d3_behavior_zoomDelta, // initialized lazily + d3_behavior_zoomWheel; diff --git a/node_modules/@plotly/d3/src/color/color.js b/node_modules/@plotly/d3/src/color/color.js new file mode 100644 index 0000000000000000000000000000000000000000..5620feaf8c23bfa44c051f91481c404dd4ec9589 --- /dev/null +++ b/node_modules/@plotly/d3/src/color/color.js @@ -0,0 +1,7 @@ +d3.color = d3_color; + +function d3_color() {} + +d3_color.prototype.toString = function() { + return this.rgb() + ""; +}; diff --git a/node_modules/@plotly/d3/src/color/hcl.js b/node_modules/@plotly/d3/src/color/hcl.js new file mode 100644 index 0000000000000000000000000000000000000000..509fe3be5cce1c61c8a91e1a90841cec89a2a66c --- /dev/null +++ b/node_modules/@plotly/d3/src/color/hcl.js @@ -0,0 +1,34 @@ +import "../math/trigonometry"; +import "color"; +import "lab"; +import "rgb"; + +d3.hcl = d3_hcl; + +function d3_hcl(h, c, l) { + return this instanceof d3_hcl ? void (this.h = +h, this.c = +c, this.l = +l) + : arguments.length < 2 ? (h instanceof d3_hcl ? new d3_hcl(h.h, h.c, h.l) + : (h instanceof d3_lab ? d3_lab_hcl(h.l, h.a, h.b) + : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b))) + : new d3_hcl(h, c, l); +} + +var d3_hclPrototype = d3_hcl.prototype = new d3_color; + +d3_hclPrototype.brighter = function(k) { + return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1))); +}; + +d3_hclPrototype.darker = function(k) { + return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1))); +}; + +d3_hclPrototype.rgb = function() { + return d3_hcl_lab(this.h, this.c, this.l).rgb(); +}; + +function d3_hcl_lab(h, c, l) { + if (isNaN(h)) h = 0; + if (isNaN(c)) c = 0; + return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c); +} diff --git a/node_modules/@plotly/d3/src/color/hsl.js b/node_modules/@plotly/d3/src/color/hsl.js new file mode 100644 index 0000000000000000000000000000000000000000..2993f06363bcfad6f4d520ebb72caf6c8fba7e83 --- /dev/null +++ b/node_modules/@plotly/d3/src/color/hsl.js @@ -0,0 +1,56 @@ +import "color"; +import "rgb"; + +d3.hsl = d3_hsl; + +function d3_hsl(h, s, l) { + return this instanceof d3_hsl ? void (this.h = +h, this.s = +s, this.l = +l) + : arguments.length < 2 ? (h instanceof d3_hsl ? new d3_hsl(h.h, h.s, h.l) + : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl)) + : new d3_hsl(h, s, l); +} + +var d3_hslPrototype = d3_hsl.prototype = new d3_color; + +d3_hslPrototype.brighter = function(k) { + k = Math.pow(0.7, arguments.length ? k : 1); + return new d3_hsl(this.h, this.s, this.l / k); +}; + +d3_hslPrototype.darker = function(k) { + k = Math.pow(0.7, arguments.length ? k : 1); + return new d3_hsl(this.h, this.s, k * this.l); +}; + +d3_hslPrototype.rgb = function() { + return d3_hsl_rgb(this.h, this.s, this.l); +}; + +function d3_hsl_rgb(h, s, l) { + var m1, + m2; + + /* Some simple corrections for h, s and l. */ + h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h; + s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s; + l = l < 0 ? 0 : l > 1 ? 1 : l; + + /* From FvD 13.37, CSS Color Module Level 3 */ + m2 = l <= 0.5 ? l * (1 + s) : l + s - l * s; + m1 = 2 * l - m2; + + function v(h) { + if (h > 360) h -= 360; + else if (h < 0) h += 360; + if (h < 60) return m1 + (m2 - m1) * h / 60; + if (h < 180) return m2; + if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60; + return m1; + } + + function vv(h) { + return Math.round(v(h) * 255); + } + + return new d3_rgb(vv(h + 120), vv(h), vv(h - 120)); +} diff --git a/node_modules/@plotly/d3/src/color/index.js b/node_modules/@plotly/d3/src/color/index.js new file mode 100644 index 0000000000000000000000000000000000000000..3be3854c99d18655549a1e6ef96a19fbb7b629f3 --- /dev/null +++ b/node_modules/@plotly/d3/src/color/index.js @@ -0,0 +1,6 @@ +import "color"; +import "rgb"; +import "hsl"; +import "hcl"; +import "lab"; +import "xyz"; diff --git a/node_modules/@plotly/d3/src/color/lab.js b/node_modules/@plotly/d3/src/color/lab.js new file mode 100644 index 0000000000000000000000000000000000000000..36d8791528c14ffb244eeaeb44cc7fdc6a435aff --- /dev/null +++ b/node_modules/@plotly/d3/src/color/lab.js @@ -0,0 +1,60 @@ +import "../math/trigonometry"; +import "color"; +import "hcl"; +import "rgb"; + +d3.lab = d3_lab; + +function d3_lab(l, a, b) { + return this instanceof d3_lab ? void (this.l = +l, this.a = +a, this.b = +b) + : arguments.length < 2 ? (l instanceof d3_lab ? new d3_lab(l.l, l.a, l.b) + : (l instanceof d3_hcl ? d3_hcl_lab(l.h, l.c, l.l) + : d3_rgb_lab((l = d3_rgb(l)).r, l.g, l.b))) + : new d3_lab(l, a, b); +} + +// Corresponds roughly to RGB brighter/darker +var d3_lab_K = 18; + +// D65 standard referent +var d3_lab_X = 0.950470, + d3_lab_Y = 1, + d3_lab_Z = 1.088830; + +var d3_labPrototype = d3_lab.prototype = new d3_color; + +d3_labPrototype.brighter = function(k) { + return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b); +}; + +d3_labPrototype.darker = function(k) { + return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b); +}; + +d3_labPrototype.rgb = function() { + return d3_lab_rgb(this.l, this.a, this.b); +}; + +function d3_lab_rgb(l, a, b) { + var y = (l + 16) / 116, + x = y + a / 500, + z = y - b / 200; + x = d3_lab_xyz(x) * d3_lab_X; + y = d3_lab_xyz(y) * d3_lab_Y; + z = d3_lab_xyz(z) * d3_lab_Z; + return new d3_rgb( + d3_xyz_rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z), + d3_xyz_rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z), + d3_xyz_rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z) + ); +} + +function d3_lab_hcl(l, a, b) { + return l > 0 + ? new d3_hcl(Math.atan2(b, a) * d3_degrees, Math.sqrt(a * a + b * b), l) + : new d3_hcl(NaN, NaN, l); +} + +function d3_lab_xyz(x) { + return x > 0.206893034 ? x * x * x : (x - 4 / 29) / 7.787037; +} diff --git a/node_modules/@plotly/d3/src/color/rgb.js b/node_modules/@plotly/d3/src/color/rgb.js new file mode 100644 index 0000000000000000000000000000000000000000..bccc2d23321d0cae4c3a10498f309c506f55f598 --- /dev/null +++ b/node_modules/@plotly/d3/src/color/rgb.js @@ -0,0 +1,301 @@ +import "../arrays/map"; +import "color"; +import "hsl"; +import "lab"; +import "xyz"; + +d3.rgb = d3_rgb; + +function d3_rgb(r, g, b) { + return this instanceof d3_rgb ? void (this.r = ~~r, this.g = ~~g, this.b = ~~b) + : arguments.length < 2 ? (r instanceof d3_rgb ? new d3_rgb(r.r, r.g, r.b) + : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb)) + : new d3_rgb(r, g, b); +} + +function d3_rgbNumber(value) { + return new d3_rgb(value >> 16, value >> 8 & 0xff, value & 0xff); +} + +function d3_rgbString(value) { + return d3_rgbNumber(value) + ""; +} + +var d3_rgbPrototype = d3_rgb.prototype = new d3_color; + +d3_rgbPrototype.brighter = function(k) { + k = Math.pow(0.7, arguments.length ? k : 1); + var r = this.r, + g = this.g, + b = this.b, + i = 30; + if (!r && !g && !b) return new d3_rgb(i, i, i); + if (r && r < i) r = i; + if (g && g < i) g = i; + if (b && b < i) b = i; + return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k)); +}; + +d3_rgbPrototype.darker = function(k) { + k = Math.pow(0.7, arguments.length ? k : 1); + return new d3_rgb(k * this.r, k * this.g, k * this.b); +}; + +d3_rgbPrototype.hsl = function() { + return d3_rgb_hsl(this.r, this.g, this.b); +}; + +d3_rgbPrototype.toString = function() { + return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b); +}; + +function d3_rgb_hex(v) { + return v < 0x10 + ? "0" + Math.max(0, v).toString(16) + : Math.min(255, v).toString(16); +} + +function d3_rgb_parse(format, rgb, hsl) { + var r = 0, // red channel; int in [0, 255] + g = 0, // green channel; int in [0, 255] + b = 0, // blue channel; int in [0, 255] + m1, // CSS color specification match + m2, // CSS color specification type (e.g., rgb) + color; + + /* Handle hsl, rgb. */ + m1 = /([a-z]+)\((.*)\)/.exec(format = format.toLowerCase()); + if (m1) { + m2 = m1[2].split(","); + switch (m1[1]) { + case "hsl": { + return hsl( + parseFloat(m2[0]), // degrees + parseFloat(m2[1]) / 100, // percentage + parseFloat(m2[2]) / 100 // percentage + ); + } + case "rgb": { + return rgb( + d3_rgb_parseNumber(m2[0]), + d3_rgb_parseNumber(m2[1]), + d3_rgb_parseNumber(m2[2]) + ); + } + } + } + + /* Named colors. */ + if (color = d3_rgb_names.get(format)) { + return rgb(color.r, color.g, color.b); + } + + /* Hexadecimal colors: #rgb and #rrggbb. */ + if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.slice(1), 16))) { + if (format.length === 4) { + r = (color & 0xf00) >> 4; r = (r >> 4) | r; + g = (color & 0xf0); g = (g >> 4) | g; + b = (color & 0xf); b = (b << 4) | b; + } else if (format.length === 7) { + r = (color & 0xff0000) >> 16; + g = (color & 0xff00) >> 8; + b = (color & 0xff); + } + } + + return rgb(r, g, b); +} + +function d3_rgb_hsl(r, g, b) { + var min = Math.min(r /= 255, g /= 255, b /= 255), + max = Math.max(r, g, b), + d = max - min, + h, + s, + l = (max + min) / 2; + if (d) { + s = l < 0.5 ? d / (max + min) : d / (2 - max - min); + if (r == max) h = (g - b) / d + (g < b ? 6 : 0); + else if (g == max) h = (b - r) / d + 2; + else h = (r - g) / d + 4; + h *= 60; + } else { + h = NaN; + s = l > 0 && l < 1 ? 0 : h; + } + return new d3_hsl(h, s, l); +} + +function d3_rgb_lab(r, g, b) { + r = d3_rgb_xyz(r); + g = d3_rgb_xyz(g); + b = d3_rgb_xyz(b); + var x = d3_xyz_lab((0.4124564 * r + 0.3575761 * g + 0.1804375 * b) / d3_lab_X), + y = d3_xyz_lab((0.2126729 * r + 0.7151522 * g + 0.0721750 * b) / d3_lab_Y), + z = d3_xyz_lab((0.0193339 * r + 0.1191920 * g + 0.9503041 * b) / d3_lab_Z); + return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z)); +} + +function d3_rgb_xyz(r) { + return (r /= 255) <= 0.04045 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4); +} + +function d3_rgb_parseNumber(c) { // either integer or percentage + var f = parseFloat(c); + return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f; +} + +var d3_rgb_names = d3.map({ + aliceblue: 0xf0f8ff, + antiquewhite: 0xfaebd7, + aqua: 0x00ffff, + aquamarine: 0x7fffd4, + azure: 0xf0ffff, + beige: 0xf5f5dc, + bisque: 0xffe4c4, + black: 0x000000, + blanchedalmond: 0xffebcd, + blue: 0x0000ff, + blueviolet: 0x8a2be2, + brown: 0xa52a2a, + burlywood: 0xdeb887, + cadetblue: 0x5f9ea0, + chartreuse: 0x7fff00, + chocolate: 0xd2691e, + coral: 0xff7f50, + cornflowerblue: 0x6495ed, + cornsilk: 0xfff8dc, + crimson: 0xdc143c, + cyan: 0x00ffff, + darkblue: 0x00008b, + darkcyan: 0x008b8b, + darkgoldenrod: 0xb8860b, + darkgray: 0xa9a9a9, + darkgreen: 0x006400, + darkgrey: 0xa9a9a9, + darkkhaki: 0xbdb76b, + darkmagenta: 0x8b008b, + darkolivegreen: 0x556b2f, + darkorange: 0xff8c00, + darkorchid: 0x9932cc, + darkred: 0x8b0000, + darksalmon: 0xe9967a, + darkseagreen: 0x8fbc8f, + darkslateblue: 0x483d8b, + darkslategray: 0x2f4f4f, + darkslategrey: 0x2f4f4f, + darkturquoise: 0x00ced1, + darkviolet: 0x9400d3, + deeppink: 0xff1493, + deepskyblue: 0x00bfff, + dimgray: 0x696969, + dimgrey: 0x696969, + dodgerblue: 0x1e90ff, + firebrick: 0xb22222, + floralwhite: 0xfffaf0, + forestgreen: 0x228b22, + fuchsia: 0xff00ff, + gainsboro: 0xdcdcdc, + ghostwhite: 0xf8f8ff, + gold: 0xffd700, + goldenrod: 0xdaa520, + gray: 0x808080, + green: 0x008000, + greenyellow: 0xadff2f, + grey: 0x808080, + honeydew: 0xf0fff0, + hotpink: 0xff69b4, + indianred: 0xcd5c5c, + indigo: 0x4b0082, + ivory: 0xfffff0, + khaki: 0xf0e68c, + lavender: 0xe6e6fa, + lavenderblush: 0xfff0f5, + lawngreen: 0x7cfc00, + lemonchiffon: 0xfffacd, + lightblue: 0xadd8e6, + lightcoral: 0xf08080, + lightcyan: 0xe0ffff, + lightgoldenrodyellow: 0xfafad2, + lightgray: 0xd3d3d3, + lightgreen: 0x90ee90, + lightgrey: 0xd3d3d3, + lightpink: 0xffb6c1, + lightsalmon: 0xffa07a, + lightseagreen: 0x20b2aa, + lightskyblue: 0x87cefa, + lightslategray: 0x778899, + lightslategrey: 0x778899, + lightsteelblue: 0xb0c4de, + lightyellow: 0xffffe0, + lime: 0x00ff00, + limegreen: 0x32cd32, + linen: 0xfaf0e6, + magenta: 0xff00ff, + maroon: 0x800000, + mediumaquamarine: 0x66cdaa, + mediumblue: 0x0000cd, + mediumorchid: 0xba55d3, + mediumpurple: 0x9370db, + mediumseagreen: 0x3cb371, + mediumslateblue: 0x7b68ee, + mediumspringgreen: 0x00fa9a, + mediumturquoise: 0x48d1cc, + mediumvioletred: 0xc71585, + midnightblue: 0x191970, + mintcream: 0xf5fffa, + mistyrose: 0xffe4e1, + moccasin: 0xffe4b5, + navajowhite: 0xffdead, + navy: 0x000080, + oldlace: 0xfdf5e6, + olive: 0x808000, + olivedrab: 0x6b8e23, + orange: 0xffa500, + orangered: 0xff4500, + orchid: 0xda70d6, + palegoldenrod: 0xeee8aa, + palegreen: 0x98fb98, + paleturquoise: 0xafeeee, + palevioletred: 0xdb7093, + papayawhip: 0xffefd5, + peachpuff: 0xffdab9, + peru: 0xcd853f, + pink: 0xffc0cb, + plum: 0xdda0dd, + powderblue: 0xb0e0e6, + purple: 0x800080, + rebeccapurple: 0x663399, + red: 0xff0000, + rosybrown: 0xbc8f8f, + royalblue: 0x4169e1, + saddlebrown: 0x8b4513, + salmon: 0xfa8072, + sandybrown: 0xf4a460, + seagreen: 0x2e8b57, + seashell: 0xfff5ee, + sienna: 0xa0522d, + silver: 0xc0c0c0, + skyblue: 0x87ceeb, + slateblue: 0x6a5acd, + slategray: 0x708090, + slategrey: 0x708090, + snow: 0xfffafa, + springgreen: 0x00ff7f, + steelblue: 0x4682b4, + tan: 0xd2b48c, + teal: 0x008080, + thistle: 0xd8bfd8, + tomato: 0xff6347, + turquoise: 0x40e0d0, + violet: 0xee82ee, + wheat: 0xf5deb3, + white: 0xffffff, + whitesmoke: 0xf5f5f5, + yellow: 0xffff00, + yellowgreen: 0x9acd32 +}); + +d3_rgb_names.forEach(function(key, value) { + d3_rgb_names.set(key, d3_rgbNumber(value)); +}); diff --git a/node_modules/@plotly/d3/src/color/xyz.js b/node_modules/@plotly/d3/src/color/xyz.js new file mode 100644 index 0000000000000000000000000000000000000000..30e79ab412bf0557483eeb8ffe632036f22ab6f7 --- /dev/null +++ b/node_modules/@plotly/d3/src/color/xyz.js @@ -0,0 +1,7 @@ +function d3_xyz_lab(x) { + return x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29; +} + +function d3_xyz_rgb(r) { + return Math.round(255 * (r <= 0.00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - 0.055)); +} diff --git a/node_modules/@plotly/d3/src/compat/array.js b/node_modules/@plotly/d3/src/compat/array.js new file mode 100644 index 0000000000000000000000000000000000000000..d5a0ab6cb86f019f2f5e2ee1df087696875d8942 --- /dev/null +++ b/node_modules/@plotly/d3/src/compat/array.js @@ -0,0 +1,15 @@ +import "../core/array"; +import "../core/document"; + +// Redefine d3_array if the browser doesn’t support slice-based conversion. +if (d3_document) { + try { + d3_array(d3_document.documentElement.childNodes)[0].nodeType; + } catch (e) { + d3_array = function(list) { + var i = list.length, array = new Array(i); + while (i--) array[i] = list[i]; + return array; + }; + } +} diff --git a/node_modules/@plotly/d3/src/compat/date.js b/node_modules/@plotly/d3/src/compat/date.js new file mode 100644 index 0000000000000000000000000000000000000000..e682d4cb8099fa20419ef16e13addeeafc767acc --- /dev/null +++ b/node_modules/@plotly/d3/src/compat/date.js @@ -0,0 +1,3 @@ +if (!Date.now) Date.now = function() { + return +new Date; +}; diff --git a/node_modules/@plotly/d3/src/compat/index.js b/node_modules/@plotly/d3/src/compat/index.js new file mode 100644 index 0000000000000000000000000000000000000000..ec0e180e2a4ab5b59a51bb42620d355fc4eeb641 --- /dev/null +++ b/node_modules/@plotly/d3/src/compat/index.js @@ -0,0 +1,3 @@ +import "array"; +import "date"; +import "style"; diff --git a/node_modules/@plotly/d3/src/compat/style.js b/node_modules/@plotly/d3/src/compat/style.js new file mode 100644 index 0000000000000000000000000000000000000000..76563a20fe906fe74e443a2b0cdf1f19ee00322c --- /dev/null +++ b/node_modules/@plotly/d3/src/compat/style.js @@ -0,0 +1,23 @@ +import "../core/document"; + +// Redefine style.setProperty et al. if the browser doesn’t coerce arguments. +if (d3_document) { + try { + d3_document.createElement("DIV").style.setProperty("opacity", 0, ""); + } catch (error) { + var d3_element_prototype = this.Element.prototype, + d3_element_setAttribute = d3_element_prototype.setAttribute, + d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, + d3_style_prototype = this.CSSStyleDeclaration.prototype, + d3_style_setProperty = d3_style_prototype.setProperty; + d3_element_prototype.setAttribute = function(name, value) { + d3_element_setAttribute.call(this, name, value + ""); + }; + d3_element_prototype.setAttributeNS = function(space, local, value) { + d3_element_setAttributeNS.call(this, space, local, value + ""); + }; + d3_style_prototype.setProperty = function(name, value, priority) { + d3_style_setProperty.call(this, name, value + "", priority); + }; + } +} diff --git a/node_modules/@plotly/d3/src/core/array.js b/node_modules/@plotly/d3/src/core/array.js new file mode 100644 index 0000000000000000000000000000000000000000..cb4fd3661b765a099c15a6662d03f7e002fa8be8 --- /dev/null +++ b/node_modules/@plotly/d3/src/core/array.js @@ -0,0 +1,2 @@ +var d3_arraySlice = [].slice, + d3_array = function(list) { return d3_arraySlice.call(list); }; // conversion for NodeLists diff --git a/node_modules/@plotly/d3/src/core/class.js b/node_modules/@plotly/d3/src/core/class.js new file mode 100644 index 0000000000000000000000000000000000000000..7f1d7439f9cebba3c65fceee3c2af3310cca8ef3 --- /dev/null +++ b/node_modules/@plotly/d3/src/core/class.js @@ -0,0 +1,8 @@ +function d3_class(ctor, properties) { + for (var key in properties) { + Object.defineProperty(ctor.prototype, key, { + value: properties[key], + enumerable: false + }); + } +} diff --git a/node_modules/@plotly/d3/src/core/document.js b/node_modules/@plotly/d3/src/core/document.js new file mode 100644 index 0000000000000000000000000000000000000000..f59a21494000dfffe831302d1326507221a8173c --- /dev/null +++ b/node_modules/@plotly/d3/src/core/document.js @@ -0,0 +1,15 @@ +var d3_document = self.document; + +function d3_documentElement(node) { + return node + && (node.ownerDocument // node is a Node + || node.document // node is a Window + || node).documentElement; // node is a Document +} + +function d3_window(node) { + return node + && ((node.ownerDocument && node.ownerDocument.defaultView) // node is a Node + || (node.document && node) // node is a Window + || node.defaultView); // node is a Document +} diff --git a/node_modules/@plotly/d3/src/core/functor.js b/node_modules/@plotly/d3/src/core/functor.js new file mode 100644 index 0000000000000000000000000000000000000000..f8b1bf7cbbd525e3983c582b71f5da7ae2ee4589 --- /dev/null +++ b/node_modules/@plotly/d3/src/core/functor.js @@ -0,0 +1,5 @@ +function d3_functor(v) { + return typeof v === "function" ? v : function() { return v; }; +} + +d3.functor = d3_functor; diff --git a/node_modules/@plotly/d3/src/core/identity.js b/node_modules/@plotly/d3/src/core/identity.js new file mode 100644 index 0000000000000000000000000000000000000000..73893f86231a56439789740ec93d51d5957f1b40 --- /dev/null +++ b/node_modules/@plotly/d3/src/core/identity.js @@ -0,0 +1,3 @@ +function d3_identity(d) { + return d; +} diff --git a/node_modules/@plotly/d3/src/core/index.js b/node_modules/@plotly/d3/src/core/index.js new file mode 100644 index 0000000000000000000000000000000000000000..f6d233e0af93589ef238b25ccbe5c2461776eb56 --- /dev/null +++ b/node_modules/@plotly/d3/src/core/index.js @@ -0,0 +1,3 @@ +import "functor"; +import "ns"; +import "rebind"; diff --git a/node_modules/@plotly/d3/src/core/noop.js b/node_modules/@plotly/d3/src/core/noop.js new file mode 100644 index 0000000000000000000000000000000000000000..35f91d114d1b3ee28ff72423a87a398adf110d55 --- /dev/null +++ b/node_modules/@plotly/d3/src/core/noop.js @@ -0,0 +1 @@ +function d3_noop() {} diff --git a/node_modules/@plotly/d3/src/core/ns.js b/node_modules/@plotly/d3/src/core/ns.js new file mode 100644 index 0000000000000000000000000000000000000000..23f476291e2c05b6d239c5982942bfdefdb83259 --- /dev/null +++ b/node_modules/@plotly/d3/src/core/ns.js @@ -0,0 +1,18 @@ +var d3_nsXhtml = "http://www.w3.org/1999/xhtml"; + +var d3_nsPrefix = { + svg: "http://www.w3.org/2000/svg", + xhtml: d3_nsXhtml, + xlink: "http://www.w3.org/1999/xlink", + xml: "http://www.w3.org/XML/1998/namespace", + xmlns: "http://www.w3.org/2000/xmlns/" +}; + +d3.ns = { + prefix: d3_nsPrefix, + qualify: function(name) { + var i = name.indexOf(":"), prefix = name; + if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1); + return d3_nsPrefix.hasOwnProperty(prefix) ? {space: d3_nsPrefix[prefix], local: name} : name; + } +}; diff --git a/node_modules/@plotly/d3/src/core/rebind.js b/node_modules/@plotly/d3/src/core/rebind.js new file mode 100644 index 0000000000000000000000000000000000000000..d61184646eee4d52f67989d84d8f4fb5af237c06 --- /dev/null +++ b/node_modules/@plotly/d3/src/core/rebind.js @@ -0,0 +1,16 @@ +// Copies a variable number of methods from source to target. +d3.rebind = function(target, source) { + var i = 1, n = arguments.length, method; + while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]); + return target; +}; + +// Method is assumed to be a standard D3 getter-setter: +// If passed with no arguments, gets the value. +// If passed with arguments, sets the value and returns the target. +function d3_rebind(target, source, method) { + return function() { + var value = method.apply(source, arguments); + return value === source ? target : value; + }; +} diff --git a/node_modules/@plotly/d3/src/core/source.js b/node_modules/@plotly/d3/src/core/source.js new file mode 100644 index 0000000000000000000000000000000000000000..f56f50138f1b12c1d6a4985ca9fde0858f30ed29 --- /dev/null +++ b/node_modules/@plotly/d3/src/core/source.js @@ -0,0 +1,3 @@ +function d3_source(d) { + return d.source; +} diff --git a/node_modules/@plotly/d3/src/core/subclass.js b/node_modules/@plotly/d3/src/core/subclass.js new file mode 100644 index 0000000000000000000000000000000000000000..ea8dc856cda0b4dca7acd27d65349717c05692a7 --- /dev/null +++ b/node_modules/@plotly/d3/src/core/subclass.js @@ -0,0 +1,11 @@ +var d3_subclass = {}.__proto__? + +// Until ECMAScript supports array subclassing, prototype injection works well. +function(object, prototype) { + object.__proto__ = prototype; +}: + +// And if your browser doesn't support __proto__, we'll use direct extension. +function(object, prototype) { + for (var property in prototype) object[property] = prototype[property]; +}; diff --git a/node_modules/@plotly/d3/src/core/target.js b/node_modules/@plotly/d3/src/core/target.js new file mode 100644 index 0000000000000000000000000000000000000000..766ba7ee21267d56a6795175da7eec1570856072 --- /dev/null +++ b/node_modules/@plotly/d3/src/core/target.js @@ -0,0 +1,3 @@ +function d3_target(d) { + return d.target; +} diff --git a/node_modules/@plotly/d3/src/core/true.js b/node_modules/@plotly/d3/src/core/true.js new file mode 100644 index 0000000000000000000000000000000000000000..0900faf20833cec1cb2aae6b17596a0743ead520 --- /dev/null +++ b/node_modules/@plotly/d3/src/core/true.js @@ -0,0 +1,3 @@ +function d3_true() { + return true; +} diff --git a/node_modules/@plotly/d3/src/core/vendor.js b/node_modules/@plotly/d3/src/core/vendor.js new file mode 100644 index 0000000000000000000000000000000000000000..b92c7fe40ebe2fc82e790e30bf3d9d4878bcd805 --- /dev/null +++ b/node_modules/@plotly/d3/src/core/vendor.js @@ -0,0 +1,10 @@ +function d3_vendorSymbol(object, name) { + if (name in object) return name; + name = name.charAt(0).toUpperCase() + name.slice(1); + for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) { + var prefixName = d3_vendorPrefixes[i] + name; + if (prefixName in object) return prefixName; + } +} + +var d3_vendorPrefixes = ["webkit", "ms", "moz", "Moz", "o", "O"]; diff --git a/node_modules/@plotly/d3/src/core/zero.js b/node_modules/@plotly/d3/src/core/zero.js new file mode 100644 index 0000000000000000000000000000000000000000..18b52afe7eb1bf1d4c60de130b4403ff87567bf6 --- /dev/null +++ b/node_modules/@plotly/d3/src/core/zero.js @@ -0,0 +1,3 @@ +function d3_zero() { + return 0; +} diff --git a/node_modules/@plotly/d3/src/d3.js b/node_modules/@plotly/d3/src/d3.js new file mode 100644 index 0000000000000000000000000000000000000000..f5524beb407c6e1bbe4b4867388bacf85aea5cce Binary files /dev/null and b/node_modules/@plotly/d3/src/d3.js differ diff --git a/node_modules/@plotly/d3/src/dsv/csv.js b/node_modules/@plotly/d3/src/dsv/csv.js new file mode 100644 index 0000000000000000000000000000000000000000..2b6d94f68376d7ef4949840ce874693692caf5aa --- /dev/null +++ b/node_modules/@plotly/d3/src/dsv/csv.js @@ -0,0 +1,3 @@ +import "dsv"; + +d3.csv = d3.dsv(",", "text/csv"); diff --git a/node_modules/@plotly/d3/src/dsv/dsv.js b/node_modules/@plotly/d3/src/dsv/dsv.js new file mode 100644 index 0000000000000000000000000000000000000000..7c34171560bc787788f3ad1de21e6a353bf96344 --- /dev/null +++ b/node_modules/@plotly/d3/src/dsv/dsv.js @@ -0,0 +1,143 @@ +import "../arrays/set"; +import "../xhr/xhr"; + +d3.dsv = function(delimiter, mimeType) { + var reFormat = new RegExp("[\"" + delimiter + "\n]"), + delimiterCode = delimiter.charCodeAt(0); + + function dsv(url, row, callback) { + if (arguments.length < 3) callback = row, row = null; + var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback); + + xhr.row = function(_) { + return arguments.length + ? xhr.response((row = _) == null ? response : typedResponse(_)) + : row; + }; + + return xhr; + } + + function response(request) { + return dsv.parse(request.responseText); + } + + function typedResponse(f) { + return function(request) { + return dsv.parse(request.responseText, f); + }; + } + + dsv.parse = function(text, f) { + var o; + return dsv.parseRows(text, function(row, i) { + if (o) return o(row, i - 1); + + var a = function(d) { + var obj = {}; + var len = row.length; + for(var k = 0; k < len; ++k) { + obj[row[k]] = d[k]; + } + return obj; + } + + o = f ? function(row, i) { return f(a(row), i); } : a; + }); + }; + + dsv.parseRows = function(text, f) { + var EOL = {}, // sentinel value for end-of-line + EOF = {}, // sentinel value for end-of-file + rows = [], // output rows + N = text.length, + I = 0, // current character index + n = 0, // the current line number + t, // the current token + eol; // is the current token followed by EOL? + + function token() { + if (I >= N) return EOF; // special case: end of file + if (eol) return eol = false, EOL; // special case: end of line + + // special case: quotes + var j = I; + if (text.charCodeAt(j) === 34) { + var i = j; + while (i++ < N) { + if (text.charCodeAt(i) === 34) { + if (text.charCodeAt(i + 1) !== 34) break; + ++i; + } + } + I = i + 2; + var c = text.charCodeAt(i + 1); + if (c === 13) { + eol = true; + if (text.charCodeAt(i + 2) === 10) ++I; + } else if (c === 10) { + eol = true; + } + return text.slice(j + 1, i).replace(/""/g, "\""); + } + + // common case: find next delimiter or newline + while (I < N) { + var c = text.charCodeAt(I++), k = 1; + if (c === 10) eol = true; // \n + else if (c === 13) { eol = true; if (text.charCodeAt(I) === 10) ++I, ++k; } // \r|\r\n + else if (c !== delimiterCode) continue; + return text.slice(j, I - k); + } + + // special case: last token before EOF + return text.slice(j); + } + + while ((t = token()) !== EOF) { + var a = []; + while (t !== EOL && t !== EOF) { + a.push(t); + t = token(); + } + if (f && (a = f(a, n++)) == null) continue; + rows.push(a); + } + + return rows; + }; + + dsv.format = function(rows) { + if (Array.isArray(rows[0])) return dsv.formatRows(rows); // deprecated; use formatRows + var fieldSet = new d3_Set, fields = []; + + // Compute unique fields in order of discovery. + rows.forEach(function(row) { + for (var field in row) { + if (!fieldSet.has(field)) { + fields.push(fieldSet.add(field)); + } + } + }); + + return [fields.map(formatValue).join(delimiter)].concat(rows.map(function(row) { + return fields.map(function(field) { + return formatValue(row[field]); + }).join(delimiter); + })).join("\n"); + }; + + dsv.formatRows = function(rows) { + return rows.map(formatRow).join("\n"); + }; + + function formatRow(row) { + return row.map(formatValue).join(delimiter); + } + + function formatValue(text) { + return reFormat.test(text) ? "\"" + text.replace(/\"/g, "\"\"") + "\"" : text; + } + + return dsv; +}; diff --git a/node_modules/@plotly/d3/src/dsv/index.js b/node_modules/@plotly/d3/src/dsv/index.js new file mode 100644 index 0000000000000000000000000000000000000000..b92fc3cc14e90e53dd4ba6493fa496c344e79e44 --- /dev/null +++ b/node_modules/@plotly/d3/src/dsv/index.js @@ -0,0 +1,3 @@ +import "dsv"; +import "csv"; +import "tsv"; diff --git a/node_modules/@plotly/d3/src/dsv/tsv.js b/node_modules/@plotly/d3/src/dsv/tsv.js new file mode 100644 index 0000000000000000000000000000000000000000..1783744e2ab091a832ae3f8ab627f7e832797f64 --- /dev/null +++ b/node_modules/@plotly/d3/src/dsv/tsv.js @@ -0,0 +1,3 @@ +import "dsv"; + +d3.tsv = d3.dsv("\t", "text/tab-separated-values"); diff --git a/node_modules/@plotly/d3/src/end.js b/node_modules/@plotly/d3/src/end.js new file mode 100644 index 0000000000000000000000000000000000000000..a483c48695a12de95f4a13b28b369f254157f060 --- /dev/null +++ b/node_modules/@plotly/d3/src/end.js @@ -0,0 +1,4 @@ + if (typeof define === "function" && define.amd) define(d3); + else if (typeof module === "object" && module.exports) module.exports = d3; + else this.d3 = d3; +}.apply(self); diff --git a/node_modules/@plotly/d3/src/event/dispatch.js b/node_modules/@plotly/d3/src/event/dispatch.js new file mode 100644 index 0000000000000000000000000000000000000000..9b85ccdb66c66f1872254d66217691aecfa5b029 --- /dev/null +++ b/node_modules/@plotly/d3/src/event/dispatch.js @@ -0,0 +1,69 @@ +import "../arrays/map"; + +d3.dispatch = function() { + var dispatch = new d3_dispatch, + i = -1, + n = arguments.length; + while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch); + return dispatch; +}; + +function d3_dispatch() {} + +d3_dispatch.prototype.on = function(type, listener) { + var i = type.indexOf("."), + name = ""; + + // Extract optional namespace, e.g., "click.foo" + if (i >= 0) { + name = type.slice(i + 1); + type = type.slice(0, i); + } + + if (type) return arguments.length < 2 + ? this[type].on(name) + : this[type].on(name, listener); + + if (arguments.length === 2) { + if (listener == null) for (type in this) { + if (this.hasOwnProperty(type)) this[type].on(name, null); + } + return this; + } +}; + +function d3_dispatch_event(dispatch) { + var listeners = [], + listenerByName = new d3_Map; + + function event() { + var z = listeners, // defensive reference + i = -1, + n = z.length, + l; + while (++i < n) if (l = z[i].on) l.apply(this, arguments); + return dispatch; + } + + event.on = function(name, listener) { + var l = listenerByName.get(name), + i; + + // return the current listener, if any + if (arguments.length < 2) return l && l.on; + + // remove the old listener, if any (with copy-on-write) + if (l) { + l.on = null; + listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1)); + listenerByName.remove(name); + } + + // add the new listener, if any + if (listener) listeners.push(listenerByName.set(name, {on: listener})); + + return dispatch; + }; + + return event; +} diff --git a/node_modules/@plotly/d3/src/event/drag.js b/node_modules/@plotly/d3/src/event/drag.js new file mode 100644 index 0000000000000000000000000000000000000000..8687ccf7f562d0b8b5dca7c870d5c1a26e9bcb88 --- /dev/null +++ b/node_modules/@plotly/d3/src/event/drag.js @@ -0,0 +1,36 @@ +import "../core/document"; +import "../core/vendor"; +import "../selection/on"; + +var d3_event_dragSelect, + d3_event_dragId = 0; + +function d3_event_dragSuppress(node) { + var name = ".dragsuppress-" + ++d3_event_dragId, + click = "click" + name, + w = d3.select(d3_window(node)) + .on("touchmove" + name, d3_eventPreventDefault) + .on("dragstart" + name, d3_eventPreventDefault) + .on("selectstart" + name, d3_eventPreventDefault); + + if (d3_event_dragSelect == null) { + d3_event_dragSelect = "onselectstart" in node ? false + : d3_vendorSymbol(node.style, "userSelect"); + } + + if (d3_event_dragSelect) { + var style = d3_documentElement(node).style, + select = style[d3_event_dragSelect]; + style[d3_event_dragSelect] = "none"; + } + + return function(suppressClick) { + w.on(name, null); + if (d3_event_dragSelect) style[d3_event_dragSelect] = select; + if (suppressClick) { // suppress the next click, but only if it’s immediate + var off = function() { w.on(click, null); }; + w.on(click, function() { d3_eventPreventDefault(); off(); }, true); + setTimeout(off, 0); + } + }; +} diff --git a/node_modules/@plotly/d3/src/event/event.js b/node_modules/@plotly/d3/src/event/event.js new file mode 100644 index 0000000000000000000000000000000000000000..71e676ee9058c9f1b14d7223285019ad039f03fe --- /dev/null +++ b/node_modules/@plotly/d3/src/event/event.js @@ -0,0 +1,50 @@ +import "dispatch"; + +d3.event = null; + +function d3_eventPreventDefault() { + d3.event.preventDefault(); +} + +function d3_eventSource() { + var e = d3.event, s; + while (s = e.sourceEvent) e = s; + return e; +} + +// Like d3.dispatch, but for custom events abstracting native UI events. These +// events have a target component (such as a brush), a target element (such as +// the svg:g element containing the brush) and the standard arguments `d` (the +// target element's data) and `i` (the selection index of the target element). +function d3_eventDispatch(target) { + var dispatch = new d3_dispatch, + i = 0, + n = arguments.length; + + while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch); + + // Creates a dispatch context for the specified `thiz` (typically, the target + // DOM element that received the source event) and `argumentz` (typically, the + // data `d` and index `i` of the target element). The returned function can be + // used to dispatch an event to any registered listeners; the function takes a + // single argument as input, being the event to dispatch. The event must have + // a "type" attribute which corresponds to a type registered in the + // constructor. This context will automatically populate the "sourceEvent" and + // "target" attributes of the event, as well as setting the `d3.event` global + // for the duration of the notification. + dispatch.of = function(thiz, argumentz) { + return function(e1) { + try { + var e0 = + e1.sourceEvent = d3.event; + e1.target = target; + d3.event = e1; + dispatch[e1.type].apply(thiz, argumentz); + } finally { + d3.event = e0; + } + }; + }; + + return dispatch; +} diff --git a/node_modules/@plotly/d3/src/event/index.js b/node_modules/@plotly/d3/src/event/index.js new file mode 100644 index 0000000000000000000000000000000000000000..4bb5a45b68caeb79359fa771a36a69f1a36bcd74 --- /dev/null +++ b/node_modules/@plotly/d3/src/event/index.js @@ -0,0 +1,6 @@ +import "dispatch"; +import "event"; +import "mouse"; +import "touch"; +import "touches"; +import "timer"; diff --git a/node_modules/@plotly/d3/src/event/mouse.js b/node_modules/@plotly/d3/src/event/mouse.js new file mode 100644 index 0000000000000000000000000000000000000000..a6994b93fdc9131ccbdb75df001d92325173bff1 --- /dev/null +++ b/node_modules/@plotly/d3/src/event/mouse.js @@ -0,0 +1,39 @@ +import "../core/document"; +import "event"; + +d3.mouse = function(container) { + return d3_mousePoint(container, d3_eventSource()); +}; + +// https://bugs.webkit.org/show_bug.cgi?id=44083 +var d3_mouse_bug44083 = this.navigator && /WebKit/.test(this.navigator.userAgent) ? -1 : 0; + +function d3_mousePoint(container, e) { + if (e.changedTouches) e = e.changedTouches[0]; + var svg = container.ownerSVGElement || container; + if (svg.createSVGPoint) { + var point = svg.createSVGPoint(); + if (d3_mouse_bug44083 < 0) { + var window = d3_window(container); + if (window.scrollX || window.scrollY) { + svg = d3.select("body").append("svg").style({ + position: "absolute", + top: 0, + left: 0, + margin: 0, + padding: 0, + border: "none" + }, "important"); + var ctm = svg[0][0].getScreenCTM(); + d3_mouse_bug44083 = !(ctm.f || ctm.e); + svg.remove(); + } + } + if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; + else point.x = e.clientX, point.y = e.clientY; + point = point.matrixTransform(container.getScreenCTM().inverse()); + return [point.x, point.y]; + } + var rect = container.getBoundingClientRect(); + return [e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop]; +}; diff --git a/node_modules/@plotly/d3/src/event/timer.js b/node_modules/@plotly/d3/src/event/timer.js new file mode 100644 index 0000000000000000000000000000000000000000..e6dd6ab97fc20876040e2c178c176785fa129ac5 --- /dev/null +++ b/node_modules/@plotly/d3/src/event/timer.js @@ -0,0 +1,82 @@ +import "../core/document"; +import "../core/vendor"; + +var d3_timer_queueHead, + d3_timer_queueTail, + d3_timer_interval, // is an interval (or frame) active? + d3_timer_timeout, // is a timeout active? + d3_timer_frame = this[d3_vendorSymbol(this, "requestAnimationFrame")] || function(callback) { setTimeout(callback, 17); }; + +// The timer will continue to fire until callback returns true. +d3.timer = function() { + d3_timer.apply(this, arguments); +}; + +function d3_timer(callback, delay, then) { + var n = arguments.length; + if (n < 2) delay = 0; + if (n < 3) then = Date.now(); + + // Add the callback to the tail of the queue. + var time = then + delay, timer = {c: callback, t: time, n: null}; + if (d3_timer_queueTail) d3_timer_queueTail.n = timer; + else d3_timer_queueHead = timer; + d3_timer_queueTail = timer; + + // Start animatin'! + if (!d3_timer_interval) { + d3_timer_timeout = clearTimeout(d3_timer_timeout); + d3_timer_interval = 1; + d3_timer_frame(d3_timer_step); + } + + return timer; +} + +function d3_timer_step() { + var now = d3_timer_mark(), + delay = d3_timer_sweep() - now; + if (delay > 24) { + if (isFinite(delay)) { + clearTimeout(d3_timer_timeout); + d3_timer_timeout = setTimeout(d3_timer_step, delay); + } + d3_timer_interval = 0; + } else { + d3_timer_interval = 1; + d3_timer_frame(d3_timer_step); + } +} + +d3.timer.flush = function() { + d3_timer_mark(); + d3_timer_sweep(); +}; + +function d3_timer_mark() { + var now = Date.now(), + timer = d3_timer_queueHead; + while (timer) { + if (now >= timer.t && timer.c(now - timer.t)) timer.c = null; + timer = timer.n; + } + return now; +} + +// Flush after callbacks to avoid concurrent queue modification. +// Returns the time of the earliest active timer, post-sweep. +function d3_timer_sweep() { + var t0, + t1 = d3_timer_queueHead, + time = Infinity; + while (t1) { + if (t1.c) { + if (t1.t < time) time = t1.t; + t1 = (t0 = t1).n; + } else { + t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n; + } + } + d3_timer_queueTail = t0; + return time; +} diff --git a/node_modules/@plotly/d3/src/event/touch.js b/node_modules/@plotly/d3/src/event/touch.js new file mode 100644 index 0000000000000000000000000000000000000000..b9828ca2671e300350d7ef634739c32e3a855fcd --- /dev/null +++ b/node_modules/@plotly/d3/src/event/touch.js @@ -0,0 +1,11 @@ +import "event"; +import "mouse"; + +d3.touch = function(container, touches, identifier) { + if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches; + if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) { + if ((touch = touches[i]).identifier === identifier) { + return d3_mousePoint(container, touch); + } + } +}; diff --git a/node_modules/@plotly/d3/src/event/touches.js b/node_modules/@plotly/d3/src/event/touches.js new file mode 100644 index 0000000000000000000000000000000000000000..a7cbaa5f91d29ea37a0033b41bf9366cb15afdc0 --- /dev/null +++ b/node_modules/@plotly/d3/src/event/touches.js @@ -0,0 +1,12 @@ +import "../core/array"; +import "event"; +import "mouse"; + +d3.touches = function(container, touches) { + if (arguments.length < 2) touches = d3_eventSource().touches; + return touches ? d3_array(touches).map(function(touch) { + var point = d3_mousePoint(container, touch); + point.identifier = touch.identifier; + return point; + }) : []; +}; diff --git a/node_modules/@plotly/d3/src/format/collapse.js b/node_modules/@plotly/d3/src/format/collapse.js new file mode 100644 index 0000000000000000000000000000000000000000..08adc3a69e755beb47b6fd28c53573c8c121763d --- /dev/null +++ b/node_modules/@plotly/d3/src/format/collapse.js @@ -0,0 +1,3 @@ +function d3_collapse(s) { + return s.trim().replace(/\s+/g, " "); +} diff --git a/node_modules/@plotly/d3/src/format/index.js b/node_modules/@plotly/d3/src/format/index.js new file mode 100644 index 0000000000000000000000000000000000000000..688fa052daf4f5afeaffbc6846d2297b8bf9ad15 --- /dev/null +++ b/node_modules/@plotly/d3/src/format/index.js @@ -0,0 +1,2 @@ +import "requote"; +import "round"; diff --git a/node_modules/@plotly/d3/src/format/requote.js b/node_modules/@plotly/d3/src/format/requote.js new file mode 100644 index 0000000000000000000000000000000000000000..99dbf15a7df497450f79cf36b4c3f18f144c5a97 --- /dev/null +++ b/node_modules/@plotly/d3/src/format/requote.js @@ -0,0 +1,5 @@ +d3.requote = function(s) { + return s.replace(d3_requote_re, "\\$&"); +}; + +var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g; diff --git a/node_modules/@plotly/d3/src/format/round.js b/node_modules/@plotly/d3/src/format/round.js new file mode 100644 index 0000000000000000000000000000000000000000..44e9574295a465695e4559b724afd7eb410b9737 --- /dev/null +++ b/node_modules/@plotly/d3/src/format/round.js @@ -0,0 +1,5 @@ +d3.round = function(x, n) { + return n + ? Math.round(x * (n = Math.pow(10, n))) / n + : Math.round(x); +}; diff --git a/node_modules/@plotly/d3/src/geom/clip-line.js b/node_modules/@plotly/d3/src/geom/clip-line.js new file mode 100644 index 0000000000000000000000000000000000000000..c83c412edaf832b4f6564ee57a8677aef519a65d --- /dev/null +++ b/node_modules/@plotly/d3/src/geom/clip-line.js @@ -0,0 +1,66 @@ +import "../math/trigonometry"; + +// Liang–Barsky line clipping. +function d3_geom_clipLine(x0, y0, x1, y1) { + return function(line) { + var a = line.a, + b = line.b, + ax = a.x, + ay = a.y, + bx = b.x, + by = b.y, + t0 = 0, + t1 = 1, + dx = bx - ax, + dy = by - ay, + r; + + r = x0 - ax; + if (!dx && r > 0) return; + r /= dx; + if (dx < 0) { + if (r < t0) return; + if (r < t1) t1 = r; + } else if (dx > 0) { + if (r > t1) return; + if (r > t0) t0 = r; + } + + r = x1 - ax; + if (!dx && r < 0) return; + r /= dx; + if (dx < 0) { + if (r > t1) return; + if (r > t0) t0 = r; + } else if (dx > 0) { + if (r < t0) return; + if (r < t1) t1 = r; + } + + r = y0 - ay; + if (!dy && r > 0) return; + r /= dy; + if (dy < 0) { + if (r < t0) return; + if (r < t1) t1 = r; + } else if (dy > 0) { + if (r > t1) return; + if (r > t0) t0 = r; + } + + r = y1 - ay; + if (!dy && r < 0) return; + r /= dy; + if (dy < 0) { + if (r > t1) return; + if (r > t0) t0 = r; + } else if (dy > 0) { + if (r < t0) return; + if (r < t1) t1 = r; + } + + if (t0 > 0) line.a = {x: ax + t0 * dx, y: ay + t0 * dy}; + if (t1 < 1) line.b = {x: ax + t1 * dx, y: ay + t1 * dy}; + return line; + }; +} diff --git a/node_modules/@plotly/d3/src/geom/delaunay.js b/node_modules/@plotly/d3/src/geom/delaunay.js new file mode 100644 index 0000000000000000000000000000000000000000..0a60cd11d00c0d48862d05de9974442998043fe3 --- /dev/null +++ b/node_modules/@plotly/d3/src/geom/delaunay.js @@ -0,0 +1,6 @@ +import "geom"; + +// @deprecated; use d3.geom.voronoi triangles instead. +d3.geom.delaunay = function(vertices) { + return d3.geom.voronoi().triangles(vertices); +}; diff --git a/node_modules/@plotly/d3/src/geom/geom.js b/node_modules/@plotly/d3/src/geom/geom.js new file mode 100644 index 0000000000000000000000000000000000000000..b17c4fc30609d35d1ba69e2b64379efdff03fc66 --- /dev/null +++ b/node_modules/@plotly/d3/src/geom/geom.js @@ -0,0 +1 @@ +d3.geom = {}; diff --git a/node_modules/@plotly/d3/src/geom/hull.js b/node_modules/@plotly/d3/src/geom/hull.js new file mode 100644 index 0000000000000000000000000000000000000000..7abce151e403f22435d18a9e81daee08c3c49e17 --- /dev/null +++ b/node_modules/@plotly/d3/src/geom/hull.js @@ -0,0 +1,91 @@ +import "../core/functor"; +import "../math/trigonometry"; +import "geom"; +import "point"; + +/** + * Computes the 2D convex hull of a set of points using the monotone chain + * algorithm: + * http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain) + * + * The runtime of this algorithm is O(n log n), where n is the number of input + * points. However in practice it outperforms other O(n log n) hulls. + * + * @param vertices [[x1, y1], [x2, y2], ...] + * @returns polygon [[x1, y1], [x2, y2], ...] + */ +d3.geom.hull = function(vertices) { + var x = d3_geom_pointX, + y = d3_geom_pointY; + + if (arguments.length) return hull(vertices); + + function hull(data) { + // Hull of < 3 points is not well-defined + if (data.length < 3) return []; + + var fx = d3_functor(x), + fy = d3_functor(y), + i, + n = data.length, + points = [], // of the form [[x0, y0, 0], ..., [xn, yn, n]] + flippedPoints = []; + + for (i = 0 ; i < n; i++) { + points.push([+fx.call(this, data[i], i), +fy.call(this, data[i], i), i]); + } + + // sort ascending by x-coord first, y-coord second + points.sort(d3_geom_hullOrder); + + // we flip bottommost points across y axis so we can use the upper hull routine on both + for (i = 0; i < n; i++) flippedPoints.push([points[i][0], -points[i][1]]); + + var upper = d3_geom_hullUpper(points), + lower = d3_geom_hullUpper(flippedPoints); + + // construct the polygon, removing possible duplicate endpoints + var skipLeft = lower[0] === upper[0], + skipRight = lower[lower.length - 1] === upper[upper.length - 1], + polygon = []; + + // add upper hull in r->l order + // then add lower hull in l->r order + for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]); + for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]); + + return polygon; + } + + hull.x = function(_) { + return arguments.length ? (x = _, hull) : x; + }; + + hull.y = function(_) { + return arguments.length ? (y = _, hull) : y; + }; + + return hull; +}; + +// finds the 'upper convex hull' (see wiki link above) +// assumes points arg has >=3 elements, is sorted by x, unique in y +// returns array of indices into points in left to right order +function d3_geom_hullUpper(points) { + var n = points.length, + hull = [0, 1], + hs = 2; // hull size + + for (var i = 2; i < n; i++) { + while (hs > 1 && d3_cross2d(points[hull[hs-2]], points[hull[hs-1]], points[i]) <= 0) --hs; + hull[hs++] = i; + } + + // we slice to make sure that the points we 'popped' from hull don't stay behind + return hull.slice(0, hs); +} + +// comparator for ascending sort by x-coord first, y-coord second +function d3_geom_hullOrder(a, b) { + return a[0] - b[0] || a[1] - b[1]; +} diff --git a/node_modules/@plotly/d3/src/geom/index.js b/node_modules/@plotly/d3/src/geom/index.js new file mode 100644 index 0000000000000000000000000000000000000000..9e2fb282d4c274ad7b6b59b6a1c1f4a9724aeed1 --- /dev/null +++ b/node_modules/@plotly/d3/src/geom/index.js @@ -0,0 +1,6 @@ +import "geom"; +import "hull"; +import "polygon"; +import "voronoi"; +import "delaunay"; +import "quadtree"; diff --git a/node_modules/@plotly/d3/src/geom/point.js b/node_modules/@plotly/d3/src/geom/point.js new file mode 100644 index 0000000000000000000000000000000000000000..10cfe3ebd17b0d80814816bb31c16fa2a3c41a07 --- /dev/null +++ b/node_modules/@plotly/d3/src/geom/point.js @@ -0,0 +1,7 @@ +function d3_geom_pointX(d) { + return d[0]; +} + +function d3_geom_pointY(d) { + return d[1]; +} diff --git a/node_modules/@plotly/d3/src/geom/polygon.js b/node_modules/@plotly/d3/src/geom/polygon.js new file mode 100644 index 0000000000000000000000000000000000000000..692bf8e44c56eacda374b442c1002511b94ee502 --- /dev/null +++ b/node_modules/@plotly/d3/src/geom/polygon.js @@ -0,0 +1,105 @@ +import "../core/subclass"; +import "geom"; + +d3.geom.polygon = function(coordinates) { + d3_subclass(coordinates, d3_geom_polygonPrototype); + return coordinates; +}; + +var d3_geom_polygonPrototype = d3.geom.polygon.prototype = []; + +d3_geom_polygonPrototype.area = function() { + var i = -1, + n = this.length, + a, + b = this[n - 1], + area = 0; + + while (++i < n) { + a = b; + b = this[i]; + area += a[1] * b[0] - a[0] * b[1]; + } + + return area * 0.5; +}; + +d3_geom_polygonPrototype.centroid = function(k) { + var i = -1, + n = this.length, + x = 0, + y = 0, + a, + b = this[n - 1], + c; + + if (!arguments.length) k = -1 / (6 * this.area()); + + while (++i < n) { + a = b; + b = this[i]; + c = a[0] * b[1] - b[0] * a[1]; + x += (a[0] + b[0]) * c; + y += (a[1] + b[1]) * c; + } + + return [x * k, y * k]; +}; + +// The Sutherland-Hodgman clipping algorithm. +// Note: requires the clip polygon to be counterclockwise and convex. +d3_geom_polygonPrototype.clip = function(subject) { + var input, + closed = d3_geom_polygonClosed(subject), + i = -1, + n = this.length - d3_geom_polygonClosed(this), + j, + m, + a = this[n - 1], + b, + c, + d; + + while (++i < n) { + input = subject.slice(); + subject.length = 0; + b = this[i]; + c = input[(m = input.length - closed) - 1]; + j = -1; + while (++j < m) { + d = input[j]; + if (d3_geom_polygonInside(d, a, b)) { + if (!d3_geom_polygonInside(c, a, b)) { + subject.push(d3_geom_polygonIntersect(c, d, a, b)); + } + subject.push(d); + } else if (d3_geom_polygonInside(c, a, b)) { + subject.push(d3_geom_polygonIntersect(c, d, a, b)); + } + c = d; + } + if (closed) subject.push(subject[0]); + a = b; + } + + return subject; +}; + +function d3_geom_polygonInside(p, a, b) { + return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]); +} + +// Intersect two infinite lines cd and ab. +function d3_geom_polygonIntersect(c, d, a, b) { + var x1 = c[0], x3 = a[0], x21 = d[0] - x1, x43 = b[0] - x3, + y1 = c[1], y3 = a[1], y21 = d[1] - y1, y43 = b[1] - y3, + ua = (x43 * (y1 - y3) - y43 * (x1 - x3)) / (y43 * x21 - x43 * y21); + return [x1 + ua * x21, y1 + ua * y21]; +} + +// Returns true if the polygon is closed. +function d3_geom_polygonClosed(coordinates) { + var a = coordinates[0], + b = coordinates[coordinates.length - 1]; + return !(a[0] - b[0] || a[1] - b[1]); +} diff --git a/node_modules/@plotly/d3/src/geom/quadtree.js b/node_modules/@plotly/d3/src/geom/quadtree.js new file mode 100644 index 0000000000000000000000000000000000000000..a9c3197bff5c2a1e8223bfe3f8fd7b146f0f8315 --- /dev/null +++ b/node_modules/@plotly/d3/src/geom/quadtree.js @@ -0,0 +1,243 @@ +import "../core/functor"; +import "../math/abs"; +import "geom"; +import "point"; + +d3.geom.quadtree = function(points, x1, y1, x2, y2) { + var x = d3_geom_pointX, + y = d3_geom_pointY, + compat; + + // For backwards-compatibility. + if (compat = arguments.length) { + x = d3_geom_quadtreeCompatX; + y = d3_geom_quadtreeCompatY; + if (compat === 3) { + y2 = y1; + x2 = x1; + y1 = x1 = 0; + } + return quadtree(points); + } + + function quadtree(data) { + var d, + fx = d3_functor(x), + fy = d3_functor(y), + xs, + ys, + i, + n, + x1_, + y1_, + x2_, + y2_; + + if (x1 != null) { + x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2; + } else { + // Compute bounds, and cache points temporarily. + x2_ = y2_ = -(x1_ = y1_ = Infinity); + xs = [], ys = []; + n = data.length; + if (compat) for (i = 0; i < n; ++i) { + d = data[i]; + if (d.x < x1_) x1_ = d.x; + if (d.y < y1_) y1_ = d.y; + if (d.x > x2_) x2_ = d.x; + if (d.y > y2_) y2_ = d.y; + xs.push(d.x); + ys.push(d.y); + } else for (i = 0; i < n; ++i) { + var x_ = +fx(d = data[i], i), + y_ = +fy(d, i); + if (x_ < x1_) x1_ = x_; + if (y_ < y1_) y1_ = y_; + if (x_ > x2_) x2_ = x_; + if (y_ > y2_) y2_ = y_; + xs.push(x_); + ys.push(y_); + } + } + + // Squarify the bounds. + var dx = x2_ - x1_, + dy = y2_ - y1_; + if (dx > dy) y2_ = y1_ + dx; + else x2_ = x1_ + dy; + + // Recursively inserts the specified point p at the node n or one of its + // descendants. The bounds are defined by [x1, x2] and [y1, y2]. + function insert(n, d, x, y, x1, y1, x2, y2) { + if (isNaN(x) || isNaN(y)) return; // ignore invalid points + if (n.leaf) { + var nx = n.x, + ny = n.y; + if (nx != null) { + // If the point at this leaf node is at the same position as the new + // point we are adding, we leave the point associated with the + // internal node while adding the new point to a child node. This + // avoids infinite recursion. + if ((abs(nx - x) + abs(ny - y)) < 0.01) { + insertChild(n, d, x, y, x1, y1, x2, y2); + } else { + var nPoint = n.point; + n.x = n.y = n.point = null; + insertChild(n, nPoint, nx, ny, x1, y1, x2, y2); + insertChild(n, d, x, y, x1, y1, x2, y2); + } + } else { + n.x = x, n.y = y, n.point = d; + } + } else { + insertChild(n, d, x, y, x1, y1, x2, y2); + } + } + + // Recursively inserts the specified point [x, y] into a descendant of node + // n. The bounds are defined by [x1, x2] and [y1, y2]. + function insertChild(n, d, x, y, x1, y1, x2, y2) { + // Compute the split point, and the quadrant in which to insert p. + var xm = (x1 + x2) * 0.5, + ym = (y1 + y2) * 0.5, + right = x >= xm, + below = y >= ym, + i = below << 1 | right; + + // Recursively insert into the child node. + n.leaf = false; + n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode()); + + // Update the bounds as we recurse. + if (right) x1 = xm; else x2 = xm; + if (below) y1 = ym; else y2 = ym; + insert(n, d, x, y, x1, y1, x2, y2); + } + + // Create the root node. + var root = d3_geom_quadtreeNode(); + + root.add = function(d) { + insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_); + }; + + root.visit = function(f) { + d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_); + }; + + // Find the closest point to the specified point. + // TODO allow the initial search extent to be specified? + // TODO allow the initial minimum distance to be specified? + // TODO allow searching below any node? + root.find = function(point) { + return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_); + }; + + // Insert all points. + i = -1; + if (x1 == null) { + while (++i < n) { + insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_); + } + --i; // index of last insertion + } else data.forEach(root.add); + + // Discard captured fields. + xs = ys = data = d = null; + + return root; + } + + quadtree.x = function(_) { + return arguments.length ? (x = _, quadtree) : x; + }; + + quadtree.y = function(_) { + return arguments.length ? (y = _, quadtree) : y; + }; + + quadtree.extent = function(_) { + if (!arguments.length) return x1 == null ? null : [[x1, y1], [x2, y2]]; + if (_ == null) x1 = y1 = x2 = y2 = null; + else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0], y2 = +_[1][1]; + return quadtree; + }; + + quadtree.size = function(_) { + if (!arguments.length) return x1 == null ? null : [x2 - x1, y2 - y1]; + if (_ == null) x1 = y1 = x2 = y2 = null; + else x1 = y1 = 0, x2 = +_[0], y2 = +_[1]; + return quadtree; + }; + + return quadtree; +}; + +function d3_geom_quadtreeCompatX(d) { return d.x; } +function d3_geom_quadtreeCompatY(d) { return d.y; } + +function d3_geom_quadtreeNode() { + return { + leaf: true, + nodes: [], + point: null, + x: null, + y: null + }; +} + +function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) { + if (!f(node, x1, y1, x2, y2)) { + var sx = (x1 + x2) * 0.5, + sy = (y1 + y2) * 0.5, + children = node.nodes; + if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy); + if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy); + if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2); + if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2); + } +} + +function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) { + var minDistance2 = Infinity, + closestPoint; + + (function find(node, x1, y1, x2, y2) { + + // stop searching if this cell can’t contain a closer node + if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return; + + // visit this point + if (point = node.point) { + var point, + dx = x - node.x, + dy = y - node.y, + distance2 = dx * dx + dy * dy; + if (distance2 < minDistance2) { + var distance = Math.sqrt(minDistance2 = distance2); + x0 = x - distance, y0 = y - distance; + x3 = x + distance, y3 = y + distance; + closestPoint = point; + } + } + + // bisect the current node + var children = node.nodes, + xm = (x1 + x2) * 0.5, + ym = (y1 + y2) * 0.5, + right = x >= xm, + below = y >= ym; + + // visit closest cell first + for (var i = below << 1 | right, j = i + 4; i < j; ++i) { + if (node = children[i & 3]) switch (i & 3) { + case 0: find(node, x1, y1, xm, ym); break; + case 1: find(node, xm, y1, x2, ym); break; + case 2: find(node, x1, ym, xm, y2); break; + case 3: find(node, xm, ym, x2, y2); break; + } + } + })(root, x0, y0, x3, y3); + + return closestPoint; +} diff --git a/node_modules/@plotly/d3/src/geom/voronoi.js b/node_modules/@plotly/d3/src/geom/voronoi.js new file mode 100644 index 0000000000000000000000000000000000000000..53f7d793afad06d09ed033cb0478c99c97a8e0b1 --- /dev/null +++ b/node_modules/@plotly/d3/src/geom/voronoi.js @@ -0,0 +1,110 @@ +import "../core/functor"; +import "voronoi/"; +import "geom"; +import "point"; + +d3.geom.voronoi = function(points) { + var x = d3_geom_pointX, + y = d3_geom_pointY, + fx = x, + fy = y, + clipExtent = d3_geom_voronoiClipExtent; + + // @deprecated; use voronoi(data) instead. + if (points) return voronoi(points); + + function voronoi(data) { + var polygons = new Array(data.length), + x0 = clipExtent[0][0], + y0 = clipExtent[0][1], + x1 = clipExtent[1][0], + y1 = clipExtent[1][1]; + + d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) { + var edges = cell.edges, + site = cell.site, + polygon = polygons[i] = edges.length ? edges.map(function(e) { var s = e.start(); return [s.x, s.y]; }) + : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [[x0, y1], [x1, y1], [x1, y0], [x0, y0]] + : []; + polygon.point = data[i]; + }); + + return polygons; + } + + function sites(data) { + return data.map(function(d, i) { + return { + x: Math.round(fx(d, i) / ε) * ε, + y: Math.round(fy(d, i) / ε) * ε, + i: i + }; + }); + } + + voronoi.links = function(data) { + return d3_geom_voronoi(sites(data)).edges.filter(function(edge) { + return edge.l && edge.r; + }).map(function(edge) { + return { + source: data[edge.l.i], + target: data[edge.r.i] + }; + }); + }; + + voronoi.triangles = function(data) { + var triangles = []; + + d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) { + var site = cell.site, + edges = cell.edges.sort(d3_geom_voronoiHalfEdgeOrder), + j = -1, + m = edges.length, + e0, + s0, + e1 = edges[m - 1].edge, + s1 = e1.l === site ? e1.r : e1.l; + + while (++j < m) { + e0 = e1; + s0 = s1; + e1 = edges[j].edge; + s1 = e1.l === site ? e1.r : e1.l; + if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) { + triangles.push([data[i], data[s0.i], data[s1.i]]); + } + } + }); + + return triangles; + }; + + voronoi.x = function(_) { + return arguments.length ? (fx = d3_functor(x = _), voronoi) : x; + }; + + voronoi.y = function(_) { + return arguments.length ? (fy = d3_functor(y = _), voronoi) : y; + }; + + voronoi.clipExtent = function(_) { + if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent; + clipExtent = _ == null ? d3_geom_voronoiClipExtent : _; + return voronoi; + }; + + // @deprecated; use clipExtent instead. + voronoi.size = function(_) { + if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1]; + return voronoi.clipExtent(_ && [[0, 0], _]); + }; + + return voronoi; +}; + +var d3_geom_voronoiClipExtent = [[-1e6, -1e6], [1e6, 1e6]]; + +function d3_geom_voronoiTriangleArea(a, b, c) { + return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y); +} diff --git a/node_modules/@plotly/d3/src/geom/voronoi/beach.js b/node_modules/@plotly/d3/src/geom/voronoi/beach.js new file mode 100644 index 0000000000000000000000000000000000000000..e0174679dfa76aaf511e904558da5512820c7607 --- /dev/null +++ b/node_modules/@plotly/d3/src/geom/voronoi/beach.js @@ -0,0 +1,186 @@ +import "../../math/abs"; + +function d3_geom_voronoiBeach() { + d3_geom_voronoiRedBlackNode(this); + this.edge = + this.site = + this.circle = null; +} + +function d3_geom_voronoiCreateBeach(site) { + var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach; + beach.site = site; + return beach; +} + +function d3_geom_voronoiDetachBeach(beach) { + d3_geom_voronoiDetachCircle(beach); + d3_geom_voronoiBeaches.remove(beach); + d3_geom_voronoiBeachPool.push(beach); + d3_geom_voronoiRedBlackNode(beach); +} + +function d3_geom_voronoiRemoveBeach(beach) { + var circle = beach.circle, + x = circle.x, + y = circle.cy, + vertex = {x: x, y: y}, + previous = beach.P, + next = beach.N, + disappearing = [beach]; + + d3_geom_voronoiDetachBeach(beach); + + var lArc = previous; + while (lArc.circle + && abs(x - lArc.circle.x) < ε + && abs(y - lArc.circle.cy) < ε) { + previous = lArc.P; + disappearing.unshift(lArc); + d3_geom_voronoiDetachBeach(lArc); + lArc = previous; + } + + disappearing.unshift(lArc); + d3_geom_voronoiDetachCircle(lArc); + + var rArc = next; + while (rArc.circle + && abs(x - rArc.circle.x) < ε + && abs(y - rArc.circle.cy) < ε) { + next = rArc.N; + disappearing.push(rArc); + d3_geom_voronoiDetachBeach(rArc); + rArc = next; + } + + disappearing.push(rArc); + d3_geom_voronoiDetachCircle(rArc); + + var nArcs = disappearing.length, + iArc; + for (iArc = 1; iArc < nArcs; ++iArc) { + rArc = disappearing[iArc]; + lArc = disappearing[iArc - 1]; + d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex); + } + + lArc = disappearing[0]; + rArc = disappearing[nArcs - 1]; + rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex); + + d3_geom_voronoiAttachCircle(lArc); + d3_geom_voronoiAttachCircle(rArc); +} + +function d3_geom_voronoiAddBeach(site) { + var x = site.x, + directrix = site.y, + lArc, + rArc, + dxl, + dxr, + node = d3_geom_voronoiBeaches._; + + while (node) { + dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x; + if (dxl > ε) node = node.L; else { + dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix); + if (dxr > ε) { + if (!node.R) { + lArc = node; + break; + } + node = node.R; + } else { + if (dxl > -ε) { + lArc = node.P; + rArc = node; + } else if (dxr > -ε) { + lArc = node; + rArc = node.N; + } else { + lArc = rArc = node; + } + break; + } + } + } + + var newArc = d3_geom_voronoiCreateBeach(site); + d3_geom_voronoiBeaches.insert(lArc, newArc); + + if (!lArc && !rArc) return; + + if (lArc === rArc) { + d3_geom_voronoiDetachCircle(lArc); + rArc = d3_geom_voronoiCreateBeach(lArc.site); + d3_geom_voronoiBeaches.insert(newArc, rArc); + newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site); + d3_geom_voronoiAttachCircle(lArc); + d3_geom_voronoiAttachCircle(rArc); + return; + } + + if (!rArc) { // && lArc + newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site); + return; + } + + // else lArc !== rArc + d3_geom_voronoiDetachCircle(lArc); + d3_geom_voronoiDetachCircle(rArc); + + var lSite = lArc.site, + ax = lSite.x, + ay = lSite.y, + bx = site.x - ax, + by = site.y - ay, + rSite = rArc.site, + cx = rSite.x - ax, + cy = rSite.y - ay, + d = 2 * (bx * cy - by * cx), + hb = bx * bx + by * by, + hc = cx * cx + cy * cy, + vertex = {x: (cy * hb - by * hc) / d + ax, y: (bx * hc - cx * hb) / d + ay}; + + d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex); + newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex); + rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex); + d3_geom_voronoiAttachCircle(lArc); + d3_geom_voronoiAttachCircle(rArc); +} + +function d3_geom_voronoiLeftBreakPoint(arc, directrix) { + var site = arc.site, + rfocx = site.x, + rfocy = site.y, + pby2 = rfocy - directrix; + + if (!pby2) return rfocx; + + var lArc = arc.P; + if (!lArc) return -Infinity; + + site = lArc.site; + var lfocx = site.x, + lfocy = site.y, + plby2 = lfocy - directrix; + + if (!plby2) return lfocx; + + var hl = lfocx - rfocx, + aby2 = 1 / pby2 - 1 / plby2, + b = hl / plby2; + + if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx; + + return (rfocx + lfocx) / 2; +} + +function d3_geom_voronoiRightBreakPoint(arc, directrix) { + var rArc = arc.N; + if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix); + var site = arc.site; + return site.y === directrix ? site.x : Infinity; +} diff --git a/node_modules/@plotly/d3/src/geom/voronoi/cell.js b/node_modules/@plotly/d3/src/geom/voronoi/cell.js new file mode 100644 index 0000000000000000000000000000000000000000..8c6628d31c192c7b06f3ce67a01ce6120122971e --- /dev/null +++ b/node_modules/@plotly/d3/src/geom/voronoi/cell.js @@ -0,0 +1,64 @@ +import "../../math/abs"; + +function d3_geom_voronoiCell(site) { + this.site = site; + this.edges = []; +} + +d3_geom_voronoiCell.prototype.prepare = function() { + var halfEdges = this.edges, + iHalfEdge = halfEdges.length, + edge; + + while (iHalfEdge--) { + edge = halfEdges[iHalfEdge].edge; + if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1); + } + + halfEdges.sort(d3_geom_voronoiHalfEdgeOrder); + return halfEdges.length; +}; + +function d3_geom_voronoiCloseCells(extent) { + var x0 = extent[0][0], + x1 = extent[1][0], + y0 = extent[0][1], + y1 = extent[1][1], + x2, + y2, + x3, + y3, + cells = d3_geom_voronoiCells, + iCell = cells.length, + cell, + iHalfEdge, + halfEdges, + nHalfEdges, + start, + end; + + while (iCell--) { + cell = cells[iCell]; + if (!cell || !cell.prepare()) continue; + halfEdges = cell.edges; + nHalfEdges = halfEdges.length; + iHalfEdge = 0; + while (iHalfEdge < nHalfEdges) { + end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y; + start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y; + if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) { + halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, + abs(x3 - x0) < ε && y1 - y3 > ε ? {x: x0, y: abs(x2 - x0) < ε ? y2 : y1} + : abs(y3 - y1) < ε && x1 - x3 > ε ? {x: abs(y2 - y1) < ε ? x2 : x1, y: y1} + : abs(x3 - x1) < ε && y3 - y0 > ε ? {x: x1, y: abs(x2 - x1) < ε ? y2 : y0} + : abs(y3 - y0) < ε && x3 - x0 > ε ? {x: abs(y2 - y0) < ε ? x2 : x0, y: y0} + : null), cell.site, null)); + ++nHalfEdges; + } + } + } +} + +function d3_geom_voronoiHalfEdgeOrder(a, b) { + return b.angle - a.angle; +} diff --git a/node_modules/@plotly/d3/src/geom/voronoi/circle.js b/node_modules/@plotly/d3/src/geom/voronoi/circle.js new file mode 100644 index 0000000000000000000000000000000000000000..d7fb6791eb19692561fd944ca4844eb1c771fbc3 --- /dev/null +++ b/node_modules/@plotly/d3/src/geom/voronoi/circle.js @@ -0,0 +1,73 @@ +function d3_geom_voronoiCircle() { + d3_geom_voronoiRedBlackNode(this); + this.x = + this.y = + this.arc = + this.site = + this.cy = null; +} + +function d3_geom_voronoiAttachCircle(arc) { + var lArc = arc.P, + rArc = arc.N; + + if (!lArc || !rArc) return; + + var lSite = lArc.site, + cSite = arc.site, + rSite = rArc.site; + + if (lSite === rSite) return; + + var bx = cSite.x, + by = cSite.y, + ax = lSite.x - bx, + ay = lSite.y - by, + cx = rSite.x - bx, + cy = rSite.y - by; + + var d = 2 * (ax * cy - ay * cx); + if (d >= -ε2) return; + + var ha = ax * ax + ay * ay, + hc = cx * cx + cy * cy, + x = (cy * ha - ay * hc) / d, + y = (ax * hc - cx * ha) / d, + cy = y + by; + + var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle; + circle.arc = arc; + circle.site = cSite; + circle.x = x + bx; + circle.y = cy + Math.sqrt(x * x + y * y); // y bottom + circle.cy = cy; + + arc.circle = circle; + + var before = null, + node = d3_geom_voronoiCircles._; + + while (node) { + if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) { + if (node.L) node = node.L; + else { before = node.P; break; } + } else { + if (node.R) node = node.R; + else { before = node; break; } + } + } + + d3_geom_voronoiCircles.insert(before, circle); + if (!before) d3_geom_voronoiFirstCircle = circle; +} + +function d3_geom_voronoiDetachCircle(arc) { + var circle = arc.circle; + if (circle) { + if (!circle.P) d3_geom_voronoiFirstCircle = circle.N; + d3_geom_voronoiCircles.remove(circle); + d3_geom_voronoiCirclePool.push(circle); + d3_geom_voronoiRedBlackNode(circle); + arc.circle = null; + } +} diff --git a/node_modules/@plotly/d3/src/geom/voronoi/clip.js b/node_modules/@plotly/d3/src/geom/voronoi/clip.js new file mode 100644 index 0000000000000000000000000000000000000000..e145965b33d972c230d1dab3951953fff53594e7 --- /dev/null +++ b/node_modules/@plotly/d3/src/geom/voronoi/clip.js @@ -0,0 +1,80 @@ +import "../../math/abs"; +import "../clip-line"; + +function d3_geom_voronoiClipEdges(extent) { + var edges = d3_geom_voronoiEdges, + clip = d3_geom_clipLine(extent[0][0], extent[0][1], extent[1][0], extent[1][1]), + i = edges.length, + e; + while (i--) { + e = edges[i]; + if (!d3_geom_voronoiConnectEdge(e, extent) + || !clip(e) + || (abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε)) { + e.a = e.b = null; + edges.splice(i, 1); + } + } +} + +function d3_geom_voronoiConnectEdge(edge, extent) { + var vb = edge.b; + if (vb) return true; + + var va = edge.a, + x0 = extent[0][0], + x1 = extent[1][0], + y0 = extent[0][1], + y1 = extent[1][1], + lSite = edge.l, + rSite = edge.r, + lx = lSite.x, + ly = lSite.y, + rx = rSite.x, + ry = rSite.y, + fx = (lx + rx) / 2, + fy = (ly + ry) / 2, + fm, + fb; + + if (ry === ly) { + if (fx < x0 || fx >= x1) return; + if (lx > rx) { + if (!va) va = {x: fx, y: y0}; + else if (va.y >= y1) return; + vb = {x: fx, y: y1}; + } else { + if (!va) va = {x: fx, y: y1}; + else if (va.y < y0) return; + vb = {x: fx, y: y0}; + } + } else { + fm = (lx - rx) / (ry - ly); + fb = fy - fm * fx; + if (fm < -1 || fm > 1) { + if (lx > rx) { + if (!va) va = {x: (y0 - fb) / fm, y: y0}; + else if (va.y >= y1) return; + vb = {x: (y1 - fb) / fm, y: y1}; + } else { + if (!va) va = {x: (y1 - fb) / fm, y: y1}; + else if (va.y < y0) return; + vb = {x: (y0 - fb) / fm, y: y0}; + } + } else { + if (ly < ry) { + if (!va) va = {x: x0, y: fm * x0 + fb}; + else if (va.x >= x1) return; + vb = {x: x1, y: fm * x1 + fb}; + } else { + if (!va) va = {x: x1, y: fm * x1 + fb}; + else if (va.x < x0) return; + vb = {x: x0, y: fm * x0 + fb}; + } + } + } + + edge.a = va; + edge.b = vb; + return true; +} diff --git a/node_modules/@plotly/d3/src/geom/voronoi/edge.js b/node_modules/@plotly/d3/src/geom/voronoi/edge.js new file mode 100644 index 0000000000000000000000000000000000000000..8e5a7345426f3757c643ff395f9a536897504ff4 --- /dev/null +++ b/node_modules/@plotly/d3/src/geom/voronoi/edge.js @@ -0,0 +1,50 @@ +function d3_geom_voronoiEdge(lSite, rSite) { + this.l = lSite; + this.r = rSite; + this.a = this.b = null; // for border edges +} + +function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) { + var edge = new d3_geom_voronoiEdge(lSite, rSite); + d3_geom_voronoiEdges.push(edge); + if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va); + if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb); + d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite)); + d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite)); + return edge; +} + +function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) { + var edge = new d3_geom_voronoiEdge(lSite, null); + edge.a = va; + edge.b = vb; + d3_geom_voronoiEdges.push(edge); + return edge; +} + +function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) { + if (!edge.a && !edge.b) { + edge.a = vertex; + edge.l = lSite; + edge.r = rSite; + } else if (edge.l === rSite) { + edge.b = vertex; + } else { + edge.a = vertex; + } +} + +function d3_geom_voronoiHalfEdge(edge, lSite, rSite) { + var va = edge.a, + vb = edge.b; + this.edge = edge; + this.site = lSite; + this.angle = rSite ? Math.atan2(rSite.y - lSite.y, rSite.x - lSite.x) + : edge.l === lSite ? Math.atan2(vb.x - va.x, va.y - vb.y) + : Math.atan2(va.x - vb.x, vb.y - va.y); +}; + +d3_geom_voronoiHalfEdge.prototype = { + start: function() { return this.edge.l === this.site ? this.edge.a : this.edge.b; }, + end: function() { return this.edge.l === this.site ? this.edge.b : this.edge.a; } +}; diff --git a/node_modules/@plotly/d3/src/geom/voronoi/index.js b/node_modules/@plotly/d3/src/geom/voronoi/index.js new file mode 100644 index 0000000000000000000000000000000000000000..a6c01a86a607148b1f89c814a4355f6ee820527b --- /dev/null +++ b/node_modules/@plotly/d3/src/geom/voronoi/index.js @@ -0,0 +1,59 @@ +import "../../math/trigonometry"; + +var d3_geom_voronoiEdges, + d3_geom_voronoiCells, + d3_geom_voronoiBeaches, + d3_geom_voronoiBeachPool = [], + d3_geom_voronoiFirstCircle, + d3_geom_voronoiCircles, + d3_geom_voronoiCirclePool = []; + +import "beach"; +import "cell"; +import "circle"; +import "clip"; +import "edge"; +import "red-black"; + +function d3_geom_voronoi(sites, bbox) { + var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), + x0, + y0, + circle; + + d3_geom_voronoiEdges = []; + d3_geom_voronoiCells = new Array(sites.length); + d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree; + d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree; + + while (true) { + circle = d3_geom_voronoiFirstCircle; + if (site && (!circle || site.y < circle.y || (site.y === circle.y && site.x < circle.x))) { + if (site.x !== x0 || site.y !== y0) { + d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site); + d3_geom_voronoiAddBeach(site); + x0 = site.x, y0 = site.y; + } + site = sites.pop(); + } else if (circle) { + d3_geom_voronoiRemoveBeach(circle.arc); + } else { + break; + } + } + + if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox); + + var diagram = {cells: d3_geom_voronoiCells, edges: d3_geom_voronoiEdges}; + + d3_geom_voronoiBeaches = + d3_geom_voronoiCircles = + d3_geom_voronoiEdges = + d3_geom_voronoiCells = null; + + return diagram; +}; + +function d3_geom_voronoiVertexOrder(a, b) { + return b.y - a.y || b.x - a.x; +} diff --git a/node_modules/@plotly/d3/src/geom/voronoi/red-black.js b/node_modules/@plotly/d3/src/geom/voronoi/red-black.js new file mode 100644 index 0000000000000000000000000000000000000000..7cf6880caa4860251dd12e751675bf38824aae59 --- /dev/null +++ b/node_modules/@plotly/d3/src/geom/voronoi/red-black.js @@ -0,0 +1,235 @@ +function d3_geom_voronoiRedBlackTree() { + this._ = null; // root node +} + +function d3_geom_voronoiRedBlackNode(node) { + node.U = // parent node + node.C = // color - true for red, false for black + node.L = // left node + node.R = // right node + node.P = // previous node + node.N = null; // next node +} + +d3_geom_voronoiRedBlackTree.prototype = { + + insert: function(after, node) { + var parent, grandpa, uncle; + + if (after) { + node.P = after; + node.N = after.N; + if (after.N) after.N.P = node; + after.N = node; + if (after.R) { + after = after.R; + while (after.L) after = after.L; + after.L = node; + } else { + after.R = node; + } + parent = after; + } else if (this._) { + after = d3_geom_voronoiRedBlackFirst(this._); + node.P = null; + node.N = after; + after.P = after.L = node; + parent = after; + } else { + node.P = node.N = null; + this._ = node; + parent = null; + } + node.L = node.R = null; + node.U = parent; + node.C = true; + + after = node; + while (parent && parent.C) { + grandpa = parent.U; + if (parent === grandpa.L) { + uncle = grandpa.R; + if (uncle && uncle.C) { + parent.C = uncle.C = false; + grandpa.C = true; + after = grandpa; + } else { + if (after === parent.R) { + d3_geom_voronoiRedBlackRotateLeft(this, parent); + after = parent; + parent = after.U; + } + parent.C = false; + grandpa.C = true; + d3_geom_voronoiRedBlackRotateRight(this, grandpa); + } + } else { + uncle = grandpa.L; + if (uncle && uncle.C) { + parent.C = uncle.C = false; + grandpa.C = true; + after = grandpa; + } else { + if (after === parent.L) { + d3_geom_voronoiRedBlackRotateRight(this, parent); + after = parent; + parent = after.U; + } + parent.C = false; + grandpa.C = true; + d3_geom_voronoiRedBlackRotateLeft(this, grandpa); + } + } + parent = after.U; + } + this._.C = false; + }, + + remove: function(node) { + if (node.N) node.N.P = node.P; + if (node.P) node.P.N = node.N; + node.N = node.P = null; + + var parent = node.U, + sibling, + left = node.L, + right = node.R, + next, + red; + + if (!left) next = right; + else if (!right) next = left; + else next = d3_geom_voronoiRedBlackFirst(right); + + if (parent) { + if (parent.L === node) parent.L = next; + else parent.R = next; + } else { + this._ = next; + } + + if (left && right) { + red = next.C; + next.C = node.C; + next.L = left; + left.U = next; + if (next !== right) { + parent = next.U; + next.U = node.U; + node = next.R; + parent.L = node; + next.R = right; + right.U = next; + } else { + next.U = parent; + parent = next; + node = next.R; + } + } else { + red = node.C; + node = next; + } + + if (node) node.U = parent; + if (red) return; + if (node && node.C) { node.C = false; return; } + + do { + if (node === this._) break; + if (node === parent.L) { + sibling = parent.R; + if (sibling.C) { + sibling.C = false; + parent.C = true; + d3_geom_voronoiRedBlackRotateLeft(this, parent); + sibling = parent.R; + } + if ((sibling.L && sibling.L.C) + || (sibling.R && sibling.R.C)) { + if (!sibling.R || !sibling.R.C) { + sibling.L.C = false; + sibling.C = true; + d3_geom_voronoiRedBlackRotateRight(this, sibling); + sibling = parent.R; + } + sibling.C = parent.C; + parent.C = sibling.R.C = false; + d3_geom_voronoiRedBlackRotateLeft(this, parent); + node = this._; + break; + } + } else { + sibling = parent.L; + if (sibling.C) { + sibling.C = false; + parent.C = true; + d3_geom_voronoiRedBlackRotateRight(this, parent); + sibling = parent.L; + } + if ((sibling.L && sibling.L.C) + || (sibling.R && sibling.R.C)) { + if (!sibling.L || !sibling.L.C) { + sibling.R.C = false; + sibling.C = true; + d3_geom_voronoiRedBlackRotateLeft(this, sibling); + sibling = parent.L; + } + sibling.C = parent.C; + parent.C = sibling.L.C = false; + d3_geom_voronoiRedBlackRotateRight(this, parent); + node = this._; + break; + } + } + sibling.C = true; + node = parent; + parent = parent.U; + } while (!node.C); + + if (node) node.C = false; + } + +}; + +function d3_geom_voronoiRedBlackRotateLeft(tree, node) { + var p = node, + q = node.R, + parent = p.U; + + if (parent) { + if (parent.L === p) parent.L = q; + else parent.R = q; + } else { + tree._ = q; + } + + q.U = parent; + p.U = q; + p.R = q.L; + if (p.R) p.R.U = p; + q.L = p; +} + +function d3_geom_voronoiRedBlackRotateRight(tree, node) { + var p = node, + q = node.L, + parent = p.U; + + if (parent) { + if (parent.L === p) parent.L = q; + else parent.R = q; + } else { + tree._ = q; + } + + q.U = parent; + p.U = q; + p.L = q.R; + if (p.L) p.L.U = p; + q.R = p; +} + +function d3_geom_voronoiRedBlackFirst(node) { + while (node.L) node = node.L; + return node; +} diff --git a/node_modules/@plotly/d3/src/interpolate/array.js b/node_modules/@plotly/d3/src/interpolate/array.js new file mode 100644 index 0000000000000000000000000000000000000000..33f8f48b58fe89e13b86eadf2653d497ca160a9f --- /dev/null +++ b/node_modules/@plotly/d3/src/interpolate/array.js @@ -0,0 +1,19 @@ +import "interpolate"; + +d3.interpolateArray = d3_interpolateArray; + +function d3_interpolateArray(a, b) { + var x = [], + c = [], + na = a.length, + nb = b.length, + n0 = Math.min(a.length, b.length), + i; + for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i])); + for (; i < na; ++i) c[i] = a[i]; + for (; i < nb; ++i) c[i] = b[i]; + return function(t) { + for (i = 0; i < n0; ++i) c[i] = x[i](t); + return c; + }; +} diff --git a/node_modules/@plotly/d3/src/interpolate/ease.js b/node_modules/@plotly/d3/src/interpolate/ease.js new file mode 100644 index 0000000000000000000000000000000000000000..ae0a3c83863f520f95d028970954abb999ffd406 --- /dev/null +++ b/node_modules/@plotly/d3/src/interpolate/ease.js @@ -0,0 +1,111 @@ +import "../arrays/map"; +import "../core/array"; +import "../core/identity"; +import "../math/trigonometry"; + +var d3_ease_default = function() { return d3_identity; }; + +var d3_ease = d3.map({ + linear: d3_ease_default, + poly: d3_ease_poly, + quad: function() { return d3_ease_quad; }, + cubic: function() { return d3_ease_cubic; }, + sin: function() { return d3_ease_sin; }, + exp: function() { return d3_ease_exp; }, + circle: function() { return d3_ease_circle; }, + elastic: d3_ease_elastic, + back: d3_ease_back, + bounce: function() { return d3_ease_bounce; } +}); + +var d3_ease_mode = d3.map({ + "in": d3_identity, + "out": d3_ease_reverse, + "in-out": d3_ease_reflect, + "out-in": function(f) { return d3_ease_reflect(d3_ease_reverse(f)); } +}); + +d3.ease = function(name) { + var i = name.indexOf("-"), + t = i >= 0 ? name.slice(0, i) : name, + m = i >= 0 ? name.slice(i + 1) : "in"; + t = d3_ease.get(t) || d3_ease_default; + m = d3_ease_mode.get(m) || d3_identity; + return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1)))); +}; + +function d3_ease_clamp(f) { + return function(t) { + return t <= 0 ? 0 : t >= 1 ? 1 : f(t); + }; +} + +function d3_ease_reverse(f) { + return function(t) { + return 1 - f(1 - t); + }; +} + +function d3_ease_reflect(f) { + return function(t) { + return 0.5 * (t < 0.5 ? f(2 * t) : (2 - f(2 - 2 * t))); + }; +} + +function d3_ease_quad(t) { + return t * t; +} + +function d3_ease_cubic(t) { + return t * t * t; +} + +// Optimized clamp(reflect(poly(3))). +function d3_ease_cubicInOut(t) { + if (t <= 0) return 0; + if (t >= 1) return 1; + var t2 = t * t, t3 = t2 * t; + return 4 * (t < 0.5 ? t3 : 3 * (t - t2) + t3 - 0.75); +} + +function d3_ease_poly(e) { + return function(t) { + return Math.pow(t, e); + }; +} + +function d3_ease_sin(t) { + return 1 - Math.cos(t * halfπ); +} + +function d3_ease_exp(t) { + return Math.pow(2, 10 * (t - 1)); +} + +function d3_ease_circle(t) { + return 1 - Math.sqrt(1 - t * t); +} + +function d3_ease_elastic(a, p) { + var s; + if (arguments.length < 2) p = 0.45; + if (arguments.length) s = p / τ * Math.asin(1 / a); + else a = 1, s = p / 4; + return function(t) { + return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p); + }; +} + +function d3_ease_back(s) { + if (!s) s = 1.70158; + return function(t) { + return t * t * ((s + 1) * t - s); + }; +} + +function d3_ease_bounce(t) { + return t < 1 / 2.75 ? 7.5625 * t * t + : t < 2 / 2.75 ? 7.5625 * (t -= 1.5 / 2.75) * t + 0.75 + : t < 2.5 / 2.75 ? 7.5625 * (t -= 2.25 / 2.75) * t + 0.9375 + : 7.5625 * (t -= 2.625 / 2.75) * t + 0.984375; +} diff --git a/node_modules/@plotly/d3/src/interpolate/hcl.js b/node_modules/@plotly/d3/src/interpolate/hcl.js new file mode 100644 index 0000000000000000000000000000000000000000..4e62591bac59a8dc27614ff39546fd1c7e7b7aaa --- /dev/null +++ b/node_modules/@plotly/d3/src/interpolate/hcl.js @@ -0,0 +1,20 @@ +import "../color/hcl"; + +d3.interpolateHcl = d3_interpolateHcl; + +function d3_interpolateHcl(a, b) { + a = d3.hcl(a); + b = d3.hcl(b); + var ah = a.h, + ac = a.c, + al = a.l, + bh = b.h - ah, + bc = b.c - ac, + bl = b.l - al; + if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac; + if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; + else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360; // shortest path + return function(t) { + return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + ""; + }; +} diff --git a/node_modules/@plotly/d3/src/interpolate/hsl.js b/node_modules/@plotly/d3/src/interpolate/hsl.js new file mode 100644 index 0000000000000000000000000000000000000000..2b8d70f2c594f9a9a1f86b5a967329fa193089bc --- /dev/null +++ b/node_modules/@plotly/d3/src/interpolate/hsl.js @@ -0,0 +1,20 @@ +import "../color/hsl"; + +d3.interpolateHsl = d3_interpolateHsl; + +function d3_interpolateHsl(a, b) { + a = d3.hsl(a); + b = d3.hsl(b); + var ah = a.h, + as = a.s, + al = a.l, + bh = b.h - ah, + bs = b.s - as, + bl = b.l - al; + if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as; + if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; + else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360; // shortest path + return function(t) { + return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + ""; + }; +} diff --git a/node_modules/@plotly/d3/src/interpolate/index.js b/node_modules/@plotly/d3/src/interpolate/index.js new file mode 100644 index 0000000000000000000000000000000000000000..ed6c5020a74d82f54603bf69fb8905d1505457d5 --- /dev/null +++ b/node_modules/@plotly/d3/src/interpolate/index.js @@ -0,0 +1,14 @@ +import "array"; +import "ease"; +import "hcl"; +import "hsl"; +import "interpolate"; +import "lab"; +import "number"; +import "object"; +import "rgb"; +import "round"; +import "string"; +import "transform"; +import "uninterpolate"; +import "zoom"; diff --git a/node_modules/@plotly/d3/src/interpolate/interpolate.js b/node_modules/@plotly/d3/src/interpolate/interpolate.js new file mode 100644 index 0000000000000000000000000000000000000000..2668e0f0d914acd71de2e2e822306b439321d82a --- /dev/null +++ b/node_modules/@plotly/d3/src/interpolate/interpolate.js @@ -0,0 +1,26 @@ +import "../color/color"; +import "../color/rgb"; +import "rgb"; +import "object"; +import "array"; +import "number"; +import "string"; + +d3.interpolate = d3_interpolate; + +function d3_interpolate(a, b) { + var i = d3.interpolators.length, f; + while (--i >= 0 && !(f = d3.interpolators[i](a, b))); + return f; +} + +d3.interpolators = [ + function(a, b) { + var t = typeof b; + return (t === "string" ? (d3_rgb_names.has(b.toLowerCase()) || /^(#|rgb\(|hsl\()/i.test(b) ? d3_interpolateRgb : d3_interpolateString) + : b instanceof d3_color ? d3_interpolateRgb + : Array.isArray(b) ? d3_interpolateArray + : t === "object" && isNaN(b) ? d3_interpolateObject + : d3_interpolateNumber)(a, b); + } +]; diff --git a/node_modules/@plotly/d3/src/interpolate/lab.js b/node_modules/@plotly/d3/src/interpolate/lab.js new file mode 100644 index 0000000000000000000000000000000000000000..6b46c044885e551faa0697aa0059928cf0dcb64c --- /dev/null +++ b/node_modules/@plotly/d3/src/interpolate/lab.js @@ -0,0 +1,17 @@ +import "../color/lab"; + +d3.interpolateLab = d3_interpolateLab; + +function d3_interpolateLab(a, b) { + a = d3.lab(a); + b = d3.lab(b); + var al = a.l, + aa = a.a, + ab = a.b, + bl = b.l - al, + ba = b.a - aa, + bb = b.b - ab; + return function(t) { + return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + ""; + }; +} diff --git a/node_modules/@plotly/d3/src/interpolate/number.js b/node_modules/@plotly/d3/src/interpolate/number.js new file mode 100644 index 0000000000000000000000000000000000000000..2f0e42adca980fed286b15045e8882dc155cedd0 --- /dev/null +++ b/node_modules/@plotly/d3/src/interpolate/number.js @@ -0,0 +1,6 @@ +d3.interpolateNumber = d3_interpolateNumber; + +function d3_interpolateNumber(a, b) { + a = +a, b = +b; + return function(t) { return a * (1 - t) + b * t; }; +} diff --git a/node_modules/@plotly/d3/src/interpolate/object.js b/node_modules/@plotly/d3/src/interpolate/object.js new file mode 100644 index 0000000000000000000000000000000000000000..a3f863af208f30e7d64cf74d5e9e81e48c3d87de --- /dev/null +++ b/node_modules/@plotly/d3/src/interpolate/object.js @@ -0,0 +1,25 @@ +import "interpolate"; + +d3.interpolateObject = d3_interpolateObject; + +function d3_interpolateObject(a, b) { + var i = {}, + c = {}, + k; + for (k in a) { + if (k in b) { + i[k] = d3_interpolate(a[k], b[k]); + } else { + c[k] = a[k]; + } + } + for (k in b) { + if (!(k in a)) { + c[k] = b[k]; + } + } + return function(t) { + for (k in i) c[k] = i[k](t); + return c; + }; +} diff --git a/node_modules/@plotly/d3/src/interpolate/rgb.js b/node_modules/@plotly/d3/src/interpolate/rgb.js new file mode 100644 index 0000000000000000000000000000000000000000..f4944d2fe6cfd796738d0f43a073b65db5825a86 --- /dev/null +++ b/node_modules/@plotly/d3/src/interpolate/rgb.js @@ -0,0 +1,20 @@ +import "../color/rgb"; + +d3.interpolateRgb = d3_interpolateRgb; + +function d3_interpolateRgb(a, b) { + a = d3.rgb(a); + b = d3.rgb(b); + var ar = a.r, + ag = a.g, + ab = a.b, + br = b.r - ar, + bg = b.g - ag, + bb = b.b - ab; + return function(t) { + return "#" + + d3_rgb_hex(Math.round(ar + br * t)) + + d3_rgb_hex(Math.round(ag + bg * t)) + + d3_rgb_hex(Math.round(ab + bb * t)); + }; +} diff --git a/node_modules/@plotly/d3/src/interpolate/round.js b/node_modules/@plotly/d3/src/interpolate/round.js new file mode 100644 index 0000000000000000000000000000000000000000..8e8797dfdf9bdbcc5609e760cb50265e64a472c9 --- /dev/null +++ b/node_modules/@plotly/d3/src/interpolate/round.js @@ -0,0 +1,6 @@ +d3.interpolateRound = d3_interpolateRound; + +function d3_interpolateRound(a, b) { + b -= a; + return function(t) { return Math.round(a + b * t); }; +} diff --git a/node_modules/@plotly/d3/src/interpolate/string.js b/node_modules/@plotly/d3/src/interpolate/string.js new file mode 100644 index 0000000000000000000000000000000000000000..3033a713abc6a7650f73c32bfdfa3a10c2e8db88 --- /dev/null +++ b/node_modules/@plotly/d3/src/interpolate/string.js @@ -0,0 +1,54 @@ +import "number"; + +d3.interpolateString = d3_interpolateString; + +function d3_interpolateString(a, b) { + var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, // scan index for next number in b + am, // current match in a + bm, // current match in b + bs, // string preceding current number in b, if any + i = -1, // index in s + s = [], // string constants and placeholders + q = []; // number interpolators + + // Coerce inputs to strings. + a = a + "", b = b + ""; + + // Interpolate pairs of numbers in a & b. + while ((am = d3_interpolate_numberA.exec(a)) + && (bm = d3_interpolate_numberB.exec(b))) { + if ((bs = bm.index) > bi) { // a string precedes the next number in b + bs = b.slice(bi, bs); + if (s[i]) s[i] += bs; // coalesce with previous string + else s[++i] = bs; + } + if ((am = am[0]) === (bm = bm[0])) { // numbers in a & b match + if (s[i]) s[i] += bm; // coalesce with previous string + else s[++i] = bm; + } else { // interpolate non-matching numbers + s[++i] = null; + q.push({i: i, x: d3_interpolateNumber(am, bm)}); + } + bi = d3_interpolate_numberB.lastIndex; + } + + // Add remains of b. + if (bi < b.length) { + bs = b.slice(bi); + if (s[i]) s[i] += bs; // coalesce with previous string + else s[++i] = bs; + } + + // Special optimization for only a single match. + // Otherwise, interpolate each of the numbers and rejoin the string. + return s.length < 2 + ? (q[0] ? (b = q[0].x, function(t) { return b(t) + ""; }) + : function() { return b; }) + : (b = q.length, function(t) { + for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t); + return s.join(""); + }); +} + +var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, + d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g"); diff --git a/node_modules/@plotly/d3/src/interpolate/transform.js b/node_modules/@plotly/d3/src/interpolate/transform.js new file mode 100644 index 0000000000000000000000000000000000000000..3261ec4126e0fc26d0f943ad7ed60b802f790310 --- /dev/null +++ b/node_modules/@plotly/d3/src/interpolate/transform.js @@ -0,0 +1,59 @@ +import "../math/transform"; +import "number"; + +d3.interpolateTransform = d3_interpolateTransform; + +function d3_interpolateTransformPop(s) { + return s.length ? s.pop() + "," : ""; +} + +function d3_interpolateTranslate(ta, tb, s, q) { + if (ta[0] !== tb[0] || ta[1] !== tb[1]) { + var i = s.push("translate(", null, ",", null, ")"); + q.push({i: i - 4, x: d3_interpolateNumber(ta[0], tb[0])}, {i: i - 2, x: d3_interpolateNumber(ta[1], tb[1])}); + } else if (tb[0] || tb[1]) { + s.push("translate(" + tb + ")"); + } +} + +function d3_interpolateRotate(ra, rb, s, q) { + if (ra !== rb) { + if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360; // shortest path + q.push({i: s.push(d3_interpolateTransformPop(s) + "rotate(", null, ")") - 2, x: d3_interpolateNumber(ra, rb)}); + } else if (rb) { + s.push(d3_interpolateTransformPop(s) + "rotate(" + rb + ")"); + } +} + +function d3_interpolateSkew(wa, wb, s, q) { + if (wa !== wb) { + q.push({i: s.push(d3_interpolateTransformPop(s) + "skewX(", null, ")") - 2, x: d3_interpolateNumber(wa, wb)}); + } else if (wb) { + s.push(d3_interpolateTransformPop(s) + "skewX(" + wb + ")"); + } +} + +function d3_interpolateScale(ka, kb, s, q) { + if (ka[0] !== kb[0] || ka[1] !== kb[1]) { + var i = s.push(d3_interpolateTransformPop(s) + "scale(", null, ",", null, ")"); + q.push({i: i - 4, x: d3_interpolateNumber(ka[0], kb[0])}, {i: i - 2, x: d3_interpolateNumber(ka[1], kb[1])}); + } else if (kb[0] !== 1 || kb[1] !== 1) { + s.push(d3_interpolateTransformPop(s) + "scale(" + kb + ")"); + } +} + +function d3_interpolateTransform(a, b) { + var s = [], // string constants and placeholders + q = []; // number interpolators + a = d3.transform(a), b = d3.transform(b); + d3_interpolateTranslate(a.translate, b.translate, s, q); + d3_interpolateRotate(a.rotate, b.rotate, s, q); + d3_interpolateSkew(a.skew, b.skew, s, q); + d3_interpolateScale(a.scale, b.scale, s, q); + a = b = null; // gc + return function(t) { + var i = -1, n = q.length, o; + while (++i < n) s[(o = q[i]).i] = o.x(t); + return s.join(""); + }; +} diff --git a/node_modules/@plotly/d3/src/interpolate/uninterpolate.js b/node_modules/@plotly/d3/src/interpolate/uninterpolate.js new file mode 100644 index 0000000000000000000000000000000000000000..d8c83321f9ff2b80be8b3482b90d11aa1ac636af --- /dev/null +++ b/node_modules/@plotly/d3/src/interpolate/uninterpolate.js @@ -0,0 +1,9 @@ +function d3_uninterpolateNumber(a, b) { + b = (b -= a = +a) || 1 / b; + return function(x) { return (x - a) / b; }; +} + +function d3_uninterpolateClamp(a, b) { + b = (b -= a = +a) || 1 / b; + return function(x) { return Math.max(0, Math.min(1, (x - a) / b)); }; +} diff --git a/node_modules/@plotly/d3/src/interpolate/zoom.js b/node_modules/@plotly/d3/src/interpolate/zoom.js new file mode 100644 index 0000000000000000000000000000000000000000..a42f2a7d8d822a757b266d9570e7bc9c64ae2d55 --- /dev/null +++ b/node_modules/@plotly/d3/src/interpolate/zoom.js @@ -0,0 +1,53 @@ +import "../math/trigonometry"; + +var ρ = Math.SQRT2, + ρ2 = 2, + ρ4 = 4; + +// p0 = [ux0, uy0, w0] +// p1 = [ux1, uy1, w1] +d3.interpolateZoom = function(p0, p1) { + var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], + ux1 = p1[0], uy1 = p1[1], w1 = p1[2], + dx = ux1 - ux0, + dy = uy1 - uy0, + d2 = dx * dx + dy * dy, + i, + S; + + // Special case for u0 ≅ u1. + if (d2 < ε2) { + S = Math.log(w1 / w0) / ρ; + i = function(t) { + return [ + ux0 + t * dx, + uy0 + t * dy, + w0 * Math.exp(ρ * t * S) + ]; + } + } + + // General case. + else { + var d1 = Math.sqrt(d2), + b0 = (w1 * w1 - w0 * w0 + ρ4 * d2) / (2 * w0 * ρ2 * d1), + b1 = (w1 * w1 - w0 * w0 - ρ4 * d2) / (2 * w1 * ρ2 * d1), + r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0), + r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1); + S = (r1 - r0) / ρ; + i = function(t) { + var s = t * S, + coshr0 = d3_cosh(r0), + u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0)); + return [ + ux0 + u * dx, + uy0 + u * dy, + w0 * coshr0 / d3_cosh(ρ * s + r0) + ]; + } + } + + i.duration = S * 1000; + + return i; +}; diff --git a/node_modules/@plotly/d3/src/layout/bundle.js b/node_modules/@plotly/d3/src/layout/bundle.js new file mode 100644 index 0000000000000000000000000000000000000000..3f3024433cd2e90cb53fbd24e483ad5a95955ecc --- /dev/null +++ b/node_modules/@plotly/d3/src/layout/bundle.js @@ -0,0 +1,59 @@ +import "layout"; + +// Implements hierarchical edge bundling using Holten's algorithm. For each +// input link, a path is computed that travels through the tree, up the parent +// hierarchy to the least common ancestor, and then back down to the destination +// node. Each path is simply an array of nodes. +d3.layout.bundle = function() { + return function(links) { + var paths = [], + i = -1, + n = links.length; + while (++i < n) paths.push(d3_layout_bundlePath(links[i])); + return paths; + }; +}; + +function d3_layout_bundlePath(link) { + var start = link.source, + end = link.target, + lca = d3_layout_bundleLeastCommonAncestor(start, end), + points = [start]; + while (start !== lca) { + start = start.parent; + points.push(start); + } + var k = points.length; + while (end !== lca) { + points.splice(k, 0, end); + end = end.parent; + } + return points; +} + +function d3_layout_bundleAncestors(node) { + var ancestors = [], + parent = node.parent; + while (parent != null) { + ancestors.push(node); + node = parent; + parent = parent.parent; + } + ancestors.push(node); + return ancestors; +} + +function d3_layout_bundleLeastCommonAncestor(a, b) { + if (a === b) return a; + var aNodes = d3_layout_bundleAncestors(a), + bNodes = d3_layout_bundleAncestors(b), + aNode = aNodes.pop(), + bNode = bNodes.pop(), + sharedNode = null; + while (aNode === bNode) { + sharedNode = aNode; + aNode = aNodes.pop(); + bNode = bNodes.pop(); + } + return sharedNode; +} diff --git a/node_modules/@plotly/d3/src/layout/chord.js b/node_modules/@plotly/d3/src/layout/chord.js new file mode 100644 index 0000000000000000000000000000000000000000..87f73c4e2dad8db8e54e3fe772409896aad1cb6d --- /dev/null +++ b/node_modules/@plotly/d3/src/layout/chord.js @@ -0,0 +1,157 @@ +import "../arrays/range"; +import "../math/trigonometry"; +import "layout"; + +d3.layout.chord = function() { + var chord = {}, + chords, + groups, + matrix, + n, + padding = 0, + sortGroups, + sortSubgroups, + sortChords; + + function relayout() { + var subgroups = {}, + groupSums = [], + groupIndex = d3.range(n), + subgroupIndex = [], + k, + x, + x0, + i, + j; + + chords = []; + groups = []; + + // Compute the sum. + k = 0, i = -1; while (++i < n) { + x = 0, j = -1; while (++j < n) { + x += matrix[i][j]; + } + groupSums.push(x); + subgroupIndex.push(d3.range(n)); + k += x; + } + + // Sort groups… + if (sortGroups) { + groupIndex.sort(function(a, b) { + return sortGroups(groupSums[a], groupSums[b]); + }); + } + + // Sort subgroups… + if (sortSubgroups) { + subgroupIndex.forEach(function(d, i) { + d.sort(function(a, b) { + return sortSubgroups(matrix[i][a], matrix[i][b]); + }); + }); + } + + // Convert the sum to scaling factor for [0, 2pi]. + // TODO Allow start and end angle to be specified. + // TODO Allow padding to be specified as percentage? + k = (τ - padding * n) / k; + + // Compute the start and end angle for each group and subgroup. + // Note: Opera has a bug reordering object literal properties! + x = 0, i = -1; while (++i < n) { + x0 = x, j = -1; while (++j < n) { + var di = groupIndex[i], + dj = subgroupIndex[di][j], + v = matrix[di][dj], + a0 = x, + a1 = x += v * k; + subgroups[di + "-" + dj] = { + index: di, + subindex: dj, + startAngle: a0, + endAngle: a1, + value: v + }; + } + groups[di] = { + index: di, + startAngle: x0, + endAngle: x, + value: groupSums[di] + }; + x += padding; + } + + // Generate chords for each (non-empty) subgroup-subgroup link. + i = -1; while (++i < n) { + j = i - 1; while (++j < n) { + var source = subgroups[i + "-" + j], + target = subgroups[j + "-" + i]; + if (source.value || target.value) { + chords.push(source.value < target.value + ? {source: target, target: source} + : {source: source, target: target}); + } + } + } + + if (sortChords) resort(); + } + + function resort() { + chords.sort(function(a, b) { + return sortChords( + (a.source.value + a.target.value) / 2, + (b.source.value + b.target.value) / 2); + }); + } + + chord.matrix = function(x) { + if (!arguments.length) return matrix; + n = (matrix = x) && matrix.length; + chords = groups = null; + return chord; + }; + + chord.padding = function(x) { + if (!arguments.length) return padding; + padding = x; + chords = groups = null; + return chord; + }; + + chord.sortGroups = function(x) { + if (!arguments.length) return sortGroups; + sortGroups = x; + chords = groups = null; + return chord; + }; + + chord.sortSubgroups = function(x) { + if (!arguments.length) return sortSubgroups; + sortSubgroups = x; + chords = null; + return chord; + }; + + chord.sortChords = function(x) { + if (!arguments.length) return sortChords; + sortChords = x; + if (chords) resort(); + return chord; + }; + + chord.chords = function() { + if (!chords) relayout(); + return chords; + }; + + chord.groups = function() { + if (!groups) relayout(); + return groups; + }; + + return chord; +}; diff --git a/node_modules/@plotly/d3/src/layout/cluster.js b/node_modules/@plotly/d3/src/layout/cluster.js new file mode 100644 index 0000000000000000000000000000000000000000..a4eec3bb25e4637420f338925d09988963eb1810 --- /dev/null +++ b/node_modules/@plotly/d3/src/layout/cluster.js @@ -0,0 +1,92 @@ +import "../arrays/max"; +import "layout"; +import "hierarchy"; +import "tree"; + +// Implements a hierarchical layout using the cluster (or dendrogram) +// algorithm. +d3.layout.cluster = function() { + var hierarchy = d3.layout.hierarchy().sort(null).value(null), + separation = d3_layout_treeSeparation, + size = [1, 1], // width, height + nodeSize = false; + + function cluster(d, i) { + var nodes = hierarchy.call(this, d, i), + root = nodes[0], + previousNode, + x = 0; + + // First walk, computing the initial x & y values. + d3_layout_hierarchyVisitAfter(root, function(node) { + var children = node.children; + if (children && children.length) { + node.x = d3_layout_clusterX(children); + node.y = d3_layout_clusterY(children); + } else { + node.x = previousNode ? x += separation(node, previousNode) : 0; + node.y = 0; + previousNode = node; + } + }); + + // Compute the left-most, right-most, and depth-most nodes for extents. + var left = d3_layout_clusterLeft(root), + right = d3_layout_clusterRight(root), + x0 = left.x - separation(left, right) / 2, + x1 = right.x + separation(right, left) / 2; + + // Second walk, normalizing x & y to the desired size. + d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) { + node.x = (node.x - root.x) * size[0]; + node.y = (root.y - node.y) * size[1]; + } : function(node) { + node.x = (node.x - x0) / (x1 - x0) * size[0]; + node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1]; + }); + + return nodes; + } + + cluster.separation = function(x) { + if (!arguments.length) return separation; + separation = x; + return cluster; + }; + + cluster.size = function(x) { + if (!arguments.length) return nodeSize ? null : size; + nodeSize = (size = x) == null; + return cluster; + }; + + cluster.nodeSize = function(x) { + if (!arguments.length) return nodeSize ? size : null; + nodeSize = (size = x) != null; + return cluster; + }; + + return d3_layout_hierarchyRebind(cluster, hierarchy); +}; + +function d3_layout_clusterY(children) { + return 1 + d3.max(children, function(child) { + return child.y; + }); +} + +function d3_layout_clusterX(children) { + return children.reduce(function(x, child) { + return x + child.x; + }, 0) / children.length; +} + +function d3_layout_clusterLeft(node) { + var children = node.children; + return children && children.length ? d3_layout_clusterLeft(children[0]) : node; +} + +function d3_layout_clusterRight(node) { + var children = node.children, n; + return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node; +} diff --git a/node_modules/@plotly/d3/src/layout/force.js b/node_modules/@plotly/d3/src/layout/force.js new file mode 100644 index 0000000000000000000000000000000000000000..41e5316b862e05f32579956549e59418d5a6fa93 --- /dev/null +++ b/node_modules/@plotly/d3/src/layout/force.js @@ -0,0 +1,372 @@ +import "../behavior/drag"; +import "../core/identity"; +import "../core/rebind"; +import "../event/event"; +import "../event/dispatch"; +import "../event/timer"; +import "../geom/quadtree"; +import "layout"; + +// A rudimentary force layout using Gauss-Seidel. +d3.layout.force = function() { + var force = {}, + event = d3.dispatch("start", "tick", "end"), + timer, + size = [1, 1], + drag, + alpha, + friction = 0.9, + linkDistance = d3_layout_forceLinkDistance, + linkStrength = d3_layout_forceLinkStrength, + charge = -30, + chargeDistance2 = d3_layout_forceChargeDistance2, + gravity = 0.1, + theta2 = 0.64, + nodes = [], + links = [], + distances, + strengths, + charges; + + function repulse(node) { + return function(quad, x1, _, x2) { + if (quad.point !== node) { + var dx = quad.cx - node.x, + dy = quad.cy - node.y, + dw = x2 - x1, + dn = dx * dx + dy * dy; + + /* Barnes-Hut criterion. */ + if (dw * dw / theta2 < dn) { + if (dn < chargeDistance2) { + var k = quad.charge / dn; + node.px -= dx * k; + node.py -= dy * k; + } + return true; + } + + if (quad.point && dn && dn < chargeDistance2) { + var k = quad.pointCharge / dn; + node.px -= dx * k; + node.py -= dy * k; + } + } + return !quad.charge; + }; + } + + force.tick = function() { + // simulated annealing, basically + if ((alpha *= 0.99) < 0.005) { + timer = null; + event.end({type: "end", alpha: alpha = 0}); + return true; + } + + var n = nodes.length, + m = links.length, + q, + i, // current index + o, // current object + s, // current source + t, // current target + l, // current distance + k, // current force + x, // x-distance + y; // y-distance + + // gauss-seidel relaxation for links + for (i = 0; i < m; ++i) { + o = links[i]; + s = o.source; + t = o.target; + x = t.x - s.x; + y = t.y - s.y; + if (l = (x * x + y * y)) { + l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l; + x *= l; + y *= l; + t.x -= x * (k = (s.weight + t.weight ? s.weight / (s.weight + t.weight) : 0.5)); + t.y -= y * k; + s.x += x * (k = 1 - k); + s.y += y * k; + } + } + + // apply gravity forces + if (k = alpha * gravity) { + x = size[0] / 2; + y = size[1] / 2; + i = -1; if (k) while (++i < n) { + o = nodes[i]; + o.x += (x - o.x) * k; + o.y += (y - o.y) * k; + } + } + + // compute quadtree center of mass and apply charge forces + if (charge) { + d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges); + i = -1; while (++i < n) { + if (!(o = nodes[i]).fixed) { + q.visit(repulse(o)); + } + } + } + + // position verlet integration + i = -1; while (++i < n) { + o = nodes[i]; + if (o.fixed) { + o.x = o.px; + o.y = o.py; + } else { + o.x -= (o.px - (o.px = o.x)) * friction; + o.y -= (o.py - (o.py = o.y)) * friction; + } + } + + event.tick({type: "tick", alpha: alpha}); + }; + + force.nodes = function(x) { + if (!arguments.length) return nodes; + nodes = x; + return force; + }; + + force.links = function(x) { + if (!arguments.length) return links; + links = x; + return force; + }; + + force.size = function(x) { + if (!arguments.length) return size; + size = x; + return force; + }; + + force.linkDistance = function(x) { + if (!arguments.length) return linkDistance; + linkDistance = typeof x === "function" ? x : +x; + return force; + }; + + // For backwards-compatibility. + force.distance = force.linkDistance; + + force.linkStrength = function(x) { + if (!arguments.length) return linkStrength; + linkStrength = typeof x === "function" ? x : +x; + return force; + }; + + force.friction = function(x) { + if (!arguments.length) return friction; + friction = +x; + return force; + }; + + force.charge = function(x) { + if (!arguments.length) return charge; + charge = typeof x === "function" ? x : +x; + return force; + }; + + force.chargeDistance = function(x) { + if (!arguments.length) return Math.sqrt(chargeDistance2); + chargeDistance2 = x * x; + return force; + }; + + force.gravity = function(x) { + if (!arguments.length) return gravity; + gravity = +x; + return force; + }; + + force.theta = function(x) { + if (!arguments.length) return Math.sqrt(theta2); + theta2 = x * x; + return force; + }; + + force.alpha = function(x) { + if (!arguments.length) return alpha; + + x = +x; + if (alpha) { // if we're already running + if (x > 0) { // we might keep it hot + alpha = x; + } else { // or we might stop + timer.c = null, timer.t = NaN, timer = null; + event.end({type: "end", alpha: alpha = 0}); + } + } else if (x > 0) { // otherwise, fire it up! + event.start({type: "start", alpha: alpha = x}); + timer = d3_timer(force.tick); + } + + return force; + }; + + force.start = function() { + var i, + n = nodes.length, + m = links.length, + w = size[0], + h = size[1], + neighbors, + o; + + for (i = 0; i < n; ++i) { + (o = nodes[i]).index = i; + o.weight = 0; + } + + for (i = 0; i < m; ++i) { + o = links[i]; + if (typeof o.source == "number") o.source = nodes[o.source]; + if (typeof o.target == "number") o.target = nodes[o.target]; + ++o.source.weight; + ++o.target.weight; + } + + for (i = 0; i < n; ++i) { + o = nodes[i]; + if (isNaN(o.x)) o.x = position("x", w); + if (isNaN(o.y)) o.y = position("y", h); + if (isNaN(o.px)) o.px = o.x; + if (isNaN(o.py)) o.py = o.y; + } + + distances = []; + if (typeof linkDistance === "function") for (i = 0; i < m; ++i) distances[i] = +linkDistance.call(this, links[i], i); + else for (i = 0; i < m; ++i) distances[i] = linkDistance; + + strengths = []; + if (typeof linkStrength === "function") for (i = 0; i < m; ++i) strengths[i] = +linkStrength.call(this, links[i], i); + else for (i = 0; i < m; ++i) strengths[i] = linkStrength; + + charges = []; + if (typeof charge === "function") for (i = 0; i < n; ++i) charges[i] = +charge.call(this, nodes[i], i); + else for (i = 0; i < n; ++i) charges[i] = charge; + + // inherit node position from first neighbor with defined position + // or if no such neighbors, initialize node position randomly + // initialize neighbors lazily to avoid overhead when not needed + function position(dimension, size) { + if (!neighbors) { + neighbors = new Array(n); + for (j = 0; j < n; ++j) { + neighbors[j] = []; + } + for (j = 0; j < m; ++j) { + var o = links[j]; + neighbors[o.source.index].push(o.target); + neighbors[o.target.index].push(o.source); + } + } + var candidates = neighbors[i], + j = -1, + l = candidates.length, + x; + while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x; + return Math.random() * size; + } + + return force.resume(); + }; + + force.resume = function() { + return force.alpha(0.1); + }; + + force.stop = function() { + return force.alpha(0); + }; + + // use `node.call(force.drag)` to make nodes draggable + force.drag = function() { + if (!drag) drag = d3.behavior.drag() + .origin(d3_identity) + .on("dragstart.force", d3_layout_forceDragstart) + .on("drag.force", dragmove) + .on("dragend.force", d3_layout_forceDragend); + + if (!arguments.length) return drag; + + this.on("mouseover.force", d3_layout_forceMouseover) + .on("mouseout.force", d3_layout_forceMouseout) + .call(drag); + }; + + function dragmove(d) { + d.px = d3.event.x, d.py = d3.event.y; + force.resume(); // restart annealing + } + + return d3.rebind(force, event, "on"); +}; + +// The fixed property has three bits: +// Bit 1 can be set externally (e.g., d.fixed = true) and show persist. +// Bit 2 stores the dragging state, from mousedown to mouseup. +// Bit 3 stores the hover state, from mouseover to mouseout. +// Dragend is a special case: it also clears the hover state. + +function d3_layout_forceDragstart(d) { + d.fixed |= 2; // set bit 2 +} + +function d3_layout_forceDragend(d) { + d.fixed &= ~6; // unset bits 2 and 3 +} + +function d3_layout_forceMouseover(d) { + d.fixed |= 4; // set bit 3 + d.px = d.x, d.py = d.y; // set velocity to zero +} + +function d3_layout_forceMouseout(d) { + d.fixed &= ~4; // unset bit 3 +} + +function d3_layout_forceAccumulate(quad, alpha, charges) { + var cx = 0, + cy = 0; + quad.charge = 0; + if (!quad.leaf) { + var nodes = quad.nodes, + n = nodes.length, + i = -1, + c; + while (++i < n) { + c = nodes[i]; + if (c == null) continue; + d3_layout_forceAccumulate(c, alpha, charges); + quad.charge += c.charge; + cx += c.charge * c.cx; + cy += c.charge * c.cy; + } + } + if (quad.point) { + // jitter internal nodes that are coincident + if (!quad.leaf) { + quad.point.x += Math.random() - 0.5; + quad.point.y += Math.random() - 0.5; + } + var k = alpha * charges[quad.point.index]; + quad.charge += quad.pointCharge = k; + cx += k * quad.point.x; + cy += k * quad.point.y; + } + quad.cx = cx / quad.charge; + quad.cy = cy / quad.charge; +} + +var d3_layout_forceLinkDistance = 20, + d3_layout_forceLinkStrength = 1, + d3_layout_forceChargeDistance2 = Infinity; diff --git a/node_modules/@plotly/d3/src/layout/hierarchy.js b/node_modules/@plotly/d3/src/layout/hierarchy.js new file mode 100644 index 0000000000000000000000000000000000000000..3bd478011dc496b5aa0dfd08f7f67524bae8d81f --- /dev/null +++ b/node_modules/@plotly/d3/src/layout/hierarchy.js @@ -0,0 +1,136 @@ +import "../arrays/merge"; +import "../core/rebind"; +import "layout"; + +d3.layout.hierarchy = function() { + var sort = d3_layout_hierarchySort, + children = d3_layout_hierarchyChildren, + value = d3_layout_hierarchyValue; + + function hierarchy(root) { + var stack = [root], + nodes = [], + node; + + root.depth = 0; + + while ((node = stack.pop()) != null) { + nodes.push(node); + if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) { + var n, childs, child; + while (--n >= 0) { + stack.push(child = childs[n]); + child.parent = node; + child.depth = node.depth + 1; + } + if (value) node.value = 0; + node.children = childs; + } else { + if (value) node.value = +value.call(hierarchy, node, node.depth) || 0; + delete node.children; + } + } + + d3_layout_hierarchyVisitAfter(root, function(node) { + var childs, parent; + if (sort && (childs = node.children)) childs.sort(sort); + if (value && (parent = node.parent)) parent.value += node.value; + }); + + return nodes; + } + + hierarchy.sort = function(x) { + if (!arguments.length) return sort; + sort = x; + return hierarchy; + }; + + hierarchy.children = function(x) { + if (!arguments.length) return children; + children = x; + return hierarchy; + }; + + hierarchy.value = function(x) { + if (!arguments.length) return value; + value = x; + return hierarchy; + }; + + // Re-evaluates the `value` property for the specified hierarchy. + hierarchy.revalue = function(root) { + if (value) { + d3_layout_hierarchyVisitBefore(root, function(node) { + if (node.children) node.value = 0; + }); + d3_layout_hierarchyVisitAfter(root, function(node) { + var parent; + if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0; + if (parent = node.parent) parent.value += node.value; + }); + } + return root; + }; + + return hierarchy; +}; + +// A method assignment helper for hierarchy subclasses. +function d3_layout_hierarchyRebind(object, hierarchy) { + d3.rebind(object, hierarchy, "sort", "children", "value"); + + // Add an alias for nodes and links, for convenience. + object.nodes = object; + object.links = d3_layout_hierarchyLinks; + + return object; +} + +// Pre-order traversal. +function d3_layout_hierarchyVisitBefore(node, callback) { + var nodes = [node]; + while ((node = nodes.pop()) != null) { + callback(node); + if ((children = node.children) && (n = children.length)) { + var n, children; + while (--n >= 0) nodes.push(children[n]); + } + } +} + +// Post-order traversal. +function d3_layout_hierarchyVisitAfter(node, callback) { + var nodes = [node], nodes2 = []; + while ((node = nodes.pop()) != null) { + nodes2.push(node); + if ((children = node.children) && (n = children.length)) { + var i = -1, n, children; + while (++i < n) nodes.push(children[i]); + } + } + while ((node = nodes2.pop()) != null) { + callback(node); + } +} + +function d3_layout_hierarchyChildren(d) { + return d.children; +} + +function d3_layout_hierarchyValue(d) { + return d.value; +} + +function d3_layout_hierarchySort(a, b) { + return b.value - a.value; +} + +// Returns an array source+target objects for the specified nodes. +function d3_layout_hierarchyLinks(nodes) { + return d3.merge(nodes.map(function(parent) { + return (parent.children || []).map(function(child) { + return {source: parent, target: child}; + }); + })); +} diff --git a/node_modules/@plotly/d3/src/layout/histogram.js b/node_modules/@plotly/d3/src/layout/histogram.js new file mode 100644 index 0000000000000000000000000000000000000000..4105d9bb503ade949b1053760394c93b32ff8c60 --- /dev/null +++ b/node_modules/@plotly/d3/src/layout/histogram.js @@ -0,0 +1,110 @@ +import "../arrays/bisect"; +import "../arrays/min"; +import "../arrays/max"; +import "../core/functor"; +import "layout"; + +d3.layout.histogram = function() { + var frequency = true, + valuer = Number, + ranger = d3_layout_histogramRange, + binner = d3_layout_histogramBinSturges; + + function histogram(data, i) { + var bins = [], + values = data.map(valuer, this), + range = ranger.call(this, values, i), + thresholds = binner.call(this, range, values, i), + bin, + i = -1, + n = values.length, + m = thresholds.length - 1, + k = frequency ? 1 : 1 / n, + x; + + // Initialize the bins. + while (++i < m) { + bin = bins[i] = []; + bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]); + bin.y = 0; + } + + // Fill the bins, ignoring values outside the range. + if (m > 0) { + i = -1; while(++i < n) { + x = values[i]; + if (x >= range[0] && x <= range[1]) { + bin = bins[d3.bisect(thresholds, x, 1, m) - 1]; + bin.y += k; + bin.push(data[i]); + } + } + } + + return bins; + } + + // Specifies how to extract a value from the associated data. The default + // value function is `Number`, which is equivalent to the identity function. + histogram.value = function(x) { + if (!arguments.length) return valuer; + valuer = x; + return histogram; + }; + + // Specifies the range of the histogram. Values outside the specified range + // will be ignored. The argument `x` may be specified either as a two-element + // array representing the minimum and maximum value of the range, or as a + // function that returns the range given the array of values and the current + // index `i`. The default range is the extent (minimum and maximum) of the + // values. + histogram.range = function(x) { + if (!arguments.length) return ranger; + ranger = d3_functor(x); + return histogram; + }; + + // Specifies how to bin values in the histogram. The argument `x` may be + // specified as a number, in which case the range of values will be split + // uniformly into the given number of bins. Or, `x` may be an array of + // threshold values, defining the bins; the specified array must contain the + // rightmost (upper) value, thus specifying n + 1 values for n bins. Or, `x` + // may be a function which is evaluated, being passed the range, the array of + // values, and the current index `i`, returning an array of thresholds. The + // default bin function will divide the values into uniform bins using + // Sturges' formula. + histogram.bins = function(x) { + if (!arguments.length) return binner; + binner = typeof x === "number" + ? function(range) { return d3_layout_histogramBinFixed(range, x); } + : d3_functor(x); + return histogram; + }; + + // Specifies whether the histogram's `y` value is a count (frequency) or a + // probability (density). The default value is true. + histogram.frequency = function(x) { + if (!arguments.length) return frequency; + frequency = !!x; + return histogram; + }; + + return histogram; +}; + +function d3_layout_histogramBinSturges(range, values) { + return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1)); +} + +function d3_layout_histogramBinFixed(range, n) { + var x = -1, + b = +range[0], + m = (range[1] - b) / n, + f = []; + while (++x <= n) f[x] = m * x + b; + return f; +} + +function d3_layout_histogramRange(values) { + return [d3.min(values), d3.max(values)]; +} diff --git a/node_modules/@plotly/d3/src/layout/index.js b/node_modules/@plotly/d3/src/layout/index.js new file mode 100644 index 0000000000000000000000000000000000000000..9c203f3d3d19635e39150dfd6ff4c2390baa370f --- /dev/null +++ b/node_modules/@plotly/d3/src/layout/index.js @@ -0,0 +1,13 @@ +import "layout"; +import "bundle"; +import "chord"; +import "force"; +import "partition"; +import "pie"; +import "stack"; +import "histogram"; +import "hierarchy"; +import "pack"; +import "cluster"; +import "tree"; +import "treemap"; diff --git a/node_modules/@plotly/d3/src/layout/layout.js b/node_modules/@plotly/d3/src/layout/layout.js new file mode 100644 index 0000000000000000000000000000000000000000..3bcbccefe6c45794b8d495bbb0c7ab66e74ffe61 --- /dev/null +++ b/node_modules/@plotly/d3/src/layout/layout.js @@ -0,0 +1 @@ +d3.layout = {}; diff --git a/node_modules/@plotly/d3/src/layout/pack.js b/node_modules/@plotly/d3/src/layout/pack.js new file mode 100644 index 0000000000000000000000000000000000000000..da573b1d9850fc5a38b9157210032b8ef6347091 --- /dev/null +++ b/node_modules/@plotly/d3/src/layout/pack.js @@ -0,0 +1,211 @@ +import "layout"; +import "hierarchy"; + +d3.layout.pack = function() { + var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), + padding = 0, + size = [1, 1], + radius; + + function pack(d, i) { + var nodes = hierarchy.call(this, d, i), + root = nodes[0], + w = size[0], + h = size[1], + r = radius == null ? Math.sqrt : typeof radius === "function" ? radius : function() { return radius; }; + + // Recursively compute the layout. + root.x = root.y = 0; + d3_layout_hierarchyVisitAfter(root, function(d) { d.r = +r(d.value); }); + d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings); + + // When padding, recompute the layout using scaled padding. + if (padding) { + var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2; + d3_layout_hierarchyVisitAfter(root, function(d) { d.r += dr; }); + d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings); + d3_layout_hierarchyVisitAfter(root, function(d) { d.r -= dr; }); + } + + // Translate and scale the layout to fit the requested size. + d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h)); + + return nodes; + } + + pack.size = function(_) { + if (!arguments.length) return size; + size = _; + return pack; + }; + + pack.radius = function(_) { + if (!arguments.length) return radius; + radius = _ == null || typeof _ === "function" ? _ : +_; + return pack; + }; + + pack.padding = function(_) { + if (!arguments.length) return padding; + padding = +_; + return pack; + }; + + return d3_layout_hierarchyRebind(pack, hierarchy); +}; + +function d3_layout_packSort(a, b) { + return a.value - b.value; +} + +function d3_layout_packInsert(a, b) { + var c = a._pack_next; + a._pack_next = b; + b._pack_prev = a; + b._pack_next = c; + c._pack_prev = b; +} + +function d3_layout_packSplice(a, b) { + a._pack_next = b; + b._pack_prev = a; +} + +function d3_layout_packIntersects(a, b) { + var dx = b.x - a.x, + dy = b.y - a.y, + dr = a.r + b.r; + return 0.999 * dr * dr > dx * dx + dy * dy; // relative error within epsilon +} + +function d3_layout_packSiblings(node) { + if (!(nodes = node.children) || !(n = nodes.length)) return; + + var nodes, + xMin = Infinity, + xMax = -Infinity, + yMin = Infinity, + yMax = -Infinity, + a, b, c, i, j, k, n; + + function bound(node) { + xMin = Math.min(node.x - node.r, xMin); + xMax = Math.max(node.x + node.r, xMax); + yMin = Math.min(node.y - node.r, yMin); + yMax = Math.max(node.y + node.r, yMax); + } + + // Create node links. + nodes.forEach(d3_layout_packLink); + + // Create first node. + a = nodes[0]; + a.x = -a.r; + a.y = 0; + bound(a); + + // Create second node. + if (n > 1) { + b = nodes[1]; + b.x = b.r; + b.y = 0; + bound(b); + + // Create third node and build chain. + if (n > 2) { + c = nodes[2]; + d3_layout_packPlace(a, b, c); + bound(c); + d3_layout_packInsert(a, c); + a._pack_prev = c; + d3_layout_packInsert(c, b); + b = a._pack_next; + + // Now iterate through the rest. + for (i = 3; i < n; i++) { + d3_layout_packPlace(a, b, c = nodes[i]); + + // Search for the closest intersection. + var isect = 0, s1 = 1, s2 = 1; + for (j = b._pack_next; j !== b; j = j._pack_next, s1++) { + if (d3_layout_packIntersects(j, c)) { + isect = 1; + break; + } + } + if (isect == 1) { + for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) { + if (d3_layout_packIntersects(k, c)) { + break; + } + } + } + + // Update node chain. + if (isect) { + if (s1 < s2 || (s1 == s2 && b.r < a.r)) d3_layout_packSplice(a, b = j); + else d3_layout_packSplice(a = k, b); + i--; + } else { + d3_layout_packInsert(a, c); + b = c; + bound(c); + } + } + } + } + + // Re-center the circles and compute the encompassing radius. + var cx = (xMin + xMax) / 2, + cy = (yMin + yMax) / 2, + cr = 0; + for (i = 0; i < n; i++) { + c = nodes[i]; + c.x -= cx; + c.y -= cy; + cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y)); + } + node.r = cr; + + // Remove node links. + nodes.forEach(d3_layout_packUnlink); +} + +function d3_layout_packLink(node) { + node._pack_next = node._pack_prev = node; +} + +function d3_layout_packUnlink(node) { + delete node._pack_next; + delete node._pack_prev; +} + +function d3_layout_packTransform(node, x, y, k) { + var children = node.children; + node.x = x += k * node.x; + node.y = y += k * node.y; + node.r *= k; + if (children) { + var i = -1, n = children.length; + while (++i < n) d3_layout_packTransform(children[i], x, y, k); + } +} + +function d3_layout_packPlace(a, b, c) { + var db = a.r + c.r, + dx = b.x - a.x, + dy = b.y - a.y; + if (db && (dx || dy)) { + var da = b.r + c.r, + dc = dx * dx + dy * dy; + da *= da; + db *= db; + var x = 0.5 + (db - da) / (2 * dc), + y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc); + c.x = a.x + x * dx + y * dy; + c.y = a.y + x * dy - y * dx; + } else { + c.x = a.x + db; + c.y = a.y; + } +} diff --git a/node_modules/@plotly/d3/src/layout/partition.js b/node_modules/@plotly/d3/src/layout/partition.js new file mode 100644 index 0000000000000000000000000000000000000000..581fd052377c0093162c1db007b23597b92999ff --- /dev/null +++ b/node_modules/@plotly/d3/src/layout/partition.js @@ -0,0 +1,51 @@ +import "layout"; +import "hierarchy"; + +d3.layout.partition = function() { + var hierarchy = d3.layout.hierarchy(), + size = [1, 1]; // width, height + + function position(node, x, dx, dy) { + var children = node.children; + node.x = x; + node.y = node.depth * dy; + node.dx = dx; + node.dy = dy; + if (children && (n = children.length)) { + var i = -1, + n, + c, + d; + dx = node.value ? dx / node.value : 0; + while (++i < n) { + position(c = children[i], x, d = c.value * dx, dy); + x += d; + } + } + } + + function depth(node) { + var children = node.children, + d = 0; + if (children && (n = children.length)) { + var i = -1, + n; + while (++i < n) d = Math.max(d, depth(children[i])); + } + return 1 + d; + } + + function partition(d, i) { + var nodes = hierarchy.call(this, d, i); + position(nodes[0], 0, size[0], size[1] / depth(nodes[0])); + return nodes; + } + + partition.size = function(x) { + if (!arguments.length) return size; + size = x; + return partition; + }; + + return d3_layout_hierarchyRebind(partition, hierarchy); +}; diff --git a/node_modules/@plotly/d3/src/layout/pie.js b/node_modules/@plotly/d3/src/layout/pie.js new file mode 100644 index 0000000000000000000000000000000000000000..5a0abb451d9843540603eac731c1825cd58e6fd0 --- /dev/null +++ b/node_modules/@plotly/d3/src/layout/pie.js @@ -0,0 +1,78 @@ +import "../arrays/range"; +import "../arrays/sum"; +import "../math/trigonometry"; +import "layout"; + +d3.layout.pie = function() { + var value = Number, + sort = d3_layout_pieSortByValue, + startAngle = 0, + endAngle = τ, + padAngle = 0; + + function pie(data) { + var n = data.length, + values = data.map(function(d, i) { return +value.call(pie, d, i); }), + a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle), + da = (typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a, + p = Math.min(Math.abs(da) / n, +(typeof padAngle === "function" ? padAngle.apply(this, arguments) : padAngle)), + pa = p * (da < 0 ? -1 : 1), + sum = d3.sum(values), + k = sum ? (da - n * pa) / sum : 0, + index = d3.range(n), + arcs = [], + v; + + // Optionally sort the data. + if (sort != null) index.sort(sort === d3_layout_pieSortByValue + ? function(i, j) { return values[j] - values[i]; } + : function(i, j) { return sort(data[i], data[j]); }); + + // Compute the arcs! They are stored in the original data's order. + index.forEach(function(i) { + arcs[i] = { + data: data[i], + value: v = values[i], + startAngle: a, + endAngle: a += v * k + pa, + padAngle: p + }; + }); + + return arcs; + } + + pie.value = function(_) { + if (!arguments.length) return value; + value = _; + return pie; + }; + + pie.sort = function(_) { + if (!arguments.length) return sort; + sort = _; + return pie; + }; + + pie.startAngle = function(_) { + if (!arguments.length) return startAngle; + startAngle = _; + return pie; + }; + + pie.endAngle = function(_) { + if (!arguments.length) return endAngle; + endAngle = _; + return pie; + }; + + pie.padAngle = function(_) { + if (!arguments.length) return padAngle; + padAngle = _; + return pie; + }; + + return pie; +}; + +var d3_layout_pieSortByValue = {}; diff --git a/node_modules/@plotly/d3/src/layout/stack.js b/node_modules/@plotly/d3/src/layout/stack.js new file mode 100644 index 0000000000000000000000000000000000000000..79ece6046dc888635fbcad8f085f36460bb774b3 --- /dev/null +++ b/node_modules/@plotly/d3/src/layout/stack.js @@ -0,0 +1,247 @@ +import "../arrays/map"; +import "../arrays/permute"; +import "../arrays/range"; +import "../core/identity"; +import "layout"; + +// data is two-dimensional array of x,y; we populate y0 +d3.layout.stack = function() { + var values = d3_identity, + order = d3_layout_stackOrderDefault, + offset = d3_layout_stackOffsetZero, + out = d3_layout_stackOut, + x = d3_layout_stackX, + y = d3_layout_stackY; + + function stack(data, index) { + if (!(n = data.length)) return data; + + // Convert series to canonical two-dimensional representation. + var series = data.map(function(d, i) { + return values.call(stack, d, i); + }); + + // Convert each series to canonical [[x,y]] representation. + var points = series.map(function(d) { + return d.map(function(v, i) { + return [x.call(stack, v, i), y.call(stack, v, i)]; + }); + }); + + // Compute the order of series, and permute them. + var orders = order.call(stack, points, index); + series = d3.permute(series, orders); + points = d3.permute(points, orders); + + // Compute the baseline… + var offsets = offset.call(stack, points, index); + + // And propagate it to other series. + var m = series[0].length, + n, + i, + j, + o; + for (j = 0; j < m; ++j) { + out.call(stack, series[0][j], o = offsets[j], points[0][j][1]); + for (i = 1; i < n; ++i) { + out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]); + } + } + + return data; + } + + stack.values = function(x) { + if (!arguments.length) return values; + values = x; + return stack; + }; + + stack.order = function(x) { + if (!arguments.length) return order; + order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault; + return stack; + }; + + stack.offset = function(x) { + if (!arguments.length) return offset; + offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero; + return stack; + }; + + stack.x = function(z) { + if (!arguments.length) return x; + x = z; + return stack; + }; + + stack.y = function(z) { + if (!arguments.length) return y; + y = z; + return stack; + }; + + stack.out = function(z) { + if (!arguments.length) return out; + out = z; + return stack; + }; + + return stack; +}; + +function d3_layout_stackX(d) { + return d.x; +} + +function d3_layout_stackY(d) { + return d.y; +} + +function d3_layout_stackOut(d, y0, y) { + d.y0 = y0; + d.y = y; +} + +var d3_layout_stackOrders = d3.map({ + + "inside-out": function(data) { + var n = data.length, + i, + j, + max = data.map(d3_layout_stackMaxIndex), + sums = data.map(d3_layout_stackReduceSum), + index = d3.range(n).sort(function(a, b) { return max[a] - max[b]; }), + top = 0, + bottom = 0, + tops = [], + bottoms = []; + for (i = 0; i < n; ++i) { + j = index[i]; + if (top < bottom) { + top += sums[j]; + tops.push(j); + } else { + bottom += sums[j]; + bottoms.push(j); + } + } + return bottoms.reverse().concat(tops); + }, + + "reverse": function(data) { + return d3.range(data.length).reverse(); + }, + + "default": d3_layout_stackOrderDefault + +}); + +var d3_layout_stackOffsets = d3.map({ + + "silhouette": function(data) { + var n = data.length, + m = data[0].length, + sums = [], + max = 0, + i, + j, + o, + y0 = []; + for (j = 0; j < m; ++j) { + for (i = 0, o = 0; i < n; i++) o += data[i][j][1]; + if (o > max) max = o; + sums.push(o); + } + for (j = 0; j < m; ++j) { + y0[j] = (max - sums[j]) / 2; + } + return y0; + }, + + "wiggle": function(data) { + var n = data.length, + x = data[0], + m = x.length, + i, + j, + k, + s1, + s2, + s3, + dx, + o, + o0, + y0 = []; + y0[0] = o = o0 = 0; + for (j = 1; j < m; ++j) { + for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1]; + for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) { + for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) { + s3 += (data[k][j][1] - data[k][j - 1][1]) / dx; + } + s2 += s3 * data[i][j][1]; + } + y0[j] = o -= s1 ? s2 / s1 * dx : 0; + if (o < o0) o0 = o; + } + for (j = 0; j < m; ++j) y0[j] -= o0; + return y0; + }, + + "expand": function(data) { + var n = data.length, + m = data[0].length, + k = 1 / n, + i, + j, + o, + y0 = []; + for (j = 0; j < m; ++j) { + for (i = 0, o = 0; i < n; i++) o += data[i][j][1]; + if (o) for (i = 0; i < n; i++) data[i][j][1] /= o; + else for (i = 0; i < n; i++) data[i][j][1] = k; + } + for (j = 0; j < m; ++j) y0[j] = 0; + return y0; + }, + + "zero": d3_layout_stackOffsetZero + +}); + +function d3_layout_stackOrderDefault(data) { + return d3.range(data.length); +} + +function d3_layout_stackOffsetZero(data) { + var j = -1, + m = data[0].length, + y0 = []; + while (++j < m) y0[j] = 0; + return y0; +} + +function d3_layout_stackMaxIndex(array) { + var i = 1, + j = 0, + v = array[0][1], + k, + n = array.length; + for (; i < n; ++i) { + if ((k = array[i][1]) > v) { + j = i; + v = k; + } + } + return j; +} + +function d3_layout_stackReduceSum(d) { + return d.reduce(d3_layout_stackSum, 0); +} + +function d3_layout_stackSum(p, d) { + return p + d[1]; +} diff --git a/node_modules/@plotly/d3/src/layout/tree.js b/node_modules/@plotly/d3/src/layout/tree.js new file mode 100644 index 0000000000000000000000000000000000000000..80afaa7d86117161408f9dfd4de2eb4755a65c65 --- /dev/null +++ b/node_modules/@plotly/d3/src/layout/tree.js @@ -0,0 +1,240 @@ +import "layout"; +import "hierarchy"; + +// Node-link tree diagram using the Reingold-Tilford "tidy" algorithm +d3.layout.tree = function() { + var hierarchy = d3.layout.hierarchy().sort(null).value(null), + separation = d3_layout_treeSeparation, + size = [1, 1], // width, height + nodeSize = null; + + function tree(d, i) { + var nodes = hierarchy.call(this, d, i), + root0 = nodes[0], + root1 = wrapTree(root0); + + // Compute the layout using Buchheim et al.'s algorithm. + d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z; + d3_layout_hierarchyVisitBefore(root1, secondWalk); + + // If a fixed node size is specified, scale x and y. + if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); + + // If a fixed tree size is specified, scale x and y based on the extent. + // Compute the left-most, right-most, and depth-most nodes for extents. + else { + var left = root0, + right = root0, + bottom = root0; + d3_layout_hierarchyVisitBefore(root0, function(node) { + if (node.x < left.x) left = node; + if (node.x > right.x) right = node; + if (node.depth > bottom.depth) bottom = node; + }); + var tx = separation(left, right) / 2 - left.x, + kx = size[0] / (right.x + separation(right, left) / 2 + tx), + ky = size[1] / (bottom.depth || 1); + d3_layout_hierarchyVisitBefore(root0, function(node) { + node.x = (node.x + tx) * kx; + node.y = node.depth * ky; + }); + } + + return nodes; + } + + function wrapTree(root0) { + var root1 = {A: null, children: [root0]}, + queue = [root1], + node1; + + while ((node1 = queue.pop()) != null) { + for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) { + queue.push((children[i] = child = { + _: children[i], // source node + parent: node1, + children: (child = children[i].children) && child.slice() || [], + A: null, // default ancestor + a: null, // ancestor + z: 0, // prelim + m: 0, // mod + c: 0, // change + s: 0, // shift + t: null, // thread + i: i // number + }).a = child); + } + } + + return root1.children[0]; + } + + // FIRST WALK + // Computes a preliminary x-coordinate for v. Before that, FIRST WALK is + // applied recursively to the children of v, as well as the function + // APPORTION. After spacing out the children by calling EXECUTE SHIFTS, the + // node v is placed to the midpoint of its outermost children. + function firstWalk(v) { + var children = v.children, + siblings = v.parent.children, + w = v.i ? siblings[v.i - 1] : null; + if (children.length) { + d3_layout_treeShift(v); + var midpoint = (children[0].z + children[children.length - 1].z) / 2; + if (w) { + v.z = w.z + separation(v._, w._); + v.m = v.z - midpoint; + } else { + v.z = midpoint; + } + } else if (w) { + v.z = w.z + separation(v._, w._); + } + v.parent.A = apportion(v, w, v.parent.A || siblings[0]); + } + + // SECOND WALK + // Computes all real x-coordinates by summing up the modifiers recursively. + function secondWalk(v) { + v._.x = v.z + v.parent.m; + v.m += v.parent.m; + } + + // APPORTION + // The core of the algorithm. Here, a new subtree is combined with the + // previous subtrees. Threads are used to traverse the inside and outside + // contours of the left and right subtree up to the highest common level. The + // vertices used for the traversals are vi+, vi-, vo-, and vo+, where the + // superscript o means outside and i means inside, the subscript - means left + // subtree and + means right subtree. For summing up the modifiers along the + // contour, we use respective variables si+, si-, so-, and so+. Whenever two + // nodes of the inside contours conflict, we compute the left one of the + // greatest uncommon ancestors using the function ANCESTOR and call MOVE + // SUBTREE to shift the subtree and prepare the shifts of smaller subtrees. + // Finally, we add a new thread (if necessary). + function apportion(v, w, ancestor) { + if (w) { + var vip = v, + vop = v, + vim = w, + vom = vip.parent.children[0], + sip = vip.m, + sop = vop.m, + sim = vim.m, + som = vom.m, + shift; + while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) { + vom = d3_layout_treeLeft(vom); + vop = d3_layout_treeRight(vop); + vop.a = v; + shift = vim.z + sim - vip.z - sip + separation(vim._, vip._); + if (shift > 0) { + d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift); + sip += shift; + sop += shift; + } + sim += vim.m; + sip += vip.m; + som += vom.m; + sop += vop.m; + } + if (vim && !d3_layout_treeRight(vop)) { + vop.t = vim; + vop.m += sim - sop; + } + if (vip && !d3_layout_treeLeft(vom)) { + vom.t = vip; + vom.m += sip - som; + ancestor = v; + } + } + return ancestor; + } + + function sizeNode(node) { + node.x *= size[0]; + node.y = node.depth * size[1]; + } + + tree.separation = function(x) { + if (!arguments.length) return separation; + separation = x; + return tree; + }; + + tree.size = function(x) { + if (!arguments.length) return nodeSize ? null : size; + nodeSize = (size = x) == null ? sizeNode : null; + return tree; + }; + + tree.nodeSize = function(x) { + if (!arguments.length) return nodeSize ? size : null; + nodeSize = (size = x) == null ? null : sizeNode; + return tree; + }; + + return d3_layout_hierarchyRebind(tree, hierarchy); +}; + +function d3_layout_treeSeparation(a, b) { + return a.parent == b.parent ? 1 : 2; +} + +// function d3_layout_treeSeparationRadial(a, b) { +// return (a.parent == b.parent ? 1 : 2) / a.depth; +// } + +// NEXT LEFT +// This function is used to traverse the left contour of a subtree (or +// subforest). It returns the successor of v on this contour. This successor is +// either given by the leftmost child of v or by the thread of v. The function +// returns null if and only if v is on the highest level of its subtree. +function d3_layout_treeLeft(v) { + var children = v.children; + return children.length ? children[0] : v.t; +} + +// NEXT RIGHT +// This function works analogously to NEXT LEFT. +function d3_layout_treeRight(v) { + var children = v.children, n; + return (n = children.length) ? children[n - 1] : v.t; +} + +// MOVE SUBTREE +// Shifts the current subtree rooted at w+. This is done by increasing +// prelim(w+) and mod(w+) by shift. +function d3_layout_treeMove(wm, wp, shift) { + var change = shift / (wp.i - wm.i); + wp.c -= change; + wp.s += shift; + wm.c += change; + wp.z += shift; + wp.m += shift; +} + +// EXECUTE SHIFTS +// All other shifts, applied to the smaller subtrees between w- and w+, are +// performed by this function. To prepare the shifts, we have to adjust +// change(w+), shift(w+), and change(w-). +function d3_layout_treeShift(v) { + var shift = 0, + change = 0, + children = v.children, + i = children.length, + w; + while (--i >= 0) { + w = children[i]; + w.z += shift; + w.m += shift; + shift += w.s + (change += w.c); + } +} + +// ANCESTOR +// If vi-’s ancestor is a sibling of v, returns vi-’s ancestor. Otherwise, +// returns the specified (default) ancestor. +function d3_layout_treeAncestor(vim, v, ancestor) { + return vim.a.parent === v.parent ? vim.a : ancestor; +} diff --git a/node_modules/@plotly/d3/src/layout/treemap.js b/node_modules/@plotly/d3/src/layout/treemap.js new file mode 100644 index 0000000000000000000000000000000000000000..cc0803a6c3c998c52dc35f978b426571e2e29a7f --- /dev/null +++ b/node_modules/@plotly/d3/src/layout/treemap.js @@ -0,0 +1,229 @@ +import "layout"; +import "hierarchy"; + +// Squarified Treemaps by Mark Bruls, Kees Huizing, and Jarke J. van Wijk +// Modified to support a target aspect ratio by Jeff Heer +d3.layout.treemap = function() { + var hierarchy = d3.layout.hierarchy(), + round = Math.round, + size = [1, 1], // width, height + padding = null, + pad = d3_layout_treemapPadNull, + sticky = false, + stickies, + mode = "squarify", + ratio = 0.5 * (1 + Math.sqrt(5)); // golden ratio + + // Compute the area for each child based on value & scale. + function scale(children, k) { + var i = -1, + n = children.length, + child, + area; + while (++i < n) { + area = (child = children[i]).value * (k < 0 ? 0 : k); + child.area = isNaN(area) || area <= 0 ? 0 : area; + } + } + + // Recursively arranges the specified node's children into squarified rows. + function squarify(node) { + var children = node.children; + if (children && children.length) { + var rect = pad(node), + row = [], + remaining = children.slice(), // copy-on-write + child, + best = Infinity, // the best row score so far + score, // the current row score + u = mode === "slice" ? rect.dx + : mode === "dice" ? rect.dy + : mode === "slice-dice" ? node.depth & 1 ? rect.dy : rect.dx + : Math.min(rect.dx, rect.dy), // initial orientation + n; + scale(remaining, rect.dx * rect.dy / node.value); + row.area = 0; + while ((n = remaining.length) > 0) { + row.push(child = remaining[n - 1]); + row.area += child.area; + if (mode !== "squarify" || (score = worst(row, u)) <= best) { // continue with this orientation + remaining.pop(); + best = score; + } else { // abort, and try a different orientation + row.area -= row.pop().area; + position(row, u, rect, false); + u = Math.min(rect.dx, rect.dy); + row.length = row.area = 0; + best = Infinity; + } + } + if (row.length) { + position(row, u, rect, true); + row.length = row.area = 0; + } + children.forEach(squarify); + } + } + + // Recursively resizes the specified node's children into existing rows. + // Preserves the existing layout! + function stickify(node) { + var children = node.children; + if (children && children.length) { + var rect = pad(node), + remaining = children.slice(), // copy-on-write + child, + row = []; + scale(remaining, rect.dx * rect.dy / node.value); + row.area = 0; + while (child = remaining.pop()) { + row.push(child); + row.area += child.area; + if (child.z != null) { + position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length); + row.length = row.area = 0; + } + } + children.forEach(stickify); + } + } + + // Computes the score for the specified row, as the worst aspect ratio. + function worst(row, u) { + var s = row.area, + r, + rmax = 0, + rmin = Infinity, + i = -1, + n = row.length; + while (++i < n) { + if (!(r = row[i].area)) continue; + if (r < rmin) rmin = r; + if (r > rmax) rmax = r; + } + s *= s; + u *= u; + return s + ? Math.max((u * rmax * ratio) / s, s / (u * rmin * ratio)) + : Infinity; + } + + // Positions the specified row of nodes. Modifies `rect`. + function position(row, u, rect, flush) { + var i = -1, + n = row.length, + x = rect.x, + y = rect.y, + v = u ? round(row.area / u) : 0, + o; + if (u == rect.dx) { // horizontal subdivision + if (flush || v > rect.dy) v = rect.dy; // over+underflow + while (++i < n) { + o = row[i]; + o.x = x; + o.y = y; + o.dy = v; + x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0); + } + o.z = true; + o.dx += rect.x + rect.dx - x; // rounding error + rect.y += v; + rect.dy -= v; + } else { // vertical subdivision + if (flush || v > rect.dx) v = rect.dx; // over+underflow + while (++i < n) { + o = row[i]; + o.x = x; + o.y = y; + o.dx = v; + y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0); + } + o.z = false; + o.dy += rect.y + rect.dy - y; // rounding error + rect.x += v; + rect.dx -= v; + } + } + + function treemap(d) { + var nodes = stickies || hierarchy(d), + root = nodes[0]; + root.x = root.y = 0; + if (root.value) root.dx = size[0], root.dy = size[1]; + else root.dx = root.dy = 0; + if (stickies) hierarchy.revalue(root); + scale([root], root.dx * root.dy / root.value); + (stickies ? stickify : squarify)(root); + if (sticky) stickies = nodes; + return nodes; + } + + treemap.size = function(x) { + if (!arguments.length) return size; + size = x; + return treemap; + }; + + treemap.padding = function(x) { + if (!arguments.length) return padding; + + function padFunction(node) { + var p = x.call(treemap, node, node.depth); + return p == null + ? d3_layout_treemapPadNull(node) + : d3_layout_treemapPad(node, typeof p === "number" ? [p, p, p, p] : p); + } + + function padConstant(node) { + return d3_layout_treemapPad(node, x); + } + + var type; + pad = (padding = x) == null ? d3_layout_treemapPadNull + : (type = typeof x) === "function" ? padFunction + : type === "number" ? (x = [x, x, x, x], padConstant) + : padConstant; + return treemap; + }; + + treemap.round = function(x) { + if (!arguments.length) return round != Number; + round = x ? Math.round : Number; + return treemap; + }; + + treemap.sticky = function(x) { + if (!arguments.length) return sticky; + sticky = x; + stickies = null; + return treemap; + }; + + treemap.ratio = function(x) { + if (!arguments.length) return ratio; + ratio = x; + return treemap; + }; + + treemap.mode = function(x) { + if (!arguments.length) return mode; + mode = x + ""; + return treemap; + }; + + return d3_layout_hierarchyRebind(treemap, hierarchy); +}; + +function d3_layout_treemapPadNull(node) { + return {x: node.x, y: node.y, dx: node.dx, dy: node.dy}; +} + +function d3_layout_treemapPad(node, padding) { + var x = node.x + padding[3], + y = node.y + padding[0], + dx = node.dx - padding[1] - padding[3], + dy = node.dy - padding[0] - padding[2]; + if (dx < 0) { x += dx / 2; dx = 0; } + if (dy < 0) { y += dy / 2; dy = 0; } + return {x: x, y: y, dx: dx, dy: dy}; +} diff --git a/node_modules/@plotly/d3/src/math/abs.js b/node_modules/@plotly/d3/src/math/abs.js new file mode 100644 index 0000000000000000000000000000000000000000..6c078b921167f52850ec723b21b71abe8ccbd1f3 --- /dev/null +++ b/node_modules/@plotly/d3/src/math/abs.js @@ -0,0 +1 @@ +var abs = Math.abs; diff --git a/node_modules/@plotly/d3/src/math/adder.js b/node_modules/@plotly/d3/src/math/adder.js new file mode 100644 index 0000000000000000000000000000000000000000..08fa289aeac64e46db3c897846213ad7a9141839 --- /dev/null +++ b/node_modules/@plotly/d3/src/math/adder.js @@ -0,0 +1,34 @@ +// Adds floating point numbers with twice the normal precision. +// Reference: J. R. Shewchuk, Adaptive Precision Floating-Point Arithmetic and +// Fast Robust Geometric Predicates, Discrete & Computational Geometry 18(3) +// 305–363 (1997). +// Code adapted from GeographicLib by Charles F. F. Karney, +// http://geographiclib.sourceforge.net/ +// See lib/geographiclib/LICENSE for details. + +function d3_adder() {} + +d3_adder.prototype = { + s: 0, // rounded value + t: 0, // exact error + add: function(y) { + d3_adderSum(y, this.t, d3_adderTemp); + d3_adderSum(d3_adderTemp.s, this.s, this); + if (this.s) this.t += d3_adderTemp.t; + else this.s = d3_adderTemp.t; + }, + reset: function() { + this.s = this.t = 0; + }, + valueOf: function() { + return this.s; + } +}; + +var d3_adderTemp = new d3_adder; + +function d3_adderSum(a, b, o) { + var x = o.s = a + b, // a + b + bv = x - a, av = x - bv; // b_virtual & a_virtual + o.t = (a - av) + (b - bv); // a_roundoff + b_roundoff +} diff --git a/node_modules/@plotly/d3/src/math/index.js b/node_modules/@plotly/d3/src/math/index.js new file mode 100644 index 0000000000000000000000000000000000000000..20f6966e2955e259bb29c7606ac0d1165f5056aa --- /dev/null +++ b/node_modules/@plotly/d3/src/math/index.js @@ -0,0 +1,2 @@ +import "random"; +import "transform"; diff --git a/node_modules/@plotly/d3/src/math/number.js b/node_modules/@plotly/d3/src/math/number.js new file mode 100644 index 0000000000000000000000000000000000000000..44ff3324fb4cb41c8a215817ed5605800377001a --- /dev/null +++ b/node_modules/@plotly/d3/src/math/number.js @@ -0,0 +1,7 @@ +function d3_number(x) { + return x === null ? NaN : +x; +} + +function d3_numeric(x) { + return !isNaN(x); +} diff --git a/node_modules/@plotly/d3/src/math/random.js b/node_modules/@plotly/d3/src/math/random.js new file mode 100644 index 0000000000000000000000000000000000000000..d0c6ba07b92c3c47dcdcc5e963689c9029f5d77f --- /dev/null +++ b/node_modules/@plotly/d3/src/math/random.js @@ -0,0 +1,34 @@ +d3.random = { + normal: function(µ, σ) { + var n = arguments.length; + if (n < 2) σ = 1; + if (n < 1) µ = 0; + return function() { + var x, y, r; + do { + x = Math.random() * 2 - 1; + y = Math.random() * 2 - 1; + r = x * x + y * y; + } while (!r || r > 1); + return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r); + }; + }, + logNormal: function() { + var random = d3.random.normal.apply(d3, arguments); + return function() { + return Math.exp(random()); + }; + }, + bates: function(m) { + var random = d3.random.irwinHall(m); + return function() { + return random() / m; + }; + }, + irwinHall: function(m) { + return function() { + for (var s = 0, j = 0; j < m; j++) s += Math.random(); + return s; + }; + } +}; diff --git a/node_modules/@plotly/d3/src/math/transform.js b/node_modules/@plotly/d3/src/math/transform.js new file mode 100644 index 0000000000000000000000000000000000000000..8a5e6cde5780d9e434e24b5637990aadf98b966c --- /dev/null +++ b/node_modules/@plotly/d3/src/math/transform.js @@ -0,0 +1,64 @@ +import "../core/document"; +import "../core/ns"; + +d3.transform = function(string) { + var g = d3_document.createElementNS(d3.ns.prefix.svg, "g"); + return (d3.transform = function(string) { + if (string != null) { + g.setAttribute("transform", string); + var t = g.transform.baseVal.consolidate(); + } + return new d3_transform(t ? t.matrix : d3_transformIdentity); + })(string); +}; + +// Compute x-scale and normalize the first row. +// Compute shear and make second row orthogonal to first. +// Compute y-scale and normalize the second row. +// Finally, compute the rotation. +function d3_transform(m) { + var r0 = [m.a, m.b], + r1 = [m.c, m.d], + kx = d3_transformNormalize(r0), + kz = d3_transformDot(r0, r1), + ky = d3_transformNormalize(d3_transformCombine(r1, r0, -kz)) || 0; + if (r0[0] * r1[1] < r1[0] * r0[1]) { + r0[0] *= -1; + r0[1] *= -1; + kx *= -1; + kz *= -1; + } + this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees; + this.translate = [m.e, m.f]; + this.scale = [kx, ky]; + this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0; +}; + +d3_transform.prototype.toString = function() { + return "translate(" + this.translate + + ")rotate(" + this.rotate + + ")skewX(" + this.skew + + ")scale(" + this.scale + + ")"; +}; + +function d3_transformDot(a, b) { + return a[0] * b[0] + a[1] * b[1]; +} + +function d3_transformNormalize(a) { + var k = Math.sqrt(d3_transformDot(a, a)); + if (k) { + a[0] /= k; + a[1] /= k; + } + return k; +} + +function d3_transformCombine(a, b, k) { + a[0] += k * b[0]; + a[1] += k * b[1]; + return a; +} + +var d3_transformIdentity = {a: 1, b: 0, c: 0, d: 1, e: 0, f: 0}; diff --git a/node_modules/@plotly/d3/src/math/trigonometry.js b/node_modules/@plotly/d3/src/math/trigonometry.js new file mode 100644 index 0000000000000000000000000000000000000000..d7099a4e730b53f8bd4161e1024db5b17da7803f --- /dev/null +++ b/node_modules/@plotly/d3/src/math/trigonometry.js @@ -0,0 +1,44 @@ +var ε = 1e-6, + ε2 = ε * ε, + π = Math.PI, + τ = 2 * π, + τε = τ - ε, + halfπ = π / 2, + d3_radians = π / 180, + d3_degrees = 180 / π; + +function d3_sgn(x) { + return x > 0 ? 1 : x < 0 ? -1 : 0; +} + +// Returns the 2D cross product of AB and AC vectors, i.e., the z-component of +// the 3D cross product in a quadrant I Cartesian coordinate system (+x is +// right, +y is up). Returns a positive value if ABC is counter-clockwise, +// negative if clockwise, and zero if the points are collinear. +function d3_cross2d(a, b, c) { + return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]); +} + +function d3_acos(x) { + return x > 1 ? 0 : x < -1 ? π : Math.acos(x); +} + +function d3_asin(x) { + return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x); +} + +function d3_sinh(x) { + return ((x = Math.exp(x)) - 1 / x) / 2; +} + +function d3_cosh(x) { + return ((x = Math.exp(x)) + 1 / x) / 2; +} + +function d3_tanh(x) { + return ((x = Math.exp(2 * x)) - 1) / (x + 1); +} + +function d3_haversin(x) { + return (x = Math.sin(x / 2)) * x; +} diff --git a/node_modules/@plotly/d3/src/scale/bilinear.js b/node_modules/@plotly/d3/src/scale/bilinear.js new file mode 100644 index 0000000000000000000000000000000000000000..ff014777c654e5a70a84cf99a02ecd1ee69dbece --- /dev/null +++ b/node_modules/@plotly/d3/src/scale/bilinear.js @@ -0,0 +1,7 @@ +function d3_scale_bilinear(domain, range, uninterpolate, interpolate) { + var u = uninterpolate(domain[0], domain[1]), + i = interpolate(range[0], range[1]); + return function(x) { + return i(u(x)); + }; +} diff --git a/node_modules/@plotly/d3/src/scale/category.js b/node_modules/@plotly/d3/src/scale/category.js new file mode 100644 index 0000000000000000000000000000000000000000..3324917c6fc509f879927da7b6908c56788d4b13 --- /dev/null +++ b/node_modules/@plotly/d3/src/scale/category.js @@ -0,0 +1,58 @@ +import "../color/rgb"; +import "ordinal"; +import "scale"; + +/* + * This product includes color specifications and designs developed by Cynthia + * Brewer (http://colorbrewer.org/). See lib/colorbrewer for more information. + */ + +d3.scale.category10 = function() { + return d3.scale.ordinal().range(d3_category10); +}; + +d3.scale.category20 = function() { + return d3.scale.ordinal().range(d3_category20); +}; + +d3.scale.category20b = function() { + return d3.scale.ordinal().range(d3_category20b); +}; + +d3.scale.category20c = function() { + return d3.scale.ordinal().range(d3_category20c); +}; + +var d3_category10 = [ + 0x1f77b4, 0xff7f0e, 0x2ca02c, 0xd62728, 0x9467bd, + 0x8c564b, 0xe377c2, 0x7f7f7f, 0xbcbd22, 0x17becf +].map(d3_rgbString); + +var d3_category20 = [ + 0x1f77b4, 0xaec7e8, + 0xff7f0e, 0xffbb78, + 0x2ca02c, 0x98df8a, + 0xd62728, 0xff9896, + 0x9467bd, 0xc5b0d5, + 0x8c564b, 0xc49c94, + 0xe377c2, 0xf7b6d2, + 0x7f7f7f, 0xc7c7c7, + 0xbcbd22, 0xdbdb8d, + 0x17becf, 0x9edae5 +].map(d3_rgbString); + +var d3_category20b = [ + 0x393b79, 0x5254a3, 0x6b6ecf, 0x9c9ede, + 0x637939, 0x8ca252, 0xb5cf6b, 0xcedb9c, + 0x8c6d31, 0xbd9e39, 0xe7ba52, 0xe7cb94, + 0x843c39, 0xad494a, 0xd6616b, 0xe7969c, + 0x7b4173, 0xa55194, 0xce6dbd, 0xde9ed6 +].map(d3_rgbString); + +var d3_category20c = [ + 0x3182bd, 0x6baed6, 0x9ecae1, 0xc6dbef, + 0xe6550d, 0xfd8d3c, 0xfdae6b, 0xfdd0a2, + 0x31a354, 0x74c476, 0xa1d99b, 0xc7e9c0, + 0x756bb1, 0x9e9ac8, 0xbcbddc, 0xdadaeb, + 0x636363, 0x969696, 0xbdbdbd, 0xd9d9d9 +].map(d3_rgbString); diff --git a/node_modules/@plotly/d3/src/scale/identity.js b/node_modules/@plotly/d3/src/scale/identity.js new file mode 100644 index 0000000000000000000000000000000000000000..0cc78095953cac2ccdd362590619a8f90a2b660b --- /dev/null +++ b/node_modules/@plotly/d3/src/scale/identity.js @@ -0,0 +1,33 @@ +import "linear"; +import "scale"; + +d3.scale.identity = function() { + return d3_scale_identity([0, 1]); +}; + +function d3_scale_identity(domain) { + + function identity(x) { return +x; } + + identity.invert = identity; + + identity.domain = identity.range = function(x) { + if (!arguments.length) return domain; + domain = x.map(identity); + return identity; + }; + + identity.ticks = function(m) { + return d3_scale_linearTicks(domain, m); + }; + + identity.tickFormat = function(m, format) { + return d3_scale_linearTickFormat(domain, m, format); + }; + + identity.copy = function() { + return d3_scale_identity(domain); + }; + + return identity; +} diff --git a/node_modules/@plotly/d3/src/scale/index.js b/node_modules/@plotly/d3/src/scale/index.js new file mode 100644 index 0000000000000000000000000000000000000000..271ea8d7138916b047e223115d1e47b9c9864901 --- /dev/null +++ b/node_modules/@plotly/d3/src/scale/index.js @@ -0,0 +1,11 @@ +import "scale"; +import "linear"; +import "log"; +import "pow"; +import "sqrt"; +import "ordinal"; +import "category"; +import "quantile"; +import "quantize"; +import "threshold"; +import "identity"; diff --git a/node_modules/@plotly/d3/src/scale/linear.js b/node_modules/@plotly/d3/src/scale/linear.js new file mode 100644 index 0000000000000000000000000000000000000000..1b60a2c650bdd4c939551f1270d51553f2f150d4 --- /dev/null +++ b/node_modules/@plotly/d3/src/scale/linear.js @@ -0,0 +1,137 @@ +import "../arrays/range"; +import "../core/rebind"; +import "../interpolate/interpolate"; +import "../interpolate/round"; +import "../interpolate/uninterpolate"; +import "../math/abs"; +import "bilinear"; +import "nice"; +import "polylinear"; +import "scale"; + +d3.scale.linear = function() { + return d3_scale_linear([0, 1], [0, 1], d3_interpolate, false); +}; + +function d3_scale_linear(domain, range, interpolate, clamp) { + var output, + input; + + function rescale() { + var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, + uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber; + output = linear(domain, range, uninterpolate, interpolate); + input = linear(range, domain, uninterpolate, d3_interpolate); + return scale; + } + + function scale(x) { + return output(x); + } + + // Note: requires range is coercible to number! + scale.invert = function(y) { + return input(y); + }; + + scale.domain = function(x) { + if (!arguments.length) return domain; + domain = x.map(Number); + return rescale(); + }; + + scale.range = function(x) { + if (!arguments.length) return range; + range = x; + return rescale(); + }; + + scale.rangeRound = function(x) { + return scale.range(x).interpolate(d3_interpolateRound); + }; + + scale.clamp = function(x) { + if (!arguments.length) return clamp; + clamp = x; + return rescale(); + }; + + scale.interpolate = function(x) { + if (!arguments.length) return interpolate; + interpolate = x; + return rescale(); + }; + + scale.ticks = function(m) { + return d3_scale_linearTicks(domain, m); + }; + + scale.tickFormat = function(m, format) { + return d3_scale_linearTickFormat(domain, m, format); + }; + + scale.nice = function(m) { + d3_scale_linearNice(domain, m); + return rescale(); + }; + + scale.copy = function() { + return d3_scale_linear(domain, range, interpolate, clamp); + }; + + return rescale(); +} + +function d3_scale_linearRebind(scale, linear) { + return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp"); +} + +function d3_scale_linearNice(domain, m) { + d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2])); + d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2])); + return domain; +} + +function d3_scale_linearTickRange(domain, m) { + if (m == null) m = 10; + + var extent = d3_scaleExtent(domain), + span = extent[1] - extent[0], + step = Math.pow(10, Math.floor(Math.log(span / m) / Math.LN10)), + err = m / span * step; + + // Filter ticks to get closer to the desired count. + if (err <= 0.15) step *= 10; + else if (err <= 0.35) step *= 5; + else if (err <= 0.75) step *= 2; + + // Round start and stop values to step interval. + extent[0] = Math.ceil(extent[0] / step) * step; + extent[1] = Math.floor(extent[1] / step) * step + step * 0.5; // inclusive + extent[2] = step; + return extent; +} + +function d3_scale_linearTicks(domain, m) { + return d3.range.apply(d3, d3_scale_linearTickRange(domain, m)); +} + +var d3_scale_linearFormatSignificant = {s: 1, g: 1, p: 1, r: 1, e: 1}; + +// Returns the number of significant digits after the decimal point. +function d3_scale_linearPrecision(value) { + return -Math.floor(Math.log(value) / Math.LN10 + 0.01); +} + +// For some format types, the precision specifies the number of significant +// digits; for others, it specifies the number of digits after the decimal +// point. For significant format types, the desired precision equals one plus +// the difference between the decimal precision of the range’s maximum absolute +// value and the tick step’s decimal precision. For format "e", the digit before +// the decimal point counts as one. +function d3_scale_linearFormatPrecision(type, range) { + var p = d3_scale_linearPrecision(range[2]); + return type in d3_scale_linearFormatSignificant + ? Math.abs(p - d3_scale_linearPrecision(Math.max(abs(range[0]), abs(range[1])))) + +(type !== "e") + : p - (type === "%") * 2; +} diff --git a/node_modules/@plotly/d3/src/scale/log.js b/node_modules/@plotly/d3/src/scale/log.js new file mode 100644 index 0000000000000000000000000000000000000000..9ba4289dcdea501b50424063f185bd53ef008c6b --- /dev/null +++ b/node_modules/@plotly/d3/src/scale/log.js @@ -0,0 +1,78 @@ +import "linear"; +import "nice"; +import "scale"; + +d3.scale.log = function() { + return d3_scale_log(d3.scale.linear().domain([0, 1]), 10, true, [1, 10]); +}; + +function d3_scale_log(linear, base, positive, domain) { + + function log(x) { + return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base); + } + + function pow(x) { + return positive ? Math.pow(base, x) : -Math.pow(base, -x); + } + + function scale(x) { + return linear(log(x)); + } + + scale.invert = function(x) { + return pow(linear.invert(x)); + }; + + scale.domain = function(x) { + if (!arguments.length) return domain; + positive = x[0] >= 0; + linear.domain((domain = x.map(Number)).map(log)); + return scale; + }; + + scale.base = function(_) { + if (!arguments.length) return base; + base = +_; + linear.domain(domain.map(log)); + return scale; + }; + + scale.nice = function() { + var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative); + linear.domain(niced); // do not modify the linear scale’s domain in-place! + domain = niced.map(pow); + return scale; + }; + + scale.ticks = function() { + var extent = d3_scaleExtent(domain), + ticks = [], + u = extent[0], + v = extent[1], + i = Math.floor(log(u)), + j = Math.ceil(log(v)), + n = base % 1 ? 2 : base; + if (isFinite(j - i)) { + if (positive) { + for (; i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k); + ticks.push(pow(i)); + } else { + ticks.push(pow(i)); + for (; i++ < j;) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k); + } + for (i = 0; ticks[i] < u; i++) {} // strip small values + for (j = ticks.length; ticks[j - 1] > v; j--) {} // strip big values + ticks = ticks.slice(i, j); + } + return ticks; + }; + + scale.copy = function() { + return d3_scale_log(linear.copy(), base, positive, domain); + }; + + return d3_scale_linearRebind(scale, linear); +} + +var d3_scale_logNiceNegative = {floor: function(x) { return -Math.ceil(-x); }, ceil: function(x) { return -Math.floor(-x); }}; diff --git a/node_modules/@plotly/d3/src/scale/nice.js b/node_modules/@plotly/d3/src/scale/nice.js new file mode 100644 index 0000000000000000000000000000000000000000..7d534e9754f127283ada24fcfb3ea46c5b8b5e1e --- /dev/null +++ b/node_modules/@plotly/d3/src/scale/nice.js @@ -0,0 +1,30 @@ +import "../core/identity"; + +function d3_scale_nice(domain, nice) { + var i0 = 0, + i1 = domain.length - 1, + x0 = domain[i0], + x1 = domain[i1], + dx; + + if (x1 < x0) { + dx = i0, i0 = i1, i1 = dx; + dx = x0, x0 = x1, x1 = dx; + } + + domain[i0] = nice.floor(x0); + domain[i1] = nice.ceil(x1); + return domain; +} + +function d3_scale_niceStep(step) { + return step ? { + floor: function(x) { return Math.floor(x / step) * step; }, + ceil: function(x) { return Math.ceil(x / step) * step; } + } : d3_scale_niceIdentity; +} + +var d3_scale_niceIdentity = { + floor: d3_identity, + ceil: d3_identity +}; diff --git a/node_modules/@plotly/d3/src/scale/ordinal.js b/node_modules/@plotly/d3/src/scale/ordinal.js new file mode 100644 index 0000000000000000000000000000000000000000..f065d541920c507702407b071baf9271e15cedbe --- /dev/null +++ b/node_modules/@plotly/d3/src/scale/ordinal.js @@ -0,0 +1,102 @@ +import "../arrays/map"; +import "../arrays/range"; +import "scale"; + +d3.scale.ordinal = function() { + return d3_scale_ordinal([], {t: "range", a: [[]]}); +}; + +function d3_scale_ordinal(domain, ranger) { + var index, + range, + rangeBand; + + function scale(x) { + return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length]; + } + + function steps(start, step) { + return d3.range(domain.length).map(function(i) { return start + step * i; }); + } + + scale.domain = function(x) { + if (!arguments.length) return domain; + domain = []; + index = new d3_Map; + var i = -1, n = x.length, xi; + while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi)); + return scale[ranger.t].apply(scale, ranger.a); + }; + + scale.range = function(x) { + if (!arguments.length) return range; + range = x; + rangeBand = 0; + ranger = {t: "range", a: arguments}; + return scale; + }; + + scale.rangePoints = function(x, padding) { + if (arguments.length < 2) padding = 0; + var start = x[0], + stop = x[1], + step = domain.length < 2 ? (start = (start + stop) / 2, 0) : (stop - start) / (domain.length - 1 + padding); + range = steps(start + step * padding / 2, step); + rangeBand = 0; + ranger = {t: "rangePoints", a: arguments}; + return scale; + }; + + scale.rangeRoundPoints = function(x, padding) { + if (arguments.length < 2) padding = 0; + var start = x[0], + stop = x[1], + step = domain.length < 2 ? (start = stop = Math.round((start + stop) / 2), 0) : (stop - start) / (domain.length - 1 + padding) | 0; // bitwise floor for symmetry + range = steps(start + Math.round(step * padding / 2 + (stop - start - (domain.length - 1 + padding) * step) / 2), step); + rangeBand = 0; + ranger = {t: "rangeRoundPoints", a: arguments}; + return scale; + }; + + scale.rangeBands = function(x, padding, outerPadding) { + if (arguments.length < 2) padding = 0; + if (arguments.length < 3) outerPadding = padding; + var reverse = x[1] < x[0], + start = x[reverse - 0], + stop = x[1 - reverse], + step = (stop - start) / (domain.length - padding + 2 * outerPadding); + range = steps(start + step * outerPadding, step); + if (reverse) range.reverse(); + rangeBand = step * (1 - padding); + ranger = {t: "rangeBands", a: arguments}; + return scale; + }; + + scale.rangeRoundBands = function(x, padding, outerPadding) { + if (arguments.length < 2) padding = 0; + if (arguments.length < 3) outerPadding = padding; + var reverse = x[1] < x[0], + start = x[reverse - 0], + stop = x[1 - reverse], + step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding)); + range = steps(start + Math.round((stop - start - (domain.length - padding) * step) / 2), step); + if (reverse) range.reverse(); + rangeBand = Math.round(step * (1 - padding)); + ranger = {t: "rangeRoundBands", a: arguments}; + return scale; + }; + + scale.rangeBand = function() { + return rangeBand; + }; + + scale.rangeExtent = function() { + return d3_scaleExtent(ranger.a[0]); + }; + + scale.copy = function() { + return d3_scale_ordinal(domain, ranger); + }; + + return scale.domain(domain); +} diff --git a/node_modules/@plotly/d3/src/scale/polylinear.js b/node_modules/@plotly/d3/src/scale/polylinear.js new file mode 100644 index 0000000000000000000000000000000000000000..3d729d785dd57ff2f6229a8cc90d694d68f53357 --- /dev/null +++ b/node_modules/@plotly/d3/src/scale/polylinear.js @@ -0,0 +1,24 @@ +import "../arrays/bisect"; + +function d3_scale_polylinear(domain, range, uninterpolate, interpolate) { + var u = [], + i = [], + j = 0, + k = Math.min(domain.length, range.length) - 1; + + // Handle descending domains. + if (domain[k] < domain[0]) { + domain = domain.slice().reverse(); + range = range.slice().reverse(); + } + + while (++j <= k) { + u.push(uninterpolate(domain[j - 1], domain[j])); + i.push(interpolate(range[j - 1], range[j])); + } + + return function(x) { + var j = d3.bisect(domain, x, 1, k) - 1; + return i[j](u[j](x)); + }; +} diff --git a/node_modules/@plotly/d3/src/scale/pow.js b/node_modules/@plotly/d3/src/scale/pow.js new file mode 100644 index 0000000000000000000000000000000000000000..9554fb8f5d272b3d8355b9ec49db109cbba3b1dd --- /dev/null +++ b/node_modules/@plotly/d3/src/scale/pow.js @@ -0,0 +1,57 @@ +import "linear"; +import "scale"; + +d3.scale.pow = function() { + return d3_scale_pow(d3.scale.linear(), 1, [0, 1]); +}; + +function d3_scale_pow(linear, exponent, domain) { + var powp = d3_scale_powPow(exponent), + powb = d3_scale_powPow(1 / exponent); + + function scale(x) { + return linear(powp(x)); + } + + scale.invert = function(x) { + return powb(linear.invert(x)); + }; + + scale.domain = function(x) { + if (!arguments.length) return domain; + linear.domain((domain = x.map(Number)).map(powp)); + return scale; + }; + + scale.ticks = function(m) { + return d3_scale_linearTicks(domain, m); + }; + + scale.tickFormat = function(m, format) { + return d3_scale_linearTickFormat(domain, m, format); + }; + + scale.nice = function(m) { + return scale.domain(d3_scale_linearNice(domain, m)); + }; + + scale.exponent = function(x) { + if (!arguments.length) return exponent; + powp = d3_scale_powPow(exponent = x); + powb = d3_scale_powPow(1 / exponent); + linear.domain(domain.map(powp)); + return scale; + }; + + scale.copy = function() { + return d3_scale_pow(linear.copy(), exponent, domain); + }; + + return d3_scale_linearRebind(scale, linear); +} + +function d3_scale_powPow(e) { + return function(x) { + return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e); + }; +} diff --git a/node_modules/@plotly/d3/src/scale/quantile.js b/node_modules/@plotly/d3/src/scale/quantile.js new file mode 100644 index 0000000000000000000000000000000000000000..b092de28d0becdcf5acc3e730d74e66ccd1b7a6e --- /dev/null +++ b/node_modules/@plotly/d3/src/scale/quantile.js @@ -0,0 +1,55 @@ +import "../arrays/ascending"; +import "../arrays/bisect"; +import "../arrays/quantile"; +import "../math/number"; +import "scale"; + +d3.scale.quantile = function() { + return d3_scale_quantile([], []); +}; + +function d3_scale_quantile(domain, range) { + var thresholds; + + function rescale() { + var k = 0, + q = range.length; + thresholds = []; + while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q); + return scale; + } + + function scale(x) { + if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)]; + } + + scale.domain = function(x) { + if (!arguments.length) return domain; + domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending); + return rescale(); + }; + + scale.range = function(x) { + if (!arguments.length) return range; + range = x; + return rescale(); + }; + + scale.quantiles = function() { + return thresholds; + }; + + scale.invertExtent = function(y) { + y = range.indexOf(y); + return y < 0 ? [NaN, NaN] : [ + y > 0 ? thresholds[y - 1] : domain[0], + y < thresholds.length ? thresholds[y] : domain[domain.length - 1] + ]; + }; + + scale.copy = function() { + return d3_scale_quantile(domain, range); // copy on write! + }; + + return rescale(); +} diff --git a/node_modules/@plotly/d3/src/scale/quantize.js b/node_modules/@plotly/d3/src/scale/quantize.js new file mode 100644 index 0000000000000000000000000000000000000000..f3b656d93ee9895d0e31608b4d22440ffca6bce6 --- /dev/null +++ b/node_modules/@plotly/d3/src/scale/quantize.js @@ -0,0 +1,44 @@ +import "scale"; + +d3.scale.quantize = function() { + return d3_scale_quantize(0, 1, [0, 1]); +}; + +function d3_scale_quantize(x0, x1, range) { + var kx, i; + + function scale(x) { + return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))]; + } + + function rescale() { + kx = range.length / (x1 - x0); + i = range.length - 1; + return scale; + } + + scale.domain = function(x) { + if (!arguments.length) return [x0, x1]; + x0 = +x[0]; + x1 = +x[x.length - 1]; + return rescale(); + }; + + scale.range = function(x) { + if (!arguments.length) return range; + range = x; + return rescale(); + }; + + scale.invertExtent = function(y) { + y = range.indexOf(y); + y = y < 0 ? NaN : y / kx + x0; + return [y, y + 1 / kx]; + }; + + scale.copy = function() { + return d3_scale_quantize(x0, x1, range); // copy on write + }; + + return rescale(); +} diff --git a/node_modules/@plotly/d3/src/scale/scale.js b/node_modules/@plotly/d3/src/scale/scale.js new file mode 100644 index 0000000000000000000000000000000000000000..b7952d4402a137dd37bcf9d275056dd495ab3e16 --- /dev/null +++ b/node_modules/@plotly/d3/src/scale/scale.js @@ -0,0 +1,10 @@ +d3.scale = {}; + +function d3_scaleExtent(domain) { + var start = domain[0], stop = domain[domain.length - 1]; + return start < stop ? [start, stop] : [stop, start]; +} + +function d3_scaleRange(scale) { + return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range()); +} diff --git a/node_modules/@plotly/d3/src/scale/sqrt.js b/node_modules/@plotly/d3/src/scale/sqrt.js new file mode 100644 index 0000000000000000000000000000000000000000..f73f1752be29919db165b6da9276d81191f6d8a9 --- /dev/null +++ b/node_modules/@plotly/d3/src/scale/sqrt.js @@ -0,0 +1,6 @@ +import "pow"; +import "scale"; + +d3.scale.sqrt = function() { + return d3.scale.pow().exponent(0.5); +}; diff --git a/node_modules/@plotly/d3/src/scale/threshold.js b/node_modules/@plotly/d3/src/scale/threshold.js new file mode 100644 index 0000000000000000000000000000000000000000..470463eaccf03a3f2d309c6e5e4c185486961f77 --- /dev/null +++ b/node_modules/@plotly/d3/src/scale/threshold.js @@ -0,0 +1,36 @@ +import "../arrays/bisect"; +import "scale"; + +d3.scale.threshold = function() { + return d3_scale_threshold([0.5], [0, 1]); +}; + +function d3_scale_threshold(domain, range) { + + function scale(x) { + if (x <= x) return range[d3.bisect(domain, x)]; + } + + scale.domain = function(_) { + if (!arguments.length) return domain; + domain = _; + return scale; + }; + + scale.range = function(_) { + if (!arguments.length) return range; + range = _; + return scale; + }; + + scale.invertExtent = function(y) { + y = range.indexOf(y); + return [domain[y - 1], domain[y]]; + }; + + scale.copy = function() { + return d3_scale_threshold(domain, range); + }; + + return scale; +}; diff --git a/node_modules/@plotly/d3/src/selection/append.js b/node_modules/@plotly/d3/src/selection/append.js new file mode 100644 index 0000000000000000000000000000000000000000..92ca7f877161c07fd03f87a68e50fa5ce6c5eccb --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/append.js @@ -0,0 +1,28 @@ +import "../core/ns"; +import "selection"; + +d3_selectionPrototype.append = function(name) { + name = d3_selection_creator(name); + return this.select(function() { + return this.appendChild(name.apply(this, arguments)); + }); +}; + +function d3_selection_creator(name) { + + function create() { + var document = this.ownerDocument, + namespace = this.namespaceURI; + return namespace === d3_nsXhtml && document.documentElement.namespaceURI === d3_nsXhtml + ? document.createElement(name) + : document.createElementNS(namespace, name); + } + + function createNS() { + return this.ownerDocument.createElementNS(name.space, name.local); + } + + return typeof name === "function" ? name + : (name = d3.ns.qualify(name)).local ? createNS + : create; +} diff --git a/node_modules/@plotly/d3/src/selection/attr.js b/node_modules/@plotly/d3/src/selection/attr.js new file mode 100644 index 0000000000000000000000000000000000000000..723199a4c89788e7a4b786ecb4dea87714a5f006 --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/attr.js @@ -0,0 +1,62 @@ +import "../core/ns"; +import "selection"; + +d3_selectionPrototype.attr = function(name, value) { + if (arguments.length < 2) { + + // For attr(string), return the attribute value for the first node. + if (typeof name === "string") { + var node = this.node(); + name = d3.ns.qualify(name); + return name.local + ? node.getAttributeNS(name.space, name.local) + : node.getAttribute(name); + } + + // For attr(object), the object specifies the names and values of the + // attributes to set or remove. The values may be functions that are + // evaluated for each element. + for (value in name) this.each(d3_selection_attr(value, name[value])); + return this; + } + + return this.each(d3_selection_attr(name, value)); +}; + +function d3_selection_attr(name, value) { + name = d3.ns.qualify(name); + + // For attr(string, null), remove the attribute with the specified name. + function attrNull() { + this.removeAttribute(name); + } + function attrNullNS() { + this.removeAttributeNS(name.space, name.local); + } + + // For attr(string, string), set the attribute with the specified name. + function attrConstant() { + this.setAttribute(name, value); + } + function attrConstantNS() { + this.setAttributeNS(name.space, name.local, value); + } + + // For attr(string, function), evaluate the function for each element, and set + // or remove the attribute as appropriate. + function attrFunction() { + var x = value.apply(this, arguments); + if (x == null) this.removeAttribute(name); + else this.setAttribute(name, x); + } + function attrFunctionNS() { + var x = value.apply(this, arguments); + if (x == null) this.removeAttributeNS(name.space, name.local); + else this.setAttributeNS(name.space, name.local, x); + } + + return value == null + ? (name.local ? attrNullNS : attrNull) : (typeof value === "function" + ? (name.local ? attrFunctionNS : attrFunction) + : (name.local ? attrConstantNS : attrConstant)); +} diff --git a/node_modules/@plotly/d3/src/selection/call.js b/node_modules/@plotly/d3/src/selection/call.js new file mode 100644 index 0000000000000000000000000000000000000000..3dfc3865bec3b45e42f1b1c41cb10922000afa46 --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/call.js @@ -0,0 +1,8 @@ +import "../core/array"; +import "selection"; + +d3_selectionPrototype.call = function(callback) { + var args = d3_array(arguments); + callback.apply(args[0] = this, args); + return this; +}; diff --git a/node_modules/@plotly/d3/src/selection/classed.js b/node_modules/@plotly/d3/src/selection/classed.js new file mode 100644 index 0000000000000000000000000000000000000000..b477ed684cb195bc471585f0617e2da09005bc7e --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/classed.js @@ -0,0 +1,76 @@ +import "../format/collapse"; +import "../format/requote"; +import "selection"; + +d3_selectionPrototype.classed = function(name, value) { + if (arguments.length < 2) { + + // For classed(string), return true only if the first node has the specified + // class or classes. Note that even if the browser supports DOMTokenList, it + // probably doesn't support it on SVG elements (which can be animated). + if (typeof name === "string") { + var node = this.node(), + n = (name = d3_selection_classes(name)).length, + i = -1; + if (value = node.classList) { + while (++i < n) if (!value.contains(name[i])) return false; + } else { + value = node.getAttribute("class"); + while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false; + } + return true; + } + + // For classed(object), the object specifies the names of classes to add or + // remove. The values may be functions that are evaluated for each element. + for (value in name) this.each(d3_selection_classed(value, name[value])); + return this; + } + + // Otherwise, both a name and a value are specified, and are handled as below. + return this.each(d3_selection_classed(name, value)); +}; + +function d3_selection_classedRe(name) { + return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g"); +} + +function d3_selection_classes(name) { + return (name + "").trim().split(/^|\s+/); +} + +// Multiple class names are allowed (e.g., "foo bar"). +function d3_selection_classed(name, value) { + name = d3_selection_classes(name).map(d3_selection_classedName); + var n = name.length; + + function classedConstant() { + var i = -1; + while (++i < n) name[i](this, value); + } + + // When the value is a function, the function is still evaluated only once per + // element even if there are multiple class names. + function classedFunction() { + var i = -1, x = value.apply(this, arguments); + while (++i < n) name[i](this, x); + } + + return typeof value === "function" + ? classedFunction + : classedConstant; +} + +function d3_selection_classedName(name) { + var re = d3_selection_classedRe(name); + return function(node, value) { + if (c = node.classList) return value ? c.add(name) : c.remove(name); + var c = node.getAttribute("class") || ""; + if (value) { + re.lastIndex = 0; + if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name)); + } else { + node.setAttribute("class", d3_collapse(c.replace(re, " "))); + } + }; +} diff --git a/node_modules/@plotly/d3/src/selection/data.js b/node_modules/@plotly/d3/src/selection/data.js new file mode 100644 index 0000000000000000000000000000000000000000..f31c867d23c2f1bebd93c9b3d68dd53815352d2e --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/data.js @@ -0,0 +1,117 @@ +import "../arrays/map"; +import "../arrays/set"; +import "selection"; + +d3_selectionPrototype.data = function(value, key) { + var i = -1, + n = this.length, + group, + node; + + // If no value is specified, return the first value. + if (!arguments.length) { + value = new Array(n = (group = this[0]).length); + while (++i < n) { + if (node = group[i]) { + value[i] = node.__data__; + } + } + return value; + } + + function bind(group, groupData) { + var i, + n = group.length, + m = groupData.length, + n0 = Math.min(n, m), + updateNodes = new Array(m), + enterNodes = new Array(m), + exitNodes = new Array(n), + node, + nodeData; + + if (key) { + var nodeByKeyValue = new d3_Map, + keyValues = new Array(n), + keyValue; + + for (i = -1; ++i < n;) { + if (node = group[i]) { + if (nodeByKeyValue.has(keyValue = key.call(node, node.__data__, i))) { + exitNodes[i] = node; // duplicate selection key + } else { + nodeByKeyValue.set(keyValue, node); + } + keyValues[i] = keyValue; + } + } + + for (i = -1; ++i < m;) { + if (!(node = nodeByKeyValue.get(keyValue = key.call(groupData, nodeData = groupData[i], i)))) { + enterNodes[i] = d3_selection_dataNode(nodeData); + } else if (node !== true) { // no duplicate data key + updateNodes[i] = node; + node.__data__ = nodeData; + } + nodeByKeyValue.set(keyValue, true); + } + + for (i = -1; ++i < n;) { + if (i in keyValues && nodeByKeyValue.get(keyValues[i]) !== true) { + exitNodes[i] = group[i]; + } + } + } else { + for (i = -1; ++i < n0;) { + node = group[i]; + nodeData = groupData[i]; + if (node) { + node.__data__ = nodeData; + updateNodes[i] = node; + } else { + enterNodes[i] = d3_selection_dataNode(nodeData); + } + } + for (; i < m; ++i) { + enterNodes[i] = d3_selection_dataNode(groupData[i]); + } + for (; i < n; ++i) { + exitNodes[i] = group[i]; + } + } + + enterNodes.update + = updateNodes; + + enterNodes.parentNode + = updateNodes.parentNode + = exitNodes.parentNode + = group.parentNode; + + enter.push(enterNodes); + update.push(updateNodes); + exit.push(exitNodes); + } + + var enter = d3_selection_enter([]), + update = d3_selection([]), + exit = d3_selection([]); + + if (typeof value === "function") { + while (++i < n) { + bind(group = this[i], value.call(group, group.parentNode.__data__, i)); + } + } else { + while (++i < n) { + bind(group = this[i], value); + } + } + + update.enter = function() { return enter; }; + update.exit = function() { return exit; }; + return update; +}; + +function d3_selection_dataNode(data) { + return {__data__: data}; +} diff --git a/node_modules/@plotly/d3/src/selection/datum.js b/node_modules/@plotly/d3/src/selection/datum.js new file mode 100644 index 0000000000000000000000000000000000000000..5434de48c8b93dce61a96dcab07412016eda7a1a --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/datum.js @@ -0,0 +1,7 @@ +import "selection"; + +d3_selectionPrototype.datum = function(value) { + return arguments.length + ? this.property("__data__", value) + : this.property("__data__"); +}; diff --git a/node_modules/@plotly/d3/src/selection/each.js b/node_modules/@plotly/d3/src/selection/each.js new file mode 100644 index 0000000000000000000000000000000000000000..45b8603c6b91f1f35a369591bab99558f3078b70 --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/each.js @@ -0,0 +1,16 @@ +import "selection"; + +d3_selectionPrototype.each = function(callback) { + return d3_selection_each(this, function(node, i, j) { + callback.call(node, node.__data__, i, j); + }); +}; + +function d3_selection_each(groups, callback) { + for (var j = 0, m = groups.length; j < m; j++) { + for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) { + if (node = group[i]) callback(node, i, j); + } + } + return groups; +} diff --git a/node_modules/@plotly/d3/src/selection/empty.js b/node_modules/@plotly/d3/src/selection/empty.js new file mode 100644 index 0000000000000000000000000000000000000000..6135c23fb1dbde732e7a72e9828580cfd1632b29 --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/empty.js @@ -0,0 +1,5 @@ +import "selection"; + +d3_selectionPrototype.empty = function() { + return !this.node(); +}; diff --git a/node_modules/@plotly/d3/src/selection/enter-insert.js b/node_modules/@plotly/d3/src/selection/enter-insert.js new file mode 100644 index 0000000000000000000000000000000000000000..f7d6c15026edaf463559ce6ae40bf5e8bb8aee52 --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/enter-insert.js @@ -0,0 +1,20 @@ +import "selection"; +import "enter"; + +d3_selection_enterPrototype.insert = function(name, before) { + if (arguments.length < 2) before = d3_selection_enterInsertBefore(this); + return d3_selectionPrototype.insert.call(this, name, before); +}; + +function d3_selection_enterInsertBefore(enter) { + var i0, j0; + return function(d, i, j) { + var group = enter[j].update, + n = group.length, + node; + if (j != j0) j0 = j, i0 = 0; + if (i >= i0) i0 = i + 1; + while (!(node = group[i0]) && ++i0 < n); + return node; + }; +} diff --git a/node_modules/@plotly/d3/src/selection/enter-select.js b/node_modules/@plotly/d3/src/selection/enter-select.js new file mode 100644 index 0000000000000000000000000000000000000000..2764c6ceef3d5bccbafd8b7ebdeb9bd5369d5232 --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/enter-select.js @@ -0,0 +1,27 @@ +import "selection"; +import "enter"; + +d3_selection_enterPrototype.select = function(selector) { + var subgroups = [], + subgroup, + subnode, + upgroup, + group, + node; + + for (var j = -1, m = this.length; ++j < m;) { + upgroup = (group = this[j]).update; + subgroups.push(subgroup = []); + subgroup.parentNode = group.parentNode; + for (var i = -1, n = group.length; ++i < n;) { + if (node = group[i]) { + subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j)); + subnode.__data__ = node.__data__; + } else { + subgroup.push(null); + } + } + } + + return d3_selection(subgroups); +}; diff --git a/node_modules/@plotly/d3/src/selection/enter.js b/node_modules/@plotly/d3/src/selection/enter.js new file mode 100644 index 0000000000000000000000000000000000000000..2533582efdfcde28d85920c33d76426e4cbae2f3 --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/enter.js @@ -0,0 +1,21 @@ +import "../core/subclass"; +import "selection"; + +function d3_selection_enter(selection) { + d3_subclass(selection, d3_selection_enterPrototype); + return selection; +} + +var d3_selection_enterPrototype = []; + +d3.selection.enter = d3_selection_enter; +d3.selection.enter.prototype = d3_selection_enterPrototype; + +d3_selection_enterPrototype.append = d3_selectionPrototype.append; +d3_selection_enterPrototype.empty = d3_selectionPrototype.empty; +d3_selection_enterPrototype.node = d3_selectionPrototype.node; +d3_selection_enterPrototype.call = d3_selectionPrototype.call; +d3_selection_enterPrototype.size = d3_selectionPrototype.size; + +import "enter-select"; +import "enter-insert"; diff --git a/node_modules/@plotly/d3/src/selection/filter.js b/node_modules/@plotly/d3/src/selection/filter.js new file mode 100644 index 0000000000000000000000000000000000000000..38728564b655c00be1ed132603084366522d51b9 --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/filter.js @@ -0,0 +1,28 @@ +import "selection"; + +d3_selectionPrototype.filter = function(filter) { + var subgroups = [], + subgroup, + group, + node; + + if (typeof filter !== "function") filter = d3_selection_filter(filter); + + for (var j = 0, m = this.length; j < m; j++) { + subgroups.push(subgroup = []); + subgroup.parentNode = (group = this[j]).parentNode; + for (var i = 0, n = group.length; i < n; i++) { + if ((node = group[i]) && filter.call(node, node.__data__, i, j)) { + subgroup.push(node); + } + } + } + + return d3_selection(subgroups); +}; + +function d3_selection_filter(selector) { + return function() { + return d3_selectMatches(this, selector); + }; +} diff --git a/node_modules/@plotly/d3/src/selection/html.js b/node_modules/@plotly/d3/src/selection/html.js new file mode 100644 index 0000000000000000000000000000000000000000..19f475d7abe08e835f2bed0eb4c47349d7c475b7 --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/html.js @@ -0,0 +1,10 @@ +import "selection"; + +d3_selectionPrototype.html = function(value) { + return arguments.length + ? this.each(typeof value === "function" + ? function() { var v = value.apply(this, arguments); this.innerHTML = v == null ? "" : v; } : value == null + ? function() { this.innerHTML = ""; } + : function() { this.innerHTML = value; }) + : this.node().innerHTML; +}; diff --git a/node_modules/@plotly/d3/src/selection/index.js b/node_modules/@plotly/d3/src/selection/index.js new file mode 100644 index 0000000000000000000000000000000000000000..3350277372863d59a1f305f78ece39be9492b2c4 --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/index.js @@ -0,0 +1 @@ +import "selection"; diff --git a/node_modules/@plotly/d3/src/selection/insert.js b/node_modules/@plotly/d3/src/selection/insert.js new file mode 100644 index 0000000000000000000000000000000000000000..909dfd97068756e6d267b00c6779f8aab67c840f --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/insert.js @@ -0,0 +1,9 @@ +import "selection"; + +d3_selectionPrototype.insert = function(name, before) { + name = d3_selection_creator(name); + before = d3_selection_selector(before); + return this.select(function() { + return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null); + }); +}; diff --git a/node_modules/@plotly/d3/src/selection/interrupt.js b/node_modules/@plotly/d3/src/selection/interrupt.js new file mode 100644 index 0000000000000000000000000000000000000000..2acf39b9b5692dde2335ba793decebc521b6ee9d --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/interrupt.js @@ -0,0 +1,27 @@ +// import "../transition/transition"; +import "selection"; + +// TODO Interrupt transitions for all namespaces? +d3_selectionPrototype.interrupt = function(name) { + return this.each(name == null + ? d3_selection_interrupt + : d3_selection_interruptNS(d3_transitionNamespace(name))); +}; + +var d3_selection_interrupt = d3_selection_interruptNS(d3_transitionNamespace()); + +function d3_selection_interruptNS(ns) { + return function() { + var lock, + activeId, + active; + if ((lock = this[ns]) && (active = lock[activeId = lock.active])) { + active.timer.c = null; + active.timer.t = NaN; + if (--lock.count) delete lock[activeId]; + else delete this[ns]; + lock.active += 0.5; + active.event && active.event.interrupt.call(this, this.__data__, active.index); + } + }; +} diff --git a/node_modules/@plotly/d3/src/selection/node.js b/node_modules/@plotly/d3/src/selection/node.js new file mode 100644 index 0000000000000000000000000000000000000000..9c9be4d82accbfbb1de7b2d3684e6181b383f31a --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/node.js @@ -0,0 +1,11 @@ +import "selection"; + +d3_selectionPrototype.node = function() { + for (var j = 0, m = this.length; j < m; j++) { + for (var group = this[j], i = 0, n = group.length; i < n; i++) { + var node = group[i]; + if (node) return node; + } + } + return null; +}; diff --git a/node_modules/@plotly/d3/src/selection/on.js b/node_modules/@plotly/d3/src/selection/on.js new file mode 100644 index 0000000000000000000000000000000000000000..9f049876dd16de409a6504adcfc9693817aa6778 --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/on.js @@ -0,0 +1,106 @@ +import "../arrays/map"; +import "../core/array"; +import "../core/document"; +import "../core/noop"; +import "../event/event"; +import "../format/requote"; +import "selection"; + +d3_selectionPrototype.on = function(type, listener, capture) { + var n = arguments.length; + if (n < 3) { + + // For on(object) or on(object, boolean), the object specifies the event + // types and listeners to add or remove. The optional boolean specifies + // whether the listener captures events. + if (typeof type !== "string") { + if (n < 2) listener = false; + for (capture in type) this.each(d3_selection_on(capture, type[capture], listener)); + return this; + } + + // For on(string), return the listener for the first node. + if (n < 2) return (n = this.node()["__on" + type]) && n._; + + // For on(string, function), use the default capture. + capture = false; + } + + // Otherwise, a type, listener and capture are specified, and handled as below. + return this.each(d3_selection_on(type, listener, capture)); +}; + +function d3_selection_on(type, listener, capture) { + var name = "__on" + type, + i = type.indexOf("."), + wrap = d3_selection_onListener; + + if (i > 0) type = type.slice(0, i); + var filter = d3_selection_onFilters.get(type); + if (filter) type = filter, wrap = d3_selection_onFilter; + + function onRemove() { + var l = this[name]; + if (l) { + this.removeEventListener(type, l, l.$); + delete this[name]; + } + } + + function onAdd() { + var l = wrap(listener, d3_array(arguments)); + onRemove.call(this); + this.addEventListener(type, this[name] = l, l.$ = capture); + l._ = listener; + } + + function removeAll() { + var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), + match; + for (var name in this) { + if (match = name.match(re)) { + var l = this[name]; + this.removeEventListener(match[1], l, l.$); + delete this[name]; + } + } + } + + return i + ? listener ? onAdd : onRemove + : listener ? d3_noop : removeAll; +} + +var d3_selection_onFilters = d3.map({ + mouseenter: "mouseover", + mouseleave: "mouseout" +}); + +if (d3_document) { + d3_selection_onFilters.forEach(function(k) { + if ("on" + k in d3_document) d3_selection_onFilters.remove(k); + }); +} + +function d3_selection_onListener(listener, argumentz) { + return function(e) { + var o = d3.event; // Events can be reentrant (e.g., focus). + d3.event = e; + argumentz[0] = this.__data__; + try { + listener.apply(this, argumentz); + } finally { + d3.event = o; + } + }; +} + +function d3_selection_onFilter(listener, argumentz) { + var l = d3_selection_onListener(listener, argumentz); + return function(e) { + var target = this, related = e.relatedTarget; + if (!related || (related !== target && !(related.compareDocumentPosition(target) & 8))) { + l.call(target, e); + } + }; +} diff --git a/node_modules/@plotly/d3/src/selection/order.js b/node_modules/@plotly/d3/src/selection/order.js new file mode 100644 index 0000000000000000000000000000000000000000..dc537ac7dde5f2f77369d22ef0214853d64ca789 --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/order.js @@ -0,0 +1,13 @@ +import "selection"; + +d3_selectionPrototype.order = function() { + for (var j = -1, m = this.length; ++j < m;) { + for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0;) { + if (node = group[i]) { + if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next); + next = node; + } + } + } + return this; +}; diff --git a/node_modules/@plotly/d3/src/selection/property.js b/node_modules/@plotly/d3/src/selection/property.js new file mode 100644 index 0000000000000000000000000000000000000000..8afcb89ad2e07d72ce5039c698eb2483f0716a2c --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/property.js @@ -0,0 +1,43 @@ +import "selection"; + +d3_selectionPrototype.property = function(name, value) { + if (arguments.length < 2) { + + // For property(string), return the property value for the first node. + if (typeof name === "string") return this.node()[name]; + + // For property(object), the object specifies the names and values of the + // properties to set or remove. The values may be functions that are + // evaluated for each element. + for (value in name) this.each(d3_selection_property(value, name[value])); + return this; + } + + // Otherwise, both a name and a value are specified, and are handled as below. + return this.each(d3_selection_property(name, value)); +}; + +function d3_selection_property(name, value) { + + // For property(name, null), remove the property with the specified name. + function propertyNull() { + delete this[name]; + } + + // For property(name, string), set the property with the specified name. + function propertyConstant() { + this[name] = value; + } + + // For property(name, function), evaluate the function for each element, and + // set or remove the property as appropriate. + function propertyFunction() { + var x = value.apply(this, arguments); + if (x == null) delete this[name]; + else this[name] = x; + } + + return value == null + ? propertyNull : (typeof value === "function" + ? propertyFunction : propertyConstant); +} diff --git a/node_modules/@plotly/d3/src/selection/remove.js b/node_modules/@plotly/d3/src/selection/remove.js new file mode 100644 index 0000000000000000000000000000000000000000..80666d9998655cfb697a619a9082cb1b866d0526 --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/remove.js @@ -0,0 +1,13 @@ +import "selection"; + +// TODO remove(selector)? +// TODO remove(node)? +// TODO remove(function)? +d3_selectionPrototype.remove = function() { + return this.each(d3_selectionRemove); +}; + +function d3_selectionRemove() { + var parent = this.parentNode; + if (parent) parent.removeChild(this); +} diff --git a/node_modules/@plotly/d3/src/selection/select.js b/node_modules/@plotly/d3/src/selection/select.js new file mode 100644 index 0000000000000000000000000000000000000000..8c1dcdee99d0ab22568b526b0910d2fcd22d541e --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/select.js @@ -0,0 +1,32 @@ +import "selection"; + +d3_selectionPrototype.select = function(selector) { + var subgroups = [], + subgroup, + subnode, + group, + node; + + selector = d3_selection_selector(selector); + + for (var j = -1, m = this.length; ++j < m;) { + subgroups.push(subgroup = []); + subgroup.parentNode = (group = this[j]).parentNode; + for (var i = -1, n = group.length; ++i < n;) { + if (node = group[i]) { + subgroup.push(subnode = selector.call(node, node.__data__, i, j)); + if (subnode && "__data__" in node) subnode.__data__ = node.__data__; + } else { + subgroup.push(null); + } + } + } + + return d3_selection(subgroups); +}; + +function d3_selection_selector(selector) { + return typeof selector === "function" ? selector : function() { + return d3_select(selector, this); + }; +} diff --git a/node_modules/@plotly/d3/src/selection/selectAll.js b/node_modules/@plotly/d3/src/selection/selectAll.js new file mode 100644 index 0000000000000000000000000000000000000000..7072f8832496f0e5d6978da5f0824d31c4d2fbf5 --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/selectAll.js @@ -0,0 +1,27 @@ +import "../core/array"; +import "selection"; + +d3_selectionPrototype.selectAll = function(selector) { + var subgroups = [], + subgroup, + node; + + selector = d3_selection_selectorAll(selector); + + for (var j = -1, m = this.length; ++j < m;) { + for (var group = this[j], i = -1, n = group.length; ++i < n;) { + if (node = group[i]) { + subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j))); + subgroup.parentNode = node; + } + } + } + + return d3_selection(subgroups); +}; + +function d3_selection_selectorAll(selector) { + return typeof selector === "function" ? selector : function() { + return d3_selectAll(selector, this); + }; +} diff --git a/node_modules/@plotly/d3/src/selection/selection.js b/node_modules/@plotly/d3/src/selection/selection.js new file mode 100644 index 0000000000000000000000000000000000000000..c96dbda2e8f61ecd2d72585801860df3ccabc4ef --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/selection.js @@ -0,0 +1,81 @@ +import "../core/array"; +import "../core/document"; +import "../core/subclass"; +import "../core/vendor"; + +function d3_selection(groups) { + d3_subclass(groups, d3_selectionPrototype); + return groups; +} + +var d3_select = function(s, n) { return n.querySelector(s); }, + d3_selectAll = function(s, n) { return n.querySelectorAll(s); }, + d3_selectMatches = function(n, s) { + var d3_selectMatcher = n.matches || n[d3_vendorSymbol(n, "matchesSelector")]; + d3_selectMatches = function(n, s) { + return d3_selectMatcher.call(n, s); + }; + return d3_selectMatches(n, s); + }; + +// Prefer Sizzle, if available. +if (typeof Sizzle === "function") { + d3_select = function(s, n) { return Sizzle(s, n)[0] || null; }; + d3_selectAll = Sizzle; + d3_selectMatches = Sizzle.matchesSelector; +} + +d3.selection = function() { + return d3.select(d3_document.documentElement); +}; + +var d3_selectionPrototype = d3.selection.prototype = []; + +import "select"; +import "selectAll"; +import "attr"; +import "classed"; +import "style"; +import "property"; +import "text"; +import "html"; +import "append"; +import "insert"; +import "remove"; +import "data"; +import "datum"; +import "filter"; +import "order"; +import "sort"; +import "on"; +import "each"; +import "call"; +import "empty"; +import "node"; +import "size"; +import "enter"; + +// TODO fast singleton implementation? +d3.select = function(node) { + var group; + if (typeof node === "string") { + group = [d3_select(node, d3_document)]; + group.parentNode = d3_document.documentElement; + } else { + group = [node]; + group.parentNode = d3_documentElement(node); + } + return d3_selection([group]); +}; + +d3.selectAll = function(nodes) { + var group; + if (typeof nodes === "string") { + group = d3_array(d3_selectAll(nodes, d3_document)); + group.parentNode = d3_document.documentElement; + } else { + group = d3_array(nodes); + group.parentNode = null; + } + return d3_selection([group]); +}; diff --git a/node_modules/@plotly/d3/src/selection/size.js b/node_modules/@plotly/d3/src/selection/size.js new file mode 100644 index 0000000000000000000000000000000000000000..206ab4fc993c707daa4c2f19c3b834c8ecefa391 --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/size.js @@ -0,0 +1,7 @@ +import "each"; + +d3_selectionPrototype.size = function() { + var n = 0; + d3_selection_each(this, function() { ++n; }); + return n; +}; diff --git a/node_modules/@plotly/d3/src/selection/sort.js b/node_modules/@plotly/d3/src/selection/sort.js new file mode 100644 index 0000000000000000000000000000000000000000..1abacd08096acf3d48d524c149a9c3a2b4e815d4 --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/sort.js @@ -0,0 +1,15 @@ +import "../arrays/ascending"; +import "selection"; + +d3_selectionPrototype.sort = function(comparator) { + comparator = d3_selection_sortComparator.apply(this, arguments); + for (var j = -1, m = this.length; ++j < m;) this[j].sort(comparator); + return this.order(); +}; + +function d3_selection_sortComparator(comparator) { + if (!arguments.length) comparator = d3_ascending; + return function(a, b) { + return a && b ? comparator(a.__data__, b.__data__) : !a - !b; + }; +} diff --git a/node_modules/@plotly/d3/src/selection/style.js b/node_modules/@plotly/d3/src/selection/style.js new file mode 100644 index 0000000000000000000000000000000000000000..1501da0ff37d5bbc3ff54a1b8860f1c62eabe37b --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/style.js @@ -0,0 +1,59 @@ +import "../core/document"; +import "selection"; + +d3_selectionPrototype.style = function(name, value, priority) { + var n = arguments.length; + if (n < 3) { + + // For style(object) or style(object, string), the object specifies the + // names and values of the attributes to set or remove. The values may be + // functions that are evaluated for each element. The optional string + // specifies the priority. + if (typeof name !== "string") { + if (n < 2) value = ""; + for (priority in name) this.each(d3_selection_style(priority, name[priority], value)); + return this; + } + + // For style(string), return the computed style value for the first node. + if (n < 2) { + var node = this.node(); + return d3_window(node).getComputedStyle(node, null).getPropertyValue(name); + } + + // For style(string, string) or style(string, function), use the default + // priority. The priority is ignored for style(string, null). + priority = ""; + } + + // Otherwise, a name, value and priority are specified, and handled as below. + return this.each(d3_selection_style(name, value, priority)); +}; + +function d3_selection_style(name, value, priority) { + + // For style(name, null) or style(name, null, priority), remove the style + // property with the specified name. The priority is ignored. + function styleNull() { + this.style.removeProperty(name); + } + + // For style(name, string) or style(name, string, priority), set the style + // property with the specified name, using the specified priority. + function styleConstant() { + this.style.setProperty(name, value, priority); + } + + // For style(name, function) or style(name, function, priority), evaluate the + // function for each element, and set or remove the style property as + // appropriate. When setting, use the specified priority. + function styleFunction() { + var x = value.apply(this, arguments); + if (x == null) this.style.removeProperty(name); + else this.style.setProperty(name, x, priority); + } + + return value == null + ? styleNull : (typeof value === "function" + ? styleFunction : styleConstant); +} diff --git a/node_modules/@plotly/d3/src/selection/text.js b/node_modules/@plotly/d3/src/selection/text.js new file mode 100644 index 0000000000000000000000000000000000000000..3daf802b98fa921b3cac48645b2f8392b2f7e51a --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/text.js @@ -0,0 +1,10 @@ +import "selection"; + +d3_selectionPrototype.text = function(value) { + return arguments.length + ? this.each(typeof value === "function" + ? function() { var v = value.apply(this, arguments); this.textContent = v == null ? "" : v; } : value == null + ? function() { this.textContent = ""; } + : function() { this.textContent = value; }) + : this.node().textContent; +}; diff --git a/node_modules/@plotly/d3/src/selection/transition.js b/node_modules/@plotly/d3/src/selection/transition.js new file mode 100644 index 0000000000000000000000000000000000000000..09f3d986f386f28b74cd435f0a30974b836de7e6 --- /dev/null +++ b/node_modules/@plotly/d3/src/selection/transition.js @@ -0,0 +1,21 @@ +// import "../transition/transition"; +import "selection"; + +d3_selectionPrototype.transition = function(name) { + var id = d3_transitionInheritId || ++d3_transitionId, + ns = d3_transitionNamespace(name), + subgroups = [], + subgroup, + node, + transition = d3_transitionInherit || {time: Date.now(), ease: d3_ease_cubicInOut, delay: 0, duration: 250}; + + for (var j = -1, m = this.length; ++j < m;) { + subgroups.push(subgroup = []); + for (var group = this[j], i = -1, n = group.length; ++i < n;) { + if (node = group[i]) d3_transitionNode(node, i, ns, id, transition); + subgroup.push(node); + } + } + + return d3_transition(subgroups, ns, id); +}; diff --git a/node_modules/@plotly/d3/src/start.js b/node_modules/@plotly/d3/src/start.js new file mode 100644 index 0000000000000000000000000000000000000000..c81ae382d9b94b3dee7e878c96e8619ecd88040d --- /dev/null +++ b/node_modules/@plotly/d3/src/start.js @@ -0,0 +1,2 @@ +!function(){ + var d3 = {version: "3.8.0"}; // semver diff --git a/node_modules/@plotly/d3/src/svg/arc.js b/node_modules/@plotly/d3/src/svg/arc.js new file mode 100644 index 0000000000000000000000000000000000000000..680e2ac1de3972dfee3d61e087ee06e383a39c65 --- /dev/null +++ b/node_modules/@plotly/d3/src/svg/arc.js @@ -0,0 +1,292 @@ +import "../core/functor"; +import "../core/zero"; +import "../math/trigonometry"; +import "../geom/polygon"; +import "svg"; + +d3.svg.arc = function() { + var innerRadius = d3_svg_arcInnerRadius, + outerRadius = d3_svg_arcOuterRadius, + cornerRadius = d3_zero, + padRadius = d3_svg_arcAuto, + startAngle = d3_svg_arcStartAngle, + endAngle = d3_svg_arcEndAngle, + padAngle = d3_svg_arcPadAngle; + + function arc() { + var r0 = Math.max(0, +innerRadius.apply(this, arguments)), + r1 = Math.max(0, +outerRadius.apply(this, arguments)), + a0 = startAngle.apply(this, arguments) - halfπ, + a1 = endAngle.apply(this, arguments) - halfπ, + da = Math.abs(a1 - a0), + cw = a0 > a1 ? 0 : 1; + + // Ensure that the outer radius is always larger than the inner radius. + if (r1 < r0) rc = r1, r1 = r0, r0 = rc; + + // Special case for an arc that spans the full circle. + if (da >= τε) return circleSegment(r1, cw) + (r0 ? circleSegment(r0, 1 - cw) : "") + "Z"; + + var rc, + cr, + rp, + ap, + p0 = 0, + p1 = 0, + x0, + y0, + x1, + y1, + x2, + y2, + x3, + y3, + path = []; + + // The recommended minimum inner radius when using padding is outerRadius * + // padAngle / sin(θ), where θ is the angle of the smallest arc (without + // padding). For example, if the outerRadius is 200 pixels and the padAngle + // is 0.02 radians, a reasonable θ is 0.04 radians, and a reasonable + // innerRadius is 100 pixels. + + if (ap = (+padAngle.apply(this, arguments) || 0) / 2) { + rp = padRadius === d3_svg_arcAuto ? Math.sqrt(r0 * r0 + r1 * r1) : +padRadius.apply(this, arguments); + if (!cw) p1 *= -1; + if (r1) p1 = d3_asin(rp / r1 * Math.sin(ap)); + if (r0) p0 = d3_asin(rp / r0 * Math.sin(ap)); + } + + // Compute the two outer corners. + if (r1) { + x0 = r1 * Math.cos(a0 + p1); + y0 = r1 * Math.sin(a0 + p1); + x1 = r1 * Math.cos(a1 - p1); + y1 = r1 * Math.sin(a1 - p1); + + // Detect whether the outer corners are collapsed. + var l1 = Math.abs(a1 - a0 - 2 * p1) <= π ? 0 : 1; + if (p1 && d3_svg_arcSweep(x0, y0, x1, y1) === cw ^ l1) { + var h1 = (a0 + a1) / 2; + x0 = r1 * Math.cos(h1); + y0 = r1 * Math.sin(h1); + x1 = y1 = null; + } + } else { + x0 = y0 = 0; + } + + // Compute the two inner corners. + if (r0) { + x2 = r0 * Math.cos(a1 - p0); + y2 = r0 * Math.sin(a1 - p0); + x3 = r0 * Math.cos(a0 + p0); + y3 = r0 * Math.sin(a0 + p0); + + // Detect whether the inner corners are collapsed. + var l0 = Math.abs(a0 - a1 + 2 * p0) <= π ? 0 : 1; + if (p0 && d3_svg_arcSweep(x2, y2, x3, y3) === (1 - cw) ^ l0) { + var h0 = (a0 + a1) / 2; + x2 = r0 * Math.cos(h0); + y2 = r0 * Math.sin(h0); + x3 = y3 = null; + } + } else { + x2 = y2 = 0; + } + + // Compute the rounded corners. + if (da > ε && (rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments))) > 1e-3) { + cr = r0 < r1 ^ cw ? 0 : 1; + var rc1 = rc, + rc0 = rc; + + // Compute the angle of the sector formed by the two sides of the arc. + if (da < π) { + var oc = x3 == null ? [x2, y2] : x1 == null ? [x0, y0] : d3_geom_polygonIntersect([x0, y0], [x3, y3], [x1, y1], [x2, y2]), + ax = x0 - oc[0], + ay = y0 - oc[1], + bx = x1 - oc[0], + by = y1 - oc[1], + kc = 1 / Math.sin(Math.acos((ax * bx + ay * by) / (Math.sqrt(ax * ax + ay * ay) * Math.sqrt(bx * bx + by * by))) / 2), + lc = Math.sqrt(oc[0] * oc[0] + oc[1] * oc[1]); + rc0 = Math.min(rc, (r0 - lc) / (kc - 1)); + rc1 = Math.min(rc, (r1 - lc) / (kc + 1)); + } + + // Compute the outer corners. + if (x1 != null) { + var t30 = d3_svg_arcCornerTangents(x3 == null ? [x2, y2] : [x3, y3], [x0, y0], r1, rc1, cw), + t12 = d3_svg_arcCornerTangents([x1, y1], [x2, y2], r1, rc1, cw); + + // Detect whether the outer edge is fully circular. + if (rc === rc1) { + path.push( + "M", t30[0], + "A", rc1, ",", rc1, " 0 0,", cr, " ", t30[1], + "A", r1, ",", r1, " 0 ", (1 - cw) ^ d3_svg_arcSweep(t30[1][0], t30[1][1], t12[1][0], t12[1][1]), ",", cw, " ", t12[1], + "A", rc1, ",", rc1, " 0 0,", cr, " ", t12[0]); + } else { + path.push( + "M", t30[0], + "A", rc1, ",", rc1, " 0 1,", cr, " ", t12[0]); + } + } else { + path.push("M", x0, ",", y0); + } + + // Compute the inner corners. + if (x3 != null) { + var t03 = d3_svg_arcCornerTangents([x0, y0], [x3, y3], r0, -rc0, cw), + t21 = d3_svg_arcCornerTangents([x2, y2], x1 == null ? [x0, y0] : [x1, y1], r0, -rc0, cw); + + // Detect whether the inner edge is fully circular. + if (rc === rc0) { + path.push( + "L", t21[0], + "A", rc0, ",", rc0, " 0 0,", cr, " ", t21[1], + "A", r0, ",", r0, " 0 ", cw ^ d3_svg_arcSweep(t21[1][0], t21[1][1], t03[1][0], t03[1][1]), ",", 1 - cw, " ", t03[1], + "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]); + } else { + path.push( + "L", t21[0], + "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]); + } + } else { + path.push("L", x2, ",", y2); + } + } + + // Compute straight corners. + else { + path.push("M", x0, ",", y0); + if (x1 != null) path.push("A", r1, ",", r1, " 0 ", l1, ",", cw, " ", x1, ",", y1); + path.push("L", x2, ",", y2); + if (x3 != null) path.push("A", r0, ",", r0, " 0 ", l0, ",", 1 - cw, " ", x3, ",", y3); + } + + path.push("Z"); + return path.join(""); + } + + function circleSegment(r1, cw) { + return "M0," + r1 + + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + -r1 + + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + r1; + } + + arc.innerRadius = function(v) { + if (!arguments.length) return innerRadius; + innerRadius = d3_functor(v); + return arc; + }; + + arc.outerRadius = function(v) { + if (!arguments.length) return outerRadius; + outerRadius = d3_functor(v); + return arc; + }; + + arc.cornerRadius = function(v) { + if (!arguments.length) return cornerRadius; + cornerRadius = d3_functor(v); + return arc; + }; + + arc.padRadius = function(v) { + if (!arguments.length) return padRadius; + padRadius = v == d3_svg_arcAuto ? d3_svg_arcAuto : d3_functor(v); + return arc; + }; + + arc.startAngle = function(v) { + if (!arguments.length) return startAngle; + startAngle = d3_functor(v); + return arc; + }; + + arc.endAngle = function(v) { + if (!arguments.length) return endAngle; + endAngle = d3_functor(v); + return arc; + }; + + arc.padAngle = function(v) { + if (!arguments.length) return padAngle; + padAngle = d3_functor(v); + return arc; + }; + + arc.centroid = function() { + var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, + a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - halfπ; + return [Math.cos(a) * r, Math.sin(a) * r]; + }; + + return arc; +}; + +var d3_svg_arcAuto = "auto"; + +function d3_svg_arcInnerRadius(d) { + return d.innerRadius; +} + +function d3_svg_arcOuterRadius(d) { + return d.outerRadius; +} + +function d3_svg_arcStartAngle(d) { + return d.startAngle; +} + +function d3_svg_arcEndAngle(d) { + return d.endAngle; +} + +function d3_svg_arcPadAngle(d) { + return d && d.padAngle; +} + +// Note: similar to d3_cross2d, d3_geom_polygonInside +function d3_svg_arcSweep(x0, y0, x1, y1) { + return (x0 - x1) * y0 - (y0 - y1) * x0 > 0 ? 0 : 1; +} + +// Compute perpendicular offset line of length rc. +// http://mathworld.wolfram.com/Circle-LineIntersection.html +function d3_svg_arcCornerTangents(p0, p1, r1, rc, cw) { + var x01 = p0[0] - p1[0], + y01 = p0[1] - p1[1], + lo = (cw ? rc : -rc) / Math.sqrt(x01 * x01 + y01 * y01), + ox = lo * y01, + oy = -lo * x01, + x1 = p0[0] + ox, + y1 = p0[1] + oy, + x2 = p1[0] + ox, + y2 = p1[1] + oy, + x3 = (x1 + x2) / 2, + y3 = (y1 + y2) / 2, + dx = x2 - x1, + dy = y2 - y1, + d2 = dx * dx + dy * dy, + r = r1 - rc, + D = x1 * y2 - x2 * y1, + d = (dy < 0 ? -1 : 1) * Math.sqrt(Math.max(0, r * r * d2 - D * D)), + cx0 = (D * dy - dx * d) / d2, + cy0 = (-D * dx - dy * d) / d2, + cx1 = (D * dy + dx * d) / d2, + cy1 = (-D * dx + dy * d) / d2, + dx0 = cx0 - x3, + dy0 = cy0 - y3, + dx1 = cx1 - x3, + dy1 = cy1 - y3; + + // Pick the closer of the two intersection points. + // TODO Is there a faster way to determine which intersection to use? + if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1; + + return [ + [cx0 - ox, cy0 - oy], + [cx0 * r1 / r, cy0 * r1 / r] + ]; +} diff --git a/node_modules/@plotly/d3/src/svg/area-radial.js b/node_modules/@plotly/d3/src/svg/area-radial.js new file mode 100644 index 0000000000000000000000000000000000000000..9a5b8625c650fbfd9155bdb30d7cade183cbc878 --- /dev/null +++ b/node_modules/@plotly/d3/src/svg/area-radial.js @@ -0,0 +1,14 @@ +import "area"; +import "svg"; +import "line-radial"; + +d3.svg.area.radial = function() { + var area = d3_svg_area(d3_svg_lineRadial); + area.radius = area.x, delete area.x; + area.innerRadius = area.x0, delete area.x0; + area.outerRadius = area.x1, delete area.x1; + area.angle = area.y, delete area.y; + area.startAngle = area.y0, delete area.y0; + area.endAngle = area.y1, delete area.y1; + return area; +}; diff --git a/node_modules/@plotly/d3/src/svg/area.js b/node_modules/@plotly/d3/src/svg/area.js new file mode 100644 index 0000000000000000000000000000000000000000..ec273a2cebf140a6d5c534d3f3bc14959a633d4d --- /dev/null +++ b/node_modules/@plotly/d3/src/svg/area.js @@ -0,0 +1,121 @@ +import "../core/functor"; +import "../core/identity"; +import "../core/true"; +import "../geom/point"; +import "svg"; +import "line"; + +function d3_svg_area(projection) { + var x0 = d3_geom_pointX, + x1 = d3_geom_pointX, + y0 = 0, + y1 = d3_geom_pointY, + defined = d3_true, + interpolate = d3_svg_lineLinear, + interpolateKey = interpolate.key, + interpolateReverse = interpolate, + L = "L", + tension = 0.7; + + function area(data) { + var segments = [], + points0 = [], + points1 = [], + i = -1, + n = data.length, + d, + fx0 = d3_functor(x0), + fy0 = d3_functor(y0), + fx1 = x0 === x1 ? function() { return x; } : d3_functor(x1), + fy1 = y0 === y1 ? function() { return y; } : d3_functor(y1), + x, + y; + + function segment() { + segments.push("M", interpolate(projection(points1), tension), + L, interpolateReverse(projection(points0.reverse()), tension), + "Z"); + } + + while (++i < n) { + if (defined.call(this, d = data[i], i)) { + points0.push([x = +fx0.call(this, d, i), y = +fy0.call(this, d, i)]); + points1.push([+fx1.call(this, d, i), +fy1.call(this, d, i)]); + } else if (points0.length) { + segment(); + points0 = []; + points1 = []; + } + } + + if (points0.length) segment(); + + return segments.length ? segments.join("") : null; + } + + area.x = function(_) { + if (!arguments.length) return x1; + x0 = x1 = _; + return area; + }; + + area.x0 = function(_) { + if (!arguments.length) return x0; + x0 = _; + return area; + }; + + area.x1 = function(_) { + if (!arguments.length) return x1; + x1 = _; + return area; + }; + + area.y = function(_) { + if (!arguments.length) return y1; + y0 = y1 = _; + return area; + }; + + area.y0 = function(_) { + if (!arguments.length) return y0; + y0 = _; + return area; + }; + + area.y1 = function(_) { + if (!arguments.length) return y1; + y1 = _; + return area; + }; + + area.defined = function(_) { + if (!arguments.length) return defined; + defined = _; + return area; + }; + + area.interpolate = function(_) { + if (!arguments.length) return interpolateKey; + if (typeof _ === "function") interpolateKey = interpolate = _; + else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key; + interpolateReverse = interpolate.reverse || interpolate; + L = interpolate.closed ? "M" : "L"; + return area; + }; + + area.tension = function(_) { + if (!arguments.length) return tension; + tension = _; + return area; + }; + + return area; +} + +d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter; +d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore; + +d3.svg.area = function() { + return d3_svg_area(d3_identity); +}; diff --git a/node_modules/@plotly/d3/src/svg/axis.js b/node_modules/@plotly/d3/src/svg/axis.js new file mode 100644 index 0000000000000000000000000000000000000000..96e78deacbc6e972e6daed50479c376ba693f300 --- /dev/null +++ b/node_modules/@plotly/d3/src/svg/axis.js @@ -0,0 +1,160 @@ +import "../core/array"; +import "../core/identity"; +import "../math/trigonometry"; +import "../scale/linear"; +import "../scale/scale"; +import "../selection/selection"; +import "../transition/transition"; +import "svg"; + +d3.svg.axis = function() { + var scale = d3.scale.linear(), + orient = d3_svg_axisDefaultOrient, + innerTickSize = 6, + outerTickSize = 6, + tickPadding = 3, + tickArguments_ = [10], + tickValues = null, + tickFormat_; + + function axis(g) { + g.each(function() { + var g = d3.select(this); + + // Stash a snapshot of the new scale, and retrieve the old snapshot. + var scale0 = this.__chart__ || scale, + scale1 = this.__chart__ = scale.copy(); + + // Ticks, or domain values for ordinal scales. + var ticks = tickValues == null ? (scale1.ticks ? scale1.ticks.apply(scale1, tickArguments_) : scale1.domain()) : tickValues, + tickFormat = tickFormat_ == null ? (scale1.tickFormat ? scale1.tickFormat.apply(scale1, tickArguments_) : d3_identity) : tickFormat_, + tick = g.selectAll(".tick").data(ticks, scale1), + tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", ε), + tickExit = d3.transition(tick.exit()).style("opacity", ε).remove(), + tickUpdate = d3.transition(tick.order()).style("opacity", 1), + tickSpacing = Math.max(innerTickSize, 0) + tickPadding, + tickTransform; + + // Domain. + var range = d3_scaleRange(scale1), + path = g.selectAll(".domain").data([0]), + pathUpdate = (path.enter().append("path").attr("class", "domain"), d3.transition(path)); + + tickEnter.append("line"); + tickEnter.append("text"); + + var lineEnter = tickEnter.select("line"), + lineUpdate = tickUpdate.select("line"), + text = tick.select("text").text(tickFormat), + textEnter = tickEnter.select("text"), + textUpdate = tickUpdate.select("text"), + sign = orient === "top" || orient === "left" ? -1 : 1, + x1, x2, y1, y2; + + if (orient === "bottom" || orient === "top") { + tickTransform = d3_svg_axisX, x1 = "x", y1 = "y", x2 = "x2", y2 = "y2"; + text.attr("dy", sign < 0 ? "0em" : ".71em").style("text-anchor", "middle"); + pathUpdate.attr("d", "M" + range[0] + "," + sign * outerTickSize + "V0H" + range[1] + "V" + sign * outerTickSize); + } else { + tickTransform = d3_svg_axisY, x1 = "y", y1 = "x", x2 = "y2", y2 = "x2"; + text.attr("dy", ".32em").style("text-anchor", sign < 0 ? "end" : "start"); + pathUpdate.attr("d", "M" + sign * outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + sign * outerTickSize); + } + + lineEnter.attr(y2, sign * innerTickSize); + textEnter.attr(y1, sign * tickSpacing); + lineUpdate.attr(x2, 0).attr(y2, sign * innerTickSize); + textUpdate.attr(x1, 0).attr(y1, sign * tickSpacing); + + // If either the new or old scale is ordinal, + // entering ticks are undefined in the old scale, + // and so can fade-in in the new scale’s position. + // Exiting ticks are likewise undefined in the new scale, + // and so can fade-out in the old scale’s position. + if (scale1.rangeBand) { + var x = scale1, dx = x.rangeBand() / 2; + scale0 = scale1 = function(d) { return x(d) + dx; }; + } else if (scale0.rangeBand) { + scale0 = scale1; + } else { + tickExit.call(tickTransform, scale1, scale0); + } + + tickEnter.call(tickTransform, scale0, scale1); + tickUpdate.call(tickTransform, scale1, scale1); + }); + } + + axis.scale = function(x) { + if (!arguments.length) return scale; + scale = x; + return axis; + }; + + axis.orient = function(x) { + if (!arguments.length) return orient; + orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient; + return axis; + }; + + axis.ticks = function() { + if (!arguments.length) return tickArguments_; + tickArguments_ = d3_array(arguments); + return axis; + }; + + axis.tickValues = function(x) { + if (!arguments.length) return tickValues; + tickValues = x; + return axis; + }; + + axis.tickFormat = function(x) { + if (!arguments.length) return tickFormat_; + tickFormat_ = x; + return axis; + }; + + axis.tickSize = function(x) { + var n = arguments.length; + if (!n) return innerTickSize; + innerTickSize = +x; + outerTickSize = +arguments[n - 1]; + return axis; + }; + + axis.innerTickSize = function(x) { + if (!arguments.length) return innerTickSize; + innerTickSize = +x; + return axis; + }; + + axis.outerTickSize = function(x) { + if (!arguments.length) return outerTickSize; + outerTickSize = +x; + return axis; + }; + + axis.tickPadding = function(x) { + if (!arguments.length) return tickPadding; + tickPadding = +x; + return axis; + }; + + axis.tickSubdivide = function() { + return arguments.length && axis; + }; + + return axis; +}; + +var d3_svg_axisDefaultOrient = "bottom", + d3_svg_axisOrients = {top: 1, right: 1, bottom: 1, left: 1}; + +function d3_svg_axisX(selection, x0, x1) { + selection.attr("transform", function(d) { var v0 = x0(d); return "translate(" + (isFinite(v0) ? v0 : x1(d)) + ",0)"; }); +} + +function d3_svg_axisY(selection, y0, y1) { + selection.attr("transform", function(d) { var v0 = y0(d); return "translate(0," + (isFinite(v0) ? v0 : y1(d)) + ")"; }); +} diff --git a/node_modules/@plotly/d3/src/svg/brush.js b/node_modules/@plotly/d3/src/svg/brush.js new file mode 100644 index 0000000000000000000000000000000000000000..77ef8d3c33a2040b0d26c48fe1ea5ed54b8d0ce1 --- /dev/null +++ b/node_modules/@plotly/d3/src/svg/brush.js @@ -0,0 +1,429 @@ +import "../core/identity"; +import "../core/document"; +import "../core/rebind"; +import "../event/drag"; +import "../event/event"; +import "../event/mouse"; +import "../scale/scale"; +import "../selection/selection"; +import "svg"; + +d3.svg.brush = function() { + var event = d3_eventDispatch(brush, "brushstart", "brush", "brushend"), + x = null, // x-scale, optional + y = null, // y-scale, optional + xExtent = [0, 0], // [x0, x1] in integer pixels + yExtent = [0, 0], // [y0, y1] in integer pixels + xExtentDomain, // x-extent in data space + yExtentDomain, // y-extent in data space + xClamp = true, // whether to clamp the x-extent to the range + yClamp = true, // whether to clamp the y-extent to the range + resizes = d3_svg_brushResizes[0]; + + function brush(g) { + g.each(function() { + + // Prepare the brush container for events. + var g = d3.select(this) + .style("pointer-events", "all") + .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)") + .on("mousedown.brush", brushstart) + .on("touchstart.brush", brushstart); + + // An invisible, mouseable area for starting a new brush. + var background = g.selectAll(".background") + .data([0]); + + background.enter().append("rect") + .attr("class", "background") + .style("visibility", "hidden") + .style("cursor", "crosshair"); + + // The visible brush extent; style this as you like! + g.selectAll(".extent") + .data([0]) + .enter().append("rect") + .attr("class", "extent") + .style("cursor", "move"); + + // More invisible rects for resizing the extent. + var resize = g.selectAll(".resize") + .data(resizes, d3_identity); + + // Remove any superfluous resizers. + resize.exit().remove(); + + resize.enter().append("g") + .attr("class", function(d) { return "resize " + d; }) + .style("cursor", function(d) { return d3_svg_brushCursor[d]; }) + .append("rect") + .attr("x", function(d) { return /[ew]$/.test(d) ? -3 : null; }) + .attr("y", function(d) { return /^[ns]/.test(d) ? -3 : null; }) + .attr("width", 6) + .attr("height", 6) + .style("visibility", "hidden"); + + // Show or hide the resizers. + resize.style("display", brush.empty() ? "none" : null); + + // When called on a transition, use a transition to update. + var gUpdate = d3.transition(g), + backgroundUpdate = d3.transition(background), + range; + + // Initialize the background to fill the defined range. + // If the range isn't defined, you can post-process. + if (x) { + range = d3_scaleRange(x); + backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]); + redrawX(gUpdate); + } + if (y) { + range = d3_scaleRange(y); + backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]); + redrawY(gUpdate); + } + redraw(gUpdate); + }); + } + + brush.event = function(g) { + g.each(function() { + var event_ = event.of(this, arguments), + extent1 = {x: xExtent, y: yExtent, i: xExtentDomain, j: yExtentDomain}, + extent0 = this.__chart__ || extent1; + this.__chart__ = extent1; + if (d3_transitionInheritId) { + d3.select(this).transition() + .each("start.brush", function() { + xExtentDomain = extent0.i; // pre-transition state + yExtentDomain = extent0.j; + xExtent = extent0.x; + yExtent = extent0.y; + event_({type: "brushstart"}); + }) + .tween("brush:brush", function() { + var xi = d3_interpolateArray(xExtent, extent1.x), + yi = d3_interpolateArray(yExtent, extent1.y); + xExtentDomain = yExtentDomain = null; // transition state + return function(t) { + xExtent = extent1.x = xi(t); + yExtent = extent1.y = yi(t); + event_({type: "brush", mode: "resize"}); + }; + }) + .each("end.brush", function() { + xExtentDomain = extent1.i; // post-transition state + yExtentDomain = extent1.j; + event_({type: "brush", mode: "resize"}); + event_({type: "brushend"}); + }); + } else { + event_({type: "brushstart"}); + event_({type: "brush", mode: "resize"}); + event_({type: "brushend"}); + } + }); + }; + + function redraw(g) { + g.selectAll(".resize").attr("transform", function(d) { + return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")"; + }); + } + + function redrawX(g) { + g.select(".extent").attr("x", xExtent[0]); + g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]); + } + + function redrawY(g) { + g.select(".extent").attr("y", yExtent[0]); + g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]); + } + + function brushstart() { + var target = this, + eventTarget = d3.select(d3.event.target), + event_ = event.of(target, arguments), + g = d3.select(target), + resizing = eventTarget.datum(), + resizingX = !/^(n|s)$/.test(resizing) && x, + resizingY = !/^(e|w)$/.test(resizing) && y, + dragging = eventTarget.classed("extent"), + dragRestore = d3_event_dragSuppress(target), + center, + origin = d3.mouse(target), + offset; + + var w = d3.select(d3_window(target)) + .on("keydown.brush", keydown) + .on("keyup.brush", keyup); + + if (d3.event.changedTouches) { + w.on("touchmove.brush", brushmove).on("touchend.brush", brushend); + } else { + w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend); + } + + // Interrupt the transition, if any. + g.interrupt().selectAll("*").interrupt(); + + // If the extent was clicked on, drag rather than brush; + // store the point between the mouse and extent origin instead. + if (dragging) { + origin[0] = xExtent[0] - origin[0]; + origin[1] = yExtent[0] - origin[1]; + } + + // If a resizer was clicked on, record which side is to be resized. + // Also, set the origin to the opposite side. + else if (resizing) { + var ex = +/w$/.test(resizing), + ey = +/^n/.test(resizing); + offset = [xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1]]; + origin[0] = xExtent[ex]; + origin[1] = yExtent[ey]; + } + + // If the ALT key is down when starting a brush, the center is at the mouse. + else if (d3.event.altKey) center = origin.slice(); + + // Propagate the active cursor to the body for the drag duration. + g.style("pointer-events", "none").selectAll(".resize").style("display", null); + d3.select("body").style("cursor", eventTarget.style("cursor")); + + // Notify listeners. + event_({type: "brushstart"}); + brushmove(); + + function keydown() { + if (d3.event.keyCode == 32) { + if (!dragging) { + center = null; + origin[0] -= xExtent[1]; + origin[1] -= yExtent[1]; + dragging = 2; + } + d3_eventPreventDefault(); + } + } + + function keyup() { + if (d3.event.keyCode == 32 && dragging == 2) { + origin[0] += xExtent[1]; + origin[1] += yExtent[1]; + dragging = 0; + d3_eventPreventDefault(); + } + } + + function brushmove() { + var point = d3.mouse(target), + moved = false; + + // Preserve the offset for thick resizers. + if (offset) { + point[0] += offset[0]; + point[1] += offset[1]; + } + + if (!dragging) { + + // If needed, determine the center from the current extent. + if (d3.event.altKey) { + if (!center) center = [(xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2]; + + // Update the origin, for when the ALT key is released. + origin[0] = xExtent[+(point[0] < center[0])]; + origin[1] = yExtent[+(point[1] < center[1])]; + } + + // When the ALT key is released, we clear the center. + else center = null; + } + + // Update the brush extent for each dimension. + if (resizingX && move1(point, x, 0)) { + redrawX(g); + moved = true; + } + if (resizingY && move1(point, y, 1)) { + redrawY(g); + moved = true; + } + + // Final redraw and notify listeners. + if (moved) { + redraw(g); + event_({type: "brush", mode: dragging ? "move" : "resize"}); + } + } + + function move1(point, scale, i) { + var range = d3_scaleRange(scale), + r0 = range[0], + r1 = range[1], + position = origin[i], + extent = i ? yExtent : xExtent, + size = extent[1] - extent[0], + min, + max; + + // When dragging, reduce the range by the extent size and position. + if (dragging) { + r0 -= position; + r1 -= size + position; + } + + // Clamp the point (unless clamp set to false) so that the extent fits within the range extent. + min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i]; + + // Compute the new extent bounds. + if (dragging) { + max = (min += position) + size; + } else { + + // If the ALT key is pressed, then preserve the center of the extent. + if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min)); + + // Compute the min and max of the position and point. + if (position < min) { + max = min; + min = position; + } else { + max = position; + } + } + + // Update the stored bounds. + if (extent[0] != min || extent[1] != max) { + if (i) yExtentDomain = null; + else xExtentDomain = null; + extent[0] = min; + extent[1] = max; + return true; + } + } + + function brushend() { + brushmove(); + + // reset the cursor styles + g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null); + d3.select("body").style("cursor", null); + + w .on("mousemove.brush", null) + .on("mouseup.brush", null) + .on("touchmove.brush", null) + .on("touchend.brush", null) + .on("keydown.brush", null) + .on("keyup.brush", null); + + dragRestore(); + event_({type: "brushend"}); + } + } + + brush.x = function(z) { + if (!arguments.length) return x; + x = z; + resizes = d3_svg_brushResizes[!x << 1 | !y]; // fore! + return brush; + }; + + brush.y = function(z) { + if (!arguments.length) return y; + y = z; + resizes = d3_svg_brushResizes[!x << 1 | !y]; // fore! + return brush; + }; + + brush.clamp = function(z) { + if (!arguments.length) return x && y ? [xClamp, yClamp] : x ? xClamp : y ? yClamp : null; + if (x && y) xClamp = !!z[0], yClamp = !!z[1]; + else if (x) xClamp = !!z; + else if (y) yClamp = !!z; + return brush; + }; + + brush.extent = function(z) { + var x0, x1, y0, y1, t; + + // Invert the pixel extent to data-space. + if (!arguments.length) { + if (x) { + if (xExtentDomain) { + x0 = xExtentDomain[0], x1 = xExtentDomain[1]; + } else { + x0 = xExtent[0], x1 = xExtent[1]; + if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1); + if (x1 < x0) t = x0, x0 = x1, x1 = t; + } + } + if (y) { + if (yExtentDomain) { + y0 = yExtentDomain[0], y1 = yExtentDomain[1]; + } else { + y0 = yExtent[0], y1 = yExtent[1]; + if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1); + if (y1 < y0) t = y0, y0 = y1, y1 = t; + } + } + return x && y ? [[x0, y0], [x1, y1]] : x ? [x0, x1] : y && [y0, y1]; + } + + // Scale the data-space extent to pixels. + if (x) { + x0 = z[0], x1 = z[1]; + if (y) x0 = x0[0], x1 = x1[0]; + xExtentDomain = [x0, x1]; + if (x.invert) x0 = x(x0), x1 = x(x1); + if (x1 < x0) t = x0, x0 = x1, x1 = t; + if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [x0, x1]; // copy-on-write + } + if (y) { + y0 = z[0], y1 = z[1]; + if (x) y0 = y0[1], y1 = y1[1]; + yExtentDomain = [y0, y1]; + if (y.invert) y0 = y(y0), y1 = y(y1); + if (y1 < y0) t = y0, y0 = y1, y1 = t; + if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [y0, y1]; // copy-on-write + } + + return brush; + }; + + brush.clear = function() { + if (!brush.empty()) { + xExtent = [0, 0], yExtent = [0, 0]; // copy-on-write + xExtentDomain = yExtentDomain = null; + } + return brush; + }; + + brush.empty = function() { + return !!x && xExtent[0] == xExtent[1] + || !!y && yExtent[0] == yExtent[1]; + }; + + return d3.rebind(brush, event, "on"); +}; + +var d3_svg_brushCursor = { + n: "ns-resize", + e: "ew-resize", + s: "ns-resize", + w: "ew-resize", + nw: "nwse-resize", + ne: "nesw-resize", + se: "nwse-resize", + sw: "nesw-resize" +}; + +var d3_svg_brushResizes = [ + ["n", "e", "s", "w", "nw", "ne", "se", "sw"], + ["e", "w"], + ["n", "s"], + [] +]; diff --git a/node_modules/@plotly/d3/src/svg/chord.js b/node_modules/@plotly/d3/src/svg/chord.js new file mode 100644 index 0000000000000000000000000000000000000000..d7611e14b908d1e7790cabc1fc6655c2dbfeacf7 --- /dev/null +++ b/node_modules/@plotly/d3/src/svg/chord.js @@ -0,0 +1,90 @@ +import "../core/functor"; +import "../core/source"; +import "../core/target"; +import "../math/trigonometry"; +import "arc"; +import "svg"; + +d3.svg.chord = function() { + var source = d3_source, + target = d3_target, + radius = d3_svg_chordRadius, + startAngle = d3_svg_arcStartAngle, + endAngle = d3_svg_arcEndAngle; + + // TODO Allow control point to be customized. + + function chord(d, i) { + var s = subgroup(this, source, d, i), + t = subgroup(this, target, d, i); + return "M" + s.p0 + + arc(s.r, s.p1, s.a1 - s.a0) + (equals(s, t) + ? curve(s.r, s.p1, s.r, s.p0) + : curve(s.r, s.p1, t.r, t.p0) + + arc(t.r, t.p1, t.a1 - t.a0) + + curve(t.r, t.p1, s.r, s.p0)) + + "Z"; + } + + function subgroup(self, f, d, i) { + var subgroup = f.call(self, d, i), + r = radius.call(self, subgroup, i), + a0 = startAngle.call(self, subgroup, i) - halfπ, + a1 = endAngle.call(self, subgroup, i) - halfπ; + return { + r: r, + a0: a0, + a1: a1, + p0: [r * Math.cos(a0), r * Math.sin(a0)], + p1: [r * Math.cos(a1), r * Math.sin(a1)] + }; + } + + function equals(a, b) { + return a.a0 == b.a0 && a.a1 == b.a1; + } + + function arc(r, p, a) { + return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p; + } + + function curve(r0, p0, r1, p1) { + return "Q 0,0 " + p1; + } + + chord.radius = function(v) { + if (!arguments.length) return radius; + radius = d3_functor(v); + return chord; + }; + + chord.source = function(v) { + if (!arguments.length) return source; + source = d3_functor(v); + return chord; + }; + + chord.target = function(v) { + if (!arguments.length) return target; + target = d3_functor(v); + return chord; + }; + + chord.startAngle = function(v) { + if (!arguments.length) return startAngle; + startAngle = d3_functor(v); + return chord; + }; + + chord.endAngle = function(v) { + if (!arguments.length) return endAngle; + endAngle = d3_functor(v); + return chord; + }; + + return chord; +}; + +function d3_svg_chordRadius(d) { + return d.radius; +} diff --git a/node_modules/@plotly/d3/src/svg/diagonal-radial.js b/node_modules/@plotly/d3/src/svg/diagonal-radial.js new file mode 100644 index 0000000000000000000000000000000000000000..c4b09fdfe93f5bc17ada47c200c50170d4b9aa2d --- /dev/null +++ b/node_modules/@plotly/d3/src/svg/diagonal-radial.js @@ -0,0 +1,27 @@ +import "../math/trigonometry"; +import "arc"; +import "diagonal"; +import "svg"; + +d3.svg.diagonal.radial = function() { + var diagonal = d3.svg.diagonal(), + projection = d3_svg_diagonalProjection, + projection_ = diagonal.projection; + + diagonal.projection = function(x) { + return arguments.length + ? projection_(d3_svg_diagonalRadialProjection(projection = x)) + : projection; + }; + + return diagonal; +}; + +function d3_svg_diagonalRadialProjection(projection) { + return function() { + var d = projection.apply(this, arguments), + r = d[0], + a = d[1] - halfπ; + return [r * Math.cos(a), r * Math.sin(a)]; + }; +} diff --git a/node_modules/@plotly/d3/src/svg/diagonal.js b/node_modules/@plotly/d3/src/svg/diagonal.js new file mode 100644 index 0000000000000000000000000000000000000000..17d15def937e8e30cf8982d26ef8ab0fe72d3852 --- /dev/null +++ b/node_modules/@plotly/d3/src/svg/diagonal.js @@ -0,0 +1,43 @@ +import "../core/functor"; +import "../core/source"; +import "../core/target"; +import "svg"; + +d3.svg.diagonal = function() { + var source = d3_source, + target = d3_target, + projection = d3_svg_diagonalProjection; + + function diagonal(d, i) { + var p0 = source.call(this, d, i), + p3 = target.call(this, d, i), + m = (p0.y + p3.y) / 2, + p = [p0, {x: p0.x, y: m}, {x: p3.x, y: m}, p3]; + p = p.map(projection); + return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3]; + } + + diagonal.source = function(x) { + if (!arguments.length) return source; + source = d3_functor(x); + return diagonal; + }; + + diagonal.target = function(x) { + if (!arguments.length) return target; + target = d3_functor(x); + return diagonal; + }; + + diagonal.projection = function(x) { + if (!arguments.length) return projection; + projection = x; + return diagonal; + }; + + return diagonal; +}; + +function d3_svg_diagonalProjection(d) { + return [d.x, d.y]; +} diff --git a/node_modules/@plotly/d3/src/svg/index.js b/node_modules/@plotly/d3/src/svg/index.js new file mode 100644 index 0000000000000000000000000000000000000000..a9201d7d49c755bf2e7de4b8a4feefeb4949f693 --- /dev/null +++ b/node_modules/@plotly/d3/src/svg/index.js @@ -0,0 +1,12 @@ +import "svg"; +import "arc"; +import "line"; +import "line-radial"; +import "area"; +import "area-radial"; +import "chord"; +import "diagonal"; +import "diagonal-radial"; +import "symbol"; +import "axis"; +import "brush"; diff --git a/node_modules/@plotly/d3/src/svg/line-radial.js b/node_modules/@plotly/d3/src/svg/line-radial.js new file mode 100644 index 0000000000000000000000000000000000000000..d69ec303a990e699f21659f15ba3f148cb8fd565 --- /dev/null +++ b/node_modules/@plotly/d3/src/svg/line-radial.js @@ -0,0 +1,27 @@ +import "../math/trigonometry"; +import "arc"; +import "line"; +import "svg"; + +d3.svg.line.radial = function() { + var line = d3_svg_line(d3_svg_lineRadial); + line.radius = line.x, delete line.x; + line.angle = line.y, delete line.y; + return line; +}; + +function d3_svg_lineRadial(points) { + var point, + i = -1, + n = points.length, + r, + a; + while (++i < n) { + point = points[i]; + r = point[0]; + a = point[1] - halfπ; + point[0] = r * Math.cos(a); + point[1] = r * Math.sin(a); + } + return points; +} diff --git a/node_modules/@plotly/d3/src/svg/line.js b/node_modules/@plotly/d3/src/svg/line.js new file mode 100644 index 0000000000000000000000000000000000000000..2531808adba8f1e0c227c557473aac4b0fdd3e88 --- /dev/null +++ b/node_modules/@plotly/d3/src/svg/line.js @@ -0,0 +1,432 @@ +import "../arrays/map"; +import "../core/functor"; +import "../core/identity"; +import "../core/true"; +import "../geom/point"; +import "../math/abs"; +import "../math/trigonometry"; +import "svg"; + +function d3_svg_line(projection) { + var x = d3_geom_pointX, + y = d3_geom_pointY, + defined = d3_true, + interpolate = d3_svg_lineLinear, + interpolateKey = interpolate.key, + tension = 0.7; + + function line(data) { + var segments = [], + points = [], + i = -1, + n = data.length, + d, + fx = d3_functor(x), + fy = d3_functor(y); + + function segment() { + segments.push("M", interpolate(projection(points), tension)); + } + + while (++i < n) { + if (defined.call(this, d = data[i], i)) { + points.push([+fx.call(this, d, i), +fy.call(this, d, i)]); + } else if (points.length) { + segment(); + points = []; + } + } + + if (points.length) segment(); + + return segments.length ? segments.join("") : null; + } + + line.x = function(_) { + if (!arguments.length) return x; + x = _; + return line; + }; + + line.y = function(_) { + if (!arguments.length) return y; + y = _; + return line; + }; + + line.defined = function(_) { + if (!arguments.length) return defined; + defined = _; + return line; + }; + + line.interpolate = function(_) { + if (!arguments.length) return interpolateKey; + if (typeof _ === "function") interpolateKey = interpolate = _; + else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key; + return line; + }; + + line.tension = function(_) { + if (!arguments.length) return tension; + tension = _; + return line; + }; + + return line; +} + +d3.svg.line = function() { + return d3_svg_line(d3_identity); +}; + +// The various interpolators supported by the `line` class. +var d3_svg_lineInterpolators = d3.map({ + "linear": d3_svg_lineLinear, + "linear-closed": d3_svg_lineLinearClosed, + "step": d3_svg_lineStep, + "step-before": d3_svg_lineStepBefore, + "step-after": d3_svg_lineStepAfter, + "basis": d3_svg_lineBasis, + "basis-open": d3_svg_lineBasisOpen, + "basis-closed": d3_svg_lineBasisClosed, + "bundle": d3_svg_lineBundle, + "cardinal": d3_svg_lineCardinal, + "cardinal-open": d3_svg_lineCardinalOpen, + "cardinal-closed": d3_svg_lineCardinalClosed, + "monotone": d3_svg_lineMonotone +}); + +d3_svg_lineInterpolators.forEach(function(key, value) { + value.key = key; + value.closed = /-closed$/.test(key); +}); + +// Linear interpolation; generates "L" commands. +function d3_svg_lineLinear(points) { + return points.length > 1 ? points.join("L") : points + "Z"; +} + +function d3_svg_lineLinearClosed(points) { + return points.join("L") + "Z"; +} + +// Step interpolation; generates "H" and "V" commands. +function d3_svg_lineStep(points) { + var i = 0, + n = points.length, + p = points[0], + path = [p[0], ",", p[1]]; + while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]); + if (n > 1) path.push("H", p[0]); + return path.join(""); +} + +// Step interpolation; generates "H" and "V" commands. +function d3_svg_lineStepBefore(points) { + var i = 0, + n = points.length, + p = points[0], + path = [p[0], ",", p[1]]; + while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]); + return path.join(""); +} + +// Step interpolation; generates "H" and "V" commands. +function d3_svg_lineStepAfter(points) { + var i = 0, + n = points.length, + p = points[0], + path = [p[0], ",", p[1]]; + while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]); + return path.join(""); +} + +// Open cardinal spline interpolation; generates "C" commands. +function d3_svg_lineCardinalOpen(points, tension) { + return points.length < 4 + ? d3_svg_lineLinear(points) + : points[1] + d3_svg_lineHermite(points.slice(1, -1), + d3_svg_lineCardinalTangents(points, tension)); +} + +// Closed cardinal spline interpolation; generates "C" commands. +function d3_svg_lineCardinalClosed(points, tension) { + return points.length < 3 + ? d3_svg_lineLinearClosed(points) + : points[0] + d3_svg_lineHermite((points.push(points[0]), points), + d3_svg_lineCardinalTangents([points[points.length - 2]] + .concat(points, [points[1]]), tension)); +} + +// Cardinal spline interpolation; generates "C" commands. +function d3_svg_lineCardinal(points, tension) { + return points.length < 3 + ? d3_svg_lineLinear(points) + : points[0] + d3_svg_lineHermite(points, + d3_svg_lineCardinalTangents(points, tension)); +} + +// Hermite spline construction; generates "C" commands. +function d3_svg_lineHermite(points, tangents) { + if (tangents.length < 1 + || (points.length != tangents.length + && points.length != tangents.length + 2)) { + return d3_svg_lineLinear(points); + } + + var quad = points.length != tangents.length, + path = "", + p0 = points[0], + p = points[1], + t0 = tangents[0], + t = t0, + pi = 1; + + if (quad) { + path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + + "," + p[0] + "," + p[1]; + p0 = points[1]; + pi = 2; + } + + if (tangents.length > 1) { + t = tangents[1]; + p = points[pi]; + pi++; + path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + + "," + p[0] + "," + p[1]; + for (var i = 2; i < tangents.length; i++, pi++) { + p = points[pi]; + t = tangents[i]; + path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + + "," + p[0] + "," + p[1]; + } + } + + if (quad) { + var lp = points[pi]; + path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + + "," + lp[0] + "," + lp[1]; + } + + return path; +} + +// Generates tangents for a cardinal spline. +function d3_svg_lineCardinalTangents(points, tension) { + var tangents = [], + a = (1 - tension) / 2, + p0, + p1 = points[0], + p2 = points[1], + i = 1, + n = points.length; + while (++i < n) { + p0 = p1; + p1 = p2; + p2 = points[i]; + tangents.push([a * (p2[0] - p0[0]), a * (p2[1] - p0[1])]); + } + return tangents; +} + +// B-spline interpolation; generates "C" commands. +function d3_svg_lineBasis(points) { + if (points.length < 3) return d3_svg_lineLinear(points); + var i = 1, + n = points.length, + pi = points[0], + x0 = pi[0], + y0 = pi[1], + px = [x0, x0, x0, (pi = points[1])[0]], + py = [y0, y0, y0, pi[1]], + path = [x0, ",", y0, "L", d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py)]; + points.push(points[n - 1]); + while (++i <= n) { + pi = points[i]; + px.shift(); px.push(pi[0]); + py.shift(); py.push(pi[1]); + d3_svg_lineBasisBezier(path, px, py); + } + points.pop(); + path.push("L", pi); + return path.join(""); +} + +// Open B-spline interpolation; generates "C" commands. +function d3_svg_lineBasisOpen(points) { + if (points.length < 4) return d3_svg_lineLinear(points); + var path = [], + i = -1, + n = points.length, + pi, + px = [0], + py = [0]; + while (++i < 3) { + pi = points[i]; + px.push(pi[0]); + py.push(pi[1]); + } + path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py)); + --i; while (++i < n) { + pi = points[i]; + px.shift(); px.push(pi[0]); + py.shift(); py.push(pi[1]); + d3_svg_lineBasisBezier(path, px, py); + } + return path.join(""); +} + +// Closed B-spline interpolation; generates "C" commands. +function d3_svg_lineBasisClosed(points) { + var path, + i = -1, + n = points.length, + m = n + 4, + pi, + px = [], + py = []; + while (++i < 4) { + pi = points[i % n]; + px.push(pi[0]); + py.push(pi[1]); + } + path = [ + d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) + ]; + --i; while (++i < m) { + pi = points[i % n]; + px.shift(); px.push(pi[0]); + py.shift(); py.push(pi[1]); + d3_svg_lineBasisBezier(path, px, py); + } + return path.join(""); +} + +function d3_svg_lineBundle(points, tension) { + var n = points.length - 1; + if (n) { + var x0 = points[0][0], + y0 = points[0][1], + dx = points[n][0] - x0, + dy = points[n][1] - y0, + i = -1, + p, + t; + while (++i <= n) { + p = points[i]; + t = i / n; + p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx); + p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy); + } + } + return d3_svg_lineBasis(points); +} + +// Returns the dot product of the given four-element vectors. +function d3_svg_lineDot4(a, b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; +} + +// Matrix to transform basis (b-spline) control points to bezier +// control points. Derived from FvD 11.2.8. +var d3_svg_lineBasisBezier1 = [0, 2/3, 1/3, 0], + d3_svg_lineBasisBezier2 = [0, 1/3, 2/3, 0], + d3_svg_lineBasisBezier3 = [0, 1/6, 2/3, 1/6]; + +// Pushes a "C" Bézier curve onto the specified path array, given the +// two specified four-element arrays which define the control points. +function d3_svg_lineBasisBezier(path, x, y) { + path.push( + "C", d3_svg_lineDot4(d3_svg_lineBasisBezier1, x), + ",", d3_svg_lineDot4(d3_svg_lineBasisBezier1, y), + ",", d3_svg_lineDot4(d3_svg_lineBasisBezier2, x), + ",", d3_svg_lineDot4(d3_svg_lineBasisBezier2, y), + ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, x), + ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, y)); +} + +// Computes the slope from points p0 to p1. +function d3_svg_lineSlope(p0, p1) { + return (p1[1] - p0[1]) / (p1[0] - p0[0]); +} + +// Compute three-point differences for the given points. +// http://en.wikipedia.org/wiki/Cubic_Hermite_spline#Finite_difference +function d3_svg_lineFiniteDifferences(points) { + var i = 0, + j = points.length - 1, + m = [], + p0 = points[0], + p1 = points[1], + d = m[0] = d3_svg_lineSlope(p0, p1); + while (++i < j) { + m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2; + } + m[i] = d; + return m; +} + +// Interpolates the given points using Fritsch-Carlson Monotone cubic Hermite +// interpolation. Returns an array of tangent vectors. For details, see +// http://en.wikipedia.org/wiki/Monotone_cubic_interpolation +function d3_svg_lineMonotoneTangents(points) { + var tangents = [], + d, + a, + b, + s, + m = d3_svg_lineFiniteDifferences(points), + i = -1, + j = points.length - 1; + + // The first two steps are done by computing finite-differences: + // 1. Compute the slopes of the secant lines between successive points. + // 2. Initialize the tangents at every point as the average of the secants. + + // Then, for each segment… + while (++i < j) { + d = d3_svg_lineSlope(points[i], points[i + 1]); + + // 3. If two successive yk = y{k + 1} are equal (i.e., d is zero), then set + // mk = m{k + 1} = 0 as the spline connecting these points must be flat to + // preserve monotonicity. Ignore step 4 and 5 for those k. + + if (abs(d) < ε) { + m[i] = m[i + 1] = 0; + } else { + // 4. Let ak = mk / dk and bk = m{k + 1} / dk. + a = m[i] / d; + b = m[i + 1] / d; + + // 5. Prevent overshoot and ensure monotonicity by restricting the + // magnitude of vector to a circle of radius 3. + s = a * a + b * b; + if (s > 9) { + s = d * 3 / Math.sqrt(s); + m[i] = s * a; + m[i + 1] = s * b; + } + } + } + + // Compute the normalized tangent vector from the slopes. Note that if x is + // not monotonic, it's possible that the slope will be infinite, so we protect + // against NaN by setting the coordinate to zero. + i = -1; while (++i <= j) { + s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i])); + tangents.push([s || 0, m[i] * s || 0]); + } + + return tangents; +} + +function d3_svg_lineMonotone(points) { + return points.length < 3 + ? d3_svg_lineLinear(points) + : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points)); +} diff --git a/node_modules/@plotly/d3/src/svg/svg.js b/node_modules/@plotly/d3/src/svg/svg.js new file mode 100644 index 0000000000000000000000000000000000000000..3749248210fd21490191e13462b5f3373b8c5bc0 --- /dev/null +++ b/node_modules/@plotly/d3/src/svg/svg.js @@ -0,0 +1 @@ +d3.svg = {}; diff --git a/node_modules/@plotly/d3/src/svg/symbol.js b/node_modules/@plotly/d3/src/svg/symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..6ac58bf8e11e377df0fe4f6d7fea0438445426ec --- /dev/null +++ b/node_modules/@plotly/d3/src/svg/symbol.js @@ -0,0 +1,105 @@ +import "../arrays/map"; +import "../core/functor"; +import "../math/trigonometry"; +import "svg"; + +d3.svg.symbol = function() { + var type = d3_svg_symbolType, + size = d3_svg_symbolSize; + + function symbol(d, i) { + return (d3_svg_symbols.get(type.call(this, d, i)) + || d3_svg_symbolCircle) + (size.call(this, d, i)); + } + + symbol.type = function(x) { + if (!arguments.length) return type; + type = d3_functor(x); + return symbol; + }; + + // size of symbol in square pixels + symbol.size = function(x) { + if (!arguments.length) return size; + size = d3_functor(x); + return symbol; + }; + + return symbol; +}; + +function d3_svg_symbolSize() { + return 64; +} + +function d3_svg_symbolType() { + return "circle"; +} + +function d3_svg_symbolCircle(size) { + var r = Math.sqrt(size / π); + return "M0," + r + + "A" + r + "," + r + " 0 1,1 0," + (-r) + + "A" + r + "," + r + " 0 1,1 0," + r + + "Z"; +} + +// TODO cross-diagonal? +var d3_svg_symbols = d3.map({ + "circle": d3_svg_symbolCircle, + "cross": function(size) { + var r = Math.sqrt(size / 5) / 2; + return "M" + -3 * r + "," + -r + + "H" + -r + + "V" + -3 * r + + "H" + r + + "V" + -r + + "H" + 3 * r + + "V" + r + + "H" + r + + "V" + 3 * r + + "H" + -r + + "V" + r + + "H" + -3 * r + + "Z"; + }, + "diamond": function(size) { + var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), + rx = ry * d3_svg_symbolTan30; + return "M0," + -ry + + "L" + rx + ",0" + + " 0," + ry + + " " + -rx + ",0" + + "Z"; + }, + "square": function(size) { + var r = Math.sqrt(size) / 2; + return "M" + -r + "," + -r + + "L" + r + "," + -r + + " " + r + "," + r + + " " + -r + "," + r + + "Z"; + }, + "triangle-down": function(size) { + var rx = Math.sqrt(size / d3_svg_symbolSqrt3), + ry = rx * d3_svg_symbolSqrt3 / 2; + return "M0," + ry + + "L" + rx +"," + -ry + + " " + -rx + "," + -ry + + "Z"; + }, + "triangle-up": function(size) { + var rx = Math.sqrt(size / d3_svg_symbolSqrt3), + ry = rx * d3_svg_symbolSqrt3 / 2; + return "M0," + -ry + + "L" + rx +"," + ry + + " " + -rx + "," + ry + + "Z"; + } +}); + +d3.svg.symbolTypes = d3_svg_symbols.keys(); + +var d3_svg_symbolSqrt3 = Math.sqrt(3), + d3_svg_symbolTan30 = Math.tan(30 * d3_radians); diff --git a/node_modules/@plotly/d3/src/transition/attr.js b/node_modules/@plotly/d3/src/transition/attr.js new file mode 100644 index 0000000000000000000000000000000000000000..31c77f1465a9bc7d38e8f8d351beed49f0cebc27 --- /dev/null +++ b/node_modules/@plotly/d3/src/transition/attr.js @@ -0,0 +1,58 @@ +import "../core/ns"; +import "../interpolate/interpolate"; +import "../interpolate/transform"; +import "transition"; +import "tween"; + +d3_transitionPrototype.attr = function(nameNS, value) { + if (arguments.length < 2) { + + // For attr(object), the object specifies the names and values of the + // attributes to transition. The values may be functions that are + // evaluated for each element. + for (value in nameNS) this.attr(value, nameNS[value]); + return this; + } + + var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, + name = d3.ns.qualify(nameNS); + + // For attr(string, null), remove the attribute with the specified name. + function attrNull() { + this.removeAttribute(name); + } + function attrNullNS() { + this.removeAttributeNS(name.space, name.local); + } + + // For attr(string, string), set the attribute with the specified name. + function attrTween(b) { + return b == null ? attrNull : (b += "", function() { + var a = this.getAttribute(name), i; + return a !== b && (i = interpolate(a, b), function(t) { this.setAttribute(name, i(t)); }); + }); + } + function attrTweenNS(b) { + return b == null ? attrNullNS : (b += "", function() { + var a = this.getAttributeNS(name.space, name.local), i; + return a !== b && (i = interpolate(a, b), function(t) { this.setAttributeNS(name.space, name.local, i(t)); }); + }); + } + + return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween); +}; + +d3_transitionPrototype.attrTween = function(nameNS, tween) { + var name = d3.ns.qualify(nameNS); + + function attrTween(d, i) { + var f = tween.call(this, d, i, this.getAttribute(name)); + return f && function(t) { this.setAttribute(name, f(t)); }; + } + function attrTweenNS(d, i) { + var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local)); + return f && function(t) { this.setAttributeNS(name.space, name.local, f(t)); }; + } + + return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween); +}; diff --git a/node_modules/@plotly/d3/src/transition/delay.js b/node_modules/@plotly/d3/src/transition/delay.js new file mode 100644 index 0000000000000000000000000000000000000000..068e040714066776673322b143537c86fecd9942 --- /dev/null +++ b/node_modules/@plotly/d3/src/transition/delay.js @@ -0,0 +1,10 @@ +import "../selection/each"; +import "transition"; + +d3_transitionPrototype.delay = function(value) { + var id = this.id, ns = this.namespace; + if (arguments.length < 1) return this.node()[ns][id].delay; + return d3_selection_each(this, typeof value === "function" + ? function(node, i, j) { node[ns][id].delay = +value.call(node, node.__data__, i, j); } + : (value = +value, function(node) { node[ns][id].delay = value; })); +}; diff --git a/node_modules/@plotly/d3/src/transition/duration.js b/node_modules/@plotly/d3/src/transition/duration.js new file mode 100644 index 0000000000000000000000000000000000000000..c9db2dc1a10587f37e2fe84cd08618b95ee1c99c --- /dev/null +++ b/node_modules/@plotly/d3/src/transition/duration.js @@ -0,0 +1,10 @@ +import "../selection/each"; +import "transition"; + +d3_transitionPrototype.duration = function(value) { + var id = this.id, ns = this.namespace; + if (arguments.length < 1) return this.node()[ns][id].duration; + return d3_selection_each(this, typeof value === "function" + ? function(node, i, j) { node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j)); } + : (value = Math.max(1, value), function(node) { node[ns][id].duration = value; })); +}; diff --git a/node_modules/@plotly/d3/src/transition/each.js b/node_modules/@plotly/d3/src/transition/each.js new file mode 100644 index 0000000000000000000000000000000000000000..f1b2057a9845468f3990a35be42757a59610fad1 --- /dev/null +++ b/node_modules/@plotly/d3/src/transition/each.js @@ -0,0 +1,26 @@ +import "../selection/each"; +import "transition"; + +d3_transitionPrototype.each = function(type, listener) { + var id = this.id, ns = this.namespace; + if (arguments.length < 2) { + var inherit = d3_transitionInherit, + inheritId = d3_transitionInheritId; + try { + d3_transitionInheritId = id; + d3_selection_each(this, function(node, i, j) { + d3_transitionInherit = node[ns][id]; + type.call(node, node.__data__, i, j); + }); + } finally { + d3_transitionInherit = inherit; + d3_transitionInheritId = inheritId; + } + } else { + d3_selection_each(this, function(node) { + var transition = node[ns][id]; + (transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener); + }); + } + return this; +}; diff --git a/node_modules/@plotly/d3/src/transition/ease.js b/node_modules/@plotly/d3/src/transition/ease.js new file mode 100644 index 0000000000000000000000000000000000000000..5c3564d465e9cb715c5fb4afe9b2d348cc8911bf --- /dev/null +++ b/node_modules/@plotly/d3/src/transition/ease.js @@ -0,0 +1,10 @@ +import "../interpolate/ease"; +import "../selection/each"; +import "transition"; + +d3_transitionPrototype.ease = function(value) { + var id = this.id, ns = this.namespace; + if (arguments.length < 1) return this.node()[ns][id].ease; + if (typeof value !== "function") value = d3.ease.apply(d3, arguments); + return d3_selection_each(this, function(node) { node[ns][id].ease = value; }); +}; diff --git a/node_modules/@plotly/d3/src/transition/filter.js b/node_modules/@plotly/d3/src/transition/filter.js new file mode 100644 index 0000000000000000000000000000000000000000..7e0e13a3421acd6c302af1b4c653d7d0a42562ac --- /dev/null +++ b/node_modules/@plotly/d3/src/transition/filter.js @@ -0,0 +1,22 @@ +import "../selection/filter"; +import "transition"; + +d3_transitionPrototype.filter = function(filter) { + var subgroups = [], + subgroup, + group, + node; + + if (typeof filter !== "function") filter = d3_selection_filter(filter); + + for (var j = 0, m = this.length; j < m; j++) { + subgroups.push(subgroup = []); + for (var group = this[j], i = 0, n = group.length; i < n; i++) { + if ((node = group[i]) && filter.call(node, node.__data__, i, j)) { + subgroup.push(node); + } + } + } + + return d3_transition(subgroups, this.namespace, this.id); +}; diff --git a/node_modules/@plotly/d3/src/transition/index.js b/node_modules/@plotly/d3/src/transition/index.js new file mode 100644 index 0000000000000000000000000000000000000000..c2a6702ff1f692fd3322b35f7e8d7ee49dc0c938 --- /dev/null +++ b/node_modules/@plotly/d3/src/transition/index.js @@ -0,0 +1 @@ +import "transition"; diff --git a/node_modules/@plotly/d3/src/transition/remove.js b/node_modules/@plotly/d3/src/transition/remove.js new file mode 100644 index 0000000000000000000000000000000000000000..8e6e56976f50b9097a0b8e503bd9dcaa4ad76899 --- /dev/null +++ b/node_modules/@plotly/d3/src/transition/remove.js @@ -0,0 +1,9 @@ +import "transition"; + +d3_transitionPrototype.remove = function() { + var ns = this.namespace; + return this.each("end.transition", function() { + var p; + if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this); + }); +}; diff --git a/node_modules/@plotly/d3/src/transition/select.js b/node_modules/@plotly/d3/src/transition/select.js new file mode 100644 index 0000000000000000000000000000000000000000..e537368f85eaac9b77c1cbb09a767b8dd6d277a3 --- /dev/null +++ b/node_modules/@plotly/d3/src/transition/select.js @@ -0,0 +1,28 @@ +import "../selection/select"; +import "transition"; + +d3_transitionPrototype.select = function(selector) { + var id = this.id, + ns = this.namespace, + subgroups = [], + subgroup, + subnode, + node; + + selector = d3_selection_selector(selector); + + for (var j = -1, m = this.length; ++j < m;) { + subgroups.push(subgroup = []); + for (var group = this[j], i = -1, n = group.length; ++i < n;) { + if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) { + if ("__data__" in node) subnode.__data__ = node.__data__; + d3_transitionNode(subnode, i, ns, id, node[ns][id]); + subgroup.push(subnode); + } else { + subgroup.push(null); + } + } + } + + return d3_transition(subgroups, ns, id); +}; diff --git a/node_modules/@plotly/d3/src/transition/selectAll.js b/node_modules/@plotly/d3/src/transition/selectAll.js new file mode 100644 index 0000000000000000000000000000000000000000..5500d90f17f3260315247ce8a5d69d2ba1c1b963 --- /dev/null +++ b/node_modules/@plotly/d3/src/transition/selectAll.js @@ -0,0 +1,31 @@ +import "../selection/selectAll"; +import "transition"; + +d3_transitionPrototype.selectAll = function(selector) { + var id = this.id, + ns = this.namespace, + subgroups = [], + subgroup, + subnodes, + node, + subnode, + transition; + + selector = d3_selection_selectorAll(selector); + + for (var j = -1, m = this.length; ++j < m;) { + for (var group = this[j], i = -1, n = group.length; ++i < n;) { + if (node = group[i]) { + transition = node[ns][id]; + subnodes = selector.call(node, node.__data__, i, j); + subgroups.push(subgroup = []); + for (var k = -1, o = subnodes.length; ++k < o;) { + if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition); + subgroup.push(subnode); + } + } + } + } + + return d3_transition(subgroups, ns, id); +}; diff --git a/node_modules/@plotly/d3/src/transition/style.js b/node_modules/@plotly/d3/src/transition/style.js new file mode 100644 index 0000000000000000000000000000000000000000..313c2a4c47ce879e9ac2cff88531b17810d898b9 --- /dev/null +++ b/node_modules/@plotly/d3/src/transition/style.js @@ -0,0 +1,53 @@ +import "../core/document"; +import "../interpolate/interpolate"; +import "transition"; +import "tween"; + +d3_transitionPrototype.style = function(name, value, priority) { + var n = arguments.length; + if (n < 3) { + + // For style(object) or style(object, string), the object specifies the + // names and values of the attributes to set or remove. The values may be + // functions that are evaluated for each element. The optional string + // specifies the priority. + if (typeof name !== "string") { + if (n < 2) value = ""; + for (priority in name) this.style(priority, name[priority], value); + return this; + } + + // For style(string, string) or style(string, function), use the default + // priority. The priority is ignored for style(string, null). + priority = ""; + } + + // For style(name, null) or style(name, null, priority), remove the style + // property with the specified name. The priority is ignored. + function styleNull() { + this.style.removeProperty(name); + } + + // For style(name, string) or style(name, string, priority), set the style + // property with the specified name, using the specified priority. + // Otherwise, a name, value and priority are specified, and handled as below. + function styleString(b) { + return b == null ? styleNull : (b += "", function() { + var a = d3_window(this).getComputedStyle(this, null).getPropertyValue(name), i; + return a !== b && (i = d3_interpolate(a, b), function(t) { this.style.setProperty(name, i(t), priority); }); + }); + } + + return d3_transition_tween(this, "style." + name, value, styleString); +}; + +d3_transitionPrototype.styleTween = function(name, tween, priority) { + if (arguments.length < 3) priority = ""; + + function styleTween(d, i) { + var f = tween.call(this, d, i, d3_window(this).getComputedStyle(this, null).getPropertyValue(name)); + return f && function(t) { this.style.setProperty(name, f(t), priority); }; + } + + return this.tween("style." + name, styleTween); +}; diff --git a/node_modules/@plotly/d3/src/transition/subtransition.js b/node_modules/@plotly/d3/src/transition/subtransition.js new file mode 100644 index 0000000000000000000000000000000000000000..7b2229e8d37e108becfdf86360cfe8d9c784dffb --- /dev/null +++ b/node_modules/@plotly/d3/src/transition/subtransition.js @@ -0,0 +1,25 @@ +import "transition"; + +d3_transitionPrototype.transition = function() { + var id0 = this.id, + id1 = ++d3_transitionId, + ns = this.namespace, + subgroups = [], + subgroup, + group, + node, + transition; + + for (var j = 0, m = this.length; j < m; j++) { + subgroups.push(subgroup = []); + for (var group = this[j], i = 0, n = group.length; i < n; i++) { + if (node = group[i]) { + transition = node[ns][id0]; + d3_transitionNode(node, i, ns, id1, {time: transition.time, ease: transition.ease, delay: transition.delay + transition.duration, duration: transition.duration}); + } + subgroup.push(node); + } + } + + return d3_transition(subgroups, ns, id1); +}; diff --git a/node_modules/@plotly/d3/src/transition/text.js b/node_modules/@plotly/d3/src/transition/text.js new file mode 100644 index 0000000000000000000000000000000000000000..0e2455a27db94490a21fda7b53cb081338481945 --- /dev/null +++ b/node_modules/@plotly/d3/src/transition/text.js @@ -0,0 +1,11 @@ +import "transition"; +import "tween"; + +d3_transitionPrototype.text = function(value) { + return d3_transition_tween(this, "text", value, d3_transition_text); +}; + +function d3_transition_text(b) { + if (b == null) b = ""; + return function() { this.textContent = b; }; +} diff --git a/node_modules/@plotly/d3/src/transition/transition.js b/node_modules/@plotly/d3/src/transition/transition.js new file mode 100644 index 0000000000000000000000000000000000000000..15af4e06fb5efee6f11fdcede7ea5028ab9244ab --- /dev/null +++ b/node_modules/@plotly/d3/src/transition/transition.js @@ -0,0 +1,161 @@ +import "../arrays/map"; +import "../core/subclass"; +import "../core/true"; +import "../event/dispatch"; +import "../event/timer"; +import "../selection/selection"; +import "../selection/transition"; +import "../selection/interrupt"; + +function d3_transition(groups, ns, id) { + d3_subclass(groups, d3_transitionPrototype); + + // Note: read-only! + groups.namespace = ns; + groups.id = id; + + return groups; +} + +var d3_transitionPrototype = [], + d3_transitionId = 0, + d3_transitionInheritId, + d3_transitionInherit; + +d3_transitionPrototype.call = d3_selectionPrototype.call; +d3_transitionPrototype.empty = d3_selectionPrototype.empty; +d3_transitionPrototype.node = d3_selectionPrototype.node; +d3_transitionPrototype.size = d3_selectionPrototype.size; + +d3.transition = function(selection, name) { + return selection && selection.transition + ? (d3_transitionInheritId ? selection.transition(name) : selection) + : d3.selection().transition(selection); +}; + +d3.transition.prototype = d3_transitionPrototype; + +import "select"; +import "selectAll"; +import "filter"; +import "attr"; +import "style"; +import "text"; +import "remove"; +import "ease"; +import "delay"; +import "duration"; +import "each"; +import "subtransition"; +import "tween"; + +function d3_transitionNamespace(name) { + return name == null ? "__transition__" : "__transition_" + name + "__"; +} + +function d3_transitionNode(node, i, ns, id, inherit) { + var lock = node[ns] || (node[ns] = {active: 0, count: 0}), + transition = lock[id], + time, + timer, + duration, + ease, + tweens; + + function schedule(elapsed) { + var delay = transition.delay; + timer.t = delay + time; + if (delay <= elapsed) return start(elapsed - delay); + timer.c = start; + } + + function start(elapsed) { + + // Interrupt the active transition, if any. + var activeId = lock.active, + active = lock[activeId]; + if (active) { + active.timer.c = null; + active.timer.t = NaN; + --lock.count; + delete lock[activeId]; + active.event && active.event.interrupt.call(node, node.__data__, active.index); + } + + // Cancel any pre-empted transitions. No interrupt event is dispatched + // because the cancelled transitions never started. + for (var cancelId in lock) { + if (+cancelId < id) { + var cancel = lock[cancelId]; + cancel.timer.c = null; + cancel.timer.t = NaN; + --lock.count; + delete lock[cancelId]; + } + } + + // Defer tween invocation to end of current frame; see mbostock/d3#1576. + // Note that this transition may be canceled before then! + // This must be scheduled before the start event; see d3/d3-transition#16! + timer.c = tick; + d3_timer(function() { + if (timer.c && tick(elapsed || 1)) { + timer.c = null; + timer.t = NaN; + } + return 1; + }, 0, time); + + // Start the transition. + lock.active = id; + transition.event && transition.event.start.call(node, node.__data__, i); + + // Initialize the tweens. + tweens = []; + transition.tween.forEach(function(key, value) { + if (value = value.call(node, node.__data__, i)) { + tweens.push(value); + } + }); + + // Defer capture to allow tween initialization to set ease & duration. + ease = transition.ease; + duration = transition.duration; + } + + function tick(elapsed) { + var t = elapsed / duration, + e = ease(t), + n = tweens.length; + + while (n > 0) { + tweens[--n].call(node, e); + } + + if (t >= 1) { + transition.event && transition.event.end.call(node, node.__data__, i); + if (--lock.count) delete lock[id]; + else delete node[ns]; + return 1; + } + } + + if (!transition) { + time = inherit.time; + timer = d3_timer(schedule, 0, time); + + transition = lock[id] = { + tween: new d3_Map, + time: time, + timer: timer, + delay: inherit.delay, + duration: inherit.duration, + ease: inherit.ease, + index: i + }; + + inherit = null; // allow gc + + ++lock.count; + } +} diff --git a/node_modules/@plotly/d3/src/transition/tween.js b/node_modules/@plotly/d3/src/transition/tween.js new file mode 100644 index 0000000000000000000000000000000000000000..108daa96bda1dd89e45d5f0078898c38e53134a1 --- /dev/null +++ b/node_modules/@plotly/d3/src/transition/tween.js @@ -0,0 +1,17 @@ +import "../selection/each"; +import "transition"; + +d3_transitionPrototype.tween = function(name, tween) { + var id = this.id, ns = this.namespace; + if (arguments.length < 2) return this.node()[ns][id].tween.get(name); + return d3_selection_each(this, tween == null + ? function(node) { node[ns][id].tween.remove(name); } + : function(node) { node[ns][id].tween.set(name, tween); }); +}; + +function d3_transition_tween(groups, name, value, tween) { + var id = groups.id, ns = groups.namespace; + return d3_selection_each(groups, typeof value === "function" + ? function(node, i, j) { node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j))); } + : (value = tween(value), function(node) { node[ns][id].tween.set(name, value); })); +} diff --git a/node_modules/@plotly/d3/src/xhr/html.js b/node_modules/@plotly/d3/src/xhr/html.js new file mode 100644 index 0000000000000000000000000000000000000000..d42283b9fe98350d055ecb8001e6907104475ff6 --- /dev/null +++ b/node_modules/@plotly/d3/src/xhr/html.js @@ -0,0 +1,12 @@ +import "../core/document"; +import "xhr"; + +d3.html = function(url, callback) { + return d3_xhr(url, "text/html", d3_html, callback); +}; + +function d3_html(request) { + var range = d3_document.createRange(); + range.selectNode(d3_document.body); + return range.createContextualFragment(request.responseText); +} diff --git a/node_modules/@plotly/d3/src/xhr/index.js b/node_modules/@plotly/d3/src/xhr/index.js new file mode 100644 index 0000000000000000000000000000000000000000..c71b4666a2c88e5c3d424a84dbbc225aa7950b47 --- /dev/null +++ b/node_modules/@plotly/d3/src/xhr/index.js @@ -0,0 +1,5 @@ +import "xhr"; +import "text"; +import "json"; +import "html"; +import "xml"; diff --git a/node_modules/@plotly/d3/src/xhr/json.js b/node_modules/@plotly/d3/src/xhr/json.js new file mode 100644 index 0000000000000000000000000000000000000000..f51bc2c047948e501de8704ea4fb3370580b7979 --- /dev/null +++ b/node_modules/@plotly/d3/src/xhr/json.js @@ -0,0 +1,9 @@ +import "xhr"; + +d3.json = function(url, callback) { + return d3_xhr(url, "application/json", d3_json, callback); +}; + +function d3_json(request) { + return JSON.parse(request.responseText); +} diff --git a/node_modules/@plotly/d3/src/xhr/text.js b/node_modules/@plotly/d3/src/xhr/text.js new file mode 100644 index 0000000000000000000000000000000000000000..1f51e3dca2fba1ca821ac9e475189b84b292872c --- /dev/null +++ b/node_modules/@plotly/d3/src/xhr/text.js @@ -0,0 +1,5 @@ +import "xhr"; + +d3.text = d3_xhrType(function(request) { + return request.responseText; +}); diff --git a/node_modules/@plotly/d3/src/xhr/xhr.js b/node_modules/@plotly/d3/src/xhr/xhr.js new file mode 100644 index 0000000000000000000000000000000000000000..66706a5e5565384b6a1a1837b17be3d5f897d8d2 --- /dev/null +++ b/node_modules/@plotly/d3/src/xhr/xhr.js @@ -0,0 +1,126 @@ +import "../core/array"; +import "../core/document"; +import "../core/identity"; +import "../core/rebind"; +import "../event/dispatch"; + +d3.xhr = d3_xhrType(d3_identity); + +function d3_xhrType(response) { + return function(url, mimeType, callback) { + if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType, mimeType = null; + return d3_xhr(url, mimeType, response, callback); + }; +} + +function d3_xhr(url, mimeType, response, callback) { + var xhr = {}, + dispatch = d3.dispatch("beforesend", "progress", "load", "error"), + headers = {}, + request = new XMLHttpRequest, + responseType = null; + + // If IE does not support CORS, use XDomainRequest. + if (self.XDomainRequest + && !("withCredentials" in request) + && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest; + + "onload" in request + ? request.onload = request.onerror = respond + : request.onreadystatechange = function() { request.readyState > 3 && respond(); }; + + function respond() { + var status = request.status, result; + if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) { + try { + result = response.call(xhr, request); + } catch (e) { + dispatch.error.call(xhr, e); + return; + } + dispatch.load.call(xhr, result); + } else { + dispatch.error.call(xhr, request); + } + } + + request.onprogress = function(event) { + var o = d3.event; + d3.event = event; + try { dispatch.progress.call(xhr, request); } + finally { d3.event = o; } + }; + + xhr.header = function(name, value) { + name = (name + "").toLowerCase(); + if (arguments.length < 2) return headers[name]; + if (value == null) delete headers[name]; + else headers[name] = value + ""; + return xhr; + }; + + // If mimeType is non-null and no Accept header is set, a default is used. + xhr.mimeType = function(value) { + if (!arguments.length) return mimeType; + mimeType = value == null ? null : value + ""; + return xhr; + }; + + // Specifies what type the response value should take; + // for instance, arraybuffer, blob, document, or text. + xhr.responseType = function(value) { + if (!arguments.length) return responseType; + responseType = value; + return xhr; + }; + + // Specify how to convert the response content to a specific type; + // changes the callback value on "load" events. + xhr.response = function(value) { + response = value; + return xhr; + }; + + // Convenience methods. + ["get", "post"].forEach(function(method) { + xhr[method] = function() { + return xhr.send.apply(xhr, [method].concat(d3_array(arguments))); + }; + }); + + // If callback is non-null, it will be used for error and load events. + xhr.send = function(method, data, callback) { + if (arguments.length === 2 && typeof data === "function") callback = data, data = null; + request.open(method, url, true); + if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*"; + if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]); + if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType); + if (responseType != null) request.responseType = responseType; + if (callback != null) xhr.on("error", callback).on("load", function(request) { callback(null, request); }); + dispatch.beforesend.call(xhr, request); + request.send(data == null ? null : data); + return xhr; + }; + + xhr.abort = function() { + request.abort(); + return xhr; + }; + + d3.rebind(xhr, dispatch, "on"); + + return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback)); +}; + +function d3_xhr_fixCallback(callback) { + return callback.length === 1 + ? function(error, request) { callback(error == null ? request : null); } + : callback; +} + +function d3_xhrHasResponse(request) { + var type = request.responseType; + return type && type !== "text" + ? request.response // null on error + : request.responseText; // "" on error +} diff --git a/node_modules/@plotly/d3/src/xhr/xml.js b/node_modules/@plotly/d3/src/xhr/xml.js new file mode 100644 index 0000000000000000000000000000000000000000..09c18e21702a92fb9425925d19e06c434cb42d54 --- /dev/null +++ b/node_modules/@plotly/d3/src/xhr/xml.js @@ -0,0 +1,5 @@ +import "xhr"; + +d3.xml = d3_xhrType(function(request) { + return request.responseXML; +}); diff --git a/node_modules/@plotly/mapbox-gl/.flowconfig b/node_modules/@plotly/mapbox-gl/.flowconfig new file mode 100644 index 0000000000000000000000000000000000000000..5eac8c94d0fd184b8d7417bad0128a9bce4403d9 --- /dev/null +++ b/node_modules/@plotly/mapbox-gl/.flowconfig @@ -0,0 +1,61 @@ +[ignore] +.*\.svg +.*\.png +.*/\.nyc_output/.* +.*/docs/.* +.*/node_modules/.cache/.* +.*/node_modules/.*/tests?/.* +.*/node_modules/@mapbox/jsonlint-lines-primitives/.* +.*/node_modules/@mapbox/mvt-fixtures/.* +.*/node_modules/@mapbox/geojson-types/fixtures/.* +.*/node_modules/@mapbox/mr-ui/.* +.*/node_modules/@mapbox/dr-ui/.* +.*/node_modules/@mapbox/batfish/.* +.*/node_modules/browserify/.* +.*/node_modules/browser-sync.*/.* +.*/node_modules/nyc/.* +.*/node_modules/fbjs/.* +.*/node_modules/es5-ext/.* +.*/node_modules/jsdom/.* +.*/node_modules/eslint.*/.* +.*/node_modules/highlight.*/.* +.*/node_modules/rxjs/.* +.*/node_modules/@?babel.*/.* +.*/node_modules/react.*/.* +.*/node_modules/svgo/.* +.*/node_modules/moment/.* +.*/node_modules/regenerate-unicode-properties/.* +.*/node_modules/remark.*/.* +.*/node_modules/webpack/.* +.*/node_modules/caniuse-lite/.* +.*/node_modules/d3.*/.* +.*/node_modules/css-tree/.* +.*/node_modules/lodash/.* +.*/node_modules/fsevents/.* +.*/node_modules/browser-sync-client/.* +.*/node_modules/core-js.*/.* +.*/node_modules/stylelint/.* +.*/node_modules/postcss.*/.* +.*/node_modules/prismjs.*/.* +.*/node_modules/documentation/.* +.*/node_modules/module-deps/.* +.*/test/unit/style-spec/fixture/invalidjson.input.json +.*/render-tests/.* +.*/query-tests/.* +.*/expression-tests/.* +.*/test/build/downstream-flow-fixture/.* +.*/_batfish_tmp/.* +.*/_site/.* + +[version] +0.100.0 + +[options] +server.max_workers=4 + +[strict] +nonstrict-import +unclear-type +untyped-import +untyped-type-import +sketchy-null diff --git a/node_modules/@plotly/mapbox-gl/CHANGELOG.md b/node_modules/@plotly/mapbox-gl/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..d5987afbc66f9076506680f9a1525c31553dd987 --- /dev/null +++ b/node_modules/@plotly/mapbox-gl/CHANGELOG.md @@ -0,0 +1,2499 @@ +## 1.13.4 + +### 🐞 Bug fixes + +* Ensure loseContext function exists before try calling it + +## 1.13.3 + +### 🐞 Bug fixes + +* Fix incorrect billing when `customAccessToken` is provided along with non-Mapbox tiles ([#12520](https://github.com/mapbox/mapbox-gl-js/issues/12520)) +* Prevent video sources from entering fullscreen on iOS Safari ([#11067](https://github.com/mapbox/mapbox-gl-js/issues/11067)) +* Upgrade minimist to ^1.2.7 to avoid [CVE-2021-44906](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-44906) ([#12442](https://github.com/mapbox/mapbox-gl-js/issues/12442)) (h/t @Spasfonx) + +## 1.13.2 + +### 🐞 Bug fixes + +* Fix an iOS 15 issue where the iOS Safari tab bar interrupts touch interactions. ([#11084](https://github.com/mapbox/mapbox-gl-js/pull/11084)) + +## 1.13.1 + +### 🐞 Bug fixes +- Fix ImageSource not working in some cases in Firefox & Safari. [#10230](https://github.com/mapbox/mapbox-gl-js/pull/10230) + +## 1.13.0 + +### ✨ Features and improvements + +- Improve accessibility by fixing issues reported by WCAG 2.1. [#9991](https://github.com/mapbox/mapbox-gl-js/pull/9991) +- Improve accessibility when opening a popup by immediately focusing on the content. [#9774](https://github.com/mapbox/mapbox-gl-js/pull/9774) (h/t @watofundefined) +- Improve rendering performance of symbols with `symbol-sort-key`. [#9751](https://github.com/mapbox/mapbox-gl-js/pull/9751) (h/t @osvodef) +- Add `Marker` `clickTolerance` option. [#9640](https://github.com/mapbox/mapbox-gl-js/pull/9640) (h/t @ChristopherChudzicki) +- Add `Map` `hasControl` method. [#10035](https://github.com/mapbox/mapbox-gl-js/pull/10035) +- Add `Popup` `setOffset` method. [#9946](https://github.com/mapbox/mapbox-gl-js/pull/9946) (h/t @jutaz) +- Add `KeyboardHandler` `disableRotation` and `enableRotation` methods. [#10072](https://github.com/mapbox/mapbox-gl-js/pull/10072) (h/t @jmbott) + +### 🐞 Bug fixes + +- Fix a bug where `queryRenderedFeatures` didn't properly expose the paint values if they were data-driven. [#10074](https://github.com/mapbox/mapbox-gl-js/pull/10074) (h/t @osvodef) +- Fix a bug where attribution didn't update when layer visibility changed during zooming. [#9943](https://github.com/mapbox/mapbox-gl-js/pull/9943) +- Fix a bug where hash control conflicted with external history manipulation (e.g. in single-page apps). [#9960](https://github.com/mapbox/mapbox-gl-js/pull/9960) (h/t @raegen) +- Fix a bug where `fitBounds` had an unexpected result with non-zero bearing and uneven padding. [#9821](https://github.com/mapbox/mapbox-gl-js/pull/9821) (h/t @allison-strandberg) +- Fix HTTP support when running GL JS against [Mapbox Atlas](https://www.mapbox.com/atlas). [#10090](https://github.com/mapbox/mapbox-gl-js/pull/10090) +- Fix a bug where the `within` expression didn't work in `querySourceFeatures`. [#9933](https://github.com/mapbox/mapbox-gl-js/pull/9933) +- Fix a bug where `Popup` content HTML element was removed on `setDOMContent`. [#10036](https://github.com/mapbox/mapbox-gl-js/pull/10036) +- Fix a compatibility bug when `icon-image` is used as a legacy categorical function. [#10060](https://github.com/mapbox/mapbox-gl-js/pull/10060) +- Reduce rapid memory growth in Safari by ensuring `Image` dataURI's are released. [#10118](https://github.com/mapbox/mapbox-gl-js/pull/10118) + +### ⚠️ Note on IE11 + +We intend to remove support for Internet Explorer 11 in a future release of GL JS later this year. + +## 1.12.0 + +### ✨ Features and improvements + +* Add methods for changing a vector tile source dynamically (e.g. `setTiles`, `setUrl`). [#8048](https://github.com/mapbox/mapbox-gl-js/pull/8048) (h/t [@stepankuzmin](https://github.com/stepankuzmin)) +* Add a `filter` option for GeoJSON sources to filter out features prior to processing (e.g. before clustering). [#9864](https://github.com/mapbox/mapbox-gl-js/pull/9864) +* Vastly increase precision of `line-gradient` for long lines. [#9694](https://github.com/mapbox/mapbox-gl-js/pull/9694) +* Improve `raster-dem` sources to properly support the `maxzoom` option and overzooming. [#9789](https://github.com/mapbox/mapbox-gl-js/pull/9789) (h/t [@brendan-ward](@brendanhttps://github.com/ward)) + +### 🐞 Bug fixes + +* Fix a bug where bearing snap interfered with `easeTo` and `flyTo` animations, freezing the map. [#9884](https://github.com/mapbox/mapbox-gl-js/pull/9884) (h/t [@andycalder](https://github.com/andycalder)) +* Fix a bug where a fallback image was not used if it was added via `addImage`. [#9911](https://github.com/mapbox/mapbox-gl-js/pull/9911) (h/t [@francois2metz](https://github.com/francois2metz)) +* Fix a bug where `promoteId` option failed for fill extrusions with defined feature ids. [#9863](https://github.com/mapbox/mapbox-gl-js/pull/9863) + +### 🛠️ Workflow + +* Renamed the default development branch from `master` to `main`. + +## 1.11.1 + +### 🐞 Bug fixes +* Fix a bug that caused `map.loaded()` to incorrectly return `false` after a click event. ([#9825](https://github.com/mapbox/mapbox-gl-js/pull/9825)) + +## 1.11.0 + +### ✨ Features and improvements +* Add an option to scale the default `Marker` icon.([#9414](https://github.com/mapbox/mapbox-gl-js/pull/9414)) (h/t [adrianababakanian](https://github.com/adrianababakanian)) +* Improving the shader compilation speed by manually getting the run-time attributes and uniforms.([#9497](https://github.com/mapbox/mapbox-gl-js/pull/9497)) +* Added `clusterMinPoints` option for clustered GeoJSON sources that defines the minimum number of points to form a cluster.([#9748](https://github.com/mapbox/mapbox-gl-js/pull/9748)) + +### 🐞 Bug fixes +* Fix a bug where map got stuck in a DragRotate interaction if it's mouseup occurred outside of the browser window or iframe.([#9512](https://github.com/mapbox/mapbox-gl-js/pull/9512)) +* Fix potential visual regression for `*-pattern` properties on AMD graphics card vendor.([#9681](https://github.com/mapbox/mapbox-gl-js/pull/9681)) +* Fix zooming with a double tap on iOS Safari 13.([#9757](https://github.com/mapbox/mapbox-gl-js/pull/9757)) +* Removed a misleading `geometry exceeds allowed extent` warning when using Mapbox Streets vector tiles.([#9753](https://github.com/mapbox/mapbox-gl-js/pull/9753)) +* Fix reference error when requiring the browser bundle in Node. ([#9749](https://github.com/mapbox/mapbox-gl-js/pull/9749)) + +## 1.10.2 + +### 🐞 Bug fixes +* Fix zooming with a double tap in iOS Safari 13.([#9757](https://github.com/mapbox/mapbox-gl-js/pull/9757)) + +## 1.10.1 + +### 🐞 Bug fixes +* Fix markers interrupting touch gestures ([#9675](https://github.com/mapbox/mapbox-gl-js/issues/9675), fixed by [#9683](https://github.com/mapbox/mapbox-gl-js/pull/9683)) +* Fix bug where `map.isMoving()` returned true while map was not moving ([#9647](https://github.com/mapbox/mapbox-gl-js/issues/9647), fixed by [#9679](https://github.com/mapbox/mapbox-gl-js/pull/9679)) +* Fix regression that prevented `touchmove` events from firing during gestures ([#9676](https://github.com/mapbox/mapbox-gl-js/issues/9676), fixed by [#9685](https://github.com/mapbox/mapbox-gl-js/pull/9685)) +* Fix `image` expression evaluation which was broken under certain conditions ([#9630](https://github.com/mapbox/mapbox-gl-js/issues/9630), fixed by [#9685](https://github.com/mapbox/mapbox-gl-js/pull/9668)) +* Fix nested `within` expressions in filters not evaluating correctly ([#9605](https://github.com/mapbox/mapbox-gl-js/issues/9605), fixed by [#9611](https://github.com/mapbox/mapbox-gl-js/pull/9611)) +* Fix potential `undefined` paint variable in `StyleLayer` ([#9688](https://github.com/mapbox/mapbox-gl-js/pull/9688)) (h/t [mannnick24](https://github.com/mannnick24)) + +## 1.10.0 + +### ✨ Features +* Add `mapboxgl.prewarm()` and `mapboxgl.clearPrewarmedResources()` methods to allow developers to optimize load times for their maps ([#9391](https://github.com/mapbox/mapbox-gl-js/pull/9391)) +* Add `index-of` and `slice` expressions to search arrays and strings for the first occurrence of a specified value and return a section of the original array or string ([#9450](https://github.com/mapbox/mapbox-gl-js/pull/9450)) (h/t [lbutler](https://github.com/lbutler)) +* Correctly set RTL text plugin status if the plugin URL could not be loaded. This allows developers to add retry logic on network errors when loading the plugin ([#9489](https://github.com/mapbox/mapbox-gl-js/pull/9489)) + +### 🍏 Gestures +This release significantly refactors and improves gesture handling on desktop and mobile. Three new touch gestures have been added: `two-finger swipe` to adjust pitch, `two-finger double tap` to zoom out, and `tap then drag` to adjust zoom with one finger ([#9365](https://github.com/mapbox/mapbox-gl-js/pull/9365)). In addition, this release brings the following changes and bug fixes: + +- It's now possible to interact with multiple maps on the same page at the same time ([#9365](https://github.com/mapbox/mapbox-gl-js/pull/9365)) +- Fix map jump when releasing one finger after pinch zoom ([#9136](https://github.com/mapbox/mapbox-gl-js/issues/9136)) +- Stop mousedown and touchstart from interrupting `easeTo` animations when interaction handlers are disabled ([#8725](https://github.com/mapbox/mapbox-gl-js/issues/8725)) +- Stop mouse wheel from interrupting animations when `map.scrollZoom` is disabled ([#9230](https://github.com/mapbox/mapbox-gl-js/issues/9230)) +- A camera change can no longer be prevented by disabling the interaction handler within the camera change event. Selectively prevent camera changes by listening to the `mousedown` or `touchstart` map event and calling [.preventDefault()](https://docs.mapbox.com/mapbox-gl-js/api/#mapmouseevent#preventdefault) ([#9365](https://github.com/mapbox/mapbox-gl-js/pull/9365)) +- Undocumented properties on the camera change events fired by the doubleClickZoom handler have been removed ([#9365](https://github.com/mapbox/mapbox-gl-js/pull/9365)) + +### 🐞 Improvements and bug fixes +* Line labels now have improved collision detection, with greater precision in placement, reduced memory footprint, better placement under pitched camera orientations ([#9219](https://github.com/mapbox/mapbox-gl-js/pull/9219)) +* Fix `GlyphManager` continually re-requesting missing glyph ranges ([#8027](https://github.com/mapbox/mapbox-gl-js/issues/8027), fixed by [#9375](https://github.com/mapbox/mapbox-gl-js/pull/9375)) (h/t [oterral](https://github.com/oterral)) +* Avoid throwing errors when calling certain popup methods before the popup element is created ([#9433](https://github.com/mapbox/mapbox-gl-js/pull/9433)) +* Fix a bug where fill-extrusion features with colinear points were not returned by `map.queryRenderedFeatures(...)` ([#9454](https://github.com/mapbox/mapbox-gl-js/pull/9454)) +* Fix a bug where using feature state on a large input could cause a stack overflow error ([#9463](https://github.com/mapbox/mapbox-gl-js/pull/9463)) +* Fix exception when using `background-pattern` with data driven expressions ([#9518](https://github.com/mapbox/mapbox-gl-js/issues/9518), fixed by [#9520](https://github.com/mapbox/mapbox-gl-js/pull/9520)) +* Fix a bug where UI popups were potentially leaking event listeners ([#9498](https://github.com/mapbox/mapbox-gl-js/pull/9498)) (h/t [mbell697](https://github.com/mbell697)) +* Fix a bug where the `within` expression would return inconsistent values for points on tile boundaries ([#9411](https://github.com/mapbox/mapbox-gl-js/issues/9411), [#9428](https://github.com/mapbox/mapbox-gl-js/pull/9428)) +* Fix a bug where the `within` expression would incorrectly evaluate geometries that cross the antimeridian ([#9440](https://github.com/mapbox/mapbox-gl-js/pull/9440)) +* Fix possible undefined exception on paint variable of style layer ([#9437](https://github.com/mapbox/mapbox-gl-js/pull/9437)) (h/t [mannnick24](https://github.com/mannnick24)) +* Upgrade minimist to ^1.2.5 to get fix for security issue [CVE-2020-7598](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-7598) upstream ([#9425](https://github.com/mapbox/mapbox-gl-js/issues/9431), fixed by [#9425](https://github.com/mapbox/mapbox-gl-js/pull/9425)) (h/t [watson](https://github.com/watson)) + +## 1.9.1 + +### 🐞 Bug fixes +* Fix a bug [#9477](https://github.com/mapbox/mapbox-gl-js/issues/9477) in `Map#fitBounds(..)` wherein the `padding` passed to options would get applied twice. +* Fix rendering bug [#9479](https://github.com/mapbox/mapbox-gl-js/issues/9479) caused when data-driven `*-pattern` properties reference images added with `Map#addImage(..)`. +* Fix a bug [#9468](https://github.com/mapbox/mapbox-gl-js/issues/9468) in which an exception would get thrown when updating symbol layer paint property using `setPaintProperty`. + +## 1.9.0 +With this release, we're adding [a new changelog policy](./CONTRIBUTING.md#changelog-conventions) to our contribution guidelines. + +This release also fixes several long-standing bugs and unintentional rendering behavior with `line-pattern`. The fixes come with a visual change to how patterns added with `line-pattern` scale. Previously, patterns that became larger than the line would be clipped, sometimes distorting the pattern, particularly on mobile and retina devices. Now the pattern will be scaled to fit under all circumstances. [#9266](https://github.com/mapbox/mapbox-gl-js/pull/9266) showcases examples of the visual differences. For more information and to provide feedback on this change, see [#9394](https://github.com/mapbox/mapbox-gl-js/pull/9394). + +### ✨ Features +* Add `within` expression for testing whether an evaluated feature lies within a given GeoJSON object ([#9352](https://github.com/mapbox/mapbox-gl-js/pull/9352)). + - We are aware of an edge case in which points with wrapped coordinates (e.g. longitude -185) are not evaluated properly. See ([#9442](https://github.com/mapbox/mapbox-gl-js/issues/9442)) for more information. + - An example of the `within` expression:
+`"icon-opacity": ["case", ["==", ["within", "some-polygon"], true], 1, +["==", ["within", "some-polygon"], false], 0]` +* Map API functions such as `easeTo` and `flyTo` now support `padding: PaddingOptions` which lets developers shift a map's center of perspective when building floating sidebars ([#8638](https://github.com/mapbox/mapbox-gl-js/pull/8638)) + +### 🍏 Improvements +* Results from `queryRenderedFeatures` now have evaluated property values rather than raw expressions ([#9198](https://github.com/mapbox/mapbox-gl-js/pull/9198)) +* Improve scaling of patterns used in `line-pattern` on all device resolutions and pixel ratios ([#9266](https://github.com/mapbox/mapbox-gl-js/pull/9266)) +* Slightly improve GPU memory footprint ([#9377](https://github.com/mapbox/mapbox-gl-js/pull/9377)) +* `LngLatBounds.extend` is more flexible because it now accepts objects with `lat` and `lon` properties as well as arrays of coordinates ([#9293](https://github.com/mapbox/mapbox-gl-js/pull/9293)) +* Reduce bundle size and improve visual quality of `showTileBoundaries` debug text ([#9267](https://github.com/mapbox/mapbox-gl-js/pull/9267)) + +### 🐞 Bug fixes +* Correctly adjust patterns added with `addImage(id, image, pixelRatio)` by the asset pixel ratio, not the device pixel ratio ([#9372](https://github.com/mapbox/mapbox-gl-js/pull/9372)) +* Allow needle argument to `in` expression to be false ([#9295](https://github.com/mapbox/mapbox-gl-js/pull/9295)) +* Fix exception thrown when trying to set `feature-state` for a layer that has been removed, fixes [#8634](https://github.com/mapbox/mapbox-gl-js/issues/8634) ([#9305](https://github.com/mapbox/mapbox-gl-js/pull/9305)) +* Fix a bug where maps were not displaying inside elements with `dir=rtl` ([#9332](https://github.com/mapbox/mapbox-gl-js/pull/9332)) +* Fix a rendering error for very old versions of Chrome (ca. 2016) where text would appear much bigger than intended ([#9349](https://github.com/mapbox/mapbox-gl-js/pull/9349)) +* Prevent exception resulting from `line-dash-array` of empty length ([#9385](https://github.com/mapbox/mapbox-gl-js/pull/9385)) +* Fix a bug where `icon-image` expression that evaluates to an empty string (`''`) produced a warning ([#9380](https://github.com/mapbox/mapbox-gl-js/pull/9380)) +* Fix a bug where certain `popup` methods threw errors when accessing the container element before it was created, fixes [#9429](https://github.com/mapbox/mapbox-gl-js/issues/9429)([#9433](https://github.com/mapbox/mapbox-gl-js/pull/9433)) + +## 1.8.1 + +* Fixed a bug where all labels showed up on a diagonal line on Windows when using an integrated Intel GPU from the Haswell generation ([#9327](https://github.com/mapbox/mapbox-gl-js/issues/9327), fixed by reverting [#9229](https://github.com/mapbox/mapbox-gl-js/pull/9229)) + +## 1.8.0 + +### ✨ Features and improvements +* Reduce size of line atlas by removing unused channels ([#9232](https://github.com/mapbox/mapbox-gl-js/pull/9232)) +* Prevent empty buffers from being created for debug data when unused ([#9237](https://github.com/mapbox/mapbox-gl-js/pull/9237)) +* Add space between distance and unit in scale control ([#9276](https://github.com/mapbox/mapbox-gl-js/pull/9276)) (h/t [gely](https://api.github.com/users/gely)) and ([#9284](https://github.com/mapbox/mapbox-gl-js/pull/9284)) (h/t [pakastin](https://api.github.com/users/pakastin)) +* Add a `showAccuracyCircle` option to GeolocateControl that shows the accuracy of the user's location as a transparent circle. Mapbox GL JS will show this circle by default. ([#9253](https://github.com/mapbox/mapbox-gl-js/pull/9253)) (h/t [Meekohi](https://api.github.com/users/Meekohi)) +* Implemented a new tile coverage algorithm to enable level-of-detail support in a future release ([#8975](https://github.com/mapbox/mapbox-gl-js/pull/8975)) + +### 🐞 Bug fixes +* `line-dasharray` is now ignored correctly when `line-pattern` is set ([#9189](https://github.com/mapbox/mapbox-gl-js/pull/9189)) +* Fix line distances breaking gradient across tile boundaries ([#9220](https://github.com/mapbox/mapbox-gl-js/pull/9220)) +* Fix a bug where lines with duplicate endpoints could disappear at zoom 18+ ([#9218](https://github.com/mapbox/mapbox-gl-js/pull/9218)) +* Fix a bug where Ctrl-click to drag rotate the map was disabled if the Alt, Cmd or Windows key is also pressed ([#9203](https://github.com/mapbox/mapbox-gl-js/pull/9203)) +* Pass errors to `getClusterExpansionZoom`, `getClusterChildren`, and `getClusterLeaves` callbacks ([#9251](https://github.com/mapbox/mapbox-gl-js/pull/9251)) +* Fix a rendering performance regression ([#9261](https://github.com/mapbox/mapbox-gl-js/pull/9261)) +* Fix visual artifact for `line-dasharray` ([#9246](https://github.com/mapbox/mapbox-gl-js/pull/9246)) +* Fixed a bug in the GeolocateControl which resulted in an error when `trackUserLocation` was `false` and the control was removed before the Geolocation API had returned a location ([#9291](https://github.com/mapbox/mapbox-gl-js/pull/9291)) +* Fix `promoteId` for line layers ([#9210](https://github.com/mapbox/mapbox-gl-js/pull/9210)) +* Improve accuracy of distance calculations ([#9202](https://github.com/mapbox/mapbox-gl-js/pull/9202)) (h/t [Meekohi](https://api.github.com/users/Meekohi)) + + +## 1.7.0 + +### ✨ Features +* Add `promoteId` option to use a feature property as ID for feature state ([#8987](https://github.com/mapbox/mapbox-gl-js/pull/8987)) +* Add a new constructor option to `mapboxgl.Popup`, `closeOnMove`, that closes the popup when the map's position changes ([#9163](https://github.com/mapbox/mapbox-gl-js/pull/9163)) +* Allow creating a map without a style (an empty one will be created automatically) ( h/t @stepankuzmin ) ([#8924](https://github.com/mapbox/mapbox-gl-js/pull/8924)) +* `map.once()` now allows specifying a layer id as a third parameter making it consistent with `map.on()` ([#8875](https://github.com/mapbox/mapbox-gl-js/pull/8875)) + +### 🍏 Improvements +* Improve performance of raster layers on large screens ([#9050](https://github.com/mapbox/mapbox-gl-js/pull/9050)) +* Improve performance for hillshade and raster layers by implementing a progressive enhancement that utilizes `ImageBitmap` and `OffscreenCanvas` ([#8845](https://github.com/mapbox/mapbox-gl-js/pull/8845)) +* Improve performance for raster tile rendering by using the stencil buffer ([#9012](https://github.com/mapbox/mapbox-gl-js/pull/9012)) +* Update `symbol-avoid-edges` documentation to acknowledge the existence of global collision detection ([#9157](https://github.com/mapbox/mapbox-gl-js/pull/9157)) +* Remove reference to `in` function which has been replaced by the `in` expression ([#9102](https://github.com/mapbox/mapbox-gl-js/pull/9102)) + +### 🐞 Bug Fixes +* Change the type of tile id key to string to prevent hash collisions ([#8979](https://github.com/mapbox/mapbox-gl-js/pull/8979)) +* Prevent changing bearing via URL hash when rotation is disabled ([#9156](https://github.com/mapbox/mapbox-gl-js/pull/9156)) +* Fix URL hash with no bearing causing map to fail to load ([#9170](https://github.com/mapbox/mapbox-gl-js/pull/9170)) +* Fix bug in `GeolocateControl` where multiple instances of the control on one page may result in the user location not being updated ([#9092](https://github.com/mapbox/mapbox-gl-js/pull/9092)) +* Fix query `fill-extrusions` made from polygons with coincident points and polygons with less than four points ([#9138](https://github.com/mapbox/mapbox-gl-js/pull/9138)) +* Fix bug where `symbol-sort-key` was not used for collisions that crossed tile boundaries ([#9054](https://github.com/mapbox/mapbox-gl-js/pull/9054)) +* Fix bug in `DragRotateHandler._onMouseUp` getting stuck in drag/rotate ([#9137](https://github.com/mapbox/mapbox-gl-js/pull/9137)) +* Fix "Click on Compass" on some mobile devices (add `clickTolerance` to `DragRotateHandler`) ([#9015](https://github.com/mapbox/mapbox-gl-js/pull/9015)) (h/t [Yanonix](https://github.com/Yanonix)) + +## 1.6.1 + +### 🐞 Bug Fixes +* Fix style validation error messages not being displayed ([#9073](https://github.com/mapbox/mapbox-gl-js/pull/9073)) +* Fix deferred loading of rtl-text-plugin not working for labels created from GeoJSON sources ([#9091](https://github.com/mapbox/mapbox-gl-js/pull/9091)) +* Fix RTL text not being rendered with the rtl-text-plugin on pages that don't allow `script-src: blob:` in their CSP.([#9122](https://github.com/mapbox/mapbox-gl-js/pull/9122)) + +## 1.6.0 + +### ✨ Features +* Add ability to insert images into text labels using an `image` expression within a `format` expression: `"text-field": ["format", "Some text", ["image", "my-image"], "some more text"]` ([#8904](https://github.com/mapbox/mapbox-gl-js/pull/8904)) +* Add support for stretchable images (aka nine-part or nine-patch images). Stretchable images can be used with `icon-text-fit` to draw resized images with unstretched corners and borders. ([#8997](https://github.com/mapbox/mapbox-gl-js/pull/8997)) +* Add `in` expression. It can check if a value is in an array (`["in", value, array]`) or a substring is in a string (`["in", substring, string]`) ([#8876](https://github.com/mapbox/mapbox-gl-js/pull/8876)) +* Add `minPitch` and `maxPitch` map options ([#8834](https://github.com/mapbox/mapbox-gl-js/pull/8834)) +* Add `rotation`, `rotationAlignment` and `pitchAlignment` options to markers ([#8836](https://github.com/mapbox/mapbox-gl-js/pull/8836)) (h/t [dburnsii](https://github.com/dburnsii)) +* Add methods to Popup to manipulate container class names ([#8759](https://github.com/mapbox/mapbox-gl-js/pull/8759)) (h/t [Ashot-KR](https://github.com/Ashot-KR)) +* Add configurable inertia settings for panning (h/t @aMoniker) ([#8887](https://github.com/mapbox/mapbox-gl-js/pull/8887)) +* Add ability to localize UI controls ([#8095](https://github.com/mapbox/mapbox-gl-js/pull/8095)) (h/t [dmytro-gokun](https://github.com/dmytro-gokun)) +* Add LatLngBounds.contains() method ([#7512](https://github.com/mapbox/mapbox-gl-js/issues/7512), fixed by [#8200](https://github.com/mapbox/mapbox-gl-js/pull/8200)) +* Add option to load rtl-text-plugin lazily ([#8865](https://github.com/mapbox/mapbox-gl-js/pull/8865)) +* Add `essential` parameter to AnimationOptions that can override `prefers-reduced-motion: reduce` ([#8743](https://github.com/mapbox/mapbox-gl-js/issues/8743), fixed by [#8883](https://github.com/mapbox/mapbox-gl-js/pull/8883)) + +### 🍏 Improvements +* Allow rendering full world smaller than 512px. To restore the previous limit call `map.setMinZoom(0)` ([#9028](https://github.com/mapbox/mapbox-gl-js/pull/9028)) +* Add an es modules build for mapbox-gl-style-spec in dist/ ([#8247](https://github.com/mapbox/mapbox-gl-js/pull/8247)) (h/t [ahocevar](https://github.com/ahocevar)) +* Add 'image/webp,*/*' accept header to fetch/ajax image requests when webp supported ([#8262](https://github.com/mapbox/mapbox-gl-js/pull/8262)) +* Improve documentation for setStyle, getStyle, and isStyleLoaded ([#8807](https://github.com/mapbox/mapbox-gl-js/pull/8807)) + +### 🐞 Bug Fixes +* Fix map rendering after addImage and removeImage are used to change a used image ([#9016](https://github.com/mapbox/mapbox-gl-js/pull/9016)) +* Fix visibility of controls in High Contrast mode in IE ([#8874](https://github.com/mapbox/mapbox-gl-js/pull/8874)) +* Fix customizable url hash string in IE 11 ([#8990](https://github.com/mapbox/mapbox-gl-js/pull/8990)) (h/t [pakastin](https://github.com/pakastin)) +* Allow expression stops up to zoom 24 instead of 22 ([#8908](https://github.com/mapbox/mapbox-gl-js/pull/8908)) (h/t [nicholas-l](https://github.com/nicholas-l)) +* Fix alignment of lines in really overscaled tiles ([#9024](https://github.com/mapbox/mapbox-gl-js/pull/9024)) +* Fix `Failed to execute 'shaderSource' on 'WebGLRenderingContext'` errors ([#9017](https://github.com/mapbox/mapbox-gl-js/pull/9017)) +* Make expression validation fail on NaN ([#8615](https://github.com/mapbox/mapbox-gl-js/pull/8615)) +* Fix setLayerZoomRange bug that caused tiles to be re-requested ([#7865](https://github.com/mapbox/mapbox-gl-js/issues/7865), fixed by [#8854](https://github.com/mapbox/mapbox-gl-js/pull/8854)) +* Fix `map.showTileBoundaries` rendering ([#7314](https://github.com/mapbox/mapbox-gl-js/pull/7314)) +* Fix using `generateId` in conjunction with `cluster` in a GeoJSONSource ([#8223](https://github.com/mapbox/mapbox-gl-js/issues/8223), fixed by [#8945](https://github.com/mapbox/mapbox-gl-js/pull/8945)) +* Fix opening popup on a marker from keyboard ([#6835](https://github.com/mapbox/mapbox-gl-js/pull/6835)) +* Fix error thrown when request aborted ([#7614](https://github.com/mapbox/mapbox-gl-js/issues/7614), fixed by [#9021](https://github.com/mapbox/mapbox-gl-js/pull/9021)) +* Fix attribution control when repeatedly removing and adding it ([#9052](https://github.com/mapbox/mapbox-gl-js/pull/9052)) + +## 1.5.1 +This patch introduces two workarounds that address longstanding issues related to unbounded memory growth in Safari, including [#8771](https://github.com/mapbox/mapbox-gl-js/issues/8771) and [#4695](https://github.com/mapbox/mapbox-gl-js/issues/4695). We’ve identified two memory leaks in Safari: one in the [CacheStorage](https://developer.mozilla.org/en-US/docs/Web/API/CacheStorage) API, addressed by [#8956](https://github.com/mapbox/mapbox-gl-js/pull/8956), and one in transferring data between web workers through [Transferables](https://developer.mozilla.org/en-US/docs/Web/API/Transferable), addressed by [#9003](https://github.com/mapbox/mapbox-gl-js/pull/9003). + +### 🍏 Improvements +* Implement workaround for memory leak in Safari when using the `CacheStorage` API. ( [#8856](https://github.com/mapbox/mapbox-gl-js/pull/8956)) +* Implement workaround for memory leak in Safari when using `Transferable` objects to transfer `ArrayBuffers` to WebWorkers. If GL-JS detetcts that it is running in Safari, the use of `Transferables` to transfer data to WebWorkers is disabled. ( [#9003](https://github.com/mapbox/mapbox-gl-js/pull/9003)) +* Improve animation performance when using `map.setData`. ([#8913](https://github.com/mapbox/mapbox-gl-js/pull/8913)) (h/t [msbarry](https://github.com/msbarry)) + +## 1.5.0 + +### ✨ Features +* Add disabled icon to GeolocateControl if user denies geolocation permission. [#8871](https://github.com/mapbox/mapbox-gl-js/pull/8871)) +* Add `outofmaxbounds` event to GeolocateControl, which is emitted when the user is outside of `map.maxBounds` ([#8756](https://github.com/mapbox/mapbox-gl-js/pull/8756)) (h/t [MoradiDavijani](https://github.com/MoradiDavijani)) +* Add `mapboxgl.getRTLTextPluginStatus()` to query the current status of the `rtl-text-plugin` to make it easier to allow clearing the plugin when necessary. (ref. [#7869](https://github.com/mapbox/mapbox-gl-js/issues/7869)) ([#8864](https://github.com/mapbox/mapbox-gl-js/pull/8864)) +* Allow `hash` Map option to be set as a string, which sets the map hash in the url to a custom query parameter. ([#8603](https://github.com/mapbox/mapbox-gl-js/pull/8603)) (h/t [SebCorbin](https://github.com/SebCorbin)) + +### 🍏 Improvements +* Fade symbols faster when zooming out quickly, reducing overlap. ([#8628](https://github.com/mapbox/mapbox-gl-js/pull/8628)) +* Reduce memory usage for vector tiles that contain long strings in feature properties. ( [#8863](https://github.com/mapbox/mapbox-gl-js/pull/8863)) + +### 🐞 Bug Fixes +* Fix `text-variable-anchor` not trying multiple placements during collision with icons when `icon-text-fit` is enabled. ([#8803](https://github.com/mapbox/mapbox-gl-js/pull/8803)) +* Fix `icon-text-fit` not properly respecting vertical labels. ([#8835](https://github.com/mapbox/mapbox-gl-js/pull/8835)) +* Fix opacity interpolation for composition expressions. ([#8818](https://github.com/mapbox/mapbox-gl-js/pull/8818)) +* Fix rotate and pitch events being fired at the same time. ([#8872](https://github.com/mapbox/mapbox-gl-js/pull/8872)) +* Fix memory leaks that occured during tile loading and map removal.([#8813](https://github.com/mapbox/mapbox-gl-js/pull/8813) and [#8850](https://github.com/mapbox/mapbox-gl-js/pull/8850)) +* Fix web-worker transfer of `ArrayBuffers` in environments where `instanceof ArrayBuffer` fails.(e.g `cypress`) ([#8868](https://github.com/mapbox/mapbox-gl-js/pull/8868)) + +## 1.4.1 + +### 🐞 Bug Fixes +* Fix the way that `coalesce` handles the `image` operator so available images are rendered properly ([#8839](https://github.com/mapbox/mapbox-gl-js/pull/8839)) +* Do not emit the `styleimagemissing` event for an empty string value ([#8840](https://github.com/mapbox/mapbox-gl-js/pull/8840)) +* Fix serialization of `ResolvedImage` type so `*-pattern` properties work properly ([#8833](https://github.com/mapbox/mapbox-gl-js/pull/8833)) + +## 1.4.0 + +### ✨ Features +* Add `image` expression operator to determine image availability ([#8684](https://github.com/mapbox/mapbox-gl-js/pull/8684)) +* Enable `text-offset` with variable label placement ([#8642](https://github.com/mapbox/mapbox-gl-js/pull/8642)) + +### 🍏 Improvements +* Faster loading and better look of raster terrain ([#8694](https://github.com/mapbox/mapbox-gl-js/pull/8694)) +* Improved code documentation around resizing and {get/set}RenderedWorldCopies and more ([#8748](https://github.com/mapbox/mapbox-gl-js/pull/8748), [#8754](https://github.com/mapbox/mapbox-gl-js/pull/8754)) +* Improve single vs. multi-touch zoom & pan interaction (#7196) ([#8100](https://github.com/mapbox/mapbox-gl-js/pull/8100)) + +### 🐞 Bug fixes +* Fix rendering of `collisionBox` when `text-translate` or `icon-translate` is enabled ([#8659](https://github.com/mapbox/mapbox-gl-js/pull/8659)) +* Fix `TypeError` when reloading a source and immediately removing the map ([#8711](https://github.com/mapbox/mapbox-gl-js/pull/8711)) +* Adding tooltip to the geolocation control button ([#8735](https://github.com/mapbox/mapbox-gl-js/pull/8735)) (h/t [BAByrne](https://github.com/BAByrne)) +* Add `originalEvent` property to NavigationControl events ([#8693](https://github.com/mapbox/mapbox-gl-js/pull/8693)) (h/t [stepankuzmin](https://github.com/stepankuzmin)) +* Don't cancel follow mode in the GeolocateControl when resizing the map or rotating the screen ([#8736](https://github.com/mapbox/mapbox-gl-js/pull/8736)) +* Fix error when calling `Popup#trackPointer` before setting its content or location ([#8757](https://github.com/mapbox/mapbox-gl-js/pull/8757)) (h/t [zxwandrew](https://github.com/zxwandrew)) +* Respect newline characters when text-max-width is set to zero ([#8706](https://github.com/mapbox/mapbox-gl-js/pull/8706)) +* Update earcut to v2.2.0 to fix polygon tesselation errors ([#8772](https://github.com/mapbox/mapbox-gl-js/pull/8772)) +* Fix icon-fit with variable label placement ([#8755](https://github.com/mapbox/mapbox-gl-js/pull/8755)) +* Icons stretched with `icon-text-fit` are now sized correctly ([#8741](https://github.com/mapbox/mapbox-gl-js/pull/8741)) +* Collision detection for icons with `icon-text-fit` now works correctly ([#8741](https://github.com/mapbox/mapbox-gl-js/pull/8741)) + +## 1.3.2 + +- Fix a SecurityError in Firefox >= 69 when accessing the cache [#8780](https://github.com/mapbox/mapbox-gl-js/pull/8780) + +## 1.3.1 + +### 🐞 Bug Fixes + +- Fix a race condition that produced an error when a map was removed while reloading a source. [#8711](https://github.com/mapbox/mapbox-gl-js/pull/8711) +- Fix a race condition were `render` event was sometimes not fired after `load` event in IE11. [#8708](https://github.com/mapbox/mapbox-gl-js/pull/8708) + +## 1.3.0 + +### 🍏 Features + +- Introduce `text-writing-mode` symbol layer property to allow placing point labels vertically. [#8399](https://github.com/mapbox/mapbox-gl-js/pull/8399) +- Extend variable text placement to work when `text/icon-allow-overlap` is set to `true`. [#8620](https://github.com/mapbox/mapbox-gl-js/pull/8620) +- Allow `text-color` to be used in formatted expressions to be able to draw different parts of a label in different colors. [#8068](https://github.com/mapbox/mapbox-gl-js/pull/8068) + +### ✨ Improvements + +- Improve tile loading logic to cancel requests more aggressively, improving performance when zooming or panning quickly. [#8633](https://github.com/mapbox/mapbox-gl-js/pull/8633) +- Display outline on control buttons when focused (e.g. with a tab key) for better accessibility. [#8520](https://github.com/mapbox/mapbox-gl-js/pull/8520) +- Improve the shape of line round joins. [#8275](https://github.com/mapbox/mapbox-gl-js/pull/8275) +- Improve performance of processing line layers. [#8303](https://github.com/mapbox/mapbox-gl-js/pull/8303) +- Improve legibility of info displayed with `map.showTileBoundaries = true`. [#8380](https://github.com/mapbox/mapbox-gl-js/pull/8380) (h/t [@andrewharvey](https://github.com/andrewharvey)) +- Add `MercatorCoordinate.meterInMercatorCoordinateUnits` method to make it easier to convert from meter units to coordinate values used in custom layers. [#8524](https://github.com/mapbox/mapbox-gl-js/pull/8524) (h/t [@andrewharvey](https://github.com/andrewharvey)) +- Improve conversion of legacy filters with duplicate values. [#8542](https://github.com/mapbox/mapbox-gl-js/pull/8542) +- Move out documentation & examples website source to a separate `mapbox-gl-js-docs` repo. [#8582](https://github.com/mapbox/mapbox-gl-js/pull/8582) + +### 🐞 Bug Fixes + +- Fix a bug where local CJK fonts would switch to server-generated ones in overzoomed tiles. [#8657](https://github.com/mapbox/mapbox-gl-js/pull/8657) +- Fix precision issues in [deck.gl](https://deck.gl)-powered custom layers. [#8502](https://github.com/mapbox/mapbox-gl-js/pull/8502) +- Fix a bug where fill and line layers wouldn't render correctly over fill extrusions when coming from the same source. [#8661](https://github.com/mapbox/mapbox-gl-js/pull/8661) +- Fix map loading for documents loaded from Blob URLs. [#8612](https://github.com/mapbox/mapbox-gl-js/pull/8612) +- Fix classification of relative file:// URLs when in documents loaded from a file URL. [#8612](https://github.com/mapbox/mapbox-gl-js/pull/8612) +- Remove `esm` from package `dependencies` (so that it's not installed on `npm install mapbox-gl`). [#8586](https://github.com/mapbox/mapbox-gl-js/pull/8586) (h/t [@DatGreekChick](https://github.com/DatGreekChick)) + +## 1.2.1 + +### 🐞 Bug fixes + +* Fix bug in `NavigationControl` compass button that prevented it from rotating with the map ([#8605](https://github.com/mapbox/mapbox-gl-js/pull/8605)) + +## 1.2.0 + +### Features and improvements +* Add `*-sort-key` layout property for circle, fill, and line layers, to dictate which features appear above others within a single layer([#8467](https://github.com/mapbox/mapbox-gl-js/pull/8467)) +* Add ability to instantiate maps with specific access tokens ([#8364](https://github.com/mapbox/mapbox-gl-js/pull/8364)) +* Accommodate `prefers-reduced-motion` settings in browser ([#8494](https://github.com/mapbox/mapbox-gl-js/pull/8494)) +* Add Map `visualizePitch` option that tilts the compass as the map pitches ([#8208](https://github.com/mapbox/mapbox-gl-js/issues/8208), fixed by [#8296](https://github.com/mapbox/mapbox-gl-js/pull/8296)) (h/t [pakastin](https://github.com/pakastin)) +* Make source options take precedence over TileJSON ([#8232](https://github.com/mapbox/mapbox-gl-js/pull/8232)) (h/t [jingsam](https://github.com/jingsam)) +* Make requirements for text offset properties more precise ([#8418](https://github.com/mapbox/mapbox-gl-js/pull/8418)) +* Expose `convertFilter` API in the style specification ([#8493](https://github.com/mapbox/mapbox-gl-js/pull/8493) + +### Bug fixes +* Fix changes to `text-variable-anchor`, such that previous anchor positions would take precedence only if they are present in the updated array (considered a bug fix, but is technically a breaking change from previous behavior) ([#8473](https://github.com/mapbox/mapbox-gl-js/pull/8473)) +* Fix rendering of opaque pass layers over heatmap and fill-extrusion layers ([#8440](https://github.com/mapbox/mapbox-gl-js/pull/8440)) +* Fix rendering of extraneous vertical line in vector tiles ([#8477](https://github.com/mapbox/mapbox-gl-js/issues/8477), fixed by [#8479](https://github.com/mapbox/mapbox-gl-js/pull/8479)) +* Turn off 'move' event listeners when removing a marker ([#8465](https://github.com/mapbox/mapbox-gl-js/pull/8465)) +* Fix class toggling on navigation control for IE ([#8495](https://github.com/mapbox/mapbox-gl-js/pull/8495)) (h/t [cs09g](https://github.com/cs09g)) +* Fix background rotation hovering on geolocate control ([#8367](https://github.com/mapbox/mapbox-gl-js/pull/8367)) (h/t [GuillaumeGomez](https://github.com/GuillaumeGomez)) +* Fix error in click events on markers where `startPos` is not defined ([#8462](https://github.com/mapbox/mapbox-gl-js/pull/8462)) (h/t [@msbarry](https://github.com/msbarry)) +* Fix malformed urls when using custom `baseAPIURL` of a certain form ([#8466](https://github.com/mapbox/mapbox-gl-js/pull/8466)) + +## 1.1.1 + +### 🐞 Bug fixes + +* Fix unbounded memory growth caused by failure to cancel requests to the cache ([#8472](https://github.com/mapbox/mapbox-gl-js/pull/8472)) +* Fix unbounded memory growth caused by failure to cancel requests in IE ([#8481](https://github.com/mapbox/mapbox-gl-js/issues/8481)) +* Fix performance of getting tiles from the cache ([#8489](https://github.com/mapbox/mapbox-gl-js/pull/8449)) + +## 1.1.0 + +### ✨ Minor features and improvements +* Improve line rendering performance by using a more compact line attributes layout ([#8306](https://github.com/mapbox/mapbox-gl-js/pull/8306)) +* Improve data-driven symbol layers rendering performance ([#8295](https://github.com/mapbox/mapbox-gl-js/pull/8295)) +* Add the ability to disable validation during `queryRenderedFeatures` and `querySourceFeatures` calls, as a performance optimization ([#8211](https://github.com/mapbox/mapbox-gl-js/pull/8211)) (h/t [gorshkov-leonid](https://github.com/gorshkov-leonid)) +* Improve `setFilter` performance by caching keys in `groupByLayout` routine ([#8122](https://github.com/mapbox/mapbox-gl-js/pull/8122)) (h/t [vallendm](https://github.com/vallendm)) +* Improve rendering of symbol layers with `symbol-z-order: viewport-y`, when icons are allowed to overlap but not text ([#8180](https://github.com/mapbox/mapbox-gl-js/pull/8180)) +* Prefer breaking lines at a zero width space to allow better break point suggestions for Japanese labels ([#8255](https://github.com/mapbox/mapbox-gl-js/pull/8255)) +* Add a `WebGLRenderingContext` argument to `onRemove` function of `CustomLayerInterface`, to allow direct cleanup of related context ([#8156](https://github.com/mapbox/mapbox-gl-js/pull/8156)) (h/t [ogiermaitre](https://github.com/ogiermaitre)) +* Allow zoom speed customization by adding `setZoomRate` and `setWheelZoomRate` methods to `ScrollZoomHandler` ([#7863](https://github.com/mapbox/mapbox-gl-js/pull/7863)) (h/t [sf31](https://github.com/sf31)) +* Add `trackPointer` method to `Popup` API that continuously repositions the popup to the mouse cursor when the cursor is within the map ([#7786](https://github.com/mapbox/mapbox-gl-js/pull/7786)) +* Add `getElement` method to `Popup` to retrieve the popup's HTML element ([#8123](https://github.com/mapbox/mapbox-gl-js/pull/8123)) (h/t [bravecow](https://github.com/bravecow)) +* Add `fill-pattern` example to the documentation ([#8022](https://github.com/mapbox/mapbox-gl-js/pull/8022)) (h/t [flawyte](https://github.com/flawyte)) +* Update script detection for Unicode 12.1 ([#8158](https://github.com/mapbox/mapbox-gl-js/pull/8158)) +* Add `nofollow` to Mapbox logo & "Improve this map" links ([#8106](https://github.com/mapbox/mapbox-gl-js/pull/8106)) (h/t [viniciuskneves](https://github.com/viniciuskneves)) +* Include source name in invalid GeoJSON error ([#8113](https://github.com/mapbox/mapbox-gl-js/pull/8113)) (h/t [Zirak](https://github.com/Zirak)) + +### 🐞 Bug fixes +* Fix `updateImage` not working as expected in Chrome ([#8199](https://github.com/mapbox/mapbox-gl-js/pull/8199)) +* Fix issues with double-tap zoom on touch devices ([#8086](https://github.com/mapbox/mapbox-gl-js/pull/8086)) +* Fix duplication of `movestart` events when zooming ([#8259](https://github.com/mapbox/mapbox-gl-js/pull/8259)) (h/t [bambielli-flex](https://github.com/bambielli-flex)) +* Fix validation of ``"format"`` expression failing when options are provided ([#8339](https://github.com/mapbox/mapbox-gl-js/pull/8339)) +* Fix `setPaintProperty` not working on `line-pattern` property ([#8289](https://github.com/mapbox/mapbox-gl-js/pull/8289)) +* Fix the GL context being left in unpredictable states when using custom layers ([#8132](https://github.com/mapbox/mapbox-gl-js/pull/8132)) +* Fix unnecessary updates to attribution control string ([#8082](https://github.com/mapbox/mapbox-gl-js/pull/8082)) (h/t [poletani](https://github.com/poletani)) +* Fix bugs in `findStopLessThanOrEqualTo` algorithm ([#8134](https://github.com/mapbox/mapbox-gl-js/pull/8134)) (h/t [Mike96Angelo](https://github.com/Mike96Angelo)) +* Fix map not displaying properly when inside an element with `text-align: center` ([#8227](https://github.com/mapbox/mapbox-gl-js/pull/8227)) (h/t [mc100s](https://github.com/mc100s)) +* Clarify in documentation that `Popup#maxWidth` accepts all `max-width` CSS values ([#8312](https://github.com/mapbox/mapbox-gl-js/pull/8312)) (h/t [viniciuskneves](https://github.com/viniciuskneves)) +* Fix location dot shadow not displaying ([#8119](https://github.com/mapbox/mapbox-gl-js/pull/8119)) (h/t [bravecow](https://github.com/bravecow)) +* Fix docs dev dependencies being mistakenly installed as package dependencies ([#8121](https://github.com/mapbox/mapbox-gl-js/pull/8121)) (h/t [bravecow](https://github.com/bravecow)) +* Various typo fixes ([#8230](https://github.com/mapbox/mapbox-gl-js/pull/8230), h/t [erictheise](https://github.com/erictheise)) ([#8236](https://github.com/mapbox/mapbox-gl-js/pull/8236), h/t [fredj](https://github.com/fredj)) +* Fix geolocate button CSS ([#8367](https://github.com/mapbox/mapbox-gl-js/pull/8367), h/t [GuillaumeGomez](https://github.com/GuillaumeGomez)) +* Fix caching for Mapbox tiles ([#8389](https://github.com/mapbox/mapbox-gl-js/pull/8389)) + +## 1.0.0 + +### ⚠️ Breaking changes + +This release replaces the existing “map views” pricing model in favor of a “map load” model. Learn more in [a recent blog post about these changes](https://blog.mapbox.com/new-pricing-46b7c26166e7). + +**By upgrading to this release, you are opting in to the new map loads pricing.** + +**Why is this change being made?** + +This change allows us to implement a more standardized and predictable method of billing GL JS map usage. You’ll be charged whenever your website or web application loads, not by when users pan and zoom around the map, incentivizing developers to create highly interactive map experiences. The new pricing structure also creates a significantly larger free tier to help developers get started building their applications with Mapbox tools while pay-as-you-go pricing and automatic volume discounts help your application scale with Mapbox. Session billing also aligns invoices with metrics web developers already track and makes it easier to compare usage with other mapping providers. + +**What is changing?** +- Add SKU token to Mapbox API requests [#8276](https://github.com/mapbox/mapbox-gl-js/pull/8276) + +When (and only when) loading tiles from a Mapbox API with a Mapbox access token set (`mapboxgl.accessToken`), a query parameter named `sku` will be added to all requests for vector, raster and raster-dem tiles. Every map instance uses a unique `sku` value, which is refreshed every 12 hours. The token itself is comprised of a token version (always “1”), a sku ID (always “01”) and a random 10-digit base-62 number. The purpose of the token is to allow for metering of map sessions on the server-side. A session lasts from a new map instantiation until the map is destroyed or 12 hours passes, whichever comes first. + +For further information on the pricing changes, you can read our [blog post](https://blog.mapbox.com/new-pricing-46b7c26166e7) and check out our new [pricing page](https://www.mapbox.com/pricing), which has a price calculator. As always, you can also contact our team at [https://support.mapbox.com](https://support.mapbox.com). + +## 0.54.1 + +### Bug fixes + +- Fix unbounded memory growth caused by failure to cancel requests in IE ([#8481](https://github.com/mapbox/mapbox-gl-js/issues/8481)) + +## 0.54.0 + +### Breaking changes + +- Turned `localIdeographFontFamily` map option on by default. This may change how CJK labels are rendered, but dramatically improves performance of CJK maps (because the browser no longer needs to download heavy amounts of font data from the server). Add `localIdeographFontFamily: false` to turn this off. [#8008](https://github.com/mapbox/mapbox-gl-js/pull/8008) +- Added `Popup` `maxWidth` option, set to `"240px"` by default. [#7906](https://github.com/mapbox/mapbox-gl-js/pull/7906) + +### Major features + +- Added support for updating and animating style images. [#7999](https://github.com/mapbox/mapbox-gl-js/pull/7999) +- Added support for generating style images dynamically (e.g. for drawing icons based on feature properties). [#7987](https://github.com/mapbox/mapbox-gl-js/pull/7987) +- Added antialiasing support for custom layers. [#7821](https://github.com/mapbox/mapbox-gl-js/pull/7821) +- Added a new `mapbox-gl-csp.js` bundle for strict CSP environments where `worker-src: blob` is disallowed. [#8044](https://github.com/mapbox/mapbox-gl-js/pull/8044) + +### Minor features and improvements + +- Improved performance of fill extrusions. [#7821](https://github.com/mapbox/mapbox-gl-js/pull/7821) +- Improved performance of symbol layers. [#7967](https://github.com/mapbox/mapbox-gl-js/pull/7967) +- Slightly improved rendering performance in general. [#7969](https://github.com/mapbox/mapbox-gl-js/pull/7969) +- Slightly improved performance of HTML markers. [#8018](https://github.com/mapbox/mapbox-gl-js/pull/8018) +- Improved diffing of styles with `"visibility": "visible"`. [#8005](https://github.com/mapbox/mapbox-gl-js/pull/8005) +- Improved zoom buttons to grey out when reaching min/max zoom. [#8023](https://github.com/mapbox/mapbox-gl-js/pull/8023) +- Added a title to fullscreen control button. [#8012](https://github.com/mapbox/mapbox-gl-js/pull/8012) +- Added `rel="noopener"` attributes to links that lead to external websites (such as Mapbox logo and OpenStreetMap edit link) for improved security. [#7914](https://github.com/mapbox/mapbox-gl-js/pull/7914) +- Added tile size info when `map.showTileBoundaries` is turned on. [#7963](https://github.com/mapbox/mapbox-gl-js/pull/7963) +- Significantly improved load times of the benchmark suite. [#8066](https://github.com/mapbox/mapbox-gl-js/pull/8066) +- Improved behavior of `canvasSource.pause` to be more reliable and able to render a single frame. [#8130](https://github.com/mapbox/mapbox-gl-js/pull/8130) + +### Bug fixes + +- Fixed a bug in Mac Safari 12+ where controls would disappear until you interact with the map. [8193](https://github.com/mapbox/mapbox-gl-js/pull/8193) +- Fixed a memory leak when calling `source.setData(url)` many times. [#8035](https://github.com/mapbox/mapbox-gl-js/pull/8035) +- Fixed a bug where marker lost focus when dragging. [#7799](https://github.com/mapbox/mapbox-gl-js/pull/7799) +- Fixed a bug where `map.getCenter()` returned a reference to an internal `LngLat` object instead of cloning it, leading to potential mutability bugs. [#7922](https://github.com/mapbox/mapbox-gl-js/pull/7922) +- Fixed a bug where default HTML marker positioning was slightly off. [#8074](https://github.com/mapbox/mapbox-gl-js/pull/8074) +- Fixed a bug where adding a fill extrusion layer for non-polygon layers would lead to visual artifacts. [#7685](https://github.com/mapbox/mapbox-gl-js/pull/7685) +- Fixed intermittent Flow failures on CI. [#8061](https://github.com/mapbox/mapbox-gl-js/pull/8061) +- Fixed a bug where calling `Map#removeFeatureState` does not remove the state from some tile zooms [#8087](https://github.com/mapbox/mapbox-gl-js/pull/8087) +- Fixed a bug where `removeFeatureState` didn't work on features with `id` equal to `0`. [#8150](https://github.com/mapbox/mapbox-gl-js/pull/8150) (h/t [jutaz](https://github.com/jutaz)) + +## 0.53.1 + +### Bug fixes +* Turn off telemetry for Mapbox Atlas ([#7945](https://github.com/mapbox/mapbox-gl-js/pull/7945)) +* Fix order of 3D features in query results (fix #7883) ([#7953](https://github.com/mapbox/mapbox-gl-js/pull/7953)) +* Fix RemovePaintState benchmarks ([#7930](https://github.com/mapbox/mapbox-gl-js/pull/7930)) + +## 0.53.0 + +### Features and improvements +* Enable `fill-extrusion` querying with ray picking ([#7499](https://github.com/mapbox/mapbox-gl-js/pull/7499)) +* Add `clusterProperties` option for aggregated cluster properties ([#2412](https://github.com/mapbox/mapbox-gl-js/issues/2412), fixed by [#7584](https://github.com/mapbox/mapbox-gl-js/pull/7584)) +* Allow initial map bounds to be adjusted with `fitBounds` options. ([#7681](https://github.com/mapbox/mapbox-gl-js/pull/7681)) (h/t [elyobo](https://github.com/elyobo)) +* Remove popups on `Map#remove` ([#7749](https://github.com/mapbox/mapbox-gl-js/pull/7749)) (h/t [andycalder](https://github.com/andycalder)) +* Add `Map#removeFeatureState` ([#7761](https://github.com/mapbox/mapbox-gl-js/pull/7761)) +* Add `number-format` expression ([#7626](https://github.com/mapbox/mapbox-gl-js/pull/7626)) +* Add `symbol-sort-key` style property ([#7678](https://github.com/mapbox/mapbox-gl-js/pull/7678)) + +### Bug fixes +* Upgrades Earcut to fix a rare bug in rendering polygons that contain a coincident chain of holes ([#7806](https://github.com/mapbox/mapbox-gl-js/issues/7806), fixed by [#7878](https://github.com/mapbox/mapbox-gl-js/pull/7878)) +* Allow `file://` protocol in XHR requests for Cordova/Ionic/etc ([#7818](https://github.com/mapbox/mapbox-gl-js/pull/7818)) +* Correctly handle WebP images in Edge 18 ([#7687](https://github.com/mapbox/mapbox-gl-js/pull/7687)) +* Fix bug which mistakenly requested WebP images in browsers that do not support WebP (#7817) ([#7819](https://github.com/mapbox/mapbox-gl-js/pull/7819)) +* Fix images not being aborted when dequeued ([#7655](https://github.com/mapbox/mapbox-gl-js/pull/7655)) +* Fix DEM layer memory leak ([#7690](https://github.com/mapbox/mapbox-gl-js/issues/7690), fixed by [#7691](https://github.com/mapbox/mapbox-gl-js/pull/7691)) +* Set correct color state before rendering custom layer ([#7711](https://github.com/mapbox/mapbox-gl-js/pull/7711)) +* Set `LngLat.toBounds()` default radius to 0 ([#7722](https://github.com/mapbox/mapbox-gl-js/issues/7722), fixed by [#7723](https://github.com/mapbox/mapbox-gl-js/pull/7723)) (h/t [cherniavskii](https://github.com/cherniavskii)) +* Fix race condition in `feature-state` dependent layers ([#7523](https://github.com/mapbox/mapbox-gl-js/issues/7523), fixed by [#7790](https://github.com/mapbox/mapbox-gl-js/pull/7790)) +* Prevent `map.repaint` from mistakenly enabling continuous repaints ([#7667](https://github.com/mapbox/mapbox-gl-js/pull/7667)) +* Prevent map shaking while zooming in on raster tiles ([#7426](https://github.com/mapbox/mapbox-gl-js/pull/7426)) +* Fix query point translation for multi-point geometry ([#6833](https://github.com/mapbox/mapbox-gl-js/issues/6833), fixed by [#7581](https://github.com/mapbox/mapbox-gl-js/pull/7581)) + +## 0.52.0 + +### Breaking changes +* Canonicalize tile urls to `mapbox://` urls so they can be transformed with `config.API_URL` ([#7594](https://github.com/mapbox/mapbox-gl-js/pull/7594)) + +### Features and improvements +* Add getter and setter for `config.API_URL` ([#7594](https://github.com/mapbox/mapbox-gl-js/pull/7594)) +* Allow user to define element other than map container for full screen control ([#7548](https://github.com/mapbox/mapbox-gl-js/pull/7548)) +* Add validation option to style setters ([#7604](https://github.com/mapbox/mapbox-gl-js/pull/7604)) +* Add 'idle' event: fires when no further rendering is expected without further interaction. ([#7625](https://github.com/mapbox/mapbox-gl-js/pull/7625)) + +### Bug fixes +* Fire error when map.getLayoutProperty references missing layer ([#7537](https://github.com/mapbox/mapbox-gl-js/issues/7537), fixed by [#7539](https://github.com/mapbox/mapbox-gl-js/pull/7539)) +* Fix shaky sprites when zooming with scrolling ([#7558](https://github.com/mapbox/mapbox-gl-js/pull/7558)) +* Fix layout problems in attribution control ([#7608](https://github.com/mapbox/mapbox-gl-js/pull/7608)) (h/t [lucaswoj](https://github.com/lucaswoj)) +* Fixes resetting map's pitch to 0 if initial bounds is set ([#7617](https://github.com/mapbox/mapbox-gl-js/pull/7617)) (h/t [stepankuzmin](https://github.com/stepankuzmin)) +* Fix occasional failure to load images after multiple image request abortions [#7641](https://github.com/mapbox/mapbox-gl-js/pull/7641) +* Update repo url to correct one ([#7486](https://github.com/mapbox/mapbox-gl-js/pull/7486)) (h/t [nicholas-l](https://github.com/nicholas-l)) +* Fix bug where symbols where sometimes not rendered immediately ([#7610](https://github.com/mapbox/mapbox-gl-js/pull/7610)) +* Fix bug where cameraForBounds returns incorrect CameraOptions with asymmetrical padding/offset ([#7517](https://github.com/mapbox/mapbox-gl-js/issues/7517), fixed by [#7518](https://github.com/mapbox/mapbox-gl-js/pull/7518)) (h/t [mike-marcacci](https://github.com/mike-marcacci)) +* Use diff+patch approach to map.setStyle when the parameter is a URL ([#4025](https://github.com/mapbox/mapbox-gl-js/issues/4025), fixed by [#7562](https://github.com/mapbox/mapbox-gl-js/pull/7562)) +* Begin touch zoom immediately when rotation disabled ([#7582](https://github.com/mapbox/mapbox-gl-js/pull/7582)) (h/t [msbarry](https://github.com/msbarry)) +* Fix symbol rendering under opaque fill layers ([#7612](https://github.com/mapbox/mapbox-gl-js/pull/7612)) +* Fix shaking by aligning raster sources to pixel grid only when map is idle ([7426](https://github.com/mapbox/mapbox-gl-js/pull/7426)) +* Fix raster layers in Edge 18 by disabling it's incomplete WebP support ([7687](https://github.com/mapbox/mapbox-gl-js/pull/7687)) +* Fix memory leak in hillshade layer ([7691](https://github.com/mapbox/mapbox-gl-js/pull/7691)) +* Fix disappearing custom layers ([7711](https://github.com/mapbox/mapbox-gl-js/pull/7711)) + +## 0.51.0 +November 7, 2018 + +### ✨ Features and improvements +* Add initial bounds as map constructor option ([#5518](https://github.com/mapbox/mapbox-gl-js/pull/5518)) (h/t [stepankuzmin](https://github.com/stepankuzmin)) +* Improve performance on machines with > 8 cores ([#7407](https://github.com/mapbox/mapbox-gl-js/issues/7407), fixed by [#7430](https://github.com/mapbox/mapbox-gl-js/pull/7430)) +* Add `MercatorCoordinate` type ([#7488](https://github.com/mapbox/mapbox-gl-js/pull/7488)) +* Allow browser-native `contextmenu` to be enabled ([#2301](https://github.com/mapbox/mapbox-gl-js/issues/2301), fixed by [#7369](https://github.com/mapbox/mapbox-gl-js/pull/7369)) +* Add an unminified production build to the NPM package ([#7403](https://github.com/mapbox/mapbox-gl-js/pull/7403)) +* Add support for `LngLat` conversion from `{lat, lon}` ([#7507](https://github.com/mapbox/mapbox-gl-js/pull/7507)) (h/t [bfrengley](https://github.com/bfrengley)) +* Add tooltips for navigation controls ([#7373](https://github.com/mapbox/mapbox-gl-js/pull/7373)) +* Show attribution only for used sources ([#7384](https://github.com/mapbox/mapbox-gl-js/pull/7384)) +* Add telemetry event to log map loads ([#7431](https://github.com/mapbox/mapbox-gl-js/pull/7431)) +* **Tighten style validation** + * Disallow expressions as stop values ([#7396](https://github.com/mapbox/mapbox-gl-js/pull/7396)) + * Disallow `feature-state` expressions in filters ([#7366](https://github.com/mapbox/mapbox-gl-js/pull/7366)) + +### 🐛 Bug fixes +* Fix for GeoJSON geometries not working when coincident with tile boundaries([#7436](https://github.com/mapbox/mapbox-gl-js/issues/7436), fixed by [#7448](https://github.com/mapbox/mapbox-gl-js/pull/7448)) +* Fix depth buffer-related rendering issues on some Android devices. ([#7471](https://github.com/mapbox/mapbox-gl-js/pull/7471)) +* Fix positioning of compact attribution strings ([#7444](https://github.com/mapbox/mapbox-gl-js/pull/7444), [#7445](https://github.com/mapbox/mapbox-gl-js/pull/7445), and [#7391](https://github.com/mapbox/mapbox-gl-js/pull/7391)) +* Fix an issue with removing markers in mouse event callbacks ([#7442](https://github.com/mapbox/mapbox-gl-js/pull/7442)) (h/t [vbud](https://github.com/vbud)) +* Remove controls before destroying a map ([#7479](https://github.com/mapbox/mapbox-gl-js/pull/7479)) +* Fix display of Scale control values < 1 ([#7469](https://github.com/mapbox/mapbox-gl-js/pull/7469)) (h/t [MichaelHedman](https://github.com/MichaelHedman)) +* Fix an error when using location `hash` within iframes in IE11 ([#7411](https://github.com/mapbox/mapbox-gl-js/pull/7411)) +* Fix depth mode usage in custom layers ([#7432](https://github.com/mapbox/mapbox-gl-js/pull/7432)) (h/t [markusjohnsson](https://github.com/markusjohnsson)) +* Fix an issue with shaky sprite images during scroll zooms ([#7558](https://github.com/mapbox/mapbox-gl-js/pull/7558)) + + +## 0.50.0 +October 10, 2018 + +### ✨ Features and improvements +* 🎉 Add Custom Layers that can be rendered into with user-provided WebGL code ([#7039](https://github.com/mapbox/mapbox-gl-js/pull/7039)) +* Add WebGL face culling for increased performance ([#7178](https://github.com/mapbox/mapbox-gl-js/pull/7178)) +* Improve speed of expression evaluation ([#7334](https://github.com/mapbox/mapbox-gl-js/pull/7334)) +* Automatically coerce to string for `concat` expression and `text-field` property ([#6190](https://github.com/mapbox/mapbox-gl-js/issues/6190), fixed by [#7280](https://github.com/mapbox/mapbox-gl-js/pull/7280)) +* Add `fill-extrusion-vertical-gradient` property for controlling shading of fill extrusions ([#5768](https://github.com/mapbox/mapbox-gl-js/issues/5768), fixed by [#6841](https://github.com/mapbox/mapbox-gl-js/pull/6841)) +* Add update functionality for images provided via `ImageSource` ([#4050](https://github.com/mapbox/mapbox-gl-js/issues/4050), fixed by [#7342](https://github.com/mapbox/mapbox-gl-js/pull/7342)) (h/t [dcervelli](https://github.com/dcervelli)) + + + +### 🐛 Bug fixes +* **Expressions** + * Fix expressions that use `log2` and `log10` in IE11 ([#7318](https://github.com/mapbox/mapbox-gl-js/issues/7318), fixed by [#7320](https://github.com/mapbox/mapbox-gl-js/pull/7320)) + * Fix `let` expression stripping expected type during parsing ([#7300](https://github.com/mapbox/mapbox-gl-js/issues/7300), fixed by [#7301](https://github.com/mapbox/mapbox-gl-js/pull/7301)) + * Fix superfluous wrapping of literals in `literal` expression ([#7336](https://github.com/mapbox/mapbox-gl-js/issues/7336), fixed by [#7337](https://github.com/mapbox/mapbox-gl-js/pull/7337)) + * Allow calling `to-color` on values that are already of type `Color` ([#7260](https://github.com/mapbox/mapbox-gl-js/pull/7260)) + * Fix `to-array` for empty arrays (([#7261](https://github.com/mapbox/mapbox-gl-js/pull/7261))) + * Fix identity functions for `text-field` when using formatted text ([#7351](https://github.com/mapbox/mapbox-gl-js/pull/7351)) + * Fix coercion of `null` to `0` in `to-number` expression ([#7083](https://github.com/mapbox/mapbox-gl-js/issues/7083), fixed by [#7274](https://github.com/mapbox/mapbox-gl-js/pull/7274)) +* **Canvas source** + * Fix missing repeats of `CanvasSource` when it crosses the antimeridian ([#7273](https://github.com/mapbox/mapbox-gl-js/pull/7273)) + * Fix `CanvasSource` not respecting alpha values set on `canvas` element ([#7302](https://github.com/mapbox/mapbox-gl-js/issues/7302), fixed by [#7309](https://github.com/mapbox/mapbox-gl-js/pull/7309)) +* **Rendering** + * Fix rendering of fill extrusions with really high heights ([#7292](https://github.com/mapbox/mapbox-gl-js/pull/7292)) + * Fix an error where the map state wouldn't return to `loaded` after certain runtime styling changes when there were errored tiles in the viewport ([#7355](https://github.com/mapbox/mapbox-gl-js/pull/7355)) + * Fix errors when rendering symbol layers without symbols ([#7241](https://github.com/mapbox/mapbox-gl-js/issues/7241), fixed by [#7253](https://github.com/mapbox/mapbox-gl-js/pull/7253)) + * Don't fade in symbols with `*-allow-overlap: true` when panning into the viewport ([#7172](https://github.com/mapbox/mapbox-gl-js/issues/7172), fixed by[#7244](https://github.com/mapbox/mapbox-gl-js/pull/7244)) +* **Library** + * Fix disambiguation for `mouseover` event ([#7295](https://github.com/mapbox/mapbox-gl-js/issues/7295), fixed by [#7299](https://github.com/mapbox/mapbox-gl-js/pull/7299)) + * Fix silent failure of `getImage` if an SVG is requested ([#7312](https://github.com/mapbox/mapbox-gl-js/issues/7312), fixed by [#7313](https://github.com/mapbox/mapbox-gl-js/pull/7313)) + * Fix empty control group box shadow ([#7303](https://github.com/mapbox/mapbox-gl-js/issues/7303), fixed by [#7304](https://github.com/mapbox/mapbox-gl-js/pull/7304)) (h/t [Duder-onomy](https://github.com/Duder-onomy)) + * Fixed an issue where a wrong timestamp was sent for Mapbox turnstile events ([#7381](https://github.com/mapbox/mapbox-gl-js/pull/7381)) + * Fixed a bug that lead to attribution not showing up correctly in Internet Explorer ([#3945](https://github.com/mapbox/mapbox-gl-js/issues/3945), fixed by [#7391](https://github.com/mapbox/mapbox-gl-js/pull/7391)) + + +## 0.49.0 +September 6, 2018 + +### ⚠️ Breaking changes +* Use `client{Height/Width}` instead of `offset{Height/Width}` for map canvas sizing ([#6848](https://github.com/mapbox/mapbox-gl-js/issues/6848), fixed by [#7128](https://github.com/mapbox/mapbox-gl-js/pull/7128)) + +### 🐛 Bug fixes +* Fix [Top Issues list](https://mapbox.github.io/top-issues/#!mapbox/mapbox-gl-js) for mapbox-gl-js ([#7108](https://github.com/mapbox/mapbox-gl-js/issues/7108), fixed by [#7112](https://github.com/mapbox/mapbox-gl-js/pull/7112)) +* Fix bug in which symbols with `icon-allow-overlap: true, text-allow-overlap: true, text-optional: false` would show icons when they shouldn't ([#7041](https://github.com/mapbox/mapbox-gl-js/pull/7041)) +* Fix bug where the map would not stop at the exact zoom level requested by Map#FlyTo (#7222) ([#7223](https://github.com/mapbox/mapbox-gl-js/pull/7223)) (h/t [benoitbzl](https://github.com/benoitbzl)) +* Keep map centered on the center point of a multi-touch gesture when zooming (#6722) ([#7191](https://github.com/mapbox/mapbox-gl-js/pull/7191)) (h/t [pakastin](https://github.com/pakastin)) +* Update the style-spec's old `gl-style-migrate` script to include conversion of legacy functions and filters to their expression equivalents ([#6927](https://github.com/mapbox/mapbox-gl-js/issues/6927), fixed by [#7095](https://github.com/mapbox/mapbox-gl-js/pull/7095)) +* Fix `icon-size` for small data-driven values ([#7125](https://github.com/mapbox/mapbox-gl-js/pull/7125)) +* Fix bug in the way AJAX requests load local files on iOS web view ([#6610](https://github.com/mapbox/mapbox-gl-js/pull/6610)) (h/t [oscarfonts](https://github.com/oscarfonts)) +* Fix bug in which canvas sources would not render in world wrapped tiles at the edge of the viewport ([#7271]https://github.com/mapbox/mapbox-gl-js/issues/7271), fixed by [#7273](https://github.com/mapbox/mapbox-gl-js/pull/7273)) + +### ✨ Features and improvements +* Performance updates: + * Improve time to first render by updating how feature ID maps are transferred to the main thread ([#7110](https://github.com/mapbox/mapbox-gl-js/issues/7110), fixed by [#7132](https://github.com/mapbox/mapbox-gl-js/pull/7132)) + * Reduce size of JSON transmitted from worker thread to main thread ([#7124](https://github.com/mapbox/mapbox-gl-js/pull/7124)) + * Improve image/glyph atlas packing algorithm ([#7171](https://github.com/mapbox/mapbox-gl-js/pull/7171)) + * Use murmur hash on symbol instance keys to reduce worker transfer costs ([#7127](https://github.com/mapbox/mapbox-gl-js/pull/7127)) +* Add GL state management for uniforms ([#6018](https://github.com/mapbox/mapbox-gl-js/pull/6018)) +* Add `symbol-z-order` symbol layout property to style spec ([#7219](https://github.com/mapbox/mapbox-gl-js/pull/7219)) +* Implement data-driven styling support for `*-pattern properties` ([#6289](https://github.com/mapbox/mapbox-gl-js/pull/6289)) +* Add `Map#fitScreenCoordinates` which fits viewport to two points, similar to `Map#fitBounds` but uses screen coordinates and supports non-zero map bearings ([#6894](https://github.com/mapbox/mapbox-gl-js/pull/6894)) +* Re-implement LAB/HSL color space interpolation for expressions ([#5326](https://github.com/mapbox/mapbox-gl-js/issues/5326), fixed by [#7123](https://github.com/mapbox/mapbox-gl-js/pull/7123)) +* Enable benchmark testing for Mapbox styles ([#7047](https://github.com/mapbox/mapbox-gl-js/pull/7047)) +* Allow `Map#setFeatureState` and `Map#getFeatureState` to accept numeric IDs ([#7106](https://github.com/mapbox/mapbox-gl-js/pull/7106)) (h/t [bfrengley](https://github.com/bfrengley)) + +## 0.48.0 +August 16, 2018 + +### ⚠️ Breaking changes +* Treat tiles that error with status 404 as empty renderable tiles to prevent rendering duplicate features in some sparse tilesets ([#6803](https://github.com/mapbox/mapbox-gl-js/pull/6803)) + +### 🐛 Bug fixes +* Fix issue where `text-max-angle` property was being calculated incorrectly internally, causing potential rendering errors when `"symbol-placement": line` +* Require `feature.id` when using `Map#setFeatureState` ([#6974](https://github.com/mapbox/mapbox-gl-js/pull/6974)) +* Fix issue with removing the `GeolocateControl` when user location is being used ([#6977](https://github.com/mapbox/mapbox-gl-js/pull/6977)) (h/t [sergei-zelinsky](https://github.com/sergei-zelinsky)) +* Fix memory leak caused by a failure to remove all controls added to the map ([#7042](https://github.com/mapbox/mapbox-gl-js/pull/7042)) +* Fix bug where the build would fail when using mapbox-gl webpack 2 and UglifyJSPlugin ([#4359](https://github.com/mapbox/mapbox-gl-js/issues/4359), fixed by [#6956](https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/6956)) +* Fix bug where fitBounds called with coordinates outside the bounds of Web Mercator resulted in uncaught error ([#6906](https://github.com/mapbox/mapbox-gl-js/issues/6906), fixed by [#6918](https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/6918)) +* Fix bug wherein `Map#querySourceFeatures` was returning bad results on zooms > maxZoom ([#7061](https://github.com/mapbox/mapbox-gl-js/pull/7061)) +* Relax typing for equality and order expressions ([#6459](https://github.com/mapbox/mapbox-gl-js/issues/6459), fixed by [#6961](https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/6961)) +* Fix bug where `queryPadding` for all layers in a source was set by the first layer, causing incorrect querying on other layers and, in some cases, incorrect firing of events associated with individual layers ([#6909](https://github.com/mapbox/mapbox-gl-js/pull/6909)) + +### ✨ Features and improvements + +* Performance Improvements: + * Stop unnecessary serialization of symbol source features. ([#7013](https://github.com/mapbox/mapbox-gl-js/pull/7013)) + * Optimize calculation for getting visible tile coordinates ([#6998](https://github.com/mapbox/mapbox-gl-js/pull/6998)) + * Improve performance of creating `{Glyph/Image}Atlas`es ([#7091](https://github.com/mapbox/mapbox-gl-js/pull/7091)) + * Optimize and simplify tile retention logic ([#6995](https://github.com/mapbox/mapbox-gl-js/pull/6995)) +* Add a user turnstile event for users accessing Mapbox APIs ([#6980](https://github.com/mapbox/mapbox-gl-js/pull/6980)) +* Add support for autogenerating feature ids for GeoJSON sources so they can be used more easily with the `Map#setFeatureState` API ([#7043](https://www.github.com/mapbox/mapbox-gl-js/pull/7043))) ([#7091](https://github.com/mapbox/mapbox-gl-js/pull/7091)) +* Add ability to style symbol layers labels with multiple fonts and text sizes via `"format"` expression ([#6994](https://www.github.com/mapbox/mapbox-gl-js/pull/6994)) +* Add customAttribution option to AttributionControl ([#7033](https://github.com/mapbox/mapbox-gl-js/pull/7033)) (h/t [mklopets](https://github.com/mklopets)) +* Publish Flow type definitions alongside compiled bundle ([#7079](https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/7079)) +* Introduce symbol cross fading when crossing integer zoom levels to prevent labels from disappearing before newly loaded tiles' labels can be rendered ([#6951](https://github.com/mapbox/mapbox-gl-js/pull/6951)) +* Improvements in label collision detection ([#6925](https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/6925))) + +## 0.47.0 + +### ✨ Features and improvements +* Add configurable drag pan threshold ([#6809](https://github.com/mapbox/mapbox-gl-js/pull/6809)) (h/t [msbarry](https://github.com/msbarry)) +* Add `raster-resampling` raster paint property ([#6411](https://github.com/mapbox/mapbox-gl-js/pull/6411)) (h/t [andrewharvey](https://github.com/andrewharvey)) +* Add `symbol-placement: line-center` ([#6821](https://github.com/mapbox/mapbox-gl-js/pull/6821)) +* Add methods for inspecting GeoJSON clusters ([#3318](https://github.com/mapbox/mapbox-gl-js/issues/3318), fixed by [#6829](https://github.com/mapbox/mapbox-gl-js/pull/6829)) +* Add warning to geolocate control when unsupported ([#6923](https://github.com/mapbox/mapbox-gl-js/pull/6923)) (h/t [aendrew](https://github.com/aendrew)) +* Upgrade geojson-vt to 3.1.4 ([#6942](https://github.com/mapbox/mapbox-gl-js/pull/6942)) +* Include link to license in compiled bundle ([#6975](https://github.com/mapbox/mapbox-gl-js/pull/6975)) + +### 🐛 Bug fixes +* Use updateData instead of re-creating buffers for repopulated paint arrays ([#6853](https://github.com/mapbox/mapbox-gl-js/pull/6853)) +* Fix ScrollZoom handler setting tr.zoom = NaN ([#6924](https://github.com/mapbox/mapbox-gl-js/pull/6924)) + - Failed to invert matrix error ([#6486](https://github.com/mapbox/mapbox-gl-js/issues/6486), fixed by [#6924](https://github.com/mapbox/mapbox-gl-js/pull/6924)) + - Fixing matrix errors ([#6782](https://github.com/mapbox/mapbox-gl-js/issues/6782), fixed by [#6924](https://github.com/mapbox/mapbox-gl-js/pull/6924)) +* Fix heatmap tile clipping when layers are ordered above it ([#6806](https://github.com/mapbox/mapbox-gl-js/issues/6806), fixed by [#6807](https://github.com/mapbox/mapbox-gl-js/pull/6807)) +* Fix video source in safari (macOS and iOS) ([#6443](https://github.com/mapbox/mapbox-gl-js/issues/6443), fixed by [#6811](https://github.com/mapbox/mapbox-gl-js/pull/6811)) +* Do not reload errored tiles ([#6813](https://github.com/mapbox/mapbox-gl-js/pull/6813)) +* Fix send / remove timing bug in Dispatcher ([#6756](https://github.com/mapbox/mapbox-gl-js/pull/6756), fixed by [#6826](https://github.com/mapbox/mapbox-gl-js/pull/6826)) +* Fix flyTo not zooming to exact given zoom ([#6828](https://github.com/mapbox/mapbox-gl-js/pull/6828)) +* Don't stop animation on map resize ([#6636](https://github.com/mapbox/mapbox-gl-js/pull/6636)) +* Fix map.getBounds() with rotated map ([#6875](https://github.com/mapbox/mapbox-gl-js/pull/6875)) (h/t [zoltan-mihalyi](https://github.com/zoltan-mihalyi)) +* Support collators in feature filter expressions. ([#6929](https://github.com/mapbox/mapbox-gl-js/pull/6929)) +* Fix Webpack production mode compatibility ([#6981](https://github.com/mapbox/mapbox-gl-js/pull/6981)) + +## 0.46.0 + +### ⚠️ Breaking changes + +* Align implicit type casting behavior of `match` expressions with with `case/==` ([#6684](https://github.com/mapbox/mapbox-gl-js/pull/6684)) + +### ✨ Features and improvements + +* :tada: Add `Map#setFeatureState` and `feature-state` expression to support interactive styling ([#6263](https://github.com/mapbox/mapbox-gl-js/pull/6263)) +* Create draggable `Marker` with `setDraggable` ([#6687](https://github.com/mapbox/mapbox-gl-js/pull/6687)) +* Add `Map#listImages` for listing all currently active sprites/images ([#6381](https://github.com/mapbox/mapbox-gl-js/issues/6381)) +* Add "crossSourceCollisions" option to disable cross-source collision detection ([#6566](https://github.com/mapbox/mapbox-gl-js/pull/6566)) +* Handle `text/icon-rotate` for symbols with `symbol-placement: point` ([#6075](https://github.com/mapbox/mapbox-gl-js/issues/6075)) +* Automatically compact Mapbox wordmark on narrow maps. ([#4282](https://github.com/mapbox/mapbox-gl-js/issues/4282)) (h/t [andrewharvey](https://github.com/andrewharvey)) +* Only show compacted AttributionControl on interactive displays ([#6506](https://github.com/mapbox/mapbox-gl-js/pull/6506)) (h/t [andrewharvey](https://github.com/andrewharvey)) +* Use postcss to inline svg files into css, reduce size of mapbox-gl.css ([#6513](https://github.com/mapbox/mapbox-gl-js/pull/6513)) (h/t [andrewharvey](https://github.com/andrewharvey)) +* Add support for GeoJSON attribution ([#6364](https://github.com/mapbox/mapbox-gl-js/pull/6364)) (h/t [andrewharvey](https://github.com/andrewharvey)) +* Add instructions for running individual unit and render tests ([#6686](https://github.com/mapbox/mapbox-gl-js/pull/6686)) +* Make Map constructor fail if WebGL init fails. ([#6744](https://github.com/mapbox/mapbox-gl-js/pull/6744)) (h/t [uforic](https://github.com/uforic)) +* Add browser fallback code for `collectResourceTiming: true` in web workers ([#6721](https://github.com/mapbox/mapbox-gl-js/pull/6721)) +* Remove ignored usage of gl.lineWidth ([#5541](https://github.com/mapbox/mapbox-gl-js/pull/5541)) +* Split new bounds calculation out of fitBounds into new method ([#6683](https://github.com/mapbox/mapbox-gl-js/pull/6683)) +* Allow integration tests to be organized in an arbitrarily deep directory structure ([#3920](https://github.com/mapbox/mapbox-gl-js/issues/3920)) +* Make "Missing Mapbox GL JS CSS" a console warning ([#5786](https://github.com/mapbox/mapbox-gl-js/issues/5786)) +* Add rel="noopener" to Mapbox attribution link. ([#6729](https://github.com/mapbox/mapbox-gl-js/pull/6729)) (h/t [gorbypark](https://github.com/gorbypark)) +* Update to deep equality check in example code ([#6599](https://github.com/mapbox/mapbox-gl-js/pull/6599)) (h/t [jonsadka](https://github.com/jonsadka)) +* Upgrades! + - Upgrade ESM dependency to ^3.0.39 ([#6750](https://github.com/mapbox/mapbox-gl-js/pull/6750)) + - Ditch gl-matrix fork in favor of the original package ([#6751](https://github.com/mapbox/mapbox-gl-js/pull/6751)) + - Update to latest sinon ([#6771](https://github.com/mapbox/mapbox-gl-js/pull/6771)) + - Upgrade to Flow 0.69 ([#6594](https://github.com/mapbox/mapbox-gl-js/pull/6594)) + - Update to mapbox-gl-supported 1.4.0 ([#6773](https://github.com/mapbox/mapbox-gl-js/pull/6773)) + +### 🐛 Bug fixes + +* `collectResourceTiming: true` generates error on iOS9 Safari, IE 11 ([#6690](https://github.com/mapbox/mapbox-gl-js/issues/6690)) +* Fix PopupOptions flow type declarations ([#6670](https://github.com/mapbox/mapbox-gl-js/pull/6670)) (h/t [TimPetricola](https://github.com/TimPetricola)) +* Add className option to Popup constructor ([#6502](https://github.com/mapbox/mapbox-gl-js/pull/6502)) (h/t [Ashot-KR](https://github.com/Ashot-KR)) +* GeoJSON MultiLineStrings with `lineMetrics=true` only rendered first line ([#6649](https://github.com/mapbox/mapbox-gl-js/issues/6649)) +* Provide target property for mouseenter/over/leave/out events ([#6623](https://github.com/mapbox/mapbox-gl-js/issues/6623)) +* Don't break on sources whose name contains "." ([#6660](https://github.com/mapbox/mapbox-gl-js/issues/6660)) +* Rotate and pitch with navigationControl broke in v0.45 ([#6650](https://github.com/mapbox/mapbox-gl-js/issues/6650)) +* Zero-width lines remained visible ([#6769](https://github.com/mapbox/mapbox-gl-js/pull/6769)) +* Heatmaps inappropriately clipped at tile boundaries ([#6806](https://github.com/mapbox/mapbox-gl-js/issues/6806)) +* Use named exports for style-spec entrypoint module ([#6601](https://github.com/mapbox/mapbox-gl-js/issues/6601) +* Don't fire click event if default is prevented on mousedown for a drag event ([#6697](https://github.com/mapbox/mapbox-gl-js/pull/6697), fixes [#6642](https://github.com/mapbox/mapbox-gl-js/issues/6642)) +* Double clicking to zoom in breaks map dragging/panning in Edge ([#6740](https://github.com/mapbox/mapbox-gl-js/issues/6740)) (h/t [GUI](https://github.com/GUI)) +* \*-transition properties cannot be set with setPaintProperty() ([#6706](https://github.com/mapbox/mapbox-gl-js/issues/6706)) +* Marker with `a` element does not open the url when clicked ([#6730](https://github.com/mapbox/mapbox-gl-js/issues/6730)) +* `setRTLTextPlugin` fails with relative URLs ([#6719](https://github.com/mapbox/mapbox-gl-js/issues/6719)) +* Collision detection incorrect for symbol layers that share the same layout properties ([#6548](https://github.com/mapbox/mapbox-gl-js/pull/6548)) +* Fix a possible crash when calling queryRenderedFeatures after querySourceFeatures + ([#6559](https://github.com/mapbox/mapbox-gl-js/pull/6559)) +* Fix a collision detection issue that could cause labels to temporarily be placed too densely during rapid panning ([#5654](https://github.com/mapbox/mapbox-gl-js/issues/5654)) + +## 0.45.0 + +### ⚠️ Breaking changes + +* `Evented#fire` and `Evented#listens` are now marked as private. Though `Evented` is still exported, and `fire` and `listens` are still functional, we encourage you to seek alternatives; a future version may remove their API accessibility or change its behavior. If you are writing a class that needs event emitting functionality, consider using [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter) or similar libraries instead. +* The `"to-string"` expression operator now converts `null` to an empty string rather than to `"null"`. [#6534](https://github.com/mapbox/mapbox-gl-js/pull/6534) + +### ✨ Features and improvements + +* :rainbow: Add `line-gradient` property [#6303](https://github.com/mapbox/mapbox-gl-js/pull/6303) +* Add `abs`, `round`, `floor`, and `ceil` expression operators [#6496](https://github.com/mapbox/mapbox-gl-js/pull/6496) +* Add `collator` expression for controlling case and diacritic sensitivity in string comparisons [#6270](https://github.com/mapbox/mapbox-gl-js/pull/6270) + - Rename `caseSensitive` and `diacriticSensitive` expressions to `case-sensitive` and `diacritic-sensitive` for consistency [#6598](https://github.com/mapbox/mapbox-gl-js/pull/6598) + - Prevent `collator` expressions for evaluating as constant to account for potential environment-specific differences in expression evaluation [#6596](https://github.com/mapbox/mapbox-gl-js/pull/6596) +* Add CSS linting to test suite (h/t @jasonbarry) [#6071](https://github.com/mapbox/mapbox-gl-js/pull/6071) +* Add support for configurable maxzoom in `raster-dem` tilesets [#6103](https://github.com/mapbox/mapbox-gl-js/pull/6103) +* Add `Map#isZooming` and `Map#isRotating` methods [#6128](https://github.com/mapbox/mapbox-gl-js/pull/6128), [#6183](https://github.com/mapbox/mapbox-gl-js/pull/6183) +* Add support for Mapzen Terrarium tiles in `raster-dem` sources [#6110](https://github.com/mapbox/mapbox-gl-js/pull/6110) +* Add `preventDefault` method on `mousedown`, `touchstart`, and `dblclick` events [#6218](https://github.com/mapbox/mapbox-gl-js/pull/6218) +* Add `originalEvent` property on `zoomend` and `moveend` for user-initiated scroll events (h/t @stepankuzmin) [#6175](https://github.com/mapbox/mapbox-gl-js/pull/6175) +* Accept arguments of type `value` in [`"length"` expressions](https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-length) [#6244](https://github.com/mapbox/mapbox-gl-js/pull/6244) +* Introduce `MapWheelEvent`[#6237](https://github.com/mapbox/mapbox-gl-js/pull/6237) +* Add setter for `ScaleControl` units (h/t @ryanhamley) [#6138](https://github.com/mapbox/mapbox-gl-js/pull/6138), [#6274](https://github.com/mapbox/mapbox-gl-js/pull/6274) +* Add `open` event for `Popup` [#6311](https://github.com/mapbox/mapbox-gl-js/pull/6311) +* Explicit `"object"` type assertions are no longer required when using expressions [#6235](https://github.com/mapbox/mapbox-gl-js/pull/6235) +* Add `anchor` option to `Marker` [#6350](https://github.com/mapbox/mapbox-gl-js/pull/6350) +* `HTMLElement` is now passed to `Marker` as part of the `options` object, but the old function signature is still supported for backwards compatibility [#6356](https://github.com/mapbox/mapbox-gl-js/pull/6356) +* Add support for custom colors when using the default `Marker` SVG element (h/t @andrewharvey) [#6416](https://github.com/mapbox/mapbox-gl-js/pull/6416) +* Allow `CanvasSource` initialization from `HTMLElement` [#6424](https://github.com/mapbox/mapbox-gl-js/pull/6424) +* Add `is-supported-script` expression [6260](https://github.com/mapbox/mapbox-gl-js/pull/6260) + +### 🐛 Bug fixes + +* Align `raster-dem` tiles to pixel grid to eliminate blurry rendering on some devices [#6059](https://github.com/mapbox/mapbox-gl-js/pull/6059) +* Fix label collision circle debug drawing on overzoomed tiles [#6073](https://github.com/mapbox/mapbox-gl-js/pull/6073) +* Improve error reporting for some failed requests [#6126](https://github.com/mapbox/mapbox-gl-js/pull/6126), [#6032](https://github.com/mapbox/mapbox-gl-js/pull/6032) +* Fix several `Map#queryRenderedFeatures` bugs: + - account for `{text, icon}-offset` when querying[#6135](https://github.com/mapbox/mapbox-gl-js/pull/6135) + - correctly query features that extend across tile boundaries [#5756](https://github.com/mapbox/mapbox-gl-js/pull/6283) + - fix querying of `circle` layer features with `-pitch-scaling: 'viewport'` or `-pitch-alignment: 'map'` [#6036](https://github.com/mapbox/mapbox-gl-js/pull/6036) + - eliminate flicker effects when using query results to set a hover effect by switching from tile-based to viewport-based symbol querying [#6497](https://github.com/mapbox/mapbox-gl-js/pull/6497) +* Preserve browser history state when updating the `Map` hash [#6140](https://github.com/mapbox/mapbox-gl-js/pull/6140) +* Fix undefined behavior when `Map#addLayer` is invoked with an `id` of a preexisting layer [#6147](https://github.com/mapbox/mapbox-gl-js/pull/6147) +* Fix bug where `icon-image` would not be rendered if `text-field` is an empty string [#6164](https://github.com/mapbox/mapbox-gl-js/pull/6164) +* Ensure all camera methods fire `rotatestart` and `rotateend` events [#6187](https://github.com/mapbox/mapbox-gl-js/pull/6187) +* Always hide duplicate labels [#6166](https://github.com/mapbox/mapbox-gl-js/pull/6166) +* Fix `DragHandler` bugs where a left-button mouse click would end a right-button drag rotate and a drag gesture would not end if the control key is down on `mouseup` [#6193](https://github.com/mapbox/mapbox-gl-js/pull/6193) +* Add support for calling `{DragPanHandler, DragRotateHandler}#disable` while a gesture is in progress [#6232](https://github.com/mapbox/mapbox-gl-js/pull/6232) +* Fix `GeolocateControl` user location dot sizing when `Map`'s `
` inherits `box-sizing: border-box;` (h/t @andrewharvey) [#6227](https://github.com/mapbox/mapbox-gl-js/pull/6232) +* Fix bug causing an off-by-one error in `array` expression error messages (h/t @drewbo) [#6269](https://github.com/mapbox/mapbox-gl-js/pull/6269) +* Improve error message when an invalid access token triggers a 401 error [#6283](https://github.com/mapbox/mapbox-gl-js/pull/6283) +* Fix bug where lines with `line-width` larger than the sprite height of the `line-pattern` property would render other sprite images [#6246](https://github.com/mapbox/mapbox-gl-js/pull/6246) +* Fix broken touch events for `DragPanHandler` on mobile using Edge (note that zoom/rotate/pitch handlers still do not support Edge touch events [#1928](https://github.com/mapbox/mapbox-gl-js/pull/1928)) [#6325](https://github.com/mapbox/mapbox-gl-js/pull/6325) +* Fix race condition in `VectorTileWorkerSource#reloadTile` causing a rendering timeout [#6308](https://github.com/mapbox/mapbox-gl-js/issues/6308) +* Fix bug causing redundant `gl.stencilFunc` calls due to incorrect state checking (h/t @yangdonglai) [#6330](https://github.com/mapbox/mapbox-gl-js/pull/6330) +* Fix bug where `mousedown` or `touchstart` would cancel camera animations in non-interactive maps [#6338](https://github.com/mapbox/mapbox-gl-js/pull/6338) +* Fix bug causing a full-screen flicker when the map is pitched and a symbol layer uses non-zero `text-translate` [#6365](https://github.com/mapbox/mapbox-gl-js/issues/6365) +* Fix bug in `to-rgba` expression causing division by zero [6388](https://github.com/mapbox/mapbox-gl-js/pull/6388) +* Fix bug in cross-fading for `*-pattern` properties with non-integer zoom stops [#6430](https://github.com/mapbox/mapbox-gl-js/pull/6430) +* Fix bug where calling `Map#remove` on a map with constructor option `hash: true` throws an error (h/t @allthesignals) [#6490](https://github.com/mapbox/mapbox-gl-js/pull/6497) +* Fix bug causing flickering when panning across the anti-meridian [#6438](https://github.com/mapbox/mapbox-gl-js/pull/6438) +* Fix error when using tiles of non-power-of-two size [#6444](https://github.com/mapbox/mapbox-gl-js/pull/6444) +* Fix bug causing `Map#moveLayer(layerId, beforeId)` to remove the layer when `layerId === beforeId` [#6542](https://github.com/mapbox/mapbox-gl-js/pull/6542) +- Fix Rollup build for style-spec module [6575](https://github.com/mapbox/mapbox-gl-js/pull/6575) +- Fix bug causing `Map#querySourceFeatures` to throw an `Uncaught TypeError`(https://github.com/mapbox/mapbox-gl-js/pull/6555) +- Fix issue where label collision detection was inaccurate for some symbol layers that shared layout properties with another layer [#6558](https://github.com/mapbox/mapbox-gl-js/pull/6558) +- Restore `target` property for `mouse{enter,over,leave,out}` events [#6623](https://github.com/mapbox/mapbox-gl-js/pull/6623) + +## 0.44.2 + +### 🐛 Bug fixes + +* Workaround a breaking change in Safari causing page to scroll/zoom in response to user actions intended to pan/zoom the map [#6095](https://github.com/mapbox/mapbox-gl-js/issues/6095). (N.B., not to be confused with the workaround from April 2017 dealing with the same breaking change in Chrome [#4259](https://github.com/mapbox/mapbox-gl-js/issues/6095). See also https://github.com/WICG/interventions/issues/18, https://bugs.webkit.org/show_bug.cgi?id=182521, https://bugs.chromium.org/p/chromium/issues/detail?id=639227 .) + +## 0.44.1 + +### 🐛 Bug fixes + +* Fix bug causing features from symbol layers to be omitted from `map.queryRenderedFeatures()` [#6074](https://github.com/mapbox/mapbox-gl-js/issues/6074) +* Fix error triggered by simultaneous scroll-zooming and drag-panning. [#6106](https://github.com/mapbox/mapbox-gl-js/issues/6106) +* Fix bug wherein drag-panning failed to resume after a brief pause [#6063](https://github.com/mapbox/mapbox-gl-js/issues/6063) + +## 0.44.0 + +### ✨ Features and improvements + +* The CSP policy of a page using mapbox-gl-js no longer needs to include `script-src 'unsafe-eval'` [#559](https://github.com/mapbox/mapbox-gl-js/issues/559) +* Add `LngLatBounds#isEmpty()` method [#5917](https://github.com/mapbox/mapbox-gl-js/pull/5917) +* Updated to flow 0.62.0 [#5923](https://github.com/mapbox/mapbox-gl-js/issues/5923) +* Make compass and zoom controls optional ([#5348](https://github.com/mapbox/mapbox-gl-js/pull/5348)) (h/t @matijs) +* Add `collectResourceTiming` option to the enable collection of [Resource Timing](https://developer.mozilla.org/en-US/docs/Web/API/Resource_Timing_API/Using_the_Resource_Timing_API) data for requests that are made from Web Workers. ([#5948](https://github.com/mapbox/mapbox-gl-js/issues/5948)) +* Improve user location dot appearance across browsers ([#5498](https://github.com/mapbox/mapbox-gl-js/pull/5498)) (h/t @jasonbarry) + +### 🐛 Bug fixes + +* Fix error triggered by `==` and `!=` expressions [#5947](https://github.com/mapbox/mapbox-gl-js/issues/5947) +* Image sources honor `renderWorldCopies` [#5932](https://github.com/mapbox/mapbox-gl-js/pull/5932) +* Fix transitions to default fill-outline-color [#5953](https://github.com/mapbox/mapbox-gl-js/issues/5953) +* Fix transitions for light properties [#5982](https://github.com/mapbox/mapbox-gl-js/issues/5982) +* Fix minor symbol collisions on pitched maps [#5913](https://github.com/mapbox/mapbox-gl-js/pull/5913) +* Fix memory leaks after `Map#remove()` [#5943](https://github.com/mapbox/mapbox-gl-js/pull/5943), [#5951](https://github.com/mapbox/mapbox-gl-js/pull/5951) +* Fix bug wherein `GeoJSONSource#setData()` caused labels to fade out and back in ([#6002](https://github.com/mapbox/mapbox-gl-js/issues/6002)) +* Fix bug that could cause incorrect collisions for labels placed very near to each other at low zoom levels ([#5993](https://github.com/mapbox/mapbox-gl-js/issues/5993)) +* Fix bug causing `move` events to be fired out of sync with actual map movements ([#6005](https://github.com/mapbox/mapbox-gl-js/pull/6005)) +* Fix bug wherein `Map` did not fire `mouseover` events ([#6000](https://github.com/mapbox/mapbox-gl-js/pull/6000)] (h/t @jay-manday) +* Fix bug causing blurry rendering of raster tiles ([#4552](https://github.com/mapbox/mapbox-gl-js/issues/4552)) +* Fix potential memory leak caused by removing layers ([#5995](https://github.com/mapbox/mapbox-gl-js/issues/5995)) +* Fix bug causing attribution icon to appear incorrectly in compact maps not using Mapbox data ([#6042](https://github.com/mapbox/mapbox-gl-js/pull/6042)) +* Fix positioning of default marker element ([#6012](https://github.com/mapbox/mapbox-gl-js/pull/6012)) (h/t @andrewharvey) + +## 0.43.0 (December 21, 2017) + +### ⚠️ Breaking changes + +* It is now an error to attempt to remove a source that is in use [#5562](https://github.com/mapbox/mapbox-gl-js/pull/5562) +* It is now an error if the layer specified by the `before` parameter to `moveLayer` does not exist [#5679](https://github.com/mapbox/mapbox-gl-js/pull/5679) +* `"colorSpace": "hcl"` now uses shortest-path interpolation for hue [#5811](https://github.com/mapbox/mapbox-gl-js/issues/5811) + +### ✨ Features and improvements + +* Introduce client-side hillshading with `raster-dem` source type and `hillshade` layer type [#5286](https://github.com/mapbox/mapbox-gl-js/pull/5286) +* GeoJSON sources take 2x less memory and generate tiles 20%–100% faster [#5799](https://github.com/mapbox/mapbox-gl-js/pull/5799) +* Enable data-driven values for text-font [#5698](https://github.com/mapbox/mapbox-gl-js/pull/5698) +* Enable data-driven values for heatmap-radius [#5898](https://github.com/mapbox/mapbox-gl-js/pull/5898) +* Add getter and setter for offset on marker [#5759](https://github.com/mapbox/mapbox-gl-js/pull/5759) +* Add `Map#hasImage` [#5775](https://github.com/mapbox/mapbox-gl-js/pull/5775) +* Improve typing for `==` and `!=` expressions [#5840](https://github.com/mapbox/mapbox-gl-js/pull/5840) +* Made `coalesce` expressions more useful [#5755](https://github.com/mapbox/mapbox-gl-js/issues/5755) +* Enable implicit type assertions for array types [#5738](https://github.com/mapbox/mapbox-gl-js/pull/5738) +* Improve hash control precision [#5767](https://github.com/mapbox/mapbox-gl-js/pull/5767) +* `supported()` now returns false on old IE 11 versions that don't support Web Worker blob URLs [#5801](https://github.com/mapbox/mapbox-gl-js/pull/5801) +* Remove flow globals TileJSON and Transferable [#5668](https://github.com/mapbox/mapbox-gl-js/pull/5668) +* Improve performance of image, video, and canvas sources [#5845](https://github.com/mapbox/mapbox-gl-js/pull/5845) + +### 🐛 Bug fixes + +* Fix popups and markers lag during pan animation [#4670](https://github.com/mapbox/mapbox-gl-js/issues/4670) +* Fix fading of symbol layers caused by setData [#5716](https://github.com/mapbox/mapbox-gl-js/issues/5716) +* Fix behavior of `to-rgba` and `rgba` expressions [#5778](https://github.com/mapbox/mapbox-gl-js/pull/5778), [#5866](https://github.com/mapbox/mapbox-gl-js/pull/5866) +* Fix cross-fading of `*-pattern` and `line-dasharray` [#5791](https://github.com/mapbox/mapbox-gl-js/pull/5791) +* Fix `colorSpace` function property [#5843](https://github.com/mapbox/mapbox-gl-js/pull/5843) +* Fix style diffing when changing GeoJSON source properties [#5731](https://github.com/mapbox/mapbox-gl-js/issues/5731) +* Fix missing labels when zooming out from overzoomed tile [#5827](https://github.com/mapbox/mapbox-gl-js/issues/5827) +* Fix missing labels when zooming out and quickly using setData [#5837](https://github.com/mapbox/mapbox-gl-js/issues/5837) +* Handle NaN as input to step and interpolate expressions [#5757](https://github.com/mapbox/mapbox-gl-js/pull/5757) +* Clone property values on input and output [#5806](https://github.com/mapbox/mapbox-gl-js/pull/5806) +* Bump geojson-rewind dependency [#5769](https://github.com/mapbox/mapbox-gl-js/pull/5769) +* Allow setting Marker's popup before LngLat [#5893](https://github.com/mapbox/mapbox-gl-js/pull/5893) + +## 0.42.2 (November 21, 2017) + +### 🐛 Bug fixes + +- Add box-sizing to the "mapboxgl-ctrl-scale"-class [#5715](https://github.com/mapbox/mapbox-gl-js/pull/5715) +- Fix rendering in Safari [#5712](https://github.com/mapbox/mapbox-gl-js/issues/5712) +- Fix "Cannot read property 'hasTransition' of undefined" error [#5714](https://github.com/mapbox/mapbox-gl-js/issues/5714) +- Fix misplaced raster tiles [#5713](https://github.com/mapbox/mapbox-gl-js/issues/5713) +- Fix raster tile fading [#5722](https://github.com/mapbox/mapbox-gl-js/issues/5722) +- Ensure that an unset filter is undefined rather than null [#5727](https://github.com/mapbox/mapbox-gl-js/pull/5727) +- Restore pitch-with-rotate to nav control [#5725](https://github.com/mapbox/mapbox-gl-js/pull/5725) +- Validate container option in map constructor [#5695](https://github.com/mapbox/mapbox-gl-js/pull/5695) +- Fix queryRenderedFeatures behavior for features displayed in multiple layers [#5172](https://github.com/mapbox/mapbox-gl-js/issues/5172) + +## 0.42.1 (November 17, 2017) + +### 🐛 Bug fixes + +- Workaround for map flashing bug on Chrome 62+ with Intel Iris Graphics 6100 cards [#5704](https://github.com/mapbox/mapbox-gl-js/pull/5704) +- Rerender map when `map.showCollisionBoxes` is set to `false` [#5673](https://github.com/mapbox/mapbox-gl-js/pull/5673) +- Fix transitions from property default values [#5682](https://github.com/mapbox/mapbox-gl-js/pull/5682) +- Fix runtime updating of `heatmap-color` [#5682](https://github.com/mapbox/mapbox-gl-js/pull/5682) +- Fix mobile Safari `history.replaceState` error [#5613](https://github.com/mapbox/mapbox-gl-js/pull/5613) + +### ✨ Features and improvements + +- Provide default element for Marker class [#5661](https://github.com/mapbox/mapbox-gl-js/pull/5661) + +## 0.42.0 (November 10, 2017) + +### ⚠️ Breaking changes + +- Require that `heatmap-color` use expressions instead of stop functions [#5624](https://github.com/mapbox/mapbox-gl-js/issues/5624) +- Remove support for validating and migrating v6 styles +- Remove support for validating v7 styles [#5604](https://github.com/mapbox/mapbox-gl-js/pull/5604) +- Remove support for including `{tokens}` in expressions for `text-field` and `icon-image` [#5599](https://github.com/mapbox/mapbox-gl-js/issues/5599) +- Split `curve` expression into `step` and `interpolate` expressions [#5542](https://github.com/mapbox/mapbox-gl-js/pull/5542) +- Disallow interpolation in expressions for `line-dasharray` [#5519](https://github.com/mapbox/mapbox-gl-js/pull/5519) + +### ✨ Features and improvements + +- Improve label collision detection [#5150](https://github.com/mapbox/mapbox-gl-js/pull/5150) + - Labels from different sources will now collide with each other + - Collisions caused by rotation and pitch are now smoothly transitioned with a fade + - Improved algorithm for fewer erroneous collisions, denser label placement, and greater label stability during rotation +- Add `sqrt` expression [#5493](https://github.com/mapbox/mapbox-gl-js/pull/5493) + +### 🐛 Bug fixes and error reporting improvements + +- Fix viewport calculations for `fitBounds` when both zooming and padding change [#4846](https://github.com/mapbox/mapbox-gl-js/issues/4846) +- Fix WebGL "range out of bounds for buffer" error caused by sorted symbol layers [#5620](https://github.com/mapbox/mapbox-gl-js/issues/5620) +- Fix symbol fading across tile reloads [#5491](https://github.com/mapbox/mapbox-gl-js/issues/5491) +- Change tile rendering order to better match GL Native [#5601](https://github.com/mapbox/mapbox-gl-js/pull/5601) +- Ensure no errors are triggered when calling `queryRenderedFeatures` on a heatmap layer [#5594](https://github.com/mapbox/mapbox-gl-js/pull/5594) +- Fix bug causing `queryRenderedSymbols` to return results from different sources [#5554](https://github.com/mapbox/mapbox-gl-js/issues/5554) +- Fix CJK rendering issues [#5544](https://github.com/mapbox/mapbox-gl-js/issues/5544), [#5546](https://github.com/mapbox/mapbox-gl-js/issues/5546) +- Account for `circle-stroke-width` in `queryRenderedFeatures` [#5514](https://github.com/mapbox/mapbox-gl-js/pull/5514) +- Fix rendering of fill layers atop raster layers [#5513](https://github.com/mapbox/mapbox-gl-js/pull/5513) +- Fix rendering of circle layers with a `circle-stroke-opacity` of 0 [#5496](https://github.com/mapbox/mapbox-gl-js/issues/5496) +- Fix memory leak caused by actor callbacks [#5443](https://github.com/mapbox/mapbox-gl-js/issues/5443) +- Fix source cache size for raster sources with tile sizes other than 512px [#4313](https://github.com/mapbox/mapbox-gl-js/issues/4313) +- Validate that zoom expressions only appear at the top level of an expression [#5609](https://github.com/mapbox/mapbox-gl-js/issues/5609) +- Validate that step and interpolate expressions don't have any duplicate stops [#5605](https://github.com/mapbox/mapbox-gl-js/issues/5605) +- Fix rendering for `icon-text-fit` with a data-driven `text-size` [#5632](https://github.com/mapbox/mapbox-gl-js/pull/5632) +- Improve validation to catch uses of deprecated function syntax [#5667](https://github.com/mapbox/mapbox-gl-js/pull/5667) +- Permit altitude coordinates in `position` field in GeoJSON [#5608](https://github.com/mapbox/mapbox-gl-js/pull/5608) + +## 0.41.0 (October 11, 2017) + +### :warning: Breaking changes +- Removed support for paint classes [#3643](https://github.com/mapbox/mapbox-gl-js/pull/3643). Instead, use runtime styling APIs or `Map#setStyle`. +- Reverted the `canvas` source `contextType` option added in 0.40.0 [#5449](https://github.com/mapbox/mapbox-gl-js/pull/5449) + +### :bug: Bug fixes +- Clip raster tiles to avoid tile overlap [#5105](https://github.com/mapbox/mapbox-gl-js/pull/5105) +- Guard for offset edgecase in flyTo [#5331](https://github.com/mapbox/mapbox-gl-js/pull/5331) +- Ensure the map is updated after the sprite loads [#5367](https://github.com/mapbox/mapbox-gl-js/pull/5367) +- Limit animation duration on flyTo with maxDuration option [#5349](https://github.com/mapbox/mapbox-gl-js/pull/5349) +- Make double-tapping on make zoom in by a factor of 2 on iOS [#5274](https://github.com/mapbox/mapbox-gl-js/pull/5274) +- Fix rendering error with translucent raster tiles [#5380](https://github.com/mapbox/mapbox-gl-js/pull/5380) +- Error if invalid 'before' argument is passed to Map#addLayer [#5401](https://github.com/mapbox/mapbox-gl-js/pull/5401) +- Revert CanvasSource intermediary image buffer fix [#5449](https://github.com/mapbox/mapbox-gl-js/pull/5449) + +### :sparkles: Features and improvements +- Use setData operation when diffing geojson sources [#5332](https://github.com/mapbox/mapbox-gl-js/pull/5332) +- Return early from draw calls on layers where opacity=0 [#5429](https://github.com/mapbox/mapbox-gl-js/pull/5429) +- A [heatmap](https://www.mapbox.com/mapbox-gl-js/example/heatmap-layer/) layer type is now available. This layer type allows you to visualize and explore massive datasets of points, reflecting the shape and density of data well while also looking beautiful. See [the blog post](https://blog.mapbox.com/sneak-peek-at-heatmaps-in-mapbox-gl-73b41d4b16ae) for further details. + ![](https://cdn-images-1.medium.com/max/1600/1*Dme5MAgdA3pYdTRHUQzvLw.png) +- The value of a style property or filter can now be an [expression](http://www.mapbox.com/mapbox-gl-js/style-spec/#expressions). Expressions are a way of doing data-driven and zoom-driven styling that provides more flexibility and control, and unifies property and filter syntax. + + Previously, data-driven and zoom-driven styling relied on stop functions: you specify a feature property and a set of input-output pairs that essentially define a “scale” for how the style should be calculated based on the feature property. For example, the following would set circle colors on a green-to-red scale based on the value of `feature.properties.population`: + + ``` + "circle-color": { + "property": "population", + "stops": [ + [0, "green"], + [1000000, "red"] + ] + } + ``` + + This approach is powerful, but we’ve seen a number of use cases that stop functions don't satisfy. Expressions provide the flexibility to address use cases like these: + + **Multiple feature properties** + Using more than one feature property to calculate a given style property. E.g., styling land polygon colors based on both `feature.properties.land_use_category` and `feature.properties.elevation`. + + **Arithmetic** + For some use cases it’s necessary to do some arithmetic on the input data. One example is sizing circles to represent quantitative data. Since a circle’s visual size on the screen is really its area (and A=πr^2), the right way to scale `circle-radius` is `square_root(feature.properties.input_data_value)`. Another example is unit conversions: feature data may include properties that are in some particular unit. Displaying such data in units appropriate to, say, a user’s preference or location, requires being able to do simple arithmetic (multiplication, division) on whatever value is in the data. + + **Conditional logic** + This is a big one: basic if-then logic, for example to decide exactly what text to display for a label based on which properties are available in the feature or even the length of the name. A key example of this is properly supporting bilingual labels, where we have to decide whether to show local + English, local-only, or English-only, based on the data that’s available for each feature. + + **String manipulation** + More dynamic control over label text with things like uppercase/lowercase/title case transforms, localized number formatting, etc. Without this functionality, crafting and iterating on label content entails a large data-prep burden. + + **Filters** + Style layer filters had similar limitations. Moreover, they use a different syntax, even though their job is very similar to that of data-driven styling functions: filters say, “here’s how to look at a feature and decide whether to draw it,” and data-driven style functions say, “here’s how to look at a feature and decide how to size/color/place it.” Expressions provide a unified syntax for defining parts of a style that need to be calculated dynamically from feature data. + + For information on the syntax and behavior of expressions, please see [the documentation](http://www.mapbox.com/mapbox-gl-js/style-spec/#expressions). + +### :wrench: Development workflow improvements +- Made the performance benchmarking runner more informative and statistically robust + +## 0.40.1 (September 18, 2017) + +### :bug: Bug fixes +- Fix bug causing flicker when zooming in on overzoomed tiles [#5295](https://github.com/mapbox/mapbox-gl-js/pull/5295) +- Remove erroneous call to Tile#redoPlacement for zoom-only or low pitch camera changes [#5284](https://github.com/mapbox/mapbox-gl-js/pull/5284) +- Fix bug where `CanvasSource` coordinates were flipped and improve performance for non-animated `CanvasSource`s [#5303](https://github.com/mapbox/mapbox-gl-js/pull/5303) +- Fix bug causing map not to render on some cases on Internet Explorer 11 [#5321](https://github.com/mapbox/mapbox-gl-js/pull/5321) +- Remove upper limit on `fill-extrusion-height` property [#5320](https://github.com/mapbox/mapbox-gl-js/pull/5320) + +## 0.40.0 (September 13, 2017) + +### :warning: Breaking changes +- `Map#addImage` now requires the image as an `HTMLImageElement`, `ImageData`, or object with `width`, `height`, and + `data` properties with the same format as `ImageData`. It no longer accepts a raw `ArrayBufferView` in the second + argument and `width` and `height` options in the third argument. +- `canvas` sources now require a `contextType` option specifying the drawing context associated with the source canvas. [#5155](https://github.com/mapbox/mapbox-gl-js/pull/5155) + + +### :sparkles: Features and improvements +- Correct rendering for multiple `fill-extrusion` layers on the same map [#5101](https://github.com/mapbox/mapbox-gl-js/pull/5101) +- Add an `icon-anchor` property to symbol layers [#5183](https://github.com/mapbox/mapbox-gl-js/pull/5183) +- Add a per-map `transformRequest` option, allowing users to provide a callback that transforms resource request URLs [#5021](https://github.com/mapbox/mapbox-gl-js/pull/5021) +- Add data-driven styling support for + - `text-max-width` [#5067](https://github.com/mapbox/mapbox-gl-js/pull/5067) + - `text-letter-spacing` [#5071](https://github.com/mapbox/mapbox-gl-js/pull/5071) + - `line-join` [#5020](https://github.com/mapbox/mapbox-gl-js/pull/5020) +- Add support for SDF icons in `Map#addImage()` [#5181](https://github.com/mapbox/mapbox-gl-js/pull/5181) +- Added nautical miles unit to ScaleControl [#5238](https://github.com/mapbox/mapbox-gl-js/pull/5238) (h/t @fmairesse) +- Eliminate the map-wide limit on the number of glyphs and sprites that may be used in a style [#141](https://github.com/mapbox/mapbox-gl-js/issues/141). (Fixed by [#5190](https://github.com/mapbox/mapbox-gl-js/pull/5190), see also [mapbox-gl-native#9213](https://github.com/mapbox/mapbox-gl-native/pull/9213) +- Numerous performance optimizations (including [#5108](https://github.com/mapbox/mapbox-gl-js/pull/5108) h/t @pirxpilot) + + +### :bug: Bug fixes +- Add missing documentation for mouseenter, mouseover, mouseleave events [#4772](https://github.com/mapbox/mapbox-gl-js/issues/4772) +- Add missing documentation for `Marker#getElement()` method [#5242](https://github.com/mapbox/mapbox-gl-js/pull/5242) +- Fix bug wherein removing canvas source with animate=true leaves map in render loop [#5097](https://github.com/mapbox/mapbox-gl-js/issues/5097) +- Fix fullscreen detection on Firefox [#5272](https://github.com/mapbox/mapbox-gl-js/pull/5272) +- Fix z-fighting on overlapping fills within the same layer [#3320](https://github.com/mapbox/mapbox-gl-js/issues/3320) +- Fix handling of fractional values for `layer.minzoom` [#2929](https://github.com/mapbox/mapbox-gl-js/issues/2929) +- Clarify coordinate ordering in documentation for `center` option [#5042](https://github.com/mapbox/mapbox-gl-js/pull/5042) (h/t @karthikb351) +- Fix output of stop functions where two stops have the same input value [#5020](https://github.com/mapbox/mapbox-gl-js/pull/5020) (h/t @edpop ) +- Fix bug wherein using `Map#addLayer()` with an inline source would mutate its input [#4040](https://github.com/mapbox/mapbox-gl-js/issues/4040) +- Fix invalid css keyframes selector [#5075](https://github.com/mapbox/mapbox-gl-js/pull/5075) (h/t @aar0nr) +- Fix GPU-specific bug wherein canvas sources caused an error [#4262](https://github.com/mapbox/mapbox-gl-js/issues/4262) +- Fix a race condition in symbol layer handling that caused sporadic uncaught errors [#5185](https://github.com/mapbox/mapbox-gl-js/pull/5185) +- Fix bug causing line labels to render incorrectly on overzoomed tiles [#5120](https://github.com/mapbox/mapbox-gl-js/pull/5120) +- Fix bug wherein `NavigationControl` triggered mouse events unexpectedly [#5148](https://github.com/mapbox/mapbox-gl-js/issues/5148) +- Fix bug wherein clicking on the `NavigationControl` compass caused an error in IE 11 [#4784](https://github.com/mapbox/mapbox-gl-js/issues/4784) +- Remove dependency on GPL-3-licensed `fast-stable-stringify` module [#5152](https://github.com/mapbox/mapbox-gl-js/issues/5152) +- Fix bug wherein layer-specific an event listener produced an error after its target layer was removed from the map [#5145](https://github.com/mapbox/mapbox-gl-js/issues/5145) +- Fix `Marker#togglePopup()` failing to return the marker instance [#5116](https://github.com/mapbox/mapbox-gl-js/issues/5116) +- Fix bug wherein a marker's position failed to adapt to the marker element's size changing [#5133](https://github.com/mapbox/mapbox-gl-js/issues/5133) +- Fix rendering bug affecting Broadcom GPUs [#5073](https://github.com/mapbox/mapbox-gl-js/pull/5073) + +### :wrench: Development workflow improvements +- Add (and now require) Flow type annotations throughout the majority of the codebase. +- Migrate to CircleCI 2.0 [#4939](https://github.com/mapbox/mapbox-gl-js/pull/4939) + + +## 0.39.1 (July 24, 2017) + +### :bug: Bug fixes +- Fix packaging issue in 0.39.0 [#5025](https://github.com/mapbox/mapbox-gl-js/issues/5025) +- Correctly evaluate enum-based identity functions [#5023](https://github.com/mapbox/mapbox-gl-js/issues/5023) + +## 0.39.0 (July 21, 2017) + +### :warning: Breaking changes + +- `GeolocateControl` breaking changes #4479 + * The option `watchPosition` has been replaced with `trackUserLocation` + * The camera operation has changed from `jumpTo` (not animated) to `fitBounds` (animated). An effect of this is the map pitch is no longer reset, although the bearing is still reset to 0. + * The accuracy of the geolocation provided by the device is used to set the view (previously it was fixed at zoom level 17). The `maxZoom` can be controlled via the new `fitBoundsOptions` option (defaults to 15). +- Anchor `Marker`s at their center by default #5019 @andrewharvey +- Increase `significantRotateThreshold` for the `TouchZoomRotateHandler` #4971, @dagjomar + +### :sparkles: Features and improvements +- Improve performance of updating GeoJSON sources #4069, @ezheidtmann +- Improve rendering speed of extrusion layers #4818 +- Improve line label legibility in pitched views #4781 +- Improve line label legibility on curved lines #4853 +- Add user location tracking capability to `GeolocateControl` #4479, @andrewharvey + * New option `showUserLocation` to draw a "dot" as a `Marker` on the map at the user's location + * An active lock and background state are introduced with `trackUserLocation`. When in active lock the camera will update to follow the user location, however if the camera is changed by the API or UI then the control will enter the background state where it won't update the camera to follow the user location. + * New option `fitBoundsOptions` to control the camera operation + * New `trackuserlocationstart` and `trackuserlocationend` events + * New `LngLat.toBounds` method to extend a point location by a given radius to a `LngLatBounds` object +- Include main CSS file in `package.json` #4809, @tomscholz +- Add property function (data-driven styling) support for `line-width` #4773 +- Add property function (data-driven styling) support for `text-anchor` #4997 +- Add property function (data-driven styling) support for `text-justify` #5000 +- Add `maxTileCacheSize` option #4778, @jczaplew +- Add new `icon-pitch-alignment` and `circle-pitch-alignment` properties #4869 #4871 +- Add `Map#getMaxBounds` method #4890, @andrewharvey @lamuertepeluda +- Add option (`localIdeographFontFamily`) to use TinySDF to avoid loading expensive CJK glyphs #4895 +- If `config.API_URL` includes a path prepend it to the request URL #4995 +- Bump `supercluster` version to expose `cluster_id` property on clustered sources #5002 + +### :bug: Bug fixes +- Do not display `FullscreenControl` on unsupported devices #4838, @stepankuzmin +- Fix yarn build on Windows machines #4887 +- Prevent potential memory leaks by dispatching `loadData` to the same worker every time #4877 +- Fix bug preventing the rtlTextPlugin from loading before the initial style `load` #4870 +- Fix bug causing runtime-stying to not take effect in some situations #4893 +- Prevent requests of vertical glyphs for labels that can't be verticalized #4720 +- Fix character detection for Zanabazar Square #4940 +- Fix `LogoControl` logic to update correctly, and hide the `
` instead of removing it from the DOM when it is not needed #4842 +- Fix `GeoJSONSource#serialize` to include all options +- Fix error handling in `GlyphSource#getSimpleGlyphs`#4992 +- Fix bug causing `setStyle` to reload raster tiles #4852 +- Fix bug causing symbol layers not to render on devices with non-integer device pixel ratios #4989 +- Fix bug where `Map#queryRenderedFeatures` would error when returning no results #4993 +- Fix bug where `Map#areTilesLoaded` would always be false on `sourcedata` events for reloading tiles #4987 +- Fix bug causing categorical property functions to error on non-ascending order stops #4996 + +### :hammer_and_wrench: Development workflow changes +- Use flow to type much of the code base #4629 #4903 #4909 #4910 #4911 #4913 #4915 #4918 #4932 #4933 #4948 #4949 #4955 #4966 #4967 #4973 :muscle: @jfirebaugh @vicapow +- Use style specification to generate flow type #4958 +- Explicitly list which files to publish in `package.json` #4819 @tomscholz +- Move render test ignores to a separate file #4977 +- Add code of conduct #5015 :sparkling_heart: + +## 0.38.0 (June 9, 2017) + +#### New features :sparkles: + +- Attenuate label size scaling with distance, improving readability of pitched maps [#4547](https://github.com/mapbox/mapbox-gl-js/pull/4547) + +#### Bug fixes :beetle: + +- Skip rendering for patterned layers when pattern is missing [#4687](https://github.com/mapbox/mapbox-gl-js/pull/4687) +- Fix bug with map failing to rerender after `webglcontextlost` event [#4725](https://github.com/mapbox/mapbox-gl-js/pull/4725) @cdawi +- Clamp zoom level in `flyTo` to within the map's specified min- and maxzoom to prevent undefined behavior [#4726](https://github.com/mapbox/mapbox-gl-js/pull/4726) @ IvanSanchez +- Fix wordmark rendering in IE [#4741](https://github.com/mapbox/mapbox-gl-js/pull/4741) +- Fix slight pixelwise symbol rendering bugs caused by incorrect sprite calculations [#4737](https://github.com/mapbox/mapbox-gl-js/pull/4737) +- Prevent exceptions thrown by certain `flyTo` calls [#4761](https://github.com/mapbox/mapbox-gl-js/pull/4761) +- Fix "Improve this map" link [#4685](https://github.com/mapbox/mapbox-gl-js/pull/4685) +- Tweak `queryRenderedSymbols` logic to better account for pitch scaling [#4792](https://github.com/mapbox/mapbox-gl-js/pull/4792) +- Fix for symbol layers sometimes failing to render, most frequently in Safari [#4795](https://github.com/mapbox/mapbox-gl-js/pull/4795) +- Apply `text-keep-upright` after `text-offset` to keep labels upright when intended [#4779](https://github.com/mapbox/mapbox-gl-js/pull/4779) **[Potentially breaking :warning: but considered a bugfix]** +- Prevent exceptions thrown by empty GeoJSON tiles [4803](https://github.com/mapbox/mapbox-gl-js/pull/4803) + +#### Accessibility improvements :sound: + +- Add `aria-label` to popup close button [#4799](https://github.com/mapbox/mapbox-gl-js/pull/4799) @andrewharvey + +#### Development workflow + testing improvements :wrench: + +- Fix equality assertion bug in tests [#4731](https://github.com/mapbox/mapbox-gl-js/pull/4731) @IvanSanchez +- Benchmark results page improvements [#4746](https://github.com/mapbox/mapbox-gl-js/pull/4746) +- Require node version >=6.4.0, enabling the use of more ES6 features [#4752](https://github.com/mapbox/mapbox-gl-js/pull/4752) +- Document missing `pitchWithRotate` option [#4800](https://github.com/mapbox/mapbox-gl-js/pull/4800) @simast +- Move Github-specific Markdown files into subdirectory [#4806](https://github.com/mapbox/mapbox-gl-js/pull/4806) @tomscholz + +## 0.37.0 (May 2nd, 2017) + +#### :warning: Breaking changes + +- Removed `LngLat#wrapToBestWorld` + +#### New features :rocket: + +- Improve popup/marker positioning #4577 +- Add `Map#isStyleLoaded` and `Map#areTilesLoaded` events #4321 +- Support offline sprites using `file:` protocol #4649 @oscarfonts + +#### Bug fixes :bug: + +- Fix fullscreen control in Firefox #4666 +- Fix rendering artifacts that caused tile boundaries to be visible in some cases #4636 +- Fix default calculation for categorical zoom-and-property functions #4657 +- Fix scaling of images on retina screens #4645 +- Rendering error when a transparent image is added via `Map#addImage` #4644 +- Fix an issue with rendering lines with duplicate points #4634 +- Fix error when switching from data-driven styles to a constant paint value #4611 +- Add check to make sure invalid bounds on tilejson don't error out #4641 + +#### Development workflow improvements :computer: + +- Add flowtype interfaces and definitions @vicapow +- Add stylelinting to ensure `mapboxgl-` prefix on all classes #4584 @asantos3026 + +## 0.36.0 (April 19, 2017) + +#### New features :sparkles: + +- Replace LogoControl logo with the new Mapbox logo #4598 + +#### Bug fixes :bug: + +- Fix bug with the BoxZoomHandler that made it glitchy if it is enabled after the DragPanHandler #4528 +- Fix undefined behavior in `fill_outline` shaders #4600 +- Fix `Camera#easeTo` interpolation on pitched maps #4540 +- Choose property function interpolation method by the `property`'s type #4614 + +#### Development workflow improvements :nerd_face: + +- Fix crash on missing `style.json` in integration tests +- `gl-style-composite` is now executable in line with the other tools @andrewharvey #4595 +- `gl-style-composite` utility now throws an error if a name conflict would occur between layers @andrewharvey #4595 + +## 0.35.1 (April 12, 2017) + +#### Bug fixes :bug: + +- Add `.json` extension to style-spec `require` statements for webpack compatibility #4563 @orangemug +- Fix documentation type for `Map#fitBounde` #4569 @andrewharvey +- Fix bug causing {Image,Video,Canvas}Source to throw exception if latitude is outside of +/-85.05113 #4574 +- Fix bug causing overzoomed raster tiles to disappear from map #4567 +- Fix bug causing queryRenderedFeatures to crash on polygon features that have an `id` field. #4581 + +## 0.35.0 (April 7, 2017) + +#### New features :rocket: +- Use anisotropic filtering to improve rendering of raster tiles on pitched maps #1064 +- Add `pitchstart` and `pitchend` events #2449 +- Add an optional `layers` parameter to `Map#on` #1002 +- Add data-driven styling support for `text-offset` #4495 +- Add data-driven styling support for `text-rotate` #3516 +- Add data-driven styling support for `icon-image` #4304 +- Add data-driven styling support for `{text,icon}-size` #4455 + +#### Bug fixes :bug: +- Suppress error messages in JS console due to missing tiles #1800 +- Fix bug wherein `GeoJSONSource#setData()` could cause unnecessary DOM updates #4447 +- Fix bug wherein `Map#flyTo` did not respect the `renderWorldCopies` setting #4449 +- Fix regression in browserify support # 4453 +- Fix bug causing poor touch event behavior on mobile devices #4259 +- Fix bug wherein duplicate stops in property functions could cause an infinite loop #4498 +- Respect image height/width in `addImage` api #4531 +- Fix bug preventing correct behavior of `shift+zoom` #3334 +- Fix bug preventing image source from rendering when coordinate area is too large #4550 +- Show image source on horizontally wrapped worlds #4555 +- Fix bug in the handling of `refreshedExpiredTiles` option #4549 +- Support the TileJSON `bounds` property #1775 + +#### Development workflow improvements :computer: +- Upgrade flow to 0.42.0 (#4500) + + +## 0.34.0 (March 17, 2017) + +#### New features :rocket: +- Add `Map#addImage` and `Map#removeImage` API to allow adding icon images at runtime #4404 +- Simplify non-browserify bundler usage by making the distribution build the main entrypoint #4423 + +#### Bug fixes :bug: +- Fix issue where coincident start/end points of LineStrings were incorrectly rendered as joined #4413 +- Fix bug causing `queryRenderedFeatures` to fail in cases where both multiple sources and data-driven paint properties were present #4417 +- Fix bug where tile request errors caused `map.loaded()` to incorrectly return `false` #4425 + +#### Testing improvements :white_check_mark: +- Improve test coverage across several core modules #4432 #4431 #4422 #4244 :bowing_man: + +## 0.33.1 (March 10, 2017) + +#### Bug fixes :bug: +- Prevent Mapbox logo from being added to the map more than once #4386 +- Add `type='button'` to `FullscreenControl` to prevent button from acting as a form submit #4397 +- Fix issue where map would continue to rotate if `Ctrl` key is released before the click during a `DragRotate` event #4389 +- Remove double `options.easing` description from the `Map#fitBounds` documentation #4402 + + +## 0.33.0 (March 8, 2017) + +#### :warning: Breaking changes +- Automatically add Mapbox wordmark when required by Mapbox TOS #3933 +- Increase default `maxZoom` from 20 to 22 #4333 +- Deprecate `tiledata` and `tiledataloading` events in favor of `sourcedata` and `sourcedataloading`. #4347 +- `mapboxgl.util` is no longer exported #1408 +- `"type": "categorical"` is now required for all categorical functions. Previously, some forms of "implicitly" categorical functions worked, and others did not. #3717 + +#### :white_check_mark: New features +- Add property functions support for most symbol paint properties #4074, #4186, #4226 +- Add ability to specify default property value for undefined or invalid property values used in property functions. #4175 +- Improve `Map#fitBounds` to accept different values for top, bottom, left, and right `padding` #3890 +- Add a `FullscreenControl` for displaying a fullscreen map #3977 + +#### :beetle: Bug fixes +- Fix validation error on categorical zoom-and-property functions #4220 +- Fix bug causing expired resources to be re-requested causing an infinite loop #4255 +- Fix problem where `MapDataEvent#isSourceLoaded` always returned false #4254 +- Resolve an issue where tiles in the source cache were prematurely deleted, resulting in tiles flickering when zooming in and out and #4311 +- Make sure `MapEventData` is passed through on calls `Map#flyTo` #4342 +- Fix incorrect returned values for `Map#isMoving` #4350 +- Fix categorical functions not allowing boolean stop domain values #4195 +- Fix piecewise-constant functions to allow non-integer zoom levels. #4196 +- Fix issues with `$id` in filters #4236 #4237 +- Fix a race condition with polygon centroid algorithm causing tiles not to load in some cases. #4273 +- Throw a meaningful error when giving non-array `layers` parameter to `queryRenderedFeatures` #4331 +- Throw a meaningful error when supplying invalid `minZoom` and `maxZoom` values #4324 +- Fix a memory leak when using the RTL Text plugin #4248 + +#### Dev workflow changes +- Merged the [Mapbox GL style specification](https://github.com/mapbox/mapbox-gl-style-spec) repo to this one (now under `src/style-spec` and `test/unit/style-spec`). + +## 0.32.1 (Jan 26, 2017) + +#### Bug Fixes + + - Fix bug causing [`mapbox-gl-rtl-text` plugin](https://github.com/mapbox/mapbox-gl-rtl-text) to not work #4055 + +## 0.32.0 (Jan 26, 2017) + +#### Deprecation Notices + +- [Style classes](https://www.mapbox.com/mapbox-gl-style-spec/#layer-paint.*) are deprecated and will be removed in an upcoming release of Mapbox GL JS. + +#### New Features + + - Add `Map#isSourceLoaded` method #4033 + - Automatically reload tiles based on their `Expires` and `Cache-Control` HTTP headers #3944 + - Add `around=center` option to `scrollZoom` and `touchZoomRotate` interaction handlers #3876 + - Add support for [`mapbox-gl-rtl-text` plugin](https://github.com/mapbox/mapbox-gl-rtl-text) to support right-to-left scripts #3758 + - Add `canvas` source type #3765 + - Add `Map#isMoving` method #2792 + +#### Bug Fixes + + - Fix bug causing garbled text on zoom #3962 + - Fix bug causing crash in Firefox and Mobile Safari when rendering a large map #4037 + - Fix bug causing raster tiles to flicker during zoom #2467 + - Fix bug causing exception when unsetting and resetting fill-outline-color #3657 + - Fix memory leak when removing raster sources #3951 + - Fix bug causing exception when when zooming in / out on empty GeoJSON tile #3985 + - Fix line join artifacts at very sharp angles #4008 + +## 0.31.0 (Jan 10 2017) + +#### New Features + +- Add `renderWorldCopies` option to the `Map` constructor to give users control over whether multiple worlds are rendered in a map #3885 + +#### Bug Fixes + +- Fix performance regression triggered when `Map` pitch or bearing is changed #3938 +- Fix null pointer exception caused by trying to clear an `undefined` source #3903 + +#### Miscellaneous + +- Incorporate integration tests formerly at [`mapbox-gl-test-suite`](https://github.com/mapbox/mapbox-gl-test-suite) into this repository #3834 + +## 0.30.0 (Jan 5 2017) + +#### New Features + + - Fire an error when map canvas is larger than allowed by `gl.MAX_RENDERBUFFER_SIZE` #2893 + - Improve error messages when referencing a nonexistent layer id #2597 + - Fire an error when layer uses a `geojson` source and specifies a `source-layer` #3896 + - Add inline source declaration syntax #3857 + - Improve line breaking behavior #3887 + +#### Performance Improvements + + - Improve `Map#setStyle` performance in some cases #3853 + +#### Bug Fixes + + - Fix unexpected popup positioning when some offsets are unspecified #3367 + - Fix incorrect interpolation in functions #3838 + - Fix incorrect opacity when multiple backgrounds are rendered #3819 + - Fix exception thrown when instantiating geolocation control in Safari #3844 + - Fix exception thrown when setting `showTileBoundaries` with no sources #3849 + - Fix incorrect rendering of transparent parts of raster layers in some cases #3723 + - Fix non-terminating render loop when zooming in in some cases #3399 + +## 0.29.0 (December 20 2016) + +#### New Features + + - Add support for property functions for many style properties on line layers #3033 + - Make `Map#setStyle` smoothly transition to the new style #3621 + - Add `styledata`, `sourcedata`, `styledataloading`, and `sourcedataloading` events + - Add `isSourceLoaded` and `source` properties to `MapDataEvent` #3590 + - Remove "max zoom" cap of 20 #3683 + - Add `circle-stroke-*` style properties #3672 + - Add a more helpful error message when the specified `container` element doesn't exist #3719 + - Add `watchPosition` option to `GeolocateControl` #3739 + - Add `positionOptions` option to `GeolocateControl` #3739 + - Add `aria-label` to map canvas #3782 + - Adjust multipoint symbol rendering behavior #3763 + - Add support for property functions for `icon-offset` #3791 + - Improved antialiasing on pitched lines #3790 + - Allow attribution control to collapse to an ⓘ button on smaller screens #3783 + - Improve line breaking algorithm #3743 + +#### Performance Improvements + + - Fix memory leak when calling `Map#removeSource` #3602 + - Reduce bundle size by adding custom build of `gl-matrix` #3734 + - Improve performance of projection code #3721 + - Improve performance of style function evaluation #3816 + +#### Bug fixes + + - Fix exception thrown when using `line-color` property functions #3639 + - Fix exception thrown when removing a layer and then adding another layer with the same id but different type #3655 + - Fix exception thrown when passing a single point to `Map#fitBounds` #3655 + - Fix exception thrown occasionally during rapid map mutations #3681 + - Fix rendering defects on pitch=0 on some systems #3740 + - Fix unnecessary CPU usage when displaying a raster layer #3764 + - Fix bug causing sprite after `Map#setStyle` #3829 + - Fix bug preventing `Map` from emitting a `contextmenu` event on Windows browsers #3822 + +## 0.28.0 (November 17 2016) + +#### New features and improvements + +- Performance improvements for `Map#addLayer` and `Map#removeLayer` #3584 +- Add method for changing layer order at runtime - `Map#moveLayer` #3584 +- Update vertical punctuation logic to Unicode 9.0 standard #3608 + +#### Bug fixes + +- Fix data-driven `fill-opacity` rendering when using a `fill-pattern` #3598 +- Fix line rendering artifacts #3627 +- Fix incorrect rendering of opaque fills on top of transparent fills #2628 +- Prevent `AssertionErrors` from pitching raster layers by only calling `Worker#redoPlacement` on vector and GeoJSON sources #3624 +- Restore IE11 compatability #3635 +- Fix symbol placement for cached tiles #3637 + + +## 0.27.0 (November 11 2016) + +#### ⚠️ Breaking changes ⚠️ + +- Replace `fill-extrude-height` and `fill-extrude-base` properties of `fill` render type with a separate `fill-extrusion` type (with corresponding `fill-extrusion-height` and `fill-extrusion-base` properties), solving problems with render parity and runtime switching between flat and extruded fills. https://github.com/mapbox/mapbox-gl-style-spec/issues/554 +- Change the units for extrusion height properties (`fill-extrusion-height`, `fill-extrusion-base`) from "magic numbers" to meters. #3509 +- Remove `mapboxgl.Control` class and change the way custom controls should be implemented. #3497 +- Remove `mapboxgl.util` functions: `inherit`, `extendAll`, `debounce`, `coalesce`, `startsWith`, `supportsGeolocation`. #3441 #3571 +- **`mapboxgl.util` is deprecated** and will be removed in the next release. #1408 + +#### New features and improvements + +- Tons of **performance improvements** that combined make rendering **up to 3 times faster**, especially for complex styles. #3485 #3489 #3490 #3491 #3498 #3499 #3501 #3510 #3514 #3515 #3486 #3527 #3574 ⚡️⚡️⚡️ +- 🈯 Added **vertical text writing mode** for languages that support it. #3438 +- 🈯 Improved **line breaking of Chinese and Japanese text** in point-placed labels. #3420 +- Reduce the default number of worker threads (`mapboxgl.workerCount`) for better performance. #3565 +- Automatically use `categorical` style function type when input values are strings. #3384 +- Improve control buttons accessibility. #3492 +- Remove geolocation button if geolocation is disabled (e.g. the page is not served through `https`). #3571 +- Added `Map#getMaxZoom` and `Map#getMinZoom` methods #3592 + +#### Bugfixes + +- Fix several line dash rendering bugs. #3451 +- Fix intermittent map flicker when using image sources. #3522 +- Fix incorrect rendering of semitransparent `background` layers. #3521 +- Fix broken `raster-fade-duration` property. #3532 +- Fix handling of extrusion heights with negative values (by clamping to `0`). #3463 +- Fix GeoJSON sources not placing labels/icons correctly after map rotation. #3366 +- Fix icon/label placement not respecting order for layers with numeric names. #3404 +- Fix `queryRenderedFeatures` working incorrectly on colliding labels. #3459 +- Fix a bug where changing extrusion properties at runtime sometimes threw an error. #3487 #3468 +- Fix a bug where `map.loaded()` always returned `true` when using raster tile sources. #3302 +- Fix a bug where moving the map out of bounds sometimes threw `failed to invert matrix` error. #3518 +- Fixed `queryRenderedFeatures` throwing an error if no parameters provided. #3542 +- Fixed a bug where using multiple `\n` in a text field resulted in an error. #3570 + +#### Misc + +- 🐞 Fix `npm install mapbox-gl` pulling in all `devDependencies`, leading to an extremely slow install. #3377 +- Switch the codebase to ES6. #3388 #3408 #3415 #3421 +- A lot of internal refactoring to make the codebase simpler and more maintainable. +- Various documentation fixes. #3440 + +## 0.26.0 (October 13 2016) + +#### New Features & Improvements + + * Add `fill-extrude-height` and `fill-extrude-base` style properties (3d buildings) :cityscape: #3223 + * Add customizable `colorSpace` interpolation to functions #3245 + * Add `identity` function type #3274 + * Add depth testing for symbols with `'pitch-alignment': 'map'` #3243 + * Add `dataloading` events for styles and sources #3306 + * Add `Control` suffix to all controls :warning: BREAKING CHANGE :warning: #3355 + * Calculate style layer `ref`s automatically and get rid of user-specified `ref`s :warning: BREAKING CHANGE :warning: #3486 + +#### Performance Improvements + + * Ensure removing style or source releases all tile resources #3359 + +#### Bugfixes + + * Fix bug causing an error when `Marker#setLngLat` is called #3294 + * Fix bug causing incorrect coordinates in `touchend` on Android Chrome #3319 + * Fix bug causing incorrect popup positioning at top of screen #3333 + * Restore `tile` property to `data` events fired when a tile is removed #3328 + * Fix bug causing "Improve this map" link to not preload map location #3356 + +## 0.25.1 (September 30 2016) + +#### Bugfixes + + * Fix bug causing attribution to not be shown #3278 + * Fix bug causing exceptions when symbol text has a trailing newline #3281 + +## 0.25.0 (September 29 2016) + +#### Breaking Changes + + * `Evented#off` now require two arguments; omitting the second argument in order to unbind all listeners for an event + type is no longer supported, as it could cause unintended unbinding of internal listeners. + +#### New Features & Improvements + + * Consolidate undocumented data lifecycle events into `data` and `dataloading` events (#3255) + * Add `auto` value for style spec properties (#3203) + +#### Bugfixes + + * Fix bug causing "Map#queryRenderedFeatures" to return no features after map rotation or filter change (#3233) + * Change webpack build process (#3235) :warning: BREAKING CHANGE :warning: + * Improved error messages for `LngLat#convert` (#3232) + * Fix bug where the `tiles` field is omitted from the `RasterTileSource#serialize` method (#3259) + * Comply with HTML spec by replacing the `div` within the `Navigation` control `