-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Implementation of arrayOk textposition for scatter3d traces #3200
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 5 commits
e6d7532
cdb0bac
37c592e
f804dae
73cd576
d4addd0
bb7adb6
bc0c5df
ee8db8d
555a541
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,14 +133,47 @@ function calculateErrorParams(errors) { | |
return {capSize: capSize, color: color, lineWidth: lineWidth}; | ||
} | ||
|
||
function calculateTextOffset(tp) { | ||
function parseAlignmentX(a) { | ||
if(a === null || a === undefined) return 0; | ||
|
||
return (a.indexOf('left') > -1) ? -1 : | ||
(a.indexOf('right') > -1) ? 1 : 0; | ||
} | ||
|
||
function parseAlignmentY(a) { | ||
if(a === null || a === undefined) return 0; | ||
|
||
return (a.indexOf('top') > -1) ? -1 : | ||
(a.indexOf('bottom') > -1) ? 1 : 0; | ||
} | ||
|
||
function calculateTextOffset(tp, dflt) { | ||
// Read out text properties | ||
var textOffset = [0, 0]; | ||
if(Array.isArray(tp)) return [0, -1]; | ||
if(tp.indexOf('bottom') >= 0) textOffset[1] += 1; | ||
if(tp.indexOf('top') >= 0) textOffset[1] -= 1; | ||
if(tp.indexOf('left') >= 0) textOffset[0] -= 1; | ||
if(tp.indexOf('right') >= 0) textOffset[0] += 1; | ||
|
||
var defaultAlignmentX = parseAlignmentX(dflt); | ||
var defaultAlignmentY = parseAlignmentY(dflt); | ||
|
||
var textOffset = [ | ||
defaultAlignmentX, | ||
defaultAlignmentY | ||
]; | ||
|
||
if(Array.isArray(tp)) { | ||
for(var i = 0; i < tp.length; i++) { | ||
textOffset[i] = [ | ||
defaultAlignmentX, | ||
defaultAlignmentY | ||
]; | ||
if(tp[i]) { | ||
textOffset[i][0] = parseAlignmentX(tp[i]); | ||
textOffset[i][1] = parseAlignmentY(tp[i]); | ||
} | ||
} | ||
} else { | ||
textOffset[0] = parseAlignmentX(tp); | ||
textOffset[1] = parseAlignmentY(tp); | ||
} | ||
|
||
return textOffset; | ||
} | ||
|
||
|
@@ -233,7 +266,7 @@ function convertPlotlyOptions(scene, data) { | |
} | ||
|
||
if('textposition' in data) { | ||
params.textOffset = calculateTextOffset(data.textposition); // arrayOk === false | ||
params.textOffset = calculateTextOffset(data.textposition, data.dflt); | ||
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. Hmm. What's |
||
params.textColor = formatColor(data.textfont, 1, len); | ||
params.textSize = formatParam(data.textfont.size, len, Lib.identity, 12); | ||
params.textFont = data.textfont.family; // arrayOk === false | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"x": [0, 1, 2, 3, 4, 5, 6, 7, 8], | ||
"y": [0, 1, 0, 1, 0, 1, 0, 1, 0], | ||
"z": [0, 1, 2, 3, 4, 5, 6, 7, 8], | ||
"type": "scatter3d", | ||
"mode":"lines+markers+text", | ||
"text": ["middle center", "bottom", "right", "bottom right", "bottom left", "left", "top right", "top", "top left"], | ||
"textposition": ["", "bottom", "right", "bottom right", "bottom left", "left", "top right", "top", "top left"] | ||
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. Nice mock! |
||
} | ||
], | ||
"layout": { | ||
"title":"Texts in scatter3d could be aligned differently using arrays", | ||
"width": 800, | ||
"height": 600, | ||
"scene":{ | ||
"camera":{ | ||
"eye":{ "x":-1.25,"y":1.25,"z":1.25 }, | ||
"center":{ "x":0,"y":0,"z":0 }, | ||
"up":{ "x":0,"y":0,"z":1 } | ||
} | ||
} | ||
} | ||
} |
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.
I think we have to be even more strict at this stage here. Anything that's not a string shouldn't fall into this block. The items inside
textposition
can really be anything.Have you tried something like:
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.
... and would you mind adding a jasmine test for this⤴️
Somewhere at the end of this describe block would be 👌