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