Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 12ce066

Browse files
committed
adjust AM/PM period case
1 parent 2920e31 commit 12ce066

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/plots/cartesian/axes.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var ONEAVGMONTH = constants.ONEAVGMONTH;
3434
var ONEMINMONTH = constants.ONEMINMONTH;
3535
var ONEWEEK = constants.ONEWEEK;
3636
var ONEDAY = constants.ONEDAY;
37+
var HALFDAY = ONEDAY / 2;
3738
var ONEHOUR = constants.ONEHOUR;
3839
var ONEMIN = constants.ONEMIN;
3940
var ONESEC = constants.ONESEC;
@@ -503,7 +504,7 @@ function autoShiftMonthBins(binStart, data, dtick, dataMin, calendar) {
503504
// will always give a somewhat odd-looking label, until we do something
504505
// smarter like showing the bin boundaries (or the bounds of the actual
505506
// data in each bin)
506-
binStart -= ONEDAY / 2;
507+
binStart -= HALFDAY;
507508
}
508509
var nextBinStart = axes.tickIncrement(binStart, dtick);
509510

@@ -705,7 +706,7 @@ axes.calcTicks = function calcTicks(ax, opts) {
705706
var tickformat = axes.getTickFormat(ax);
706707
if(isPeriod && tickformat) {
707708
if(
708-
!(/%[fLQsSMHIpX]/.test(tickformat))
709+
!(/%[fLQsSMHIX]/.test(tickformat))
709710
// %f: microseconds as a decimal number [000000, 999999]
710711
// %L: milliseconds as a decimal number [000, 999]
711712
// %Q: milliseconds since UNIX epoch
@@ -714,10 +715,12 @@ axes.calcTicks = function calcTicks(ax, opts) {
714715
// %M: minute as a decimal number [00,59]
715716
// %H: hour (24-hour clock) as a decimal number [00,23]
716717
// %I: hour (12-hour clock) as a decimal number [01,12]
717-
// %p: either AM or PM
718718
// %X: the locale’s time, such as %-I:%M:%S %p
719719
) {
720720
if(
721+
/%p/.test(tickformat) // %p: either AM or PM
722+
) definedDelta = HALFDAY;
723+
else if(
721724
/%[Aadejuwx]/.test(tickformat)
722725
// %A: full weekday name
723726
// %a: abbreviated weekday name
@@ -819,6 +822,8 @@ axes.calcTicks = function calcTicks(ax, opts) {
819822
periodLength = ONEWEEK;
820823
} else if(delta >= ONEDAY) {
821824
periodLength = ONEDAY;
825+
} else if(definedDelta === HALFDAY && delta >= HALFDAY) {
826+
periodLength = HALFDAY;
822827
}
823828

824829
if(periodLength && ax.rangebreaks) {

test/jasmine/tests/axes_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5568,8 +5568,8 @@ describe('Test axes', function() {
55685568
[
55695569
{
55705570
formatter: '%p',
5571-
positions: ['2019-12-31 21:00', '2020-01-01', '2020-01-01 12:00', '2020-01-02'],
5572-
labels: ['', 'Wed-AM', 'Wed-PM', 'Thu-AM']
5571+
positions: ['2019-12-31 21:00', '2020-01-01 06:00', '2020-01-01 18:00', '2020-01-02 06:00'],
5572+
labels: ['', 'Wed-AM', 'Wed-PM', '']
55735573
},
55745574
{
55755575
formatter: '%M',

0 commit comments

Comments
 (0)