Skip to content
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

Implementation of arrayOk textposition for scatter3d traces #3200

Merged
merged 10 commits into from
Nov 9, 2018
Merged

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Oct 31, 2018

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

Copy link
Contributor

@etpinard etpinard left a comment

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

@@ -160,7 +160,7 @@ var attrs = module.exports = overrideAll({
colorAttributes('marker')
),

textposition: extendFlat({}, scatterAttrs.textposition, {dflt: 'top center', arrayOk: false}),
textposition: extendFlat({}, scatterAttrs.textposition, {dflt: 'top center', arrayOk: true}),
Copy link
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(' ')
},

@@ -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;
Copy link
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
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
Contributor

Choose a reason for hiding this comment

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

Nice mock!

@@ -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);
Copy link
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
Copy link
Contributor

etpinard commented Nov 6, 2018

@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.


if(textposition.indexOf('left') !== -1) posX = 'left';
else if(textposition.indexOf('right') !== -1) posX = 'right';
if(textposition !== undefined && textposition !== null) {
Copy link
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
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
Copy link
Contributor

etpinard commented Nov 9, 2018

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