8
8
9
9
'use strict' ;
10
10
11
+ var isNumeric = require ( 'fast-isnumeric' ) ;
11
12
var Lib = require ( '../../lib' ) ;
12
13
var attributes = require ( './attributes' ) ;
13
14
var handleDomainDefaults = require ( '../../plots/domain' ) . defaults ;
14
15
var Template = require ( '../../plot_api/plot_template' ) ;
15
16
var handleArrayContainerDefaults = require ( '../../plots/array_container_defaults' ) ;
17
+
18
+ var Axes = require ( '../../plots/cartesian/axes' ) ;
19
+ var axesAttrs = require ( '../../plots/cartesian/layout_attributes' ) ;
20
+ var handleAxisDefaults = require ( '../../plots/cartesian/axis_defaults' ) ;
21
+ var handleAxisPositionDefaults = require ( '../../plots/cartesian/position_defaults' ) ;
22
+
16
23
var cn = require ( './constants.js' ) ;
17
24
18
25
var handleTickValueDefaults = require ( '../../plots/cartesian/tick_value_defaults' ) ;
@@ -33,13 +40,21 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
33
40
traceOut . _hasGauge = traceOut . mode . indexOf ( 'gauge' ) !== - 1 ;
34
41
35
42
coerce ( 'value' ) ;
43
+ var dfltRange0 = 0 ;
44
+ var dfltRange1 = 1.5 * traceOut . value ;
45
+ var range = Lib . coerce ( traceIn , traceOut , attributes . gauge . axis , 'range' , [ dfltRange0 , dfltRange1 ] ) ;
46
+ var keepRangeIn ;
47
+ if ( traceIn . gauge && traceIn . gauge . axis && traceIn . gauge . axis . range ) {
48
+ keepRangeIn = [ traceIn . gauge . axis . range [ 0 ] , traceIn . gauge . axis . range [ 1 ] ] ;
49
+ if ( ! isNumeric ( traceIn . gauge . axis . range [ 0 ] ) ) traceIn . gauge . axis . range [ 0 ] = dfltRange0 ;
50
+ if ( ! isNumeric ( traceIn . gauge . axis . range [ 1 ] ) ) traceIn . gauge . axis . range [ 1 ] = dfltRange1 ;
51
+ }
36
52
37
53
// Number attributes
38
54
var auto = new Array ( 2 ) ;
39
55
var bignumberFontSize ;
40
56
if ( traceOut . _hasNumber ) {
41
57
coerce ( 'number.valueformat' ) ;
42
- if ( ! traceOut . number . valueformat ) traceOut . number . valueformat = attributes . number . valueformat . dflt ;
43
58
coerce ( 'number.font.color' , layout . font . color ) ;
44
59
coerce ( 'number.font.family' , layout . font . family ) ;
45
60
coerce ( 'number.font.size' ) ;
@@ -65,7 +80,6 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
65
80
coerce ( 'delta.reference' , traceOut . value ) ;
66
81
coerce ( 'delta.relative' ) ;
67
82
coerce ( 'delta.valueformat' ) ;
68
- if ( ! traceOut . delta . valueformat ) traceOut . delta . valueformat = traceOut . delta . relative ? '2%' : '.3s' ;
69
83
coerce ( 'delta.increasing.symbol' ) ;
70
84
coerce ( 'delta.increasing.color' ) ;
71
85
coerce ( 'delta.decreasing.symbol' ) ;
@@ -82,13 +96,12 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
82
96
coerce ( 'title.text' ) ;
83
97
84
98
// Gauge attributes
85
- var gaugeIn , gaugeOut , axisIn , axisOut ;
99
+ var gaugeIn , gaugeOut ;
100
+
86
101
function coerceGauge ( attr , dflt ) {
87
102
return Lib . coerce ( gaugeIn , gaugeOut , attributes . gauge , attr , dflt ) ;
88
103
}
89
- function coerceGaugeAxis ( attr , dflt ) {
90
- return Lib . coerce ( axisIn , axisOut , attributes . gauge . axis , attr , dflt ) ;
91
- }
104
+
92
105
if ( traceOut . _hasGauge ) {
93
106
gaugeIn = traceIn . gauge ;
94
107
if ( ! gaugeIn ) gaugeIn = { } ;
@@ -126,23 +139,156 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
126
139
coerceGauge ( 'threshold.thickness' ) ;
127
140
coerceGauge ( 'threshold.line.width' ) ;
128
141
coerceGauge ( 'threshold.line.color' ) ;
129
-
130
- // Gauge axis
131
- axisIn = { } ;
132
- if ( gaugeIn ) axisIn = gaugeIn . axis || { } ;
133
- axisOut = Template . newContainer ( gaugeOut , 'axis' ) ;
134
- coerceGaugeAxis ( 'visible' ) ;
135
- coerceGaugeAxis ( 'range' , [ 0 , 1.5 * traceOut . value ] ) ;
136
-
137
- var opts = { outerTicks : true } ;
138
- handleTickValueDefaults ( axisIn , axisOut , coerceGaugeAxis , 'linear' ) ;
139
- handleTickLabelDefaults ( axisIn , axisOut , coerceGaugeAxis , 'linear' , opts ) ;
140
- handleTickMarkDefaults ( axisIn , axisOut , coerceGaugeAxis , opts ) ;
141
142
} else {
142
143
coerce ( 'title.align' , 'center' ) ;
143
144
coerce ( 'align' , 'center' ) ;
144
145
traceOut . _isAngular = traceOut . _isBullet = false ;
145
146
}
147
+
148
+ var axType = 'linear' ;
149
+
150
+ function prepareAxis ( axisOut , axisIn , axisAttr ) {
151
+ var coerceAxis = function ( attr , dflt ) {
152
+ return Lib . coerce ( axisIn , axisOut , axisAttr , attr , dflt ) ;
153
+ } ;
154
+
155
+ axisOut . _id = 'x' ;
156
+ axisOut . type = 'linear' ;
157
+ axisOut . range = range ;
158
+ axisOut . dtick = 0.1 * Math . abs ( range [ 1 ] - range [ 0 ] ) || 1 ;
159
+
160
+ coerceAxis ( 'visible' ) ;
161
+ Axes . setConvert ( axisOut , layout ) ;
162
+ Axes . prepTicks ( axisOut ) ;
163
+
164
+ var tickOptions = {
165
+ outerTicks : true
166
+ } ;
167
+ handleTickLabelDefaults ( axisIn , axisOut , coerceAxis , axType , tickOptions , { pass : 1 } ) ;
168
+ handleTickValueDefaults ( axisIn , axisOut , coerceAxis , axType ) ;
169
+ handleTickLabelDefaults ( axisIn , axisOut , coerceAxis , axType , tickOptions , { pass : 2 } ) ;
170
+ handleTickMarkDefaults ( axisIn , axisOut , coerceAxis , tickOptions ) ;
171
+
172
+ var axisOptions = {
173
+ letter : 'x' ,
174
+ font : layout . font ,
175
+ noHover : true ,
176
+ noTickson : true
177
+ } ;
178
+ handleAxisDefaults ( axisIn , axisOut , coerceAxis , axisOptions , layout ) ;
179
+ handleAxisPositionDefaults ( axisIn , axisOut , coerceAxis , axisOptions ) ;
180
+
181
+ return axisOut ;
182
+ }
183
+
184
+ // Gauge axis
185
+ if ( traceOut . _hasGauge ) {
186
+ var ax = ( traceIn . gauge || { } ) . axis || { } ;
187
+ var e ;
188
+
189
+ // interface for all possible inputs
190
+ var axIn = {
191
+ range : ax . range ,
192
+ visible : ax . visible ,
193
+ tickmode : ax . tickmode ,
194
+ nticks : ax . nticks ,
195
+ tick0 : ax . tick0 ,
196
+ dtick : ax . dtick ,
197
+ tickvals : ax . tickvals ,
198
+ ticktext : ax . ticktext ,
199
+ ticks : ax . ticks ,
200
+ ticklen : ax . ticklen ,
201
+ tickwidth : ax . tickwidth ,
202
+ tickcolor : ax . tickcolor ,
203
+ showticklabels : ax . showticklabels ,
204
+ tickfont : ax . tickfont ,
205
+ tickangle : ax . tickangle ,
206
+ tickformat : ax . tickformat ,
207
+ tickformatstops : ax . tickformatstops ,
208
+ tickprefix : ax . tickprefix ,
209
+ showtickprefix : ax . showtickprefix ,
210
+ ticksuffix : ax . ticksuffix ,
211
+ showticksuffix : ax . showticksuffix ,
212
+ separatethousands : ax . separatethousands ,
213
+ exponentformat : ax . exponentformat ,
214
+ showexponent : ax . showexponent
215
+ } ;
216
+
217
+ // remove undefind keys
218
+ for ( e in axIn ) {
219
+ if ( axIn [ e ] === undefined ) {
220
+ delete axIn [ e ] ;
221
+ }
222
+ }
223
+
224
+ traceOut . gauge . _axis = prepareAxis (
225
+ Template . newContainer ( traceOut . gauge , '_axis' ) ,
226
+ axIn ,
227
+ axesAttrs
228
+ ) ;
229
+
230
+ ax = traceOut . gauge . _axis ;
231
+
232
+ // interface for all possible outputs
233
+ var axOut = traceOut . gauge . axis = {
234
+ range : ax . range ,
235
+ visible : ax . visible ,
236
+ tickmode : ax . tickmode ,
237
+ nticks : ax . nticks ,
238
+ tick0 : ax . tick0 ,
239
+ dtick : ax . dtick ,
240
+ tickvals : ax . tickvals ,
241
+ ticktext : ax . ticktext ,
242
+ ticks : ax . ticks ,
243
+ ticklen : ax . ticklen ,
244
+ tickwidth : ax . tickwidth ,
245
+ tickcolor : ax . tickcolor ,
246
+ showticklabels : ax . showticklabels ,
247
+ tickfont : ax . tickfont ,
248
+ tickangle : ax . tickangle ,
249
+ tickformat : ax . tickformat ,
250
+ tickformatstops : ax . tickformatstops ,
251
+ tickprefix : ax . tickprefix ,
252
+ showtickprefix : ax . showtickprefix ,
253
+ ticksuffix : ax . ticksuffix ,
254
+ showticksuffix : ax . showticksuffix ,
255
+ separatethousands : ax . separatethousands ,
256
+ exponentformat : ax . exponentformat ,
257
+ showexponent : ax . showexponent
258
+ } ;
259
+
260
+ // remove undefind keys
261
+ for ( e in axOut ) {
262
+ if ( axOut [ e ] === undefined ) {
263
+ delete axOut [ e ] ;
264
+ }
265
+ }
266
+ }
267
+
268
+ // Number axis
269
+ if ( traceOut . _hasNumber ) {
270
+ traceOut . number . _axis = prepareAxis (
271
+ Template . newContainer ( traceOut . number , '_axis' ) ,
272
+ {
273
+ tickformat : traceOut . number . valueformat
274
+ } ,
275
+ axesAttrs
276
+ ) ;
277
+ }
278
+
279
+ // Delta axis
280
+ if ( traceOut . _hasDelta && traceOut . delta ) {
281
+ traceOut . delta . _axis = prepareAxis (
282
+ Template . newContainer ( traceOut . delta , '_axis' ) ,
283
+ {
284
+ tickformat : traceOut . delta . valueformat
285
+ } ,
286
+ axesAttrs
287
+ ) ;
288
+ }
289
+
290
+ delete traceOut . range ;
291
+ if ( keepRangeIn ) traceIn . gauge . axis . range = keepRangeIn ;
146
292
}
147
293
148
294
function stepDefaults ( stepIn , stepOut ) {
0 commit comments