Skip to content

Commit ee2d07a

Browse files
committed
define constants for *hour* and *day of week* flags
1 parent 94f8ef8 commit ee2d07a

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/plots/cartesian/constants.js

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ module.exports = {
3131
// and for 2D subplots
3232
SUBPLOT_PATTERN: /^x([0-9]*)y([0-9]*)$/,
3333

34+
HOUR_PATTERN: 'hour',
35+
WEEKDAY_PATTERN: 'day of week',
36+
3437
// pixels to move mouse before you stop clamping to starting point
3538
MINDRAG: 8,
3639

src/plots/cartesian/set_convert.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ var ONEHOUR = numConstants.ONEHOUR;
2727
var ONEMIN = numConstants.ONEMIN;
2828
var ONESEC = numConstants.ONESEC;
2929

30-
var constants = require('./constants');
3130
var axisIds = require('./axis_ids');
3231

32+
var constants = require('./constants');
33+
var HOUR_PATTERN = constants.HOUR_PATTERN;
34+
var WEEKDAY_PATTERN = constants.WEEKDAY_PATTERN;
35+
3336
function fromLog(v) {
3437
return Math.pow(10, v);
3538
}
@@ -625,14 +628,14 @@ module.exports = function setConvert(ax, fullLayout) {
625628
var doesCrossPeriod = false;
626629

627630
switch(brk.pattern) {
628-
case 'day of week':
631+
case WEEKDAY_PATTERN:
629632
bnds = Lib.simpleMap(brk.bounds, cleanNumber);
630633
b0 = bnds[0];
631634
b1 = bnds[1];
632635
vb = (new Date(v)).getUTCDay();
633636
if(bnds[0] > bnds[1]) doesCrossPeriod = true;
634637
break;
635-
case 'hour':
638+
case HOUR_PATTERN:
636639
bnds = Lib.simpleMap(brk.bounds, cleanNumber);
637640
b0 = bnds[0];
638641
b1 = bnds[1];
@@ -699,8 +702,8 @@ module.exports = function setConvert(ax, fullLayout) {
699702
if(!ax.rangebreaks) return rangebreaksOut;
700703

701704
var rangebreaksIn = ax.rangebreaks.slice().sort(function(a, b) {
702-
if(a.pattern === 'day of week' && b.pattern === 'hour') return -1;
703-
else if(b.pattern === 'day of week' && a.pattern === 'hour') return 1;
705+
if(a.pattern === WEEKDAY_PATTERN && b.pattern === HOUR_PATTERN) return -1;
706+
if(b.pattern === WEEKDAY_PATTERN && a.pattern === HOUR_PATTERN) return 1;
704707
return 0;
705708
});
706709

@@ -756,7 +759,7 @@ module.exports = function setConvert(ax, fullLayout) {
756759
var t;
757760

758761
switch(brk.pattern) {
759-
case 'day of week':
762+
case WEEKDAY_PATTERN:
760763
b0 = bnds[0] + (op0 === '(' ? 1 : 0);
761764
b1 = bnds[1];
762765
r0Pattern = r0Date.getUTCDay();
@@ -771,7 +774,7 @@ module.exports = function setConvert(ax, fullLayout) {
771774
r0Date.getUTCSeconds() * ONESEC -
772775
r0Date.getUTCMilliseconds();
773776
break;
774-
case 'hour':
777+
case HOUR_PATTERN:
775778
b0 = bnds[0];
776779
b1 = bnds[1];
777780
r0Pattern = r0Date.getUTCHours();

0 commit comments

Comments
 (0)