Skip to content

Commit a03d64d

Browse files
committed
Handle day of week str - add auto dflt for pattern
1 parent b52e990 commit a03d64d

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

src/plots/cartesian/axis_defaults.js

+38-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ var handleCategoryOrderDefaults = require('./category_order_defaults');
2121
var handleLineGridDefaults = require('./line_grid_defaults');
2222
var setConvert = require('./set_convert');
2323

24+
var DAY_OF_WEEK = require('./constants').WEEKDAY_PATTERN;
25+
2426
/**
2527
* options: object containing:
2628
*
@@ -161,6 +163,27 @@ function rangebreaksDefaults(itemIn, itemOut, containerOut) {
161163
itemOut.bounds = itemOut.bounds.slice(0, 2);
162164
}
163165

166+
var dfltPattern = '';
167+
var i, q;
168+
for(i = 0; i < bnds.length; i++) {
169+
q = indexOfDay(bnds[i]);
170+
if(q !== -1) {
171+
dfltPattern = DAY_OF_WEEK;
172+
break;
173+
}
174+
}
175+
var pattern = coerce('pattern', dfltPattern);
176+
177+
if(pattern === DAY_OF_WEEK) {
178+
for(i = 0; i < bnds.length; i++) {
179+
q = indexOfDay(bnds[i]);
180+
if(q !== -1) {
181+
// convert to integers i.e 'Monday' --> 1
182+
itemOut.bounds[i] = bnds[i] = q;
183+
}
184+
}
185+
}
186+
164187
if(containerOut.autorange === false) {
165188
var rng = containerOut.range;
166189

@@ -175,8 +198,6 @@ function rangebreaksDefaults(itemIn, itemOut, containerOut) {
175198
return;
176199
}
177200
}
178-
179-
coerce('pattern');
180201
} else {
181202
var values = coerce('values');
182203

@@ -189,3 +210,18 @@ function rangebreaksDefaults(itemIn, itemOut, containerOut) {
189210
}
190211
}
191212
}
213+
214+
var weekSTR = [
215+
'sun',
216+
'mon',
217+
'tue',
218+
'wed',
219+
'thu',
220+
'fri',
221+
'sat'
222+
];
223+
224+
function indexOfDay(v) {
225+
var str = String(v).substr(0, 3).toLowerCase();
226+
return weekSTR.indexOf(str);
227+
}

src/plots/cartesian/layout_attributes.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,17 @@ module.exports = {
280280
pattern: {
281281
valType: 'enumerated',
282282
values: [DAY_OF_WEEK, HOUR, ''],
283-
dflt: '',
284283
role: 'info',
285284
editType: 'calc',
286285
description: [
287286
'Determines a pattern on the time line that generates breaks.',
288-
'If *' + DAY_OF_WEEK + '* - Sunday-based weekday as a decimal number [0, 6].',
287+
'If *' + DAY_OF_WEEK + '* - days of the week in English e.g. \'Sunday\' or `\sun\`',
288+
'as well as Sunday-based integers between 0 and 6.',
289289
'If *' + HOUR + '* - hour (24-hour clock) as decimal numbers between 0 and 24.',
290290
'for more info.',
291291
'Examples:',
292-
'- { pattern: \'' + DAY_OF_WEEK + '\', bounds: [6, 0] }',
292+
'- { pattern: \'' + DAY_OF_WEEK + '\', bounds: [6, 1] }',
293+
' or simply { bounds: [\'sat\', \'mon\'] }',
293294
' breaks from Saturday to Monday (i.e. skips the weekends).',
294295
'- { pattern: \'' + HOUR + '\', bounds: [17, 8] }',
295296
' breaks from 5pm to 8am (i.e. skips non-work hours).'

0 commit comments

Comments
 (0)