forked from plotly/plotly.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattributes.js
375 lines (368 loc) · 12.1 KB
/
attributes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
'use strict';
var extendFlat = require('../../lib/extend').extendFlat;
var extendDeep = require('../../lib/extend').extendDeep;
var overrideAll = require('../../plot_api/edit_types').overrideAll;
var fontAttrs = require('../../plots/font_attributes');
var colorAttrs = require('../../components/color/attributes');
var domainAttrs = require('../../plots/domain').attributes;
var axesAttrs = require('../../plots/cartesian/layout_attributes');
var templatedArray = require('../../plot_api/plot_template').templatedArray;
var delta = require('../../constants/delta.js');
var descriptionOnlyNumbers = require('../../plots/cartesian/axis_format_attributes').descriptionOnlyNumbers;
var textFontAttrs = fontAttrs({
editType: 'plot',
colorEditType: 'plot'
});
var gaugeBarAttrs = {
color: {
valType: 'color',
editType: 'plot',
description: [
'Sets the background color of the arc.'
].join(' ')
},
line: {
color: {
valType: 'color',
dflt: colorAttrs.defaultLine,
editType: 'plot',
description: [
'Sets the color of the line enclosing each sector.'
].join(' ')
},
width: {
valType: 'number',
min: 0,
dflt: 0,
editType: 'plot',
description: [
'Sets the width (in px) of the line enclosing each sector.'
].join(' ')
},
editType: 'calc'
},
thickness: {
valType: 'number',
min: 0,
max: 1,
dflt: 1,
editType: 'plot',
description: [
'Sets the thickness of the bar as a fraction of the total thickness of the gauge.'
].join(' ')
},
editType: 'calc'
};
var rangeAttr = {
valType: 'info_array',
items: [
{valType: 'number', editType: 'plot'},
{valType: 'number', editType: 'plot'}
],
editType: 'plot',
description: [
'Sets the range of this axis.'
// TODO: add support for other axis type
// 'If the axis `type` is *log*, then you must take the log of your',
// 'desired range (e.g. to set the range from 1 to 100,',
// 'set the range from 0 to 2).',
// 'If the axis `type` is *date*, it should be date strings,',
// 'like date data, though Date objects and unix milliseconds',
// 'will be accepted and converted to strings.',
// 'If the axis `type` is *category*, it should be numbers,',
// 'using the scale where each category is assigned a serial',
// 'number from zero in the order it appears.'
].join(' ')
};
var stepsAttrs = templatedArray('step', extendDeep({}, gaugeBarAttrs, {
range: rangeAttr
}));
module.exports = {
mode: {
valType: 'flaglist',
editType: 'calc',
flags: ['number', 'delta', 'gauge'],
dflt: 'number',
description: [
'Determines how the value is displayed on the graph.',
'`number` displays the value numerically in text.',
'`delta` displays the difference to a reference value in text.',
'Finally, `gauge` displays the value graphically on an axis.',
].join(' ')
},
value: {
valType: 'number',
editType: 'calc',
anim: true,
description: [
'Sets the number to be displayed.'
].join(' ')
},
align: {
valType: 'enumerated',
values: ['left', 'center', 'right'],
editType: 'plot',
description: [
'Sets the horizontal alignment of the `text` within the box.',
'Note that this attribute has no effect if an angular gauge is displayed:',
'in this case, it is always centered'
].join(' ')
},
// position
domain: domainAttrs({name: 'indicator', trace: true, editType: 'calc'}),
title: {
text: {
valType: 'string',
editType: 'plot',
description: [
'Sets the title of this indicator.'
].join(' ')
},
align: {
valType: 'enumerated',
values: ['left', 'center', 'right'],
editType: 'plot',
description: [
'Sets the horizontal alignment of the title.',
'It defaults to `center` except for bullet charts',
'for which it defaults to right.'
].join(' ')
},
font: extendFlat({}, textFontAttrs, {
description: [
'Set the font used to display the title'
].join(' ')
}),
editType: 'plot'
},
number: {
valueformat: {
valType: 'string',
dflt: '',
editType: 'plot',
description: descriptionOnlyNumbers('value')
},
font: extendFlat({}, textFontAttrs, {
description: [
'Set the font used to display main number'
].join(' ')
}),
prefix: {
valType: 'string',
dflt: '',
editType: 'plot',
description: [
'Sets a prefix appearing before the number.'
].join(' ')
},
suffix: {
valType: 'string',
dflt: '',
editType: 'plot',
description: [
'Sets a suffix appearing next to the number.'
].join(' ')
},
editType: 'plot'
},
delta: {
reference: {
valType: 'number',
editType: 'calc',
description: [
'Sets the reference value to compute the delta.',
'By default, it is set to the current value.'
].join(' ')
},
position: {
valType: 'enumerated',
values: ['top', 'bottom', 'left', 'right'],
dflt: 'bottom',
editType: 'plot',
description: [
'Sets the position of delta with respect to the number.'
].join(' ')
},
relative: {
valType: 'boolean',
editType: 'plot',
dflt: false,
description: [
'Show relative change'
].join(' ')
},
valueformat: {
valType: 'string',
editType: 'plot',
description: descriptionOnlyNumbers('value')
},
increasing: {
symbol: {
valType: 'string',
dflt: delta.INCREASING.SYMBOL,
editType: 'plot',
description: [
'Sets the symbol to display for increasing value'
].join(' ')
},
color: {
valType: 'color',
dflt: delta.INCREASING.COLOR,
editType: 'plot',
description: [
'Sets the color for increasing value.'
].join(' ')
},
// TODO: add attribute to show sign
editType: 'plot'
},
decreasing: {
symbol: {
valType: 'string',
dflt: delta.DECREASING.SYMBOL,
editType: 'plot',
description: [
'Sets the symbol to display for increasing value'
].join(' ')
},
color: {
valType: 'color',
dflt: delta.DECREASING.COLOR,
editType: 'plot',
description: [
'Sets the color for increasing value.'
].join(' ')
},
// TODO: add attribute to hide sign
editType: 'plot'
},
font: extendFlat({}, textFontAttrs, {
description: [
'Set the font used to display the delta'
].join(' ')
}),
prefix: {
valType: 'string',
dflt: '',
editType: 'plot',
description: [
'Sets a prefix appearing before the delta.'
].join(' ')
},
suffix: {
valType: 'string',
dflt: '',
editType: 'plot',
description: [
'Sets a suffix appearing next to the delta.'
].join(' ')
},
editType: 'calc'
},
gauge: {
shape: {
valType: 'enumerated',
editType: 'plot',
dflt: 'angular',
values: ['angular', 'bullet'],
description: [
'Set the shape of the gauge'
].join(' ')
},
bar: extendDeep({}, gaugeBarAttrs, {
color: {dflt: 'green'},
description: [
'Set the appearance of the gauge\'s value'
].join(' ')
}),
// Background of the gauge
bgcolor: {
valType: 'color',
editType: 'plot',
description: 'Sets the gauge background color.'
},
bordercolor: {
valType: 'color',
dflt: colorAttrs.defaultLine,
editType: 'plot',
description: 'Sets the color of the border enclosing the gauge.'
},
borderwidth: {
valType: 'number',
min: 0,
dflt: 1,
editType: 'plot',
description: 'Sets the width (in px) of the border enclosing the gauge.'
},
axis: overrideAll({
range: rangeAttr,
visible: extendFlat({}, axesAttrs.visible, {
dflt: true
}),
// tick and title properties named and function exactly as in axes
tickmode: axesAttrs.minor.tickmode,
nticks: axesAttrs.nticks,
tick0: axesAttrs.tick0,
dtick: axesAttrs.dtick,
tickvals: axesAttrs.tickvals,
ticktext: axesAttrs.ticktext,
ticks: extendFlat({}, axesAttrs.ticks, {dflt: 'outside'}),
ticklen: axesAttrs.ticklen,
tickwidth: axesAttrs.tickwidth,
tickcolor: axesAttrs.tickcolor,
ticklabelstep: axesAttrs.ticklabelstep,
showticklabels: axesAttrs.showticklabels,
tickfont: fontAttrs({
description: 'Sets the color bar\'s tick label font'
}),
tickangle: axesAttrs.tickangle,
tickformat: axesAttrs.tickformat,
tickformatstops: axesAttrs.tickformatstops,
tickprefix: axesAttrs.tickprefix,
showtickprefix: axesAttrs.showtickprefix,
ticksuffix: axesAttrs.ticksuffix,
showticksuffix: axesAttrs.showticksuffix,
separatethousands: axesAttrs.separatethousands,
exponentformat: axesAttrs.exponentformat,
minexponent: axesAttrs.minexponent,
showexponent: axesAttrs.showexponent,
editType: 'plot'
}, 'plot'),
// Steps (or ranges) and thresholds
steps: stepsAttrs,
threshold: {
line: {
color: extendFlat({}, gaugeBarAttrs.line.color, {
description: [
'Sets the color of the threshold line.'
].join(' ')
}),
width: extendFlat({}, gaugeBarAttrs.line.width, {
dflt: 1,
description: [
'Sets the width (in px) of the threshold line.'
].join(' ')
}),
editType: 'plot'
},
thickness: extendFlat({}, gaugeBarAttrs.thickness, {
dflt: 0.85,
description: [
'Sets the thickness of the threshold line as a fraction of the thickness of the gauge.'
].join(' ')
}),
value: {
valType: 'number',
editType: 'calc',
dflt: false,
description: [
'Sets a treshold value drawn as a line.'
].join(' ')
},
editType: 'plot'
},
description: 'The gauge of the Indicator plot.',
editType: 'plot'
// TODO: in future version, add marker: (bar|needle)
}
};