Skip to content

Commit 14908d0

Browse files
committed
plotly#189 Renaming attributes
1 parent 53f12da commit 14908d0

13 files changed

+189
-189
lines changed

src/plots/cartesian/axis_defaults.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var layoutAttributes = require('./layout_attributes');
2020
var handleTickValueDefaults = require('./tick_value_defaults');
2121
var handleTickMarkDefaults = require('./tick_mark_defaults');
2222
var handleTickLabelDefaults = require('./tick_label_defaults');
23-
var handleCategoryModeDefaults = require('./category_mode_defaults');
23+
var handleCategoryOrderDefaults = require('./category_order_defaults');
2424
var setConvert = require('./set_convert');
2525
var orderedCategories = require('./ordered_categories');
2626
var cleanDatum = require('./clean_datum');
@@ -75,7 +75,7 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
7575
}
7676

7777
containerOut._initialCategories = axType === 'category' ?
78-
orderedCategories(letter, containerIn.categorymode, containerIn.categorylist, options.data) :
78+
orderedCategories(letter, containerIn.categoryorder, containerIn.categoryarray, options.data) :
7979
[];
8080

8181
setConvert(containerOut);
@@ -111,7 +111,7 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
111111
handleTickValueDefaults(containerIn, containerOut, coerce, axType);
112112
handleTickLabelDefaults(containerIn, containerOut, coerce, axType, options);
113113
handleTickMarkDefaults(containerIn, containerOut, coerce, options);
114-
handleCategoryModeDefaults(containerIn, containerOut, coerce);
114+
handleCategoryOrderDefaults(containerIn, containerOut, coerce);
115115

116116
var lineColor = coerce2('linecolor', dfltColor),
117117
lineWidth = coerce2('linewidth'),

src/plots/cartesian/category_mode_defaults.js

-39
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var layoutAttributes = require('./layout_attributes');
12+
13+
module.exports = function handleCategoryOrderDefaults(containerIn, containerOut, coerce) {
14+
15+
if(containerIn.type !== 'category') return;
16+
17+
var validCategories = layoutAttributes.categoryorder.values;
18+
19+
var propercategoryarray = Array.isArray(containerIn.categoryarray) && containerIn.categoryarray.length > 0;
20+
21+
if(validCategories.indexOf(containerIn.categoryorder) === -1 && propercategoryarray) {
22+
23+
// when unspecified or invalid, use the default, unless categoryarray implies 'array'
24+
coerce('categoryorder', 'array'); // promote to 'array'
25+
26+
} else if(containerIn.categoryorder === 'array' && !propercategoryarray) {
27+
28+
// when mode is 'array' but no list is given, revert to default
29+
30+
containerIn.categoryorder = 'trace'; // revert to default
31+
coerce('categoryorder');
32+
33+
} else {
34+
35+
// otherwise use the supplied mode, or the default one if unsupplied or invalid
36+
coerce('categoryorder');
37+
38+
}
39+
};

src/plots/cartesian/layout_attributes.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ module.exports = {
465465
'Only has an effect if `anchor` is set to *free*.'
466466
].join(' ')
467467
},
468-
categorymode: {
468+
categoryorder: {
469469
valType: 'enumerated',
470470
values: [
471471
'trace', 'category ascending', 'category descending', 'array'
@@ -476,22 +476,22 @@ module.exports = {
476476
description: [
477477
'Specifies the ordering logic for the case of categorical variables.',
478478
'By default, plotly uses *trace*, which specifies the order that is present in the data supplied.',
479-
'Set `categorymode` to *category ascending* or *category descending* if order should be determined by',
479+
'Set `categoryorder` to *category ascending* or *category descending* if order should be determined by',
480480
'the alphanumerical order of the category names.',
481-
/*'Set `categorymode` to *value ascending* or *value descending* if order should be determined by the',
481+
/*'Set `categoryorder` to *value ascending* or *value descending* if order should be determined by the',
482482
'numerical order of the values.',*/ // // value ascending / descending to be implemented later
483-
'Set `categorymode` to *array* to derive the ordering from the attribute `categorylist`. If a category',
484-
'is not found in the `categorylist` array, the sorting behavior for that attribute will be identical to',
485-
'the *trace* mode. The unspecified categories will follow the categories in `categorylist`.'
483+
'Set `categoryorder` to *array* to derive the ordering from the attribute `categoryarray`. If a category',
484+
'is not found in the `categoryarray` array, the sorting behavior for that attribute will be identical to',
485+
'the *trace* mode. The unspecified categories will follow the categories in `categoryarray`.'
486486
].join(' ')
487487
},
488-
categorylist: {
488+
categoryarray: {
489489
valType: 'data_array',
490490
role: 'info',
491491
description: [
492492
'Sets the order in which categories on this axis appear.',
493-
'Only has an effect if `categorymode` is set to *array*.',
494-
'Used with `categorymode`.'
493+
'Only has an effect if `categoryorder` is set to *array*.',
494+
'Used with `categoryorder`.'
495495
].join(' ')
496496
},
497497

src/plots/cartesian/ordered_categories.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@ function flattenUniqueSort(axisLetter, sortFunction, data) {
5353

5454

5555
/**
56-
* This pure function returns the ordered categories for specified axisLetter, categorymode, categorylist and data.
56+
* This pure function returns the ordered categories for specified axisLetter, categoryorder, categoryarray and data.
5757
*
58-
* If categorymode is 'array', the result is a fresh copy of categorylist, or if unspecified, an empty array.
58+
* If categoryorder is 'array', the result is a fresh copy of categoryarray, or if unspecified, an empty array.
5959
*
60-
* If categorymode is 'category ascending' or 'category descending', the result is an array of ascending or descending
60+
* If categoryorder is 'category ascending' or 'category descending', the result is an array of ascending or descending
6161
* order of the unique categories encountered in the data for specified axisLetter.
6262
*
63-
* See cartesian/layout_attributes.js for the definition of categorymode and categorylist
63+
* See cartesian/layout_attributes.js for the definition of categoryorder and categoryarray
6464
*
6565
*/
6666

6767
// orderedCategories :: String -> String -> [String] -> [[String]] -> [String]
68-
module.exports = function orderedCategories(axisLetter, categorymode, categorylist, data) {
68+
module.exports = function orderedCategories(axisLetter, categoryorder, categoryarray, data) {
6969

70-
switch(categorymode) {
71-
case 'array': return Array.isArray(categorylist) ? categorylist.slice() : [];
70+
switch(categoryorder) {
71+
case 'array': return Array.isArray(categoryarray) ? categoryarray.slice() : [];
7272
case 'category ascending': return flattenUniqueSort(axisLetter, d3.ascending, data);
7373
case 'category descending': return flattenUniqueSort(axisLetter, d3.descending, data);
7474
case 'trace': return [];

src/plots/gl3d/layout/axis_attributes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ module.exports = {
6868
description: 'Sets whether or not this axis is labeled'
6969
},
7070
color: axesAttrs.color,
71-
categorymode: axesAttrs.categorymode,
72-
categorylist: axesAttrs.categorylist,
71+
categoryorder: axesAttrs.categoryorder,
72+
categoryarray: axesAttrs.categoryarray,
7373
title: axesAttrs.title,
7474
titlefont: axesAttrs.titlefont,
7575
type: axesAttrs.type,

test/image/mocks/axes_category_ascending.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"xaxis": {
88
"title": "category ascending",
99
"type": "category",
10-
"categorymode": "category ascending",
11-
"categorylist": ["y","b","x","a","d","z","e","c", "q", "k"]
10+
"categoryorder": "category ascending",
11+
"categoryarray": ["y","b","x","a","d","z","e","c", "q", "k"]
1212
}}
1313
}

test/image/mocks/axes_category_categorylist.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
3.1833667334669338
2929
],
3030
"autorange": true,
31-
"categorymode": "array",
32-
"categorylist": [2,4,5,1]
31+
"categoryorder": "array",
32+
"categoryarray": [2,4,5,1]
3333
},
3434
"yaxis": {
3535
"type": "linear",

test/image/mocks/axes_category_categorylist_truncated_tails.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"title": "categorylist with truncated tails (y, q, k not plotted)",
88
"xaxis": {
99
"type": "category",
10-
"categorymode": "array",
11-
"categorylist": ["y","b","x","a","d","z","e","c", "q", "k"]
10+
"categoryorder": "array",
11+
"categoryarray": ["y","b","x","a","d","z","e","c", "q", "k"]
1212
}}
1313
}

test/image/mocks/axes_category_descending.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"title": "category descending",
2424
"xaxis": {
2525
"type": "category",
26-
"categorymode": "category descending",
27-
"categorylist": [2,4,5,1]
26+
"categoryorder": "category descending",
27+
"categoryarray": [2,4,5,1]
2828
},
2929
"yaxis": {
3030
"type": "linear",

test/image/mocks/axes_category_descending_with_gaps.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"title": "category descending",
2424
"xaxis": {
2525
"type": "category",
26-
"categorymode": "category descending",
27-
"categorylist": [2,4,5,1]
26+
"categoryorder": "category descending",
27+
"categoryarray": [2,4,5,1]
2828
},
2929
"yaxis": {
3030
"type": "linear",

0 commit comments

Comments
 (0)