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

Conversation

Projects
None yet
2 participants
@archmoj
Copy link
Collaborator

commented Oct 31, 2018

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

@etpinard
Copy link
Member

left a comment

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}),

This comment has been minimized.

Copy link
@etpinard

etpinard Nov 1, 2018

Member

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;

This comment has been minimized.

Copy link
@etpinard

etpinard Nov 1, 2018

Member

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

This comment has been minimized.

Copy link
@archmoj

archmoj Nov 1, 2018

Author Collaborator

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

This comment has been minimized.

Copy link
@etpinard

etpinard Nov 1, 2018

Member

Nice mock!

archmoj added some commits Nov 1, 2018

@@ -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);

This comment has been minimized.

Copy link
@etpinard

etpinard Nov 6, 2018

Member

Hmm. What's data.dflt here?

@etpinard

This comment has been minimized.

Copy link
Member

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) {

This comment has been minimized.

Copy link
@etpinard

etpinard Nov 7, 2018

Member

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]
}])

This comment has been minimized.

Copy link
@etpinard

etpinard Nov 7, 2018

Member

... and would you mind adding a jasmine test for this ⤴️

Somewhere at the end of this describe block would be 👌

@etpinard

This comment has been minimized.

Copy link
Member

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 added some commits Nov 9, 2018

@archmoj archmoj merged commit 427fd14 into master Nov 9, 2018

7 checks passed

ci/circleci: build Your tests passed on CircleCI!
Details
ci/circleci: publish Your tests passed on CircleCI!
Details
ci/circleci: test-image Your tests passed on CircleCI!
Details
ci/circleci: test-image2 Your tests passed on CircleCI!
Details
ci/circleci: test-jasmine Your tests passed on CircleCI!
Details
ci/circleci: test-jasmine2 Your tests passed on CircleCI!
Details
ci/circleci: test-syntax Your tests passed on CircleCI!
Details

@archmoj archmoj deleted the issue-2872 branch Nov 9, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.