Skip to content

Implementation of arrayOk textposition for scatter3d traces - #3200

Merged
archmoj merged 10 commits into
masterfrom
issue-2872
Nov 9, 2018
Merged

archmoj merged 10 commits into
masterfrom
issue-2872

Conversation

@archmoj

@archmoj archmoj commented Oct 31, 2018

Copy link
Copy Markdown
Contributor

This PR resolves #2872 so that the arrays could be used for different alignments of texts in scatter3d.
@etpinard
@alexcjohnson

@etpinard etpinard left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice PR @archmoj - thanks!

The changes in gl-vis/gl-scatter3d#11 also look good. I made two small comments here.

As this is a new feature, we'll hold off on merging it for at least one week - in case we need to make another patch under 1.42.x

Comment thread src/traces/scatter3d/attributes.js Outdated
),

textposition: extendFlat({}, scatterAttrs.textposition, {dflt: 'top center', arrayOk: false}),
textposition: extendFlat({}, scatterAttrs.textposition, {dflt: 'top center', arrayOk: true}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this line

textposition: extendFlat({}, scatterAttrs.textposition, {dflt: 'top center'}),

would suffice as textposition in the scatter attributes is already arrayOk:

textposition: {
valType: 'enumerated',
values: [
'top left', 'top center', 'top right',
'middle left', 'middle center', 'middle right',
'bottom left', 'bottom center', 'bottom right'
],
dflt: 'middle center',
arrayOk: true,
role: 'style',
editType: 'calc',
description: [
'Sets the positions of the `text` elements',
'with respects to the (x,y) coordinates.'
].join(' ')
},

Comment thread src/traces/scatter3d/convert.js Outdated

function parseAlignmentX(a) {
if(a === null || a === undefined) return 0;
else if(typeof(a) === 'number') return a;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would textposition[i] ever be a number here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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?

"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"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice mock!

Comment thread src/traces/scatter3d/convert.js Outdated

if('textposition' in data) {
params.textOffset = calculateTextOffset(data.textposition); // arrayOk === false
params.textOffset = calculateTextOffset(data.textposition, data.dflt);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. What's data.dflt here?

@etpinard

etpinard commented Nov 6, 2018

Copy link
Copy Markdown
Contributor

@archmoj I'm trying to plot

Plotly.newPlot(gd, [{
  type: 'scatter3d',
  mode: 'markers+text',
  x: [1, 2],
  y: [1, 2],
  z: [1, 2],
  text: ['a', 'b'],
  textposition: [null, undefined]
}])

off this branch, but I'm getting:

image

which points to:

if(!Registry.traceIs(trace, 'pie') && !Registry.traceIs(trace, 'bar')) {
if(Array.isArray(trace.textposition)) {
for(i = 0; i < trace.textposition.length; i++) {
trace.textposition[i] = cleanTextPosition(trace.textposition[i]);
}
}
else if(trace.textposition) {
trace.textposition = cleanTextPosition(trace.textposition);
}
}

so we might have to patch that cleanTextPosition helper.

Comment thread src/plot_api/helpers.js Outdated

if(textposition.indexOf('left') !== -1) posX = 'left';
else if(textposition.indexOf('right') !== -1) posX = 'right';
if(textposition !== undefined && textposition !== null) {

Copy link
Copy Markdown
Contributor

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:

Plotly.newPlot(gd, [{
  type: 'scatter3d',
  mode: 'markers+text',
  x: [1, 2],
  y: [1, 2],
  z: [1, 2],
  text: ['a', 'b'],
  textposition: [null, undefined, true, false, [], {}, NaN, Infinity]
}])

Copy link
Copy Markdown
Contributor

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 👌

@etpinard

etpinard commented Nov 9, 2018

Copy link
Copy Markdown
Contributor

This PR is ✅

You can go ahead and merge gl-vis/gl-scatter3d#11 , release gl-scatter3d patch. Looks like you'll also need to merge a conflict in gl3d_plot_interact. Once that's done 💃

@archmoj
archmoj merged commit 427fd14 into master Nov 9, 2018
@archmoj
archmoj deleted the issue-2872 branch November 9, 2018 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature something new

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement arrayOk textposition for scatter3d traces

2 participants