Skip to content

Commit a5a94cd

Browse files
committed
Merge remote-tracking branch 'origin/master' into new-d3-number-format
2 parents 05b221c + 6630336 commit a5a94cd

File tree

134 files changed

+383
-281
lines changed

Some content is hidden

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

134 files changed

+383
-281
lines changed

draftlogs/5500_fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Improve rendering of scattergl, splom and parcoords by implementing plotGlPixelRatio for those traces [[#5500](https://github.com/plotly/plotly.js/pull/5500)]

draftlogs/5818_fix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Adjust links to time format options so that they point to the d3-time-format v2.2.3 applied not the latest [[#5818](https://github.com/plotly/plotly.js/pull/5818)]

src/constants/docs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
module.exports = {
44
FORMAT_LINK: 'https://github.com/d3/d3-format/tree/v1.4.5#d3-format',
5-
DATE_FORMAT_LINK: 'https://github.com/d3/d3-time-format#locale_format'
5+
DATE_FORMAT_LINK: 'https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format'
66
};

src/plot_api/plot_api.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,20 @@ function _doPlot(gd, data, layout, config) {
222222
});
223223
}
224224

225+
var plotGlPixelRatio = gd._context.plotGlPixelRatio;
225226
if(fullLayout._glcanvas) {
226227
fullLayout._glcanvas
227-
.attr('width', fullLayout.width)
228-
.attr('height', fullLayout.height);
228+
.attr('width', fullLayout.width * plotGlPixelRatio)
229+
.attr('height', fullLayout.height * plotGlPixelRatio)
230+
.style('width', fullLayout.width + 'px')
231+
.style('height', fullLayout.height + 'px');
229232

230233
var regl = fullLayout._glcanvas.data()[0].regl;
231234
if(regl) {
232235
// Unfortunately, this can happen when relayouting to large
233236
// width/height on some browsers.
234-
if(Math.floor(fullLayout.width) !== regl._gl.drawingBufferWidth ||
235-
Math.floor(fullLayout.height) !== regl._gl.drawingBufferHeight
237+
if(Math.floor(fullLayout.width * plotGlPixelRatio) !== regl._gl.drawingBufferWidth ||
238+
Math.floor(fullLayout.height * plotGlPixelRatio) !== regl._gl.drawingBufferHeight
236239
) {
237240
var msg = 'WebGL context buffer and canvas dimensions do not match due to browser/WebGL bug.';
238241
if(drawFrameworkCalls) {

src/plots/cartesian/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,8 @@ exports.toSVG = function(gd) {
596596
preserveAspectRatio: 'none',
597597
x: 0,
598598
y: 0,
599-
width: canvas.width,
600-
height: canvas.height
599+
width: canvas.style.width,
600+
height: canvas.style.height
601601
});
602602
}
603603

src/traces/parcoords/base_plot.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ exports.toSVG = function(gd) {
3939
preserveAspectRatio: 'none',
4040
x: 0,
4141
y: 0,
42-
width: canvas.width,
43-
height: canvas.height
42+
width: canvas.style.width,
43+
height: canvas.style.height
4444
});
4545
}
4646

src/traces/parcoords/lines.js

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,27 @@ function emptyAttributes(regl) {
160160
return attributes;
161161
}
162162

163-
function makeItem(model, leftmost, rightmost, itemNumber, i0, i1, x, y, panelSizeX, panelSizeY, crossfilterDimensionIndex, drwLayer, constraints) {
163+
function makeItem(
164+
model, leftmost, rightmost, itemNumber, i0, i1, x, y, panelSizeX, panelSizeY,
165+
crossfilterDimensionIndex, drwLayer, constraints, plotGlPixelRatio
166+
) {
164167
var dims = [[], []];
165168
for(var k = 0; k < 64; k++) {
166169
dims[0][k] = (k === i0) ? 1 : 0;
167170
dims[1][k] = (k === i1) ? 1 : 0;
168171
}
169-
170-
var overdrag = model.lines.canvasOverdrag;
172+
x *= plotGlPixelRatio;
173+
y *= plotGlPixelRatio;
174+
panelSizeX *= plotGlPixelRatio;
175+
panelSizeY *= plotGlPixelRatio;
176+
var overdrag = model.lines.canvasOverdrag * plotGlPixelRatio;
171177
var domain = model.domain;
172-
var canvasWidth = model.canvasWidth;
173-
var canvasHeight = model.canvasHeight;
178+
var canvasWidth = model.canvasWidth * plotGlPixelRatio;
179+
var canvasHeight = model.canvasHeight * plotGlPixelRatio;
180+
var padL = model.pad.l * plotGlPixelRatio;
181+
var padB = model.pad.b * plotGlPixelRatio;
182+
var layoutHeight = model.layoutHeight * plotGlPixelRatio;
183+
var layoutWidth = model.layoutWidth * plotGlPixelRatio;
174184

175185
var deselectedLinesColor = model.deselectedLines.color;
176186

@@ -201,13 +211,13 @@ function makeItem(model, leftmost, rightmost, itemNumber, i0, i1, x, y, panelSiz
201211
Math.max(1 / 255, Math.pow(1 / model.lines.color.length, 1 / 3))
202212
],
203213

204-
scissorX: (itemNumber === leftmost ? 0 : x + overdrag) + (model.pad.l - overdrag) + model.layoutWidth * domain.x[0],
214+
scissorX: (itemNumber === leftmost ? 0 : x + overdrag) + (padL - overdrag) + layoutWidth * domain.x[0],
205215
scissorWidth: (itemNumber === rightmost ? canvasWidth - x + overdrag : panelSizeX + 0.5) + (itemNumber === leftmost ? x + overdrag : 0),
206-
scissorY: y + model.pad.b + model.layoutHeight * domain.y[0],
216+
scissorY: y + padB + layoutHeight * domain.y[0],
207217
scissorHeight: panelSizeY,
208218

209-
viewportX: model.pad.l - overdrag + model.layoutWidth * domain.x[0],
210-
viewportY: model.pad.b + model.layoutHeight * domain.y[0],
219+
viewportX: padL - overdrag + layoutWidth * domain.x[0],
220+
viewportY: padB + layoutHeight * domain.y[0],
211221
viewportWidth: canvasWidth,
212222
viewportHeight: canvasHeight
213223
}, constraints);
@@ -231,6 +241,16 @@ module.exports = function(canvasGL, d) {
231241
var isPick = d.pick;
232242

233243
var regl = d.regl;
244+
var gl = regl._gl;
245+
var supportedLineWidth = gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE);
246+
// ensure here that plotGlPixelRatio is within supported range; otherwise regl throws error
247+
var plotGlPixelRatio = Math.max(
248+
supportedLineWidth[0],
249+
Math.min(
250+
supportedLineWidth[1],
251+
d.viewModel.plotGlPixelRatio
252+
)
253+
);
234254

235255
var renderState = {
236256
currentRafs: {},
@@ -307,7 +327,7 @@ module.exports = function(canvasGL, d) {
307327
frag: fragmentShaderSource,
308328

309329
primitive: 'lines',
310-
lineWidth: 1,
330+
lineWidth: plotGlPixelRatio,
311331
attributes: attributes,
312332
uniforms: {
313333
resolution: regl.prop('resolution'),
@@ -454,6 +474,7 @@ module.exports = function(canvasGL, d) {
454474
var x = p.canvasX;
455475
var y = p.canvasY;
456476
var nextX = x + p.panelSizeX;
477+
var plotGlPixelRatio = p.plotGlPixelRatio;
457478
if(setChanged ||
458479
!prevAxisOrder[i0] ||
459480
prevAxisOrder[i0][0] !== x ||
@@ -467,7 +488,8 @@ module.exports = function(canvasGL, d) {
467488
p.panelSizeX, p.panelSizeY,
468489
p.dim0.crossfilterDimensionIndex,
469490
isContext ? 0 : isPick ? 2 : 1,
470-
constraints
491+
constraints,
492+
plotGlPixelRatio
471493
);
472494

473495
renderState.clearOnly = clearOnly;

src/traces/parcoords/parcoords.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ function calcTilt(angle, position) {
370370
};
371371
}
372372

373-
function updatePanelLayout(yAxis, vm) {
373+
function updatePanelLayout(yAxis, vm, plotGlPixelRatio) {
374374
var panels = vm.panels || (vm.panels = []);
375375
var data = yAxis.data();
376376
for(var i = 0; i < data.length - 1; i++) {
@@ -384,6 +384,7 @@ function updatePanelLayout(yAxis, vm) {
384384
p.panelSizeY = vm.model.canvasHeight;
385385
p.y = 0;
386386
p.canvasY = 0;
387+
p.plotGlPixelRatio = plotGlPixelRatio;
387388
}
388389
}
389390

@@ -434,6 +435,7 @@ module.exports = function parcoords(gd, cdModule, layout, callbacks) {
434435
var fullLayout = gd._fullLayout;
435436
var svg = fullLayout._toppaper;
436437
var glContainer = fullLayout._glcontainer;
438+
var plotGlPixelRatio = gd._context.plotGlPixelRatio;
437439
var paperColor = gd._fullLayout.paper_bgcolor;
438440

439441
calcAllTicks(cdModule);
@@ -453,6 +455,7 @@ module.exports = function parcoords(gd, cdModule, layout, callbacks) {
453455
.each(function(d) {
454456
// FIXME: figure out how to handle multiple instances
455457
d.viewModel = vm[0];
458+
d.viewModel.plotGlPixelRatio = plotGlPixelRatio;
456459
d.viewModel.paperColor = paperColor;
457460
d.model = d.viewModel ? d.viewModel.model : null;
458461
});
@@ -537,7 +540,7 @@ module.exports = function parcoords(gd, cdModule, layout, callbacks) {
537540
.classed(c.cn.yAxis, true);
538541

539542
parcoordsControlView.each(function(p) {
540-
updatePanelLayout(yAxis, p);
543+
updatePanelLayout(yAxis, p, plotGlPixelRatio);
541544
});
542545

543546
glLayers
@@ -576,7 +579,7 @@ module.exports = function parcoords(gd, cdModule, layout, callbacks) {
576579
e.canvasX = e.x * e.model.canvasPixelRatio;
577580
});
578581

579-
updatePanelLayout(yAxis, p);
582+
updatePanelLayout(yAxis, p, plotGlPixelRatio);
580583

581584
yAxis.filter(function(e) { return Math.abs(d.xIndex - e.xIndex) !== 0; })
582585
.attr('transform', function(d) { return strTranslate(d.xScale(d.xIndex), 0); });
@@ -589,7 +592,7 @@ module.exports = function parcoords(gd, cdModule, layout, callbacks) {
589592
var p = d.parent;
590593
d.x = d.xScale(d.xIndex);
591594
d.canvasX = d.x * d.model.canvasPixelRatio;
592-
updatePanelLayout(yAxis, p);
595+
updatePanelLayout(yAxis, p, plotGlPixelRatio);
593596
d3.select(this)
594597
.attr('transform', function(d) { return strTranslate(d.x, 0); });
595598
p.contextLayer && p.contextLayer.render(p.panels, false, !someFiltersActive(p));

src/traces/scatter/make_bubble_size_func.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ var isNumeric = require('fast-isnumeric');
55

66
// used in the drawing step for 'scatter' and 'scattegeo' and
77
// in the convert step for 'scatter3d'
8-
module.exports = function makeBubbleSizeFn(trace) {
8+
module.exports = function makeBubbleSizeFn(trace, factor) {
9+
if(!factor) {
10+
factor = 2;
11+
}
912
var marker = trace.marker;
1013
var sizeRef = marker.sizeref || 1;
1114
var sizeMin = marker.sizemin || 0;
@@ -21,7 +24,7 @@ module.exports = function makeBubbleSizeFn(trace) {
2124
// TODO add support for position/negative bubbles?
2225
// TODO add 'sizeoffset' attribute?
2326
return function(v) {
24-
var baseSize = baseFn(v / 2);
27+
var baseSize = baseFn(v / factor);
2528

2629
// don't show non-numeric and negative sizes
2730
return (isNumeric(baseSize) && (baseSize > 0)) ?

src/traces/scattergl/calc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ module.exports = function calc(gd, trace) {
8383
if(!hasTooManyPoints) {
8484
ppad = calcMarkerSize(trace, len);
8585
} else if(opts.marker) {
86-
ppad = 2 * (opts.marker.sizeAvg || Math.max(opts.marker.size, 3));
86+
ppad = opts.marker.sizeAvg || Math.max(opts.marker.size, 3);
8787
}
8888
calcAxisExpansion(gd, trace, xa, ya, x, y, ppad);
8989
if(opts.errorX) expandForErrorBars(trace, xa, opts.errorX);

0 commit comments

Comments
 (0)