-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
cartesian 2dMap: implement sorting of categorical axes #3827
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
Changes from 13 commits
e1716c7
d8ef1d7
9735683
5798dd8
56c6a4d
f878387
a34ca45
6b06516
59edb57
22cfa82
02e4089
5160948
e966030
ae3ecf5
e68c170
ebf545f
793c2a3
4d4b0b7
f180c79
0c41776
c7cd1f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,16 +9,17 @@ | |
'use strict'; | ||
|
||
var isNumeric = require('fast-isnumeric'); | ||
var Lib = require('../../lib'); | ||
|
||
module.exports = function clean2dArray(zOld, transpose) { | ||
module.exports = function clean2dArray(zOld, trace, xa, ya) { | ||
var rowlen, collen, getCollen, old2new, i, j; | ||
|
||
function cleanZvalue(v) { | ||
if(!isNumeric(v)) return undefined; | ||
return +v; | ||
} | ||
|
||
if(transpose) { | ||
if(trace && trace.transpose) { | ||
etpinard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rowlen = 0; | ||
for(i = 0; i < zOld.length; i++) rowlen = Math.max(rowlen, zOld[i].length); | ||
if(rowlen === 0) return false; | ||
|
@@ -30,12 +31,31 @@ module.exports = function clean2dArray(zOld, transpose) { | |
old2new = function(zOld, i, j) { return zOld[i][j]; }; | ||
} | ||
|
||
function axisMapping(ax) { | ||
if(trace && trace.type !== 'carpet' && trace.type !== 'contourcarpet' && | ||
ax && ax.type === 'category' && trace['_' + ax._id.charAt(0)].length) { | ||
var axMapping = []; | ||
for(i = 0; i < ax._categories.length; i++) { | ||
axMapping.push((trace['_' + ax._id.charAt(0) + 'Map'] || trace[ax._id.charAt(0)]).indexOf(ax._categories[i])); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh and can we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One more thing, grepping for EDIT: Nevermind. I found them in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Unfortunately, we cannot. For example, in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, that's very unfortunate, because for(i = 0; i < ax._categories.length; i++) {
trace[ax._id.charAt(0)]).indexOf(ax._categories[i]))
} can be very costly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if instead you made That is, instead of: if(ax1 && ax1.type === 'category') {
trace['_' + var1Name + 'CategoryMap'] = col1vals.map(function(v) { return ax1._categories[v];});
} we could have if(ax1 && ax1.type === 'category') {
var lookup = trace['_' + var1Name + 'CategoryMap'] = {};
for(var i = 0; i < col1vals.length; i++) {
var v = col1vals[i];
lookup[v] = i;
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. About your questions regarding
However, we now run it for every element so in the end, I'm not sure which is faster with real data. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry @antoinerg I got confused (again). Your logic looks right to me. The way you have it setup right now, I think we can get rid of the function(i) {
var ind = axMapping[ax._categories[i]];
return ind + 1 ? ind : BADNUM;
}; where the This comment is non-blocking as I don't expect much of a performance gain from it 😏 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Awesome trick :) Done in c7cd1f3 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💃 💃 |
||
} | ||
console.log('axMapping', axMapping); | ||
return function(i) {return axMapping[i] === -1 ? undefined : axMapping[i];}; | ||
etpinard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
return Lib.identity; | ||
} | ||
} | ||
|
||
var xMap = axisMapping(xa); | ||
var yMap = axisMapping(ya); | ||
|
||
var zNew = new Array(rowlen); | ||
|
||
if(ya && ya.type === 'category') rowlen = ya._categories.length; | ||
for(i = 0; i < rowlen; i++) { | ||
collen = getCollen(zOld, i); | ||
if(xa && xa.type === 'category') collen = xa._categories.length; | ||
zNew[i] = new Array(collen); | ||
for(j = 0; j < collen; j++) zNew[i][j] = cleanZvalue(old2new(zOld, i, j)); | ||
for(j = 0; j < collen; j++) zNew[i][j] = cleanZvalue(old2new(zOld, yMap(i), xMap(j))); | ||
} | ||
|
||
return zNew; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"layout": { | ||
"xaxis": { | ||
"type": "category", | ||
"categoryorder": "category descending" | ||
}, | ||
"yaxis": { | ||
"type": "category", | ||
"categoryorder": "category descending" | ||
}, | ||
"height": 400, | ||
"width": 400 | ||
}, | ||
"data": [{ | ||
"type": "heatmap", | ||
|
||
"x": ["z", "y", "x", "w"], | ||
"y": ["d", "c", "b", "a"], | ||
"z": [ | ||
[100, 75, 50, 0], | ||
[90, 65, 40, 0], | ||
[80, 55, 30, 0], | ||
[0, 0, 0, 0] | ||
] | ||
}] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"data": [{ | ||
"type": "heatmap", | ||
"x": ["a", "a", "a", "b", "b", "b", "c", "c", "c"], | ||
"y": ["A", "B", "C", "A", "B", "C", "A", "B", "C"], | ||
"z": [0, 50, 100, 50, 0, 255, 100, 510, 1010] | ||
}], | ||
"layout": { | ||
"xaxis": { | ||
"categoryorder": "category descending" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"data": [{ | ||
"type": "heatmap", | ||
"x": ["Team A", "Team B", "Team C"], | ||
"xaxis": "x", | ||
"y": ["Game Three", "Game Two", "Game One"], | ||
"z": [ | ||
[0.1, 0.3, 0.5], | ||
[1, 0.8, 0.6], | ||
[0.6, 0.4, 0.2] | ||
], | ||
"yaxis": "y" | ||
}, { | ||
"type": "heatmap", | ||
"x": ["Team B", "Team C"], | ||
"xaxis": "x", | ||
"y": ["Game Three", "Game Two", "Game One"], | ||
"z": [ | ||
[0.3, 0.5], | ||
[0.8, 0.6], | ||
[0.4, 0.2] | ||
], | ||
"yaxis": "y2" | ||
}], | ||
"layout": { | ||
etpinard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"xaxis": { | ||
"anchor": "y2", | ||
"domain": [0, 1], | ||
"type": "category", | ||
"range": [-0.5, 2.5], | ||
"autorange": true | ||
}, | ||
"yaxis": { | ||
"anchor": "free", | ||
"domain": [0.575, 1], | ||
"position": 0, | ||
"type": "category", | ||
"range": [-0.5, 2.5], | ||
"autorange": true | ||
}, | ||
"yaxis2": { | ||
"anchor": "x", | ||
"domain": [0, 0.425], | ||
"type": "category", | ||
"range": [-0.5, 2.5], | ||
"autorange": true | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.