Skip to content

Commit 3de73d5

Browse files
committed
Merge pull request #4 from plotly/fix-d3-geo-dblclick
More consistent geo maps configs
2 parents 19886d2 + 050e53b commit 3de73d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+112120
-112434
lines changed

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,4 @@ node_modules
33
build/*
44
!build/README.md
55

6-
dist/*
7-
!dist/README.md
8-
96
npm-debug.log

devtools/test_dashboard/index.html

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111

1212
<script type="text/javascript" src="../../dist/extras/mathjax/MathJax.js?config=TeX-AMS-MML_SVG"></script>
1313

14-
<script type="text/javascript" src="../../dist/plotly.js" charset="utf-8"></script>
15-
<script>PLOTLYENV = { TOPOJSON_URL: '../../src/assets/topojson/' };</script>
14+
<!-- use dev plotly.js build -->
15+
<script type="text/javascript" src="../../build/plotly.js" charset="utf-8"></script>
16+
17+
<!-- use local topojson files -->
18+
<script>Plotly.setPlotConfig({ topojsonURL: '../../dist/topojson/' });</script>
1619

1720
<script type="text/javascript" src="../../build/test_dashboard-bundle.js"></script>
1821

19-
<!-- helper functions to manipulate graph div -->
22+
<!-- helper functions to manipulate the graph div -->
2023
<script>
2124
var Tabs = {
2225
getGraph: function() {

dist/plotly-geo-assets.js

+42-34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/plotly-with-meta.js

+56,656-56,258
Large diffs are not rendered by default.

dist/plotly.js

+55,284-56,043
Large diffs are not rendered by default.

dist/plotly.min.js

+35-36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/assets/topojson/south-america_50m.json renamed to dist/topojson/south-america_50m.json

+1-1
Large diffs are not rendered by default.
File renamed without changes.

src/assets/topojson/usa_50m.json renamed to dist/topojson/usa_50m.json

+1-1
Large diffs are not rendered by default.
File renamed without changes.
File renamed without changes.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"delaunay-triangulate": "^1.1.6",
6565
"es6-promise": "^3.0.2",
6666
"fast-isnumeric": "^1.1.1",
67+
"fs-extra": "^0.26.2",
6768
"gl-error2d": "^1.0.0",
6869
"gl-error3d": "^1.0.0",
6970
"gl-line2d": "^1.2.1",
@@ -87,6 +88,7 @@
8788
"node-sass": "^3.4.1",
8889
"right-now": "^1.0.0",
8990
"robust-orientation": "^1.1.3",
91+
"sane-topojson": "^1.2.0",
9092
"superscript-text": "^1.0.0",
9193
"through2": "^2.0.0",
9294
"tinycolor2": "1.1.2",

src/assets/geo_assets.js

+2-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
exports.topojsons = {};
1+
var saneTopojson = require('sane-topojson');
22

3-
exports.topojsons['world_110m'] = require('./topojson/world_110m.json');
4-
exports.topojsons['africa_110m'] = require('./topojson/africa_110m.json');
5-
exports.topojsons['asia_110m'] = require('./topojson/asia_110m.json');
6-
exports.topojsons['europe_110m'] = require('./topojson/europe_110m.json');
7-
exports.topojsons['north-america_110m'] = require('./topojson/north-america_110m.json');
8-
exports.topojsons['south-america_110m'] = require('./topojson/south-america_110m.json');
9-
exports.topojsons['usa_110m'] = require('./topojson/usa_110m');
10-
11-
exports.topojsons['world_50m'] = require('./topojson/world_50m.json');
12-
exports.topojsons['africa_50m'] = require('./topojson/africa_50m.json');
13-
exports.topojsons['asia_50m'] = require('./topojson/asia_50m.json');
14-
exports.topojsons['europe_50m'] = require('./topojson/europe_50m.json');
15-
exports.topojsons['north-america_50m'] = require('./topojson/north-america_50m.json');
16-
exports.topojsons['south-america_50m'] = require('./topojson/south-america_50m.json');
17-
exports.topojsons['usa_50m'] = require('./topojson/usa_50m.json');
3+
exports.topojson = saneTopojson;

src/components/modebar/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,14 @@ proto.toImage = function() {
450450

451451
var ev = Plotly.Snapshot.toImage(this.graphInfo, {format: format});
452452

453-
var filename = this.graphInfo.fn || "newplot";
453+
var filename = this.graphInfo.fn || 'newplot';
454454
filename += '.' + format;
455455

456456
ev.once('success', function(result) {
457457

458458
_this._snapshotInProgress = false;
459459

460-
var downloadLink = document.createElement("a");
460+
var downloadLink = document.createElement('a');
461461
downloadLink.href = result;
462462
downloadLink.download = filename; // only supported by FF and Chrome
463463

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ exports.Plots = Plotly.Plots;
2525
exports.Fx = Plotly.Fx;
2626
exports.Snapshot = Plotly.Snapshot;
2727
exports.PlotSchema = Plotly.PlotSchema;
28+
exports.Queue = Plotly.Queue;
2829

2930
// export d3 used in the bundle
3031
exports.d3 = require('d3');

src/lib/events.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
/* global $:false */
4+
35
var EventEmitter = require('events').EventEmitter;
46

57
var Events = {

src/lib/topojson_utils.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ topojsonUtils.getTopojsonName = function(geoLayout) {
1313
].join('');
1414
};
1515

16-
topojsonUtils.getTopojsonPath = function(topojsonName) {
17-
var topojsonUrl = (window.PLOTLYENV &&
18-
window.PLOTLYENV.TOPOJSON_URL) || './topojson/';
19-
20-
return topojsonUrl + topojsonName + '.json';
16+
topojsonUtils.getTopojsonPath = function(topojsonURL, topojsonName) {
17+
return topojsonURL + topojsonName + '.json';
2118
};
2219

2320
topojsonUtils.getTopojsonFeatures = function(trace, topojson) {

src/plot_api/plot_api.js

+26-14
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,10 @@ function plotGeo(gd) {
455455

456456
var i, geoId, fullGeoData, geo;
457457

458-
// if plotlyjs-geo-assets-bundle is not included,
459-
// initialize object to keep reference to every loaded topojsons
458+
// if 'plotly-geo-assets.js' is not included,
459+
// initialize object to keep reference to every loaded topojson
460460
if(window.PlotlyGeoAssets === undefined) {
461-
window.PlotlyGeoAssets = { topojsons : {} };
461+
window.PlotlyGeoAssets = { topojson : {} };
462462
}
463463

464464
for (i = 0; i < geoIds.length; i++) {
@@ -471,7 +471,8 @@ function plotGeo(gd) {
471471
geo = new Plotly.Geo(
472472
{
473473
id: geoId,
474-
container: fullLayout._geocontainer.node()
474+
container: fullLayout._geocontainer.node(),
475+
topojsonURL: gd._context.topojsonURL
475476
},
476477
fullLayout
477478
);
@@ -1358,7 +1359,9 @@ Plotly.extendTraces = function extendTraces (gd, update, indices, maxPoints) {
13581359
Plotly.redraw(gd);
13591360

13601361
var undoArgs = [gd, undo.update, indices, undo.maxPoints];
1361-
Plotly.Queue.add(gd, Plotly.prependTraces, undoArgs, extendTraces, arguments);
1362+
if (Plotly.Queue) {
1363+
Plotly.Queue.add(gd, Plotly.prependTraces, undoArgs, extendTraces, arguments);
1364+
}
13621365
};
13631366

13641367
Plotly.prependTraces = function prependTraces (gd, update, indices, maxPoints) {
@@ -1383,7 +1386,9 @@ Plotly.prependTraces = function prependTraces (gd, update, indices, maxPoints)
13831386
Plotly.redraw(gd);
13841387

13851388
var undoArgs = [gd, undo.update, indices, undo.maxPoints];
1386-
Plotly.Queue.add(gd, Plotly.extendTraces, undoArgs, prependTraces, arguments);
1389+
if (Plotly.Queue) {
1390+
Plotly.Queue.add(gd, Plotly.extendTraces, undoArgs, prependTraces, arguments);
1391+
}
13871392
};
13881393

13891394
/**
@@ -1427,7 +1432,7 @@ Plotly.addTraces = function addTraces (gd, traces, newIndices) {
14271432
// i.e., we can simply redraw and be done
14281433
if (typeof newIndices === 'undefined') {
14291434
Plotly.redraw(gd);
1430-
Plotly.Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);
1435+
if (Plotly.Queue) Plotly.Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);
14311436
return;
14321437
}
14331438

@@ -1450,10 +1455,10 @@ Plotly.addTraces = function addTraces (gd, traces, newIndices) {
14501455

14511456
// if we're here, the user has defined specific places to place the new traces
14521457
// this requires some extra work that moveTraces will do
1453-
Plotly.Queue.startSequence(gd);
1454-
Plotly.Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);
1458+
if (Plotly.Queue) Plotly.Queue.startSequence(gd);
1459+
if (Plotly.Queue) Plotly.Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);
14551460
Plotly.moveTraces(gd, currentIndices, newIndices);
1456-
Plotly.Queue.stopSequence(gd);
1461+
if (Plotly.Queue) Plotly.Queue.stopSequence(gd);
14571462
};
14581463

14591464
/**
@@ -1493,7 +1498,8 @@ Plotly.deleteTraces = function deleteTraces (gd, indices) {
14931498
}
14941499

14951500
Plotly.redraw(gd);
1496-
Plotly.Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);
1501+
1502+
if (Plotly.Queue) Plotly.Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);
14971503
};
14981504

14991505
/**
@@ -1587,8 +1593,10 @@ Plotly.moveTraces = function moveTraces (gd, currentIndices, newIndices) {
15871593
}
15881594

15891595
gd.data = newData;
1596+
15901597
Plotly.redraw(gd);
1591-
Plotly.Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);
1598+
1599+
if (Plotly.Queue) Plotly.Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);
15921600
};
15931601

15941602
// -----------------------------------------------------
@@ -2025,7 +2033,9 @@ Plotly.restyle = function restyle(gd, astr, val, traces) {
20252033

20262034
// now all attribute mods are done, as are redo and undo
20272035
// so we can save them
2028-
Plotly.Queue.add(gd, restyle, [gd, undoit, traces], restyle, [gd, redoit, traces]);
2036+
if(Plotly.Queue) {
2037+
Plotly.Queue.add(gd, restyle, [gd, undoit, traces], restyle, [gd, redoit, traces]);
2038+
}
20292039

20302040
// do we need to force a recalc?
20312041
var autorangeOn = false;
@@ -2403,7 +2413,9 @@ Plotly.relayout = function relayout(gd, astr, val) {
24032413
}
24042414
// now all attribute mods are done, as are
24052415
// redo and undo so we can save them
2406-
Plotly.Queue.add(gd, relayout, [gd, undoit], relayout, [gd, redoit]);
2416+
if(Plotly.Queue) {
2417+
Plotly.Queue.add(gd, relayout, [gd, undoit], relayout, [gd, redoit]);
2418+
}
24072419

24082420
// calculate autosizing - if size hasn't changed,
24092421
// will remove h&w so we don't need to redraw

src/plot_api/plot_config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ module.exports = {
5757

5858
// function to add the background color to a different container
5959
// or 'opaque' to ensure there's white behind it
60-
setBackground: defaultSetBackground
60+
setBackground: defaultSetBackground,
61+
62+
// URL to topojson files used in geo charts
63+
topojsonURL: 'https://cdn.plot.ly/'
6164

6265
};
6366

src/plots/geo/geo.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function Geo(options, fullLayout) {
2222

2323
this.id = options.id;
2424
this.container = options.container;
25+
this.topojsonURL = options.topojsonURL;
2526

2627
// add a few projection types to d3.geo,
2728
// a subset of https://github.com/d3/d3-geo-projection
@@ -73,27 +74,27 @@ proto.plot = function(geoData, fullLayout) {
7374

7475
_this.framework
7576
.call(_this.zoom)
76-
.on('dblclick', _this.zoomReset);
77-
78-
// N.B. the on 'dblclick doesn't in d3 3.5+
79-
// https://github.com/mbostock/d3/issues/1985
77+
.on('dblclick.zoom', _this.zoomReset);
8078

8179
topojsonNameNew = topojsonUtils.getTopojsonName(geoLayout);
8280

8381
if(_this.topojson===null || topojsonNameNew!==_this.topojsonName) {
8482
_this.topojsonName = topojsonNameNew;
8583

86-
if(PlotlyGeoAssets.topojsons[_this.topojsonName] !== undefined) {
87-
_this.topojson = PlotlyGeoAssets.topojsons[_this.topojsonName];
84+
if(PlotlyGeoAssets.topojson[_this.topojsonName] !== undefined) {
85+
_this.topojson = PlotlyGeoAssets.topojson[_this.topojsonName];
8886
_this.onceTopojsonIsLoaded(geoData, geoLayout);
8987
}
9088
else {
91-
topojsonPath = topojsonUtils.getTopojsonPath(_this.topojsonName);
89+
topojsonPath = topojsonUtils.getTopojsonPath(
90+
_this.topojsonURL,
91+
_this.topojsonName
92+
);
9293

9394
// N.B this is async
9495
d3.json(topojsonPath, function(error, topojson) {
9596
_this.topojson = topojson;
96-
PlotlyGeoAssets.topojsons[_this.topojsonName] = topojson;
97+
PlotlyGeoAssets.topojson[_this.topojsonName] = topojson;
9798
_this.onceTopojsonIsLoaded(geoData, geoLayout);
9899
});
99100
}

src/plots/geo/projections.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
// jshint ignore: start
2+
3+
/**
4+
* Forked from https://github.com/d3/d3-geo-projection
5+
* Pasted from https://github.com/etpinard/d3-geo-projection
6+
*
7+
* Containing only the 'most useful' projection types
8+
* and compatible with CommonJs
9+
*
10+
*/
11+
112
var d3 = require('d3');
213

314
function addProjectionToD3() {
@@ -61,7 +72,7 @@ function addProjectionToD3() {
6172
d3_geo_projectPoints.push([ x, y ]);
6273
},
6374
lineEnd: function() {
64-
if (d3_geo_projectPoints.length) d3_geo_projectLines.push(d3_geo_projectPoints),
75+
if (d3_geo_projectPoints.length) d3_geo_projectLines.push(d3_geo_projectPoints),
6576
d3_geo_projectPoints = [];
6677
},
6778
result: function() {
@@ -188,7 +199,7 @@ function addProjectionToD3() {
188199
};
189200
var projection = d3.geo.projection(forward), stream_ = projection.stream;
190201
projection.stream = function(stream) {
191-
var rotate = projection.rotate(), rotateStream = stream_(stream), sphereStream = (projection.rotate([ 0, 0 ]),
202+
var rotate = projection.rotate(), rotateStream = stream_(stream), sphereStream = (projection.rotate([ 0, 0 ]),
192203
stream_(stream));
193204
projection.rotate(rotate);
194205
rotateStream.sphere = function() {

src/plots/gl3d/camera.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ function createCamera(element, options) {
221221
return true;
222222
});
223223

224-
mouseWheel(element, function(dx, dy, dz) {
224+
mouseWheel(element, function(dx, dy) {
225225
var flipX = camera.flipX ? 1 : -1;
226226
var flipY = camera.flipY ? 1 : -1;
227227
var t = now();

src/plots/polar/micropolar.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// jshint ignore: start
2+
13
var Plotly = require('../../plotly');
24
var d3 = require('d3');
35

src/plots/polar/undo_manager.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// jshint ignore: start
2+
13
'use strict';
24

35
//Modified from https://github.com/ArthurClemens/Javascript-Undo-Manager

src/traces/boxes/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ boxes.supplyDefaults = function(traceIn, traceOut, defaultColor) {
7575
coerce('marker.line.width');
7676

7777
if(boxpoints==='suspectedoutliers') {
78-
coerce('marker.line.outliercolor', traceOut.marker.color)
78+
coerce('marker.line.outliercolor', traceOut.marker.color);
7979
coerce('marker.line.outlierwidth');
8080
}
8181
}

src/traces/histogram/attributes.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var barAttrs = require('../bars/attributes');
24

35

src/traces/scatter3d/convert.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ function constructDelaunay(points, color, axis) {
7070
var v = (axis+2)%3;
7171
var filteredPoints = [];
7272
var filteredIds = [];
73-
for(var i=0; i<points.length; ++i) {
73+
var i;
74+
75+
for(i=0; i<points.length; ++i) {
7476
var p = points[i];
7577
if(isNaN(p[u]) || !isFinite(p[u]) ||
7678
isNaN(p[v]) || !isFinite(p[v])) {
@@ -80,7 +82,7 @@ function constructDelaunay(points, color, axis) {
8082
filteredIds.push(i);
8183
}
8284
var cells = triangulate(filteredPoints);
83-
for(var i=0; i<cells.length; ++i) {
85+
for(i=0; i<cells.length; ++i) {
8486
var c = cells[i];
8587
for(var j=0; j<c.length; ++j) {
8688
c[j] = filteredIds[c[j]];

tasks/bundle.js

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ var constants = require('./util/constants');
1313
* Run `npm run build -- dev` or `npm run build -- --dev`
1414
* to include source map in the plotly.js bundle
1515
*
16+
* N.B. This script is meant for dist builds; the output bundles are placed
17+
* in plotly.js/dist/.
18+
* Use `npm run watch` for dev builds.
1619
*/
1720

1821
var arg = process.argv[2];

tasks/preprocess.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var fs = require('fs');
1+
var fs = require('fs-extra');
22

33
var sass = require('node-sass');
44

@@ -22,3 +22,10 @@ sass.render({
2222
fs.readFile(constants.pathToFontSVG, function(err, data) {
2323
pullFontSVG(data.toString(), constants.pathToFontSVGBuild);
2424
});
25+
26+
// copy topojson files from sane-topojson to dist/
27+
fs.copy(constants.pathToTopojsonSrc, constants.pathToTopojsonDist,
28+
{ clobber: true },
29+
function(err) {
30+
if(err) throw err;
31+
});

0 commit comments

Comments
 (0)