-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Enable text for scattergl trace #2737
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 16 commits
8ec98b9
862905c
d1a06c0
cbc7f3f
cc2cca1
e5a771c
349b551
71c1acb
4fe4e3a
ff1d4fc
95a3d1a
ed7e0a0
fa96cc7
9653fcf
17c1b0b
0154571
c47d258
79eae53
bd4491c
741bfb1
4d67fa4
90479a7
6def5e4
47cf7e2
a53baf6
b3fb445
e09a4e1
668d7ee
a41ea35
1702b30
62bf263
65f97f3
55906cc
46bc623
7d75169
1a64005
bdc8f4a
959a555
431c564
9f3827c
3af4d2f
a83077b
29fa2ef
e462eda
52614d1
143a61e
fb08f55
a5637dd
6aedaa6
235f1ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -37,9 +37,13 @@ var attrs = module.exports = overrideAll({ | |||||||||||||||||||||||||||||
'this trace\'s (x,y) coordinates.' | ||||||||||||||||||||||||||||||
].join(' ') | ||||||||||||||||||||||||||||||
}), | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
textposition: scatterAttrs.textposition, | ||||||||||||||||||||||||||||||
textfont: scatterAttrs.textfont, | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
mode: { | ||||||||||||||||||||||||||||||
valType: 'flaglist', | ||||||||||||||||||||||||||||||
flags: ['lines', 'markers'], | ||||||||||||||||||||||||||||||
flags: ['lines', 'markers', 'text'], | ||||||||||||||||||||||||||||||
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. Now that scattergl supports on-graph, we can add plotly.js/src/traces/scatter/attributes.js Lines 91 to 104 in 6ac47ec
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. done in 959a555 |
||||||||||||||||||||||||||||||
extras: ['none'], | ||||||||||||||||||||||||||||||
role: 'info', | ||||||||||||||||||||||||||||||
description: [ | ||||||||||||||||||||||||||||||
|
@@ -77,10 +81,12 @@ var attrs = module.exports = overrideAll({ | |||||||||||||||||||||||||||||
hoveron: scatterAttrs.hoveron, | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
selected: { | ||||||||||||||||||||||||||||||
marker: scatterAttrs.selected.marker | ||||||||||||||||||||||||||||||
marker: scatterAttrs.selected.marker, | ||||||||||||||||||||||||||||||
textfont: scatterAttrs.selected.textfont | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
unselected: { | ||||||||||||||||||||||||||||||
marker: scatterAttrs.unselected.marker | ||||||||||||||||||||||||||||||
marker: scatterAttrs.unselected.marker, | ||||||||||||||||||||||||||||||
textfont: scatterAttrs.unselected.textfont | ||||||||||||||||||||||||||||||
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. Does this work? And what about 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. Confirmed. 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. mostly done in 1a64005 |
||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
opacity: plotAttrs.opacity | ||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ var createLine = require('regl-line2d'); | |
var createError = require('regl-error2d'); | ||
var cluster = require('point-cluster'); | ||
var arrayRange = require('array-range'); | ||
var Text = require('gl-text'); | ||
|
||
var Registry = require('../../registry'); | ||
var Lib = require('../../lib'); | ||
|
@@ -103,6 +104,7 @@ function calc(gd, trace) { | |
if(opts.marker && !scene.scatter2d) scene.scatter2d = true; | ||
if(opts.line && !scene.line2d) scene.line2d = true; | ||
if((opts.errorX || opts.errorY) && !scene.error2d) scene.error2d = true; | ||
if(opts.text && !scene.glText) scene.glText = true; | ||
|
||
// FIXME: organize it in a more appropriate manner, probably in sceneOptions | ||
// put point-cluster instance for optimized regl calc | ||
|
@@ -118,6 +120,7 @@ function calc(gd, trace) { | |
scene.markerOptions.push(opts.marker); | ||
scene.selectedOptions.push(opts.selected); | ||
scene.unselectedOptions.push(opts.unselected); | ||
scene.textOptions.push(opts.text); | ||
scene.count++; | ||
|
||
// stash scene ref | ||
|
@@ -132,6 +135,7 @@ function calc(gd, trace) { | |
return [{x: false, y: false, t: stash, trace: trace}]; | ||
} | ||
|
||
|
||
// create scene options | ||
function sceneOptions(gd, subplot, trace, positions, x, y) { | ||
var opts = convertStyle(gd, trace); | ||
|
@@ -161,6 +165,7 @@ function sceneOptions(gd, subplot, trace, positions, x, y) { | |
return opts; | ||
} | ||
|
||
|
||
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. Again here. Please don't commit lines like this. 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, but in this case all functions are separated by 2 new lines and here by just one, so hope you don't mind a bit of perfectionism |
||
// make sure scene exists on subplot, return it | ||
function sceneUpdate(gd, subplot) { | ||
var scene = subplot._scene; | ||
|
@@ -178,7 +183,8 @@ function sceneUpdate(gd, subplot) { | |
selectedOptions: [], | ||
unselectedOptions: [], | ||
errorXOptions: [], | ||
errorYOptions: [] | ||
errorYOptions: [], | ||
textOptions: [] | ||
}; | ||
|
||
var initOpts = { | ||
|
@@ -189,6 +195,7 @@ function sceneUpdate(gd, subplot) { | |
scatter2d: false, | ||
error2d: false, | ||
line2d: false, | ||
glText: false, | ||
select2d: null | ||
}; | ||
|
||
|
@@ -213,6 +220,11 @@ function sceneUpdate(gd, subplot) { | |
if(scene.line2d) scene.line2d.update(opts); | ||
if(scene.error2d) scene.error2d.update(opts.concat(opts)); | ||
if(scene.select2d) scene.select2d.update(opts); | ||
if(scene.glText) { | ||
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. Can you 🔪 this out? |
||
// scene.glText.forEach(function (text) { | ||
// text.update(opts); | ||
// }) | ||
} | ||
|
||
scene.draw(); | ||
}; | ||
|
@@ -248,6 +260,14 @@ function sceneUpdate(gd, subplot) { | |
scene.scatter2d.draw(scene.unselectBatch); | ||
} | ||
|
||
if(scene.glText.length) { | ||
scene.glText.forEach(function(items) { | ||
items.forEach(function(item) { | ||
item.render(); | ||
}); | ||
}); | ||
} | ||
|
||
scene.dirty = false; | ||
}; | ||
|
||
|
@@ -293,7 +313,13 @@ function sceneUpdate(gd, subplot) { | |
if(scene.error2d) scene.error2d.destroy(); | ||
if(scene.line2d) scene.line2d.destroy(); | ||
if(scene.select2d) scene.select2d.destroy(); | ||
if(scene.glText) {scene.glText.forEach(function(items) { | ||
items.forEach(function(item) { | ||
item.destroy(); | ||
}); | ||
});} | ||
|
||
scene.textOptions = null; | ||
scene.lineOptions = null; | ||
scene.fillOptions = null; | ||
scene.markerOptions = null; | ||
|
@@ -318,9 +344,12 @@ function sceneUpdate(gd, subplot) { | |
return scene; | ||
} | ||
|
||
|
||
function plot(gd, subplot, cdata) { | ||
if(!cdata.length) return; | ||
|
||
var i, j, items, textOptions; | ||
|
||
var fullLayout = gd._fullLayout; | ||
var scene = cdata[0][0].t._scene; | ||
var dragmode = fullLayout.dragmode; | ||
|
@@ -357,8 +386,27 @@ function plot(gd, subplot, cdata) { | |
if(scene.fill2d === true) { | ||
scene.fill2d = createLine(regl); | ||
} | ||
if(scene.glText === true) { | ||
scene.glText = []; | ||
for(i = 0; i < scene.textOptions.length; i++) { | ||
textOptions = scene.textOptions[i]; | ||
items = []; | ||
for(j = 0; j < textOptions.length; j++) { | ||
items.push(new Text(regl)); | ||
} | ||
scene.glText[i] = items; | ||
} | ||
} | ||
|
||
// update main marker options | ||
if(scene.glText) { | ||
for(i = 0; i < scene.textOptions.length; i++) { | ||
textOptions = scene.textOptions[i]; | ||
for(j = 0; j < textOptions.length; j++) { | ||
scene.glText[i][j].update(textOptions[j]); | ||
} | ||
} | ||
} | ||
if(scene.line2d) { | ||
scene.line2d.update(scene.lineOptions); | ||
} | ||
|
@@ -572,12 +620,20 @@ function plot(gd, subplot, cdata) { | |
if(scene.select2d) { | ||
scene.select2d.update(vpRange); | ||
} | ||
if(scene.glText) { | ||
scene.glText.forEach(function(items, i) { | ||
items.forEach(function(item) { | ||
item.update(vpRange[i]); | ||
}); | ||
}); | ||
} | ||
|
||
scene.draw(); | ||
|
||
return; | ||
} | ||
|
||
|
||
function hoverPoints(pointData, xval, yval, hovermode) { | ||
var cd = pointData.cd; | ||
var stash = cd[0].t; | ||
|
@@ -816,6 +872,7 @@ function selectPoints(searchInfo, polygon) { | |
return selection; | ||
} | ||
|
||
|
||
function style(gd, cds) { | ||
if(!cds) return; | ||
|
||
|
@@ -831,6 +888,7 @@ function style(gd, cds) { | |
scene.draw(); | ||
} | ||
|
||
|
||
module.exports = { | ||
moduleType: 'trace', | ||
name: 'scattergl', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,10 @@ function updateHeadersInSrcFiles() { | |
}); | ||
|
||
function isCorrect(header) { | ||
return (header.value === licenseStr); | ||
return ( | ||
header.value.replace(/\s+$/gm, '') === | ||
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. Is this for windows compat? If so, I would prefer a different solution. Trimming spaces here could lead to false positive assertions. 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. never mind. Thanks for the fix! |
||
licenseStr.replace(/\s+$/gm, '') | ||
); | ||
} | ||
|
||
function hasWrongDate(header) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you try not committing things like that in the future? Thank you.