Skip to content

Commit 38e528e

Browse files
authored
Merge pull request #5175 from plotly/fixup-period-mock
Drop period positioning for all histogram traces
2 parents efd9bc4 + 1046406 commit 38e528e

File tree

12 files changed

+25
-299
lines changed

12 files changed

+25
-299
lines changed

src/traces/histogram/attributes.js

-7
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ module.exports = {
3030
].join(' ')
3131
},
3232

33-
xperiod: barAttrs.xperiod,
34-
yperiod: barAttrs.yperiod,
35-
xperiod0: barAttrs.xperiod0,
36-
yperiod0: barAttrs.yperiod0,
37-
xperiodalignment: barAttrs.xperiodalignment,
38-
yperiodalignment: barAttrs.yperiodalignment,
39-
4033
text: extendFlat({}, barAttrs.text, {
4134
description: [
4235
'Sets hover text elements associated with each bar.',

src/traces/histogram/calc.js

+8-22
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ var isNumeric = require('fast-isnumeric');
1313
var Lib = require('../../lib');
1414
var Registry = require('../../registry');
1515
var Axes = require('../../plots/cartesian/axes');
16-
var alignPeriod = require('../../plots/cartesian/align_period');
1716

1817
var arraysToCalcdata = require('../bar/arrays_to_calcdata');
1918
var binFunctions = require('./bin_functions');
@@ -24,19 +23,16 @@ var getBinSpanLabelRound = require('./bin_label_vals');
2423
function calc(gd, trace) {
2524
var pos = [];
2625
var size = [];
27-
var isHorizontal = trace.orientation === 'h';
28-
var pa = Axes.getFromId(gd, isHorizontal ? trace.yaxis : trace.xaxis);
29-
var mainData = isHorizontal ? 'y' : 'x';
26+
var pa = Axes.getFromId(gd, trace.orientation === 'h' ? trace.yaxis : trace.xaxis);
27+
var mainData = trace.orientation === 'h' ? 'y' : 'x';
3028
var counterData = {x: 'y', y: 'x'}[mainData];
3129
var calendar = trace[mainData + 'calendar'];
32-
var hasPeriod = trace[mainData + 'periodalignment'];
3330
var cumulativeSpec = trace.cumulative;
3431
var i;
3532

3633
var binsAndPos = calcAllAutoBins(gd, trace, pa, mainData);
3734
var binSpec = binsAndPos[0];
3835
var pos0 = binsAndPos[1];
39-
var origPos = binsAndPos[2];
4036

4137
var nonuniformBins = typeof binSpec.size === 'string';
4238
var binEdges = [];
@@ -189,21 +185,13 @@ function calc(gd, trace) {
189185
b: 0
190186
};
191187

192-
if(hasPeriod) {
193-
cdi.orig_p = origPos[i];
194-
}
195-
196188
// setup hover and event data fields,
197189
// N.B. pts and "hover" positions ph0/ph1 don't seem to make much sense
198190
// for cumulative distributions
199191
if(!cumulativeSpec.enabled) {
200192
cdi.pts = inputPoints[i];
201193
if(uniqueValsPerBin) {
202-
if(hasPeriod) {
203-
cdi.ph0 = cdi.ph1 = cdi.pts.length ? origPos[cdi.pts[0]] : cdi.orig_p;
204-
} else {
205-
cdi.ph0 = cdi.ph1 = cdi.pts.length ? pos0[cdi.pts[0]] : cdi.p;
206-
}
194+
cdi.ph0 = cdi.ph1 = (inputPoints[i].length) ? pos0[inputPoints[i][0]] : pos[i];
207195
} else {
208196
// Defer evaluation of ph(0|1) in crossTraceCalc
209197
trace._computePh = true;
@@ -245,7 +233,7 @@ function calcAllAutoBins(gd, trace, pa, mainData, _overlayEdgeCase) {
245233
var groupName = trace['_' + mainData + 'bingroup'];
246234
var binOpts = fullLayout._histogramBinOpts[groupName];
247235
var isOverlay = fullLayout.barmode === 'overlay';
248-
var i, traces, tracei, calendar, pos0, origPos, autoVals, cumulativeSpec;
236+
var i, traces, tracei, calendar, pos0, autoVals, cumulativeSpec;
249237

250238
var r2c = function(v) { return pa.r2c(v, 0, calendar); };
251239
var c2r = function(v) { return pa.c2r(v, 0, calendar); };
@@ -284,9 +272,7 @@ function calcAllAutoBins(gd, trace, pa, mainData, _overlayEdgeCase) {
284272

285273
if(tracei.visible) {
286274
var mainDatai = binOpts.dirs[i];
287-
origPos = pa.makeCalcdata(tracei, mainDatai);
288-
pos0 = alignPeriod(trace, pa, mainData, origPos);
289-
tracei['_' + mainDatai + 'pos0'] = pos0;
275+
pos0 = tracei['_' + mainDatai + 'pos0'] = pa.makeCalcdata(tracei, mainDatai);
290276

291277
allPos = Lib.concat(allPos, pos0);
292278
delete tracei['_' + mainData + 'autoBinFinished'];
@@ -334,7 +320,7 @@ function calcAllAutoBins(gd, trace, pa, mainData, _overlayEdgeCase) {
334320
// Several single-valued histograms! Stop infinite recursion,
335321
// just return an extra flag that tells handleSingleValueOverlays
336322
// to sort out this trace too
337-
if(_overlayEdgeCase) return [newBinSpec, pos0, origPos, true];
323+
if(_overlayEdgeCase) return [newBinSpec, pos0, true];
338324

339325
newBinSpec = handleSingleValueOverlays(gd, trace, pa, mainData, binAttr);
340326
}
@@ -421,7 +407,7 @@ function calcAllAutoBins(gd, trace, pa, mainData, _overlayEdgeCase) {
421407
delete trace[autoBinAttr];
422408
}
423409

424-
return [traceBinOptsCalc, pos0, origPos, false];
410+
return [traceBinOptsCalc, pos0];
425411
}
426412

427413
/*
@@ -455,7 +441,7 @@ function handleSingleValueOverlays(gd, trace, pa, mainData, binAttr) {
455441
} else {
456442
var resulti = calcAllAutoBins(gd, tracei, pa, mainData, true);
457443
var binSpeci = resulti[0];
458-
var isSingleValued = resulti[3];
444+
var isSingleValued = resulti[2];
459445

460446
// so we can use this result when we get to tracei in the normal
461447
// course of events, mark it as done and put _pos0 back

src/traces/histogram/defaults.js

-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ var Registry = require('../../registry');
1212
var Lib = require('../../lib');
1313
var Color = require('../../components/color');
1414

15-
var handlePeriodDefaults = require('../scatter/period_defaults');
1615
var handleStyleDefaults = require('../bar/style_defaults');
1716
var attributes = require('./attributes');
1817

@@ -47,8 +46,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
4746
return;
4847
}
4948

50-
handlePeriodDefaults(traceIn, traceOut, layout, coerce);
51-
5249
traceOut._length = len;
5350

5451
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');

src/traces/histogram2d/attributes.js

-7
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ module.exports = extendFlat(
2222
x: histogramAttrs.x,
2323
y: histogramAttrs.y,
2424

25-
xperiod: histogramAttrs.xperiod,
26-
yperiod: histogramAttrs.yperiod,
27-
xperiod0: histogramAttrs.xperiod0,
28-
yperiod0: histogramAttrs.yperiod0,
29-
xperiodalignment: histogramAttrs.xperiodalignment,
30-
yperiodalignment: histogramAttrs.yperiodalignment,
31-
3225
z: {
3326
valType: 'data_array',
3427
editType: 'calc',

src/traces/histogram2d/calc.js

+2-19
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,13 @@ module.exports = function calc(gd, trace) {
3434
var xBinsAndPos = calcAllAutoBins(gd, trace, xa, 'x');
3535
var xBinSpec = xBinsAndPos[0];
3636
var xPos0 = xBinsAndPos[1];
37-
var origX = xBinsAndPos[2];
3837
var yBinsAndPos = calcAllAutoBins(gd, trace, ya, 'y');
3938
var yBinSpec = yBinsAndPos[0];
4039
var yPos0 = yBinsAndPos[1];
41-
var origY = yBinsAndPos[2];
4240

4341
var serieslen = trace._length;
44-
if(xPos0.length > serieslen) {
45-
xPos0.splice(serieslen, xPos0.length - serieslen);
46-
origX.splice(serieslen, origX.length - serieslen);
47-
}
48-
if(yPos0.length > serieslen) {
49-
yPos0.splice(serieslen, yPos0.length - serieslen);
50-
origY.splice(serieslen, origY.length - serieslen);
51-
}
42+
if(xPos0.length > serieslen) xPos0.splice(serieslen, xPos0.length - serieslen);
43+
if(yPos0.length > serieslen) yPos0.splice(serieslen, yPos0.length - serieslen);
5244

5345
// make the empty bin array & scale the map
5446
var z = [];
@@ -139,8 +131,6 @@ module.exports = function calc(gd, trace) {
139131
var uniqueValsPerY = true;
140132
var xVals = new Array(nx);
141133
var yVals = new Array(ny);
142-
var xOrig = [];
143-
var yOrig = [];
144134
var xGapLow = Infinity;
145135
var xGapHigh = Infinity;
146136
var yGapLow = Infinity;
@@ -151,9 +141,6 @@ module.exports = function calc(gd, trace) {
151141
n = Lib.findBin(xi, xbins);
152142
m = Lib.findBin(yi, ybins);
153143
if(n >= 0 && n < nx && m >= 0 && m < ny) {
154-
if(origX) xOrig[n] = origX[i];
155-
if(origY) yOrig[m] = origY[i];
156-
157144
total += binfunc(n, i, z[m], rawCounterData, counts[m]);
158145
inputPoints[m][n].push(i);
159146

@@ -181,18 +168,14 @@ module.exports = function calc(gd, trace) {
181168
}
182169

183170
return {
184-
orig_x: xOrig,
185171
x: xPos0,
186172
xRanges: getRanges(xEdges, uniqueValsPerX && xVals, xGapLow, xGapHigh, xa, xcalendar),
187173
x0: x0,
188174
dx: dx,
189-
190-
orig_y: yOrig,
191175
y: yPos0,
192176
yRanges: getRanges(yEdges, uniqueValsPerY && yVals, yGapLow, yGapHigh, ya, ycalendar),
193177
y0: y0,
194178
dy: dy,
195-
196179
z: z,
197180
pts: inputPoints
198181
};

src/traces/histogram2d/defaults.js

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

1212
var Lib = require('../../lib');
1313

14-
var handlePeriodDefaults = require('../scatter/period_defaults');
1514
var handleSampleDefaults = require('./sample_defaults');
1615
var handleStyleDefaults = require('../heatmap/style_defaults');
1716
var colorscaleDefaults = require('../../components/colorscale/defaults');
@@ -26,8 +25,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2625
handleSampleDefaults(traceIn, traceOut, coerce, layout);
2726
if(traceOut.visible === false) return;
2827

29-
handlePeriodDefaults(traceIn, traceOut, layout, coerce);
30-
3128
handleStyleDefaults(traceIn, traceOut, coerce, layout);
3229
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'});
3330
coerce('hovertemplate');

src/traces/histogram2d/hover.js

+4-16
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,11 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLay
2222
var ny = indices[0];
2323
var nx = indices[1];
2424
var cd0 = pointData.cd[0];
25+
var xRange = cd0.xRanges[nx];
26+
var yRange = cd0.yRanges[ny];
2527

26-
var trace = cd0.trace;
27-
var hasPeriodX = !!trace.xperiodalignment;
28-
var hasPeriodY = !!trace.yperiodalignment;
29-
30-
if(hasPeriodX) {
31-
pointData.xLabel = hoverLabelText(pointData.xa, cd0.orig_x[nx]);
32-
} else {
33-
var xRange = cd0.xRanges[nx];
34-
pointData.xLabel = hoverLabelText(pointData.xa, xRange[0], xRange[1]);
35-
}
36-
if(hasPeriodY) {
37-
pointData.yLabel = hoverLabelText(pointData.ya, cd0.orig_x[ny]);
38-
} else {
39-
var yRange = cd0.yRanges[ny];
40-
pointData.yLabel = hoverLabelText(pointData.ya, yRange[0], yRange[1]);
41-
}
28+
pointData.xLabel = hoverLabelText(pointData.xa, xRange[0], xRange[1]);
29+
pointData.yLabel = hoverLabelText(pointData.ya, yRange[0], yRange[1]);
4230

4331
return pts;
4432
};

src/traces/histogram2dcontour/attributes.js

-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ var colorScaleAttrs = require('../../components/colorscale/attributes');
1515
var extendFlat = require('../../lib/extend').extendFlat;
1616

1717
module.exports = extendFlat({
18-
xperiod: histogram2dAttrs.xperiod,
19-
yperiod: histogram2dAttrs.yperiod,
20-
xperiod0: histogram2dAttrs.xperiod0,
21-
yperiod0: histogram2dAttrs.yperiod0,
22-
xperiodalignment: histogram2dAttrs.xperiodalignment,
23-
yperiodalignment: histogram2dAttrs.yperiodalignment,
24-
2518
x: histogram2dAttrs.x,
2619
y: histogram2dAttrs.y,
2720
z: histogram2dAttrs.z,

src/traces/histogram2dcontour/defaults.js

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

1212
var Lib = require('../../lib');
1313

14-
var handlePeriodDefaults = require('../scatter/period_defaults');
1514
var handleSampleDefaults = require('../histogram2d/sample_defaults');
1615
var handleContoursDefaults = require('../contour/contours_defaults');
1716
var handleStyleDefaults = require('../contour/style_defaults');
@@ -30,8 +29,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3029
handleSampleDefaults(traceIn, traceOut, coerce, layout);
3130
if(traceOut.visible === false) return;
3231

33-
handlePeriodDefaults(traceIn, traceOut, layout, coerce);
34-
3532
handleContoursDefaults(traceIn, traceOut, coerce, coerce2);
3633
handleStyleDefaults(traceIn, traceOut, coerce, layout);
3734
coerce('hovertemplate');
-41.3 KB
Loading

0 commit comments

Comments
 (0)