@@ -403,6 +403,31 @@ function ticksFromTimestamps(values, majorUnit) {
403
403
return ticks ;
404
404
}
405
405
406
+ function determineLabelFormat ( data , timeOpts ) {
407
+ var i , momentDate , hasTime ;
408
+ var ilen = data . length ;
409
+
410
+ if ( timeOpts . tooltipFormat ) {
411
+ return timeOpts . tooltipFormat ;
412
+ }
413
+
414
+ // find the label with the most parts (milliseconds, minutes, etc.)
415
+ // format all labels with the same level of detail as the most specific label
416
+ for ( i = 0 ; i < ilen ; i ++ ) {
417
+ momentDate = momentify ( data [ i ] , timeOpts ) ;
418
+ if ( momentDate . millisecond ( ) !== 0 ) {
419
+ return 'MMM D, YYYY h:mm:ss.SSS a' ;
420
+ }
421
+ if ( momentDate . second ( ) !== 0 || momentDate . minute ( ) !== 0 || momentDate . hour ( ) !== 0 ) {
422
+ hasTime = true ;
423
+ }
424
+ }
425
+ if ( hasTime ) {
426
+ return 'MMM D, YYYY h:mm:ss a' ;
427
+ }
428
+ return 'MMM D, YYYY' ;
429
+ }
430
+
406
431
module . exports = function ( Chart ) {
407
432
408
433
var defaultConfig = {
@@ -621,6 +646,7 @@ module.exports = function(Chart) {
621
646
me . _majorUnit = determineMajorUnit ( me . _unit ) ;
622
647
me . _table = buildLookupTable ( me . _timestamps . data , min , max , options . distribution ) ;
623
648
me . _offsets = computeOffsets ( me . _table , ticks , min , max , options ) ;
649
+ me . _labelFormat = determineLabelFormat ( me . _timestamps . data , timeOpts ) ;
624
650
625
651
return ticksFromTimestamps ( ticks , me . _majorUnit ) ;
626
652
} ,
@@ -635,11 +661,8 @@ module.exports = function(Chart) {
635
661
if ( helpers . isObject ( value ) ) {
636
662
label = me . getRightValue ( value ) ;
637
663
}
638
- if ( timeOpts . tooltipFormat ) {
639
- label = momentify ( label , timeOpts ) . format ( timeOpts . tooltipFormat ) ;
640
- }
641
664
642
- return label ;
665
+ return momentify ( label , timeOpts ) . format ( me . _labelFormat ) ;
643
666
} ,
644
667
645
668
/**
0 commit comments