-
-
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 2 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,49 @@ function calculateErrorParams(errors) { | |
return {capSize: capSize, color: color, lineWidth: lineWidth}; | ||
} | ||
|
||
function parseAlignmentX(a) { | ||
if(a === null || a === undefined) return 0; | ||
else if(typeof(a) === 'number') return a; | ||
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. Why would 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. Well, I thought we could somehow make use of other numbers (instead than only -1|0|1) to scale the distances. But yeah I may remove those condition checks (also for null & undefined) since I noticed the inputs seem to be parsed and validated before getting to there? |
||
else if(a.indexOf('left') > -1) return -1; | ||
else if(a.indexOf('right') > -1) return 1; | ||
return 0; | ||
} | ||
|
||
function parseAlignmentY(a) { | ||
if(a === null || a === undefined) return 0; | ||
else if(typeof(a) === 'number') return a; | ||
else if(a.indexOf('top') > -1) return -1; | ||
else if(a.indexOf('bottom') > -1) return 1; | ||
return 0; | ||
} | ||
|
||
function calculateTextOffset(tp) { | ||
// 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 = 0; // center | ||
var defaultAlignmentY = -1; // top | ||
|
||
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 +268,7 @@ function convertPlotlyOptions(scene, data) { | |
} | ||
|
||
if('textposition' in data) { | ||
params.textOffset = calculateTextOffset(data.textposition); // arrayOk === false | ||
params.textOffset = calculateTextOffset(data.textposition); | ||
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.
Making this line
would suffice as
textposition
in the scatter attributes is alreadyarrayOk
:plotly.js/src/traces/scatter/attributes.js
Lines 520 to 535 in fe2d8d7