Skip to content

Commit 5101174

Browse files
committed
Merge branch 'master' into mapbox-on-move-end
2 parents 3807018 + 4232ab1 commit 5101174

Some content is hidden

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

69 files changed

+5642
-1339
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
// This code adapted from:
10+
//
11+
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
12+
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
13+
14+
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
15+
16+
// MIT license
17+
18+
19+
'use strict';
20+
21+
if(!Date.now) {
22+
Date.now = function() { return new Date().getTime(); };
23+
}
24+
25+
var vendors = ['webkit', 'moz'];
26+
for(var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) {
27+
var vp = vendors[i];
28+
window.requestAnimationFrame = window[vp + 'RequestAnimationFrame'];
29+
window.cancelAnimationFrame = (window[vp + 'CancelAnimationFrame'] ||
30+
window[vp + 'CancelRequestAnimationFrame']);
31+
}
32+
if(/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) || // iOS6 is buggy
33+
!window.requestAnimationFrame || !window.cancelAnimationFrame) {
34+
var lastTime = 0;
35+
window.requestAnimationFrame = function(callback) {
36+
var now = Date.now();
37+
var nextTime = Math.max(lastTime + 16, now);
38+
return setTimeout(function() { callback(lastTime = nextTime); },
39+
nextTime - now);
40+
};
41+
window.cancelAnimationFrame = clearTimeout;
42+
}

dist/plotly.min.js

Lines changed: 53 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index-gl2d.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var Plotly = require('./core');
1212

1313
Plotly.register([
1414
require('./scattergl'),
15+
require('./pointcloud'),
1516
require('./heatmapgl'),
1617
require('./contourgl')
1718
]);

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Plotly.register([
2525
require('./scattergeo'),
2626
require('./choropleth'),
2727
require('./scattergl'),
28+
require('./pointcloud'),
2829
require('./scatterternary'),
2930
require('./scattermapbox')
3031
]);

lib/pointcloud.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
module.exports = require('../src/traces/pointcloud');

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"gl-plot3d": "^1.5.0",
6969
"gl-scatter2d": "^1.0.5",
7070
"gl-scatter2d-fancy": "^1.1.1",
71+
"gl-pointcloud2d": "^1.0.0",
7172
"gl-scatter3d": "^1.0.4",
7273
"gl-select-box": "^1.0.1",
7374
"gl-spikes2d": "^1.0.1",
@@ -109,6 +110,7 @@
109110
"open": "0.0.5",
110111
"prepend-file": "^1.3.0",
111112
"prettysize": "0.0.3",
113+
"requirejs": "^2.3.1",
112114
"through2": "^2.0.0",
113115
"uglify-js": "^2.6.1",
114116
"watchify": "^3.7.0",

src/.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"Promise": true,
88
"Float32Array": true,
99
"Uint8Array": true,
10+
"Int32Array": true,
1011
"ArrayBuffer": true
1112
},
1213
"rules": {

src/components/color/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ color.stroke = function(s, c) {
7474

7575
color.fill = function(s, c) {
7676
var tc = tinycolor(c);
77-
s.style({'fill': color.tinyRGB(tc), 'fill-opacity': tc.getAlpha()});
77+
s.style({
78+
'fill': color.tinyRGB(tc),
79+
'fill-opacity': tc.getAlpha()
80+
});
7881
};
7982

8083
// search container for colors with the deprecated rgb(fractions) format

src/components/drawing/index.js

Lines changed: 93 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,26 @@ drawing.setRect = function(s, x, y, w, h) {
4646
s.call(drawing.setPosition, x, y).call(drawing.setSize, w, h);
4747
};
4848

49-
drawing.translatePoints = function(s, xa, ya) {
50-
s.each(function(d) {
51-
// put xp and yp into d if pixel scaling is already done
52-
var x = d.xp || xa.c2p(d.x),
53-
y = d.yp || ya.c2p(d.y),
54-
p = d3.select(this);
55-
if(isNumeric(x) && isNumeric(y)) {
56-
// for multiline text this works better
57-
if(this.nodeName === 'text') p.attr('x', x).attr('y', y);
58-
else p.attr('transform', 'translate(' + x + ',' + y + ')');
49+
drawing.translatePoint = function(d, sel, xa, ya) {
50+
// put xp and yp into d if pixel scaling is already done
51+
var x = d.xp || xa.c2p(d.x),
52+
y = d.yp || ya.c2p(d.y);
53+
54+
if(isNumeric(x) && isNumeric(y)) {
55+
// for multiline text this works better
56+
if(this.nodeName === 'text') {
57+
sel.node().attr('x', x).attr('y', y);
58+
} else {
59+
sel.attr('transform', 'translate(' + x + ',' + y + ')');
5960
}
60-
else p.remove();
61+
}
62+
else sel.remove();
63+
};
64+
65+
drawing.translatePoints = function(s, xa, ya, trace) {
66+
s.each(function(d) {
67+
var sel = d3.select(this);
68+
drawing.translatePoint(d, sel, xa, ya, trace);
6169
});
6270
};
6371

@@ -80,6 +88,16 @@ drawing.crispRound = function(td, lineWidth, dflt) {
8088
return Math.round(lineWidth);
8189
};
8290

91+
drawing.singleLineStyle = function(d, s, lw, lc, ld) {
92+
s.style('fill', 'none');
93+
var line = (((d || [])[0] || {}).trace || {}).line || {},
94+
lw1 = lw || line.width||0,
95+
dash = ld || line.dash || '';
96+
97+
Color.stroke(s, lc || line.color);
98+
drawing.dashLine(s, dash, lw1);
99+
};
100+
83101
drawing.lineGroupStyle = function(s, lw, lc, ld) {
84102
s.style('fill', 'none')
85103
.each(function(d) {
@@ -175,18 +193,13 @@ drawing.symbolNumber = function(v) {
175193
return Math.floor(Math.max(v, 0));
176194
};
177195

178-
drawing.pointStyle = function(s, trace) {
179-
if(!s.size()) return;
180-
181-
var marker = trace.marker,
182-
markerLine = marker.line;
183-
196+
function singlePointStyle(d, sel, trace, markerScale, lineScale, marker, markerLine) {
184197
// only scatter & box plots get marker path and opacity
185198
// bars, histograms don't
186199
if(Registry.traceIs(trace, 'symbols')) {
187200
var sizeFn = makeBubbleSizeFn(trace);
188201

189-
s.attr('d', function(d) {
202+
sel.attr('d', function(d) {
190203
var r;
191204

192205
// handle multi-trace graph edit case
@@ -212,54 +225,75 @@ drawing.pointStyle = function(s, trace) {
212225
return (d.mo + 1 || marker.opacity + 1) - 1;
213226
});
214227
}
228+
229+
// 'so' is suspected outliers, for box plots
230+
var fillColor,
231+
lineColor,
232+
lineWidth;
233+
if(d.so) {
234+
lineWidth = markerLine.outlierwidth;
235+
lineColor = markerLine.outliercolor;
236+
fillColor = marker.outliercolor;
237+
}
238+
else {
239+
lineWidth = (d.mlw + 1 || markerLine.width + 1 ||
240+
// TODO: we need the latter for legends... can we get rid of it?
241+
(d.trace ? d.trace.marker.line.width : 0) + 1) - 1;
242+
243+
if('mlc' in d) lineColor = d.mlcc = lineScale(d.mlc);
244+
// weird case: array wasn't long enough to apply to every point
245+
else if(Array.isArray(markerLine.color)) lineColor = Color.defaultLine;
246+
else lineColor = markerLine.color;
247+
248+
if('mc' in d) fillColor = d.mcc = markerScale(d.mc);
249+
else if(Array.isArray(marker.color)) fillColor = Color.defaultLine;
250+
else fillColor = marker.color || 'rgba(0,0,0,0)';
251+
}
252+
253+
if(d.om) {
254+
// open markers can't have zero linewidth, default to 1px,
255+
// and use fill color as stroke color
256+
sel.call(Color.stroke, fillColor)
257+
.style({
258+
'stroke-width': (lineWidth || 1) + 'px',
259+
fill: 'none'
260+
});
261+
}
262+
else {
263+
sel.style('stroke-width', lineWidth + 'px')
264+
.call(Color.fill, fillColor);
265+
if(lineWidth) {
266+
sel.call(Color.stroke, lineColor);
267+
}
268+
}
269+
}
270+
271+
drawing.singlePointStyle = function(d, sel, trace) {
272+
var marker = trace.marker,
273+
markerLine = marker.line;
274+
215275
// allow array marker and marker line colors to be
216276
// scaled by given max and min to colorscales
217277
var markerIn = (trace._input || {}).marker || {},
218278
markerScale = drawing.tryColorscale(marker, markerIn, ''),
219279
lineScale = drawing.tryColorscale(marker, markerIn, 'line.');
220280

221-
s.each(function(d) {
222-
// 'so' is suspected outliers, for box plots
223-
var fillColor,
224-
lineColor,
225-
lineWidth;
226-
if(d.so) {
227-
lineWidth = markerLine.outlierwidth;
228-
lineColor = markerLine.outliercolor;
229-
fillColor = marker.outliercolor;
230-
}
231-
else {
232-
lineWidth = (d.mlw + 1 || markerLine.width + 1 ||
233-
// TODO: we need the latter for legends... can we get rid of it?
234-
(d.trace ? d.trace.marker.line.width : 0) + 1) - 1;
235-
236-
if('mlc' in d) lineColor = d.mlcc = lineScale(d.mlc);
237-
// weird case: array wasn't long enough to apply to every point
238-
else if(Array.isArray(markerLine.color)) lineColor = Color.defaultLine;
239-
else lineColor = markerLine.color;
240-
241-
if('mc' in d) fillColor = d.mcc = markerScale(d.mc);
242-
else if(Array.isArray(marker.color)) fillColor = Color.defaultLine;
243-
else fillColor = marker.color || 'rgba(0,0,0,0)';
244-
}
281+
singlePointStyle(d, sel, trace, markerScale, lineScale, marker, markerLine);
245282

246-
var p = d3.select(this);
247-
if(d.om) {
248-
// open markers can't have zero linewidth, default to 1px,
249-
// and use fill color as stroke color
250-
p.call(Color.stroke, fillColor)
251-
.style({
252-
'stroke-width': (lineWidth || 1) + 'px',
253-
fill: 'none'
254-
});
255-
}
256-
else {
257-
p.style('stroke-width', lineWidth + 'px')
258-
.call(Color.fill, fillColor);
259-
if(lineWidth) {
260-
p.call(Color.stroke, lineColor);
261-
}
262-
}
283+
};
284+
285+
drawing.pointStyle = function(s, trace) {
286+
if(!s.size()) return;
287+
288+
// allow array marker and marker line colors to be
289+
// scaled by given max and min to colorscales
290+
var marker = trace.marker;
291+
var markerIn = (trace._input || {}).marker || {},
292+
markerScale = drawing.tryColorscale(marker, markerIn, ''),
293+
lineScale = drawing.tryColorscale(marker, markerIn, 'line.');
294+
295+
s.each(function(d) {
296+
drawing.singlePointStyle(d, d3.select(this), trace, markerScale, lineScale);
263297
});
264298
};
265299

0 commit comments

Comments
 (0)