Skip to content

Axis category ordering - adds feature #189 #419

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

Merged
merged 9 commits into from
Apr 18, 2016
30 changes: 30 additions & 0 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,36 @@ module.exports = {
'Only has an effect if `anchor` is set to *free*.'
].join(' ')
},
categorymode: {
valType: 'enumerated',
values: [
'trace', 'category ascending', 'category descending', 'array'
Copy link
Contributor

Choose a reason for hiding this comment

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

@cldougl @chriddyp does ⏫ look ok to you?

Copy link
Member

Choose a reason for hiding this comment

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

👍 for me

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should include truncated versions of those values as well e.g. 'cat asc', 'cat des' ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest avoiding muti-word strings. Maybe just ascending and descending?

Copy link
Member

Choose a reason for hiding this comment

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

for me just ascending`descendingdoesn't have a clear relation to _alpha_numeric ordering. I definitely understand the aversion to multi-word strings, but I would vote for more description thanascending\descending`

plus if 'value ascending' \ 'value descending' are going to be implemented eventually

Copy link
Contributor

Choose a reason for hiding this comment

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

but I gotta say, catergoryorder doesn't sound bad at all.

Copy link
Member

@chriddyp chriddyp Apr 14, 2016

Choose a reason for hiding this comment

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

You can add them as labels to the axes (currently described as ticktext) or use them as data (currently described as x). Given that the axis.type is category, one might think that categories is how you would add data to that axis.

Copy link
Contributor

Choose a reason for hiding this comment

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

and maybe categoryarray instead of categorylist

@chriddyp we're already using the value 'array' for tickmode.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can add them as labels to the axes

More like: categories are added automatically. Categories have no effect on ticktext.

Copy link
Contributor

@etpinard etpinard Apr 14, 2016

Choose a reason for hiding this comment

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

Given that the axis.type is category, one might think that categories is how you would add data to that axis.

Great point 👍

That's why I'm thinking that categoryorder might be the winner here.

/*, 'value ascending', 'value descending'*/ // value ascending / descending to be implemented later
],
dflt: 'trace',
role: 'info',
description: [
'Specifies the ordering logic for the case of categorical variables.',
'By default, plotly uses *trace*, which specifies the order that is present in the data supplied.',
'Set `categorymode` to *category ascending* or *category descending* if order should be determined by',
'the alphanumerical order of the category names.',
/*'Set `categorymode` to *value ascending* or *value descending* if order should be determined by the',
'numerical order of the values.',*/ // // value ascending / descending to be implemented later
'Set `categorymode` to *array* to derive the ordering from the attribute `categorylist`. If a category',
'is not found in the `categorylist` array, the sorting behavior for that attribute will be identical to',
'the *trace* mode. The unspecified categories will follow the categories in `categorylist`.'
].join(' ')
},
categorylist: {
Copy link
Contributor

Choose a reason for hiding this comment

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

other possibilities include: categories, categoryvals (similar to tickvals).

But I'd vote for the more verbose categorylist.

Copy link
Member

Choose a reason for hiding this comment

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

+1 for categorylist list as well

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd just go for categories but maybe categorylist is more clear? @cldougl @chriddyp?

Copy link
Member

@chriddyp chriddyp Apr 14, 2016

Choose a reason for hiding this comment

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

categories implies strings. This should work for dates and numbers too, right?

We don't want to confuse categories with ticklabels / ticktext (intuitively, I would think that categories would refer to the the tick labels or even the x data itself)

Other options:

  • tickorderarray or tickordervals (if we use tickorder above)
  • orderingvals

Copy link
Contributor

@etpinard etpinard Apr 14, 2016

Choose a reason for hiding this comment

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

This should work for dates and numbers too, right?

No. Only for axis type set or auto-typed to 'category'.

Copy link
Member

Choose a reason for hiding this comment

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

Got it. But eventually it would, right? And shouldn't need a different key?

Copy link
Contributor

@etpinard etpinard Apr 14, 2016

Choose a reason for hiding this comment

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

That wasn't in the plans.

Why would anyone want to reorder dates or numeric independent coordinates?

Copy link
Member

Choose a reason for hiding this comment

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

oh duh, woops my bad.

Copy link
Member

Choose a reason for hiding this comment

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

But my second point "We don't want to confuse categories with ticklabels" still stands :)

valType: 'data_array',
role: 'info',
description: [
'Sets the order in which categories on this axis appear.',
'Only has an effect if `categorymode` is set to *array*.',
'Used with `categorymode`.'
].join(' ')
},


_deprecated: {
autotick: {
Expand Down
29 changes: 29 additions & 0 deletions src/plots/gl3d/layout/axis_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,35 @@ module.exports = {
description: 'Sets whether or not this axis is labeled'
},
color: axesAttrs.color,
categorymode: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Reuse the cartesian axis definitions:

categorymode: axesAttrs.categorymode,
categorylist: axesAttrs.categorylist,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@etpinard good point! I'll await all PR responses and do them in one to not go wild with commits.

valType: 'enumerated',
values: [
'trace', 'category ascending', 'category descending', 'array'
/*, 'value ascending', 'value descending'*/ // value ascending / descending to be implemented later
],
dflt: 'trace',
role: 'info',
description: [
'Specifies the ordering logic for the case of categorical variables.',
'By default, plotly uses *trace*, which specifies the order that is present in the data supplied.',
'Set `categorymode` to *category ascending* or *category descending* if order should be determined by',
'the alphanumerical order of the category names.',
/*'Set `categorymode` to *value ascending* or *value descending* if order should be determined by the',
'numerical order of the values.',*/ // // value ascending / descending to be implemented later
'Set `categorymode` to *array* to derive the ordering from the attribute `categorylist`. If a category',
'is not found in the `categorylist` array, the sorting behavior for that attribute will be identical to',
'the *trace* mode. The unspecified categories will follow the categories in `categorylist`.'
].join(' ')
},
categorylist: {
valType: 'data_array',
role: 'info',
description: [
'Sets the order in which categories on this axis appear.',
'Only has an effect if `categorymode` is set to *array*.',
'Used with `categorymode`.'
].join(' ')
},
title: axesAttrs.title,
titlefont: axesAttrs.titlefont,
type: axesAttrs.type,
Expand Down