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

Sort + set 'categoryarray' #1689

Merged
merged 3 commits into from
May 16, 2017
Merged

Sort + set 'categoryarray' #1689

merged 3 commits into from
May 16, 2017

Conversation

etpinard
Copy link
Contributor

@etpinard etpinard commented May 15, 2017

Plotly.newPlot('graph', [{
  mode: 'markers',
  x: ['A', 'B', 'C'],
  y: ['a', 'b', 'c'],
  marker: { size: [20, 30, 50] },
  transforms: [{
    type: 'sort',
    target: [2, 1, 0]
  }]
}])

currently gives:

image

where the categories are re-arranged after the sort transform - which is consistent with how we handle categories in filter transforms. See PR #1260 for more details.

But setting layout.xaxis.categoryarray: ['A', 'B', 'C] -- which implies that the category positions are fixed -- curently gives the same results as above.

With commit 7a2a2e1

Plotly.newPlot('graph', [{
  mode: 'markers',
  x: ['A', 'B', 'C'],
  y: ['a', 'b', 'c'],
  marker: { size: [20, 30, 50] },
  transforms: [{
    type: 'sort',
    target: [2, 1, 0]
  }]
}], {
  xaxis: {
    categoryarray: ['A', 'B', 'C']
  }
})

now gives:

image

where categoryarray is honored.

cc @n-riesco @alexcjohnson

@etpinard etpinard added status: reviewable bug something broken labels May 15, 2017
@@ -2099,6 +2085,26 @@ plots.doCalcdata = function(gd, traces) {
}
};

plots.initCategories = function(axList) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a reason to export this fn?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not a big deal, but I'd prefer not to since it goes into Plotly.Plots

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good call 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in b8e5f52

// initialize the category list, if there is one, so we start over
// to be filled in later by ax.d2c
for(var i = 0; i < axList.length; i++) {
axList[i]._categories = axList[i]._initialCategories.slice();
Copy link
Contributor

Choose a reason for hiding this comment

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

Certainly would have been caught by now if this could ever be undefined, right? (I'm too cautious about checking for undefined unnecessarily)

Copy link
Contributor Author

@etpinard etpinard May 15, 2017

Choose a reason for hiding this comment

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

Yeah. That _initialCategories thing is set in the defaults. Calling Plots.doCalcdata before supplyDefaults is like 🔫 yourself in the 👣 .

Copy link
Contributor

Choose a reason for hiding this comment

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

Haha the squirt gun. And then your socks are wet for the rest of the day.

@alexcjohnson
Copy link
Collaborator

💃 very clean! But consider #1689 (comment) before merging.

@etpinard etpinard merged commit a86a5ac into master May 16, 2017
@etpinard etpinard deleted the sort-with-categoryarray branch May 16, 2017 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants