8000 sort categorical Cartesian axes by value by antoinerg · Pull Request #3864 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

sort categorical Cartesian axes by value #3864

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

Merged
merged 13 commits into from
May 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
sort categories by values: improve splom logic
  • Loading branch information
antoinerg committed May 16, 2019
commit fac239b7b8db0ac7d9f68850c75a9bca1c03a4c6
10 changes: 2 additions & 8 deletions src/plots/cartesian/type_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,8 @@ function setAutoType(ax, data) {
ax.type = autoType(boxPositions, calendar, opts);
} else if(d0.type === 'splom') {
var dimensions = d0.dimensions;
var diag = d0._diag;
for(i = 0; i < dimensions.length; i++) {
var dim = dimensions[i];
if(dim.visible && (diag[i][0] === id || diag[i][1] === id)) {
ax.type = autoType(dim.values, calendar, opts);
break;
}
}
var dim = dimensions[d0._axesDim[id]];
if(dim.visible) ax.type = autoType(dim.values, calendar, opts);
} else {
ax.type = autoType(d0[axLetter] || [d0[axLetter + '0']], calendar, opts);
}
Expand Down
10 changes: 4 additions & 6 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -2919,22 +2919,20 @@ function sortAxisCategoriesByValue(axList, gd) {
// If `splom`, collect values across dimensions
if(type === 'splom') {
// Find which dimension the current axis is representing
var currentDimensionIndex = cdi.trace[axLetter + 'axes'].indexOf(ax._id);
var currentDimensionIndex = fullTrace._axesDim[ax._id];

// Apply logic to associated x axis
if(axLetter === 'y') {
var associatedXAxis = ax._id.split('');
associatedXAxis[0] = 'x';
associatedXAxis = associatedXAxis.join('');
ax = gd._fullLayout[axisIDs.id2name(associatedXAxis)];
var associatedXAxisID = fullTrace._diag[currentDimensionIndex][0];
ax = gd._fullLayout[axisIDs.id2name(associatedXAxisID)];
}

var categories = cdi.trace.dimensions[currentDimensionIndex].values;
for(l = 0; l < categories.length; l++) {
cat = categories[l];
catIndex = ax._categoriesMap[cat];

// Collect values over all other dimensions
// Collect associated values at index `l` over all other dimensions
for(o = 0; o < cdi.trace.dimensions.length; o++) {
if(o === currentDimensionIndex) continue;
var dimension = cdi.trace.dimensions[o];
Expand Down
3 changes: 3 additions & 0 deletions src/traces/splom/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ function handleAxisDefaults(traceIn, traceOut, layout, coerce) {
var mustShiftX = !showDiag && !showLower;
var mustShiftY = !showDiag && !showUpper;

traceOut._axesDim = {};
for(i = 0; i < dimLength; i++) {
var dim = dimensions[i];
var i0 = i === 0;
Expand All @@ -143,6 +144,8 @@ function handleAxisDefaults(traceIn, traceOut, layout, coerce) {
fillAxisStashes(xaId, yaId, dim, xList);
fillAxisStashes(yaId, xaId, dim, yList);
diag[i] = [xaId, yaId];
traceOut._axesDim[xaId] = i;
traceOut._axesDim[yaId] = i;
}

// fill in splom subplot keys
Expand Down
0