Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop period positioning for all histogram traces #5175

Merged
merged 2 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/traces/histogram/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ module.exports = {
].join(' ')
},

xperiod: barAttrs.xperiod,
yperiod: barAttrs.yperiod,
xperiod0: barAttrs.xperiod0,
yperiod0: barAttrs.yperiod0,
xperiodalignment: barAttrs.xperiodalignment,
yperiodalignment: barAttrs.yperiodalignment,

text: extendFlat({}, barAttrs.text, {
description: [
'Sets hover text elements associated with each bar.',
Expand Down
30 changes: 8 additions & 22 deletions src/traces/histogram/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var isNumeric = require('fast-isnumeric');
var Lib = require('../../lib');
var Registry = require('../../registry');
var Axes = require('../../plots/cartesian/axes');
var alignPeriod = require('../../plots/cartesian/align_period');

var arraysToCalcdata = require('../bar/arrays_to_calcdata');
var binFunctions = require('./bin_functions');
Expand All @@ -24,19 +23,16 @@ var getBinSpanLabelRound = require('./bin_label_vals');
function calc(gd, trace) {
var pos = [];
var size = [];
var isHorizontal = trace.orientation === 'h';
var pa = Axes.getFromId(gd, isHorizontal ? trace.yaxis : trace.xaxis);
var mainData = isHorizontal ? 'y' : 'x';
var pa = Axes.getFromId(gd, trace.orientation === 'h' ? trace.yaxis : trace.xaxis);
var mainData = trace.orientation === 'h' ? 'y' : 'x';
var counterData = {x: 'y', y: 'x'}[mainData];
var calendar = trace[mainData + 'calendar'];
var hasPeriod = trace[mainData + 'periodalignment'];
var cumulativeSpec = trace.cumulative;
var i;

var binsAndPos = calcAllAutoBins(gd, trace, pa, mainData);
var binSpec = binsAndPos[0];
var pos0 = binsAndPos[1];
var origPos = binsAndPos[2];

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

if(hasPeriod) {
cdi.orig_p = origPos[i];
}

// setup hover and event data fields,
// N.B. pts and "hover" positions ph0/ph1 don't seem to make much sense
// for cumulative distributions
if(!cumulativeSpec.enabled) {
cdi.pts = inputPoints[i];
if(uniqueValsPerBin) {
if(hasPeriod) {
cdi.ph0 = cdi.ph1 = cdi.pts.length ? origPos[cdi.pts[0]] : cdi.orig_p;
} else {
cdi.ph0 = cdi.ph1 = cdi.pts.length ? pos0[cdi.pts[0]] : cdi.p;
}
cdi.ph0 = cdi.ph1 = (inputPoints[i].length) ? pos0[inputPoints[i][0]] : pos[i];
} else {
// Defer evaluation of ph(0|1) in crossTraceCalc
trace._computePh = true;
Expand Down Expand Up @@ -245,7 +233,7 @@ function calcAllAutoBins(gd, trace, pa, mainData, _overlayEdgeCase) {
var groupName = trace['_' + mainData + 'bingroup'];
var binOpts = fullLayout._histogramBinOpts[groupName];
var isOverlay = fullLayout.barmode === 'overlay';
var i, traces, tracei, calendar, pos0, origPos, autoVals, cumulativeSpec;
var i, traces, tracei, calendar, pos0, autoVals, cumulativeSpec;

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

if(tracei.visible) {
var mainDatai = binOpts.dirs[i];
origPos = pa.makeCalcdata(tracei, mainDatai);
pos0 = alignPeriod(trace, pa, mainData, origPos);
tracei['_' + mainDatai + 'pos0'] = pos0;
pos0 = tracei['_' + mainDatai + 'pos0'] = pa.makeCalcdata(tracei, mainDatai);

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

newBinSpec = handleSingleValueOverlays(gd, trace, pa, mainData, binAttr);
}
Expand Down Expand Up @@ -421,7 +407,7 @@ function calcAllAutoBins(gd, trace, pa, mainData, _overlayEdgeCase) {
delete trace[autoBinAttr];
}

return [traceBinOptsCalc, pos0, origPos, false];
return [traceBinOptsCalc, pos0];
}

/*
Expand Down Expand Up @@ -455,7 +441,7 @@ function handleSingleValueOverlays(gd, trace, pa, mainData, binAttr) {
} else {
var resulti = calcAllAutoBins(gd, tracei, pa, mainData, true);
var binSpeci = resulti[0];
var isSingleValued = resulti[3];
var isSingleValued = resulti[2];

// so we can use this result when we get to tracei in the normal
// course of events, mark it as done and put _pos0 back
Expand Down
3 changes: 0 additions & 3 deletions src/traces/histogram/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var Registry = require('../../registry');
var Lib = require('../../lib');
var Color = require('../../components/color');

var handlePeriodDefaults = require('../scatter/period_defaults');
var handleStyleDefaults = require('../bar/style_defaults');
var attributes = require('./attributes');

Expand Down Expand Up @@ -47,8 +46,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
return;
}

handlePeriodDefaults(traceIn, traceOut, layout, coerce);

traceOut._length = len;

var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
Expand Down
7 changes: 0 additions & 7 deletions src/traces/histogram2d/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ module.exports = extendFlat(
x: histogramAttrs.x,
y: histogramAttrs.y,

xperiod: histogramAttrs.xperiod,
yperiod: histogramAttrs.yperiod,
xperiod0: histogramAttrs.xperiod0,
yperiod0: histogramAttrs.yperiod0,
xperiodalignment: histogramAttrs.xperiodalignment,
yperiodalignment: histogramAttrs.yperiodalignment,

z: {
valType: 'data_array',
editType: 'calc',
Expand Down
21 changes: 2 additions & 19 deletions src/traces/histogram2d/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,13 @@ module.exports = function calc(gd, trace) {
var xBinsAndPos = calcAllAutoBins(gd, trace, xa, 'x');
var xBinSpec = xBinsAndPos[0];
var xPos0 = xBinsAndPos[1];
var origX = xBinsAndPos[2];
var yBinsAndPos = calcAllAutoBins(gd, trace, ya, 'y');
var yBinSpec = yBinsAndPos[0];
var yPos0 = yBinsAndPos[1];
var origY = yBinsAndPos[2];

var serieslen = trace._length;
if(xPos0.length > serieslen) {
xPos0.splice(serieslen, xPos0.length - serieslen);
origX.splice(serieslen, origX.length - serieslen);
}
if(yPos0.length > serieslen) {
yPos0.splice(serieslen, yPos0.length - serieslen);
origY.splice(serieslen, origY.length - serieslen);
}
if(xPos0.length > serieslen) xPos0.splice(serieslen, xPos0.length - serieslen);
if(yPos0.length > serieslen) yPos0.splice(serieslen, yPos0.length - serieslen);

// make the empty bin array & scale the map
var z = [];
Expand Down Expand Up @@ -139,8 +131,6 @@ module.exports = function calc(gd, trace) {
var uniqueValsPerY = true;
var xVals = new Array(nx);
var yVals = new Array(ny);
var xOrig = [];
var yOrig = [];
var xGapLow = Infinity;
var xGapHigh = Infinity;
var yGapLow = Infinity;
Expand All @@ -151,9 +141,6 @@ module.exports = function calc(gd, trace) {
n = Lib.findBin(xi, xbins);
m = Lib.findBin(yi, ybins);
if(n >= 0 && n < nx && m >= 0 && m < ny) {
if(origX) xOrig[n] = origX[i];
if(origY) yOrig[m] = origY[i];

total += binfunc(n, i, z[m], rawCounterData, counts[m]);
inputPoints[m][n].push(i);

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

return {
orig_x: xOrig,
x: xPos0,
xRanges: getRanges(xEdges, uniqueValsPerX && xVals, xGapLow, xGapHigh, xa, xcalendar),
x0: x0,
dx: dx,

orig_y: yOrig,
y: yPos0,
yRanges: getRanges(yEdges, uniqueValsPerY && yVals, yGapLow, yGapHigh, ya, ycalendar),
y0: y0,
dy: dy,

z: z,
pts: inputPoints
};
Expand Down
3 changes: 0 additions & 3 deletions src/traces/histogram2d/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

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

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

handlePeriodDefaults(traceIn, traceOut, layout, coerce);

handleStyleDefaults(traceIn, traceOut, coerce, layout);
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'});
coerce('hovertemplate');
Expand Down
20 changes: 4 additions & 16 deletions src/traces/histogram2d/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,11 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLay
var ny = indices[0];
var nx = indices[1];
var cd0 = pointData.cd[0];
var xRange = cd0.xRanges[nx];
var yRange = cd0.yRanges[ny];

var trace = cd0.trace;
var hasPeriodX = !!trace.xperiodalignment;
var hasPeriodY = !!trace.yperiodalignment;

if(hasPeriodX) {
pointData.xLabel = hoverLabelText(pointData.xa, cd0.orig_x[nx]);
} else {
var xRange = cd0.xRanges[nx];
pointData.xLabel = hoverLabelText(pointData.xa, xRange[0], xRange[1]);
}
if(hasPeriodY) {
pointData.yLabel = hoverLabelText(pointData.ya, cd0.orig_x[ny]);
} else {
var yRange = cd0.yRanges[ny];
pointData.yLabel = hoverLabelText(pointData.ya, yRange[0], yRange[1]);
}
pointData.xLabel = hoverLabelText(pointData.xa, xRange[0], xRange[1]);
pointData.yLabel = hoverLabelText(pointData.ya, yRange[0], yRange[1]);

return pts;
};
7 changes: 0 additions & 7 deletions src/traces/histogram2dcontour/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ var colorScaleAttrs = require('../../components/colorscale/attributes');
var extendFlat = require('../../lib/extend').extendFlat;

module.exports = extendFlat({
xperiod: histogram2dAttrs.xperiod,
yperiod: histogram2dAttrs.yperiod,
xperiod0: histogram2dAttrs.xperiod0,
yperiod0: histogram2dAttrs.yperiod0,
xperiodalignment: histogram2dAttrs.xperiodalignment,
yperiodalignment: histogram2dAttrs.yperiodalignment,

x: histogram2dAttrs.x,
y: histogram2dAttrs.y,
z: histogram2dAttrs.z,
Expand Down
3 changes: 0 additions & 3 deletions src/traces/histogram2dcontour/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

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

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

handlePeriodDefaults(traceIn, traceOut, layout, coerce);

handleContoursDefaults(traceIn, traceOut, coerce, coerce2);
handleStyleDefaults(traceIn, traceOut, coerce, layout);
coerce('hovertemplate');
Expand Down
Binary file modified test/image/baselines/period_positioning2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading