8000 refactor - centralize axis format descriptions · plotly/plotly.js@efcbfaa · GitHub
[go: up one dir, main page]

Skip to content

Commit efcbfaa

Browse files
committed
refactor - centralize axis format descriptions
1 parent e2508bc commit efcbfaa

File tree

28 files changed

+86
-122
lines changed

28 files changed

+86
-122
lines changed

src/plots/cartesian/axis_format.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
3+
var docs = require('../../constants/docs');
4+
var FORMAT_LINK = docs.FORMAT_LINK;
5+
var DATE_FORMAT_LINK = docs.DATE_FORMAT_LINK;
6+
7+
function axisHoverFormat(x, noDates) {
8+
return {
9+
valType: 'string',
10+
dflt: '',
11+
editType: 'none',
12+
description: [
13+
'Sets the hover text formatting rule for `' + x + '`',
14+
' using d3 formatting mini-languages which are very similar to those in Python.',
15+
'See: ' + FORMAT_LINK + (
16+
noDates ?
17+
'' :
18+
' And for dates see: ' + DATE_FORMAT_LINK
19+
),
20+
'By default the values are formatted using ' + (
21+
noDates ?
22+
'generic number format' :
23+
('`' + x + 'axis.hoverformat`')
24+
) + '.',
25+
].join(' ')
26+
};
27+
}
28+
29+
function descriptionOnlyNumbers(label) {
30+
return [
31+
'Sets the ' + label + ' formatting rule using d3 formatting mini-languages',
32+
'which are very similar to those in Python. For numbers, see: ' + FORMAT_LINK
33+
].join(' ');
34+
}
35+
36+
function descriptionWithDates(label) {
37+
return descriptionOnlyNumbers(label) + [
38+
' And for dates see: ' + DATE_FORMAT_LINK,
39+
'We add one item to d3\'s date formatter: *%{n}f* for fractional seconds',
40+
'with n digits. For example, *2016-10-13 09:15:23.456* with tickformat',
41+
'*%H~%M~%S.%2f* would display *09~15~23.46*'
42+
].join(' ');
43+
}
44+
45+
module.exports = {
46+
axisHoverFormat: axisHoverFormat,
47+
descriptionOnlyNumbers: descriptionOnlyNumbers,
48+
descriptionWithDates: descriptionWithDates
49+
};

src/plots/cartesian/layout_attributes.js

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ var colorAttrs = require('../../components/color/attributes');
55
var dash = require('../../components/drawing/attributes').dash;
66
var extendFlat = require('../../lib/extend').extendFlat;
77
var templatedArray = require('../../plot_api/plot_template').templatedArray;
8-
9-
var docs = require('../../constants/docs');
10-
var FORMAT_LINK = docs.FORMAT_LINK;
11-
var DATE_FORMAT_LINK = docs.DATE_FORMAT_LINK;
8+
var descriptionWithDates = require('../../plots/cartesian/axis_format').descriptionWithDates;
129

1310
var ONEDAY = require('../../constants/numerical').ONEDAY;
1411
var constants = require('./constants');
@@ -702,16 +699,7 @@ module.exports = {
702699
valType: 'string',
703700
dflt: '',
704701
editType: 'ticks',
705-
description: [
706-
'Sets the tick label formatting rule using d3 formatting mini-languages',
707-
'which are very similar to those in Python. For numbers, see:',
708-
FORMAT_LINK,
709-
'And for dates see:',
710-
DATE_FORMAT_LINK,
711-
'We add one item to d3\'s date formatter: *%{n}f* for fractional seconds',
712-
'with n digits. For example, *2016-10-13 09:15:23.456* with tickformat',
713-
'*%H~%M~%S.%2f* would display *09~15~23.46*'
714-
].join(' ')
702+
description: descriptionWithDates('tick label')
715703
},
716704
tickformatstops: templatedArray('tickformatstop', {
717705
enabled: {
@@ -750,16 +738,7 @@ module.exports = {
750738
valType: 'string',
751739
dflt: '',
752740
editType: 'none',
753-
description: [
754-
'Sets the hover text formatting rule using d3 formatting mini-languages',
755-
'which are very similar to those in Python. For numbers, see:',
756-
FORMAT_LINK,
757-
'And for dates see:',
758-
DATE_FORMAT_LINK,
759-
'We add one item to d3\'s date formatter: *%{n}f* for fractional seconds',
760-
'with n digits. For example, *2016-10-13 09:15:23.456* with tickformat',
761-
'*%H~%M~%S.%2f* would display *09~15~23.46*'
762-
].join(' ')
741+
description: descriptionWithDates('hover text')
763742
},
764743
// lines and grids
765744
showline: {

src/plots/hoverformat_attributes.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/traces/bar/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
var scatterAttrs = require('../scatter/attributes');
4-
var axisHoverFormat = require('../../plots/hoverformat_attributes');
4+
var axisHoverFormat = require('../../plots/cartesian/axis_format').axisHoverFormat;
55
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
66
var texttemplateAttrs = require('../../plots/template_attributes').texttemplateAttrs;
77
var colorScaleAttrs = require('../../components/colorscale/attributes');

src/traces/box/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var scatterAttrs = require('../scatter/attributes');
44
var barAttrs = require('../bar/attributes');
55
var colorAttrs = require('../../components/color/attributes');
6-
var axisHoverFormat = require('../../plots/hoverformat_attributes');
6+
var axisHoverFormat = require('../../plots/cartesian/axis_format').axisHoverFormat;
77
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
88
var extendFlat = require('../../lib/extend').extendFlat;
99

src/traces/candlestick/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
var extendFlat = require('../../lib').extendFlat;
4-
var axisHoverFormat = require('../../plots/hoverformat_attributes');
4+
var axisHoverFormat = require('../../plots/cartesian/axis_format').axisHoverFormat;
55
var OHLCattrs = require('../ohlc/attributes');
66
var boxAttrs = require('../box/attributes');
77

src/traces/carpet/axis_attributes.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
var fontAttrs = require('../../plots/font_attributes');
44
var colorAttrs = require('../../components/color/attributes');
55
var axesAttrs = require('../../plots/cartesian/layout_attributes');
6+
var descriptionWithDates = require('../../plots/cartesian/axis_format').descriptionWithDates;
67
var overrideAll = require('../../plot_api/edit_types').overrideAll;
78

8-
var docs = require('../../constants/docs');
9-
var FORMAT_LINK = docs.FORMAT_LINK;
10-
var DATE_FORMAT_LINK = docs.DATE_FORMAT_LINK;
11-
129
module.exports = {
1310
color: {
1411
valType: 'color',
@@ -279,16 +276,7 @@ module.exports = {
279276
valType: 'string',
280277
dflt: '',
281278
editType: 'calc',
282-
description: [
283-
'Sets the tick label formatting rule using d3 formatting mini-languages',
284-
'which are very similar to those in Python. For numbers, see:',
285-
FORMAT_LINK,
286-
'And for dates see:',
287-
DATE_FORMAT_LINK,
288-
'We add one item to d3\'s date formatter: *%{n}f* for fractional seconds',
289-
'with n digits. For example, *2016-10-13 09:15:23.456* with tickformat',
290-
'*%H~%M~%S.%2f* would display *09~15~23.46*'
291-
].join(' ')
279+
description: descriptionWithDates('tick label')
292280
},
293281
tickformatstops: overrideAll(axesAttrs.tickformatstops, 'calc', 'from-root'),
294282
categoryorder: {

src/traces/cone/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
var colorScaleAttrs = require('../../components/colorscale/attributes');
4-
var axisHoverFormat = require('../../plots/hoverformat_attributes');
4+
var axisHoverFormat = require('../../plots/cartesian/axis_format').axisHoverFormat;
55
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
66
var mesh3dAttrs = require('../mesh3d/attributes');
77
var baseAttrs = require('../../plots/attributes');

src/traces/contour/attributes.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
var heatmapAttrs = require('../heatmap/attributes');
44
var scatterAttrs = require('../scatter/attributes');
5-
var axisHoverFormat = require('../../plots/hoverformat_attributes');
5+
var axisFormat = require('../../plots/cartesian/axis_format');
6+
var axisHoverFormat = axisFormat.axisHoverFormat;
7+
var descriptionOnlyNumbers = axisFormat.descriptionOnlyNumbers;
68
var colorScaleAttrs = require('../../components/colorscale/attributes');
79
var dash = require('../../components/drawing/attributes').dash;
810
var fontAttrs = require('../../plots/font_attributes');
@@ -12,7 +14,6 @@ var filterOps = require('../../constants/filter_ops');
1214
var COMPARISON_OPS2 = filterOps.COMPARISON_OPS2;
1315
var INTERVAL_OPS = filterOps.INTERVAL_OPS;
1416

15-
var FORMAT_LINK = require('../../constants/docs').FORMAT_LINK;
1617

1718
var scatterLineAttrs = scatterAttrs.line;
1819

@@ -181,11 +182,7 @@ module.exports = extendFlat({
181182
valType: 'string',
182183
dflt: '',
183184
editType: 'plot',
184-
description: [
185-
'Sets the contour label formatting rule using d3 formatting',
186-
'mini-language which is very similar to Python, see:',
187-
FORMAT_LINK
188-
].join(' ')
185+
description: descriptionOnlyNumbers('contour label')
189186
},
190187
operation: {
191188
valType: 'enumerated',

src/traces/funnel/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var barAttrs = require('../bar/attributes');
44
var lineAttrs = require('../scatter/attributes').line;
55
var baseAttrs = require('../../plots/attributes');
6-
var axisHoverFormat = require('../../plots/hoverformat_attributes');
6+
var axisHoverFormat = require('../../plots/cartesian/axis_format').axisHoverFormat;
77
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
88
var texttemplateAttrs = require('../../plots/template_attributes').texttemplateAttrs;
99
var constants = require('./constants');

src/traces/heatmap/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var scatterAttrs = require('../scatter/attributes');
44
var baseAttrs = require('../../plots/attributes');
5-
var axisHoverFormat = require('../../plots/hoverformat_attributes');
5+
var axisHoverFormat = require('../../plots/cartesian/axis_format').axisHoverFormat;
66
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
77
var colorScaleAttrs = require('../../components/colorscale/attributes');
88

src/traces/histogram/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
var barAttrs = require('../bar/attributes');
4-
var axisHoverFormat = require('../../plots/hoverformat_attributes');
4+
var axisHoverFormat = require('../../plots/cartesian/axis_format').axisHoverFormat;
55
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
66
var makeBinAttrs = require('./bin_attributes');
77
var constants = require('./constants');

src/traces/histogram2d/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var histogramAttrs = require('../histogram/attributes');
44
var makeBinAttrs = require('../histogram/bin_attributes');
55
var heatmapAttrs = require('../heatmap/attributes');
66
var baseAttrs = require('../../plots/attributes');
7-
var axisHoverFormat = require('../../plots/hoverformat_attributes');
7+
var axisHoverFormat = require('../../plots/cartesian/axis_format').axisHoverFormat;
88
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
99
var colorScaleAttrs = require('../../components/colorscale/attributes');
1010

src/traces/histogram2dcontour/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var histogram2dAttrs = require('../histogram2d/attributes');
44
var contourAttrs = require('../contour/attributes');
55
var colorScaleAttrs = require('../../components/colorscale/attributes');
6-
var axisHoverFormat = require('../../plots/hoverformat_attributes');
6+
var axisHoverFormat = require('../../plots/cartesian/axis_format').axisHoverFormat;
77

88
var extendFlat = require('../../lib/extend').extendFlat;
99

src/traces/indicator/attributes.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var domainAttrs = require('../../plots/domain').attributes;
99
var axesAttrs = require('../../plots/cartesian/layout_attributes');
1010
var templatedArray = require('../../plot_api/plot_template').templatedArray;
1111
var delta = require('../../constants/delta.js');
12-
var FORMAT_LINK = require('../../constants/docs').FORMAT_LINK;
12+
var descriptionOnlyNumbers = require('../../plots/cartesian/axis_format').descriptionOnlyNumbers;
1313

1414
var textFontAttrs = fontAttrs({
1515
editType: 'plot',
@@ -147,11 +147,7 @@ module.exports = {
147147
valType: 'string',
148148
dflt: '',
149149
editType: 'plot',
150-
description: [
151-
'Sets the value formatting rule using d3 formatting mini-language',
152-
'which is similar to those of Python. See',
153-
FORMAT_LINK
154-
].join(' ')
150+
description: descriptionOnlyNumbers('value')
155151
},
156152
font: extendFlat({}, textFontAttrs, {
157153
description: [
@@ -205,11 +201,7 @@ module.exports = {
205201
valueformat: {
206202
valType: 'string',
207203
editType: 'plot',
208-
description: [
209-
'Sets the value formatting rule using d3 formatting mini-language',
210-
'which is similar to those of Python. See',
211-
FORMAT_LINK
212-
].join(' ')
204+
description: descriptionOnlyNumbers('value')
213205
},
214206
increasing: {
215207
symbol: {

src/traces/isosurface/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
var colorScaleAttrs = require('../../components/colorscale/attributes');
4-
var axisHoverFormat = require('../../plots/hoverformat_attributes');
4+
var axisHoverFormat = require('../../plots/cartesian/axis_format').axisHoverFormat;
55
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
66
var meshAttrs = require('../mesh3d/attributes');
77
var baseAttrs = require('../../plots/attributes');

src/traces/mesh3d/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
var colorScaleAttrs = require('../../components/colorscale/attributes');
4-
var axisHoverFormat = require('../../plots/hoverformat_attributes');
4+
var axisHoverFormat = require('../../plots/cartesian/axis_format').axisHoverFormat;
55
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
66
var surfaceAttrs = require('../surface/attributes');
77
var baseAttrs = require('../../plots/attributes');

src/traces/ohlc/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var extendFlat = require('../../lib').extendFlat;
44
var scatterAttrs = require('../scatter/attributes');
5-
var axisHoverFormat = require('../../plots/hoverformat_attributes');
5+
var axisHoverFormat = require('../../plots/cartesian/axis_format').axisHoverFormat;
66
var dash = require('../../components/drawing/attributes').dash;
77
var fxAttrs = require('../../components/fx/attributes');
88
var delta = require('../../constants/delta.js');

src/traces/sankey/attributes.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ var domainAttrs = require('../../plots/domain').attributes;
88
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
99
var colorAttributes = require('../../components/colorscale/attributes');
1010
var templatedArray = require('../../plot_api/plot_template').templatedArray;
11+
var descriptionOnlyNumbers = require('../../plots/cartesian/axis_format').descriptionOnlyNumbers;
1112

1213
var extendFlat = require('../../lib/extend').extendFlat;
1314
var overrideAll = require('../../plot_api/edit_types').overrideAll;
1415

15-
var FORMAT_LINK = require('../../constants/docs').FORMAT_LINK;
16-
1716
var attrs = module.exports = overrideAll({
1817
hoverinfo: extendFlat({}, baseAttrs.hoverinfo, {
1918
flags: [],
@@ -39,11 +38,7 @@ var attrs = module.exports = overrideAll({
3938
valueformat: {
4039
valType: 'string',
4140
dflt: '.3s',
42-
description: [
43-
'Sets the value formatting rule using d3 formatting mini-language',
44-
'which is similar to those of Python. See',
45-
FORMAT_LINK
46-
].join(' ')
41+
description: descriptionOnlyNumbers('value')
4742
},
4843

4944
valuesuffix: {

src/traces/scatter/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
var axisHoverFormat = require('../../plots/hoverformat_attributes');
3+
var axisHoverFormat = require('../../plots/cartesian/axis_format').axisHoverFormat;
44
var texttemplateAttrs = require('../../plots/template_attributes').texttemplateAttrs;
55
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
66
var colorScaleAttrs = require('../../components/colorscale/attributes');

src/traces/scatter3d/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var scatterAttrs = require('../scatter/attributes');
44
var colorAttributes = require('../../components/colorscale/attributes');
5-
var axisHoverFormat = require('../../plots/hoverformat_attributes');
5+
var axisHoverFormat = require('../../plots/cartesian/axis_format').axisHoverFormat;
66
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
77
var texttemplateAttrs = require('../../plots/template_attributes').texttemplateAttrs;
88
var baseAttrs = require('../../plots/attributes');

src/traces/scattergl/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var baseAttrs = require('../../plots/attributes');
44
var scatterAttrs = require('../scatter/attributes');
5-
var axisHoverFormat = require('../../plots/hoverformat_attributes');
5+
var axisHoverFormat = require('../../plots/cartesian/axis_format').axisHoverFormat;
66
var colorScaleAttrs = require('../../components/colorscale/attributes');
77

88
var extendFlat = require('../../lib/extend').extendFlat;

src/traces/splom/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var scatterAttrs = require('../scatter/attributes');
44
var colorScaleAttrs = require('../../components/colorscale/attributes');
5-
var axisHoverFormat = require('../../plots/hoverformat_attributes');
5+
var axisHoverFormat = require('../../plots/cartesian/axis_format').axisHoverFormat;
66
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs;
77
var scatterGlAttrs = require('../scattergl/attributes');
88
var cartesianIdRegex = require('../../plots/cartesian/constants').idRegex;

0 commit comments

Comments
 (0)
0