Skip to content

Commit 6bc7e13

Browse files
committed
add minor tick and grid options to cartesian subplot
1 parent 12a49c0 commit 6bc7e13

File tree

2 files changed

+400
-131
lines changed

2 files changed

+400
-131
lines changed

src/plots/cartesian/layout_attributes.js

+180-131
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,152 @@ var constants = require('./constants');
1212
var HOUR = constants.HOUR_PATTERN;
1313
var DAY_OF_WEEK = constants.WEEKDAY_PATTERN;
1414

15+
var tickmode = {
16+
valType: 'enumerated',
17+
values: ['auto', 'linear', 'array'],
18+
editType: 'ticks',
19+
impliedEdits: {tick0: undefined, dtick: undefined},
20+
description: [
21+
'Sets the tick mode for this axis.',
22+
'If *auto*, the number of ticks is set via `nticks`.',
23+
'If *linear*, the placement of the ticks is determined by',
24+
'a starting position `tick0` and a tick step `dtick`',
25+
'(*linear* is the default value if `tick0` and `dtick` are provided).',
26+
'If *array*, the placement of the ticks is set via `tickvals`',
27+
'and the tick text is `ticktext`.',
28+
'(*array* is the default value if `tickvals` is provided).'
29+
].join(' ')
30+
};
31+
32+
var nticks = {
33+
valType: 'integer',
34+
min: 0,
35+
dflt: 0,
36+
editType: 'ticks',
37+
description: [
38+
'Specifies the maximum number of ticks for the particular axis.',
39+
'The actual number of ticks will be chosen automatically to be',
40+
'less than or equal to `nticks`.',
41+
'Has an effect only if `tickmode` is set to *auto*.'
42+
].join(' ')
43+
};
44+
45+
var tick0 = {
46+
valType: 'any',
47+
editType: 'ticks',
48+
impliedEdits: {tickmode: 'linear'},
49+
description: [
50+
'Sets the placement of the first tick on this axis.',
51+
'Use with `dtick`.',
52+
'If the axis `type` is *log*, then you must take the log of your starting tick',
53+
'(e.g. to set the starting tick to 100, set the `tick0` to 2)',
54+
'except when `dtick`=*L<f>* (see `dtick` for more info).',
55+
'If the axis `type` is *date*, it should be a date string, like date data.',
56+
'If the axis `type` is *category*, it should be a number, using the scale where',
57+
'each category is assigned a serial number from zero in the order it appears.'
58+
].join(' ')
59+
};
60+
61+
var dtick = {
62+
valType: 'any',
63+
editType: 'ticks',
64+
impliedEdits: {tickmode: 'linear'},
65+
description: [
66+
'Sets the step in-between ticks on this axis. Use with `tick0`.',
67+
'Must be a positive number, or special strings available to *log* and *date* axes.',
68+
'If the axis `type` is *log*, then ticks are set every 10^(n*dtick) where n',
69+
'is the tick number. For example,',
70+
'to set a tick mark at 1, 10, 100, 1000, ... set dtick to 1.',
71+
'To set tick marks at 1, 100, 10000, ... set dtick to 2.',
72+
'To set tick marks at 1, 5, 25, 125, 625, 3125, ... set dtick to log_10(5), or 0.69897000433.',
73+
'*log* has several special values; *L<f>*, where `f` is a positive number,',
74+
'gives ticks linearly spaced in value (but not position).',
75+
'For example `tick0` = 0.1, `dtick` = *L0.5* will put ticks at 0.1, 0.6, 1.1, 1.6 etc.',
76+
'To show powers of 10 plus small digits between, use *D1* (all digits) or *D2* (only 2 and 5).',
77+
'`tick0` is ignored for *D1* and *D2*.',
78+
'If the axis `type` is *date*, then you must convert the time to milliseconds.',
79+
'For example, to set the interval between ticks to one day,',
80+
'set `dtick` to 86400000.0.',
81+
'*date* also has special values *M<n>* gives ticks spaced by a number of months.',
82+
'`n` must be a positive integer.',
83+
'To set ticks on the 15th of every third month, set `tick0` to *2000-01-15* and `dtick` to *M3*.',
84+
'To set ticks every 4 years, set `dtick` to *M48*'
85+
].join(' ')
86+
};
87+
88+
var tickvals = {
89+
valType: 'data_array',
90+
editType: 'ticks',
91+
description: [
92+
'Sets the values at which ticks on this axis appear.',
93+
'Only has an effect if `tickmode` is set to *array*.',
94+
'Used with `ticktext`.'
95+
].join(' ')
96+
};
97+
98+
var ticks = {
99+
valType: 'enumerated',
100+
values: ['outside', 'inside', ''],
101+
editType: 'ticks',
102+
description: [
103+
'Determines whether ticks are drawn or not.',
104+
'If **, this axis\' ticks are not drawn.',
105+
'If *outside* (*inside*), this axis\' are drawn outside (inside)',
106+
'the axis lines.'
107+
].join(' ')
108+
};
109+
110+
function makeTicklen(minor) {
111+
return {
112+
valType: 'number',
113+
min: 0,
114+
dflt: minor ? 3 : 5,
115+
editType: 'ticks',
116+
description: 'Sets the tick length (in px).'
117+
};
118+
}
119+
120+
var tickwidth = {
121+
valType: 'number',
122+
min: 0,
123+
dflt: 1,
124+
editType: 'ticks',
125+
description: 'Sets the tick width (in px).'
126+
};
127+
128+
var tickcolor = {
129+
valType: 'color',
130+
dflt: colorAttrs.defaultLine,
131+
editType: 'ticks',
132+
description: 'Sets the tick color.'
133+
};
134+
135+
var gridcolor = {
136+
valType: 'color',
137+
dflt: colorAttrs.lightLine,
138+
editType: 'ticks',
139+
description: 'Sets the color of the grid lines.'
140+
};
141+
142+
var gridwidth = {
143+
valType: 'number',
144+
min: 0,
145+
dflt: 1,
146+
editType: 'ticks',
147+
description: 'Sets the width (in px) of the grid lines.'
148+
};
149+
150+
var griddash = extendFlat({}, dash, {editType: 'ticks'});
151+
152+
var showgrid = {
153+
valType: 'boolean',
154+
editType: 'ticks',
155+
description: [
156+
'Determines whether or not grid lines are drawn.',
157+
'If *true*, the grid lines are drawn at every tick mark.'
158+
].join(' ')
159+
};
160+
15161
module.exports = {
16162
visible: {
17163
valType: 'boolean',
@@ -343,75 +489,10 @@ module.exports = {
343489
}),
344490

345491
// ticks
346-
tickmode: {
347-
valType: 'enumerated',
348-
values: ['auto', 'linear', 'array'],
349-
editType: 'ticks',
350-
impliedEdits: {tick0: undefined, dtick: undefined},
351-
description: [
352-
'Sets the tick mode for this axis.',
353-
'If *auto*, the number of ticks is set via `nticks`.',
354-
'If *linear*, the placement of the ticks is determined by',
355-
'a starting position `tick0` and a tick step `dtick`',
356-
'(*linear* is the default value if `tick0` and `dtick` are provided).',
357-
'If *array*, the placement of the ticks is set via `tickvals`',
358-
'and the tick text is `ticktext`.',
359-
'(*array* is the default value if `tickvals` is provided).'
360-
].join(' ')
361-
},
362-
nticks: {
363-
valType: 'integer',
364-
min: 0,
365-
dflt: 0,
366-
editType: 'ticks',
367-
description: [
368-
'Specifies the maximum number of ticks for the particular axis.',
369-
'The actual number of ticks will be chosen automatically to be',
370-
'less than or equal to `nticks`.',
371-
'Has an effect only if `tickmode` is set to *auto*.'
372-
].join(' ')
373-
},
374-
tick0: {
375-
valType: 'any',
376-
editType: 'ticks',
377-
impliedEdits: {tickmode: 'linear'},
378-
description: [
379-
'Sets the placement of the first tick on this axis.',
380-
'Use with `dtick`.',
381-
'If the axis `type` is *log*, then you must take the log of your starting tick',
382-
'(e.g. to set the starting tick to 100, set the `tick0` to 2)',
383-
'except when `dtick`=*L<f>* (see `dtick` for more info).',
384-
'If the axis `type` is *date*, it should be a date string, like date data.',
385-
'If the axis `type` is *category*, it should be a number, using the scale where',
386-
'each category is assigned a serial number from zero in the order it appears.'
387-
].join(' ')
388-
},
389-
dtick: {
390-
valType: 'any',
391-
editType: 'ticks',
392-
impliedEdits: {tickmode: 'linear'},
393-
description: [
394-
'Sets the step in-between ticks on this axis. Use with `tick0`.',
395-
'Must be a positive number, or special strings available to *log* and *date* axes.',
396-
'If the axis `type` is *log*, then ticks are set every 10^(n*dtick) where n',
397-
'is the tick number. For example,',
398-
'to set a tick mark at 1, 10, 100, 1000, ... set dtick to 1.',
399-
'To set tick marks at 1, 100, 10000, ... set dtick to 2.',
400-
'To set tick marks at 1, 5, 25, 125, 625, 3125, ... set dtick to log_10(5), or 0.69897000433.',
401-
'*log* has several special values; *L<f>*, where `f` is a positive number,',
402-
'gives ticks linearly spaced in value (but not position).',
403-
'For example `tick0` = 0.1, `dtick` = *L0.5* will put ticks at 0.1, 0.6, 1.1, 1.6 etc.',
404-
'To show powers of 10 plus small digits between, use *D1* (all digits) or *D2* (only 2 and 5).',
405-
'`tick0` is ignored for *D1* and *D2*.',
406-
'If the axis `type` is *date*, then you must convert the time to milliseconds.',
407-
'For example, to set the interval between ticks to one day,',
408-
'set `dtick` to 86400000.0.',
409-
'*date* also has special values *M<n>* gives ticks spaced by a number of months.',
410-
'`n` must be a positive integer.',
411-
'To set ticks on the 15th of every third month, set `tick0` to *2000-01-15* and `dtick` to *M3*.',
412-
'To set ticks every 4 years, set `dtick` to *M48*'
413-
].join(' ')
414-
},
492+
tickmode: tickmode,
493+
nticks: nticks,
494+
tick0: tick0,
495+
dtick: dtick,
415496
ticklabelstep: {
416497
valType: 'integer',
417498
min: 1,
@@ -426,15 +507,7 @@ module.exports = {
426507
'Not implemented for axes with `type` *log* or *multicategory*, or when `tickmode` is *array*.'
427508
].join(' ')
428509
},
429-
tickvals: {
430-
valType: 'data_array',
431-
editType: 'ticks',
432-
description: [
433-
'Sets the values at which ticks on this axis appear.',
434-
'Only has an effect if `tickmode` is set to *array*.',
435-
'Used with `ticktext`.'
436-
].join(' ')
437-
},
510+
tickvals: tickvals,
438511
ticktext: {
439512
valType: 'data_array',
440513
editType: 'ticks',
@@ -444,17 +517,7 @@ module.exports = {
444517
'Used with `tickvals`.'
445518
].join(' ')
446519
},
447-
ticks: {
448-
valType: 'enumerated',
449-
values: ['outside', 'inside', ''],
450-
editType: 'ticks',
451-
description: [
452-
'Determines whether ticks are drawn or not.',
453-
'If **, this axis\' ticks are not drawn.',
454-
'If *outside* (*inside*), this axis\' are drawn outside (inside)',
455-
'the axis lines.'
456-
].join(' ')
457-
},
520+
ticks: ticks,
458521
tickson: {
459522
valType: 'enumerated',
460523
values: ['labels', 'boundaries'],
@@ -537,26 +600,9 @@ module.exports = {
537600
'on all shared-axes subplots.'
538601
].join(' ')
539602
},
540-
ticklen: {
541-
valType: 'number',
542-
min: 0,
543-
dflt: 5,
544-
editType: 'ticks',
545-
description: 'Sets the tick length (in px).'
546-
},
547-
tickwidth: {
548-
valType: 'number',
549-
min: 0,
550-
dflt: 1,
551-
editType: 'ticks',
552-
description: 'Sets the tick width (in px).'
553-
},
554-
tickcolor: {
555-
valType: 'color',
556-
dflt: colorAttrs.defaultLine,
557-
editType: 'ticks',
558-
description: 'Sets the tick color.'
559-
},
603+
ticklen: makeTicklen(),
604+
tickwidth: tickwidth,
605+
tickcolor: tickcolor,
560606
showticklabels: {
561607
valType: 'boolean',
562608
dflt: true,
@@ -776,28 +822,11 @@ module.exports = {
776822
editType: 'ticks+layoutstyle',
777823
description: 'Sets the width (in px) of the axis line.'
778824
},
779-
showgrid: {
780-
valType: 'boolean',
781-
editType: 'ticks',
782-
description: [
783-
'Determines whether or not grid lines are drawn.',
784-
'If *true*, the grid lines are drawn at every tick mark.'
785-
].join(' ')
786-
},
787-
gridcolor: {
788-
valType: 'color',
789-
dflt: colorAttrs.lightLine,
790-
editType: 'ticks',
791-
description: 'Sets the color of the grid lines.'
792-
},
793-
gridwidth: {
794-
valType: 'number',
795-
min: 0,
796-
dflt: 1,
797-
editType: 'ticks',
798-
description: 'Sets the width (in px) of the grid lines.'
799-
},
800-
griddash: extendFlat({}, dash, {editType: 'ticks'}),
825+
showgrid: showgrid,
826+
gridcolor: gridcolor,
827+
gridwidth: gridwidth,
828+
griddash: griddash,
829+
801830
zeroline: {
802831
valType: 'boolean',
803832
editType: 'ticks',
@@ -899,6 +928,26 @@ module.exports = {
899928
'axis will be visible.'
900929
].join(' ')
901930
},
931+
932+
minor: {
933+
tickmode: tickmode,
934+
nticks: nticks,
935+
tick0: tick0,
936+
dtick: dtick,
937+
tickvals: tickvals,
938+
ticks: ticks,
939+
ticklen: makeTicklen('minor'),
940+
tickwidth: tickwidth,
941+
tickcolor: tickcolor,
942+
943+
gridcolor: gridcolor,
944+
gridwidth: gridwidth,
945+
griddash: griddash,
946+
showgrid: showgrid,
947+
948+
editType: 'ticks'
949+
},
950+
902951
layer: {
903952
valType: 'enumerated',
904953
values: ['above traces', 'below traces'],

0 commit comments

Comments
 (0)