@@ -14,23 +14,25 @@ class Formatters {
14
14
this . tooltipKeyFormat = 'dd MMM'
15
15
}
16
16
17
- xLabelFormat ( fn , val ) {
17
+ xLabelFormat ( fn , val , timestamp ) {
18
18
let w = this . w
19
19
20
20
if ( w . config . xaxis . type === 'datetime' ) {
21
- // if user has not specified a custom formatter, use the default tooltip.x.format
22
- if ( w . config . tooltip . x . formatter === undefined ) {
23
- let datetimeObj = new DateTime ( this . ctx )
24
- return datetimeObj . formatDate (
25
- new Date ( val ) ,
26
- w . config . tooltip . x . format ,
27
- true ,
28
- true
29
- )
21
+ if ( w . config . xaxis . labels . formatter === undefined ) {
22
+ // if user has not specified a custom formatter, use the default tooltip.x.format
23
+ if ( w . config . tooltip . x . formatter === undefined ) {
24
+ let datetimeObj = new DateTime ( this . ctx )
25
+ return datetimeObj . formatDate (
26
+ new Date ( val ) ,
27
+ w . config . tooltip . x . format ,
28
+ true ,
29
+ true
30
+ )
31
+ }
30
32
}
31
33
}
32
34
33
- return fn ( val )
35
+ return fn ( val , timestamp )
34
36
}
35
37
36
38
setLabelFormatters ( ) {
@@ -56,8 +58,26 @@ class Formatters {
56
58
return val
57
59
}
58
60
61
+ // formatter function will always overwrite format property
62
+ if ( w . config . xaxis . labels . formatter !== undefined ) {
63
+ w . globals . xLabelFormatter = w . config . xaxis . labels . formatter
64
+ } else {
65
+ w . globals . xLabelFormatter = function ( val ) {
66
+ if ( Utils . isNumber ( val ) ) {
67
+ // numeric xaxis may have smaller range, so defaulting to 1 decimal
68
+ if ( w . config . xaxis . type === 'numeric' && w . globals . dataPoints < 50 ) {
69
+ return val . toFixed ( 1 )
70
+ }
71
+ return val . toFixed ( 0 )
72
+ }
73
+ return val
74
+ }
75
+ }
76
+
59
77
if ( typeof w . config . tooltip . x . formatter === 'function' ) {
60
78
w . globals . ttKeyFormatter = w . config . tooltip . x . formatter
79
+ } else {
80
+ w . globals . ttKeyFormatter = w . globals . xLabelFormatter
61
81
}
62
82
63
83
if ( typeof w . config . xaxis . tooltip . formatter === 'function' ) {
@@ -81,22 +101,6 @@ class Formatters {
81
101
w . globals . legendFormatter = w . config . legend . formatter
82
102
}
83
103
84
- // formatter function will always overwrite format property
85
- if ( w . config . xaxis . labels . formatter !== undefined ) {
86
- w . globals . xLabelFormatter = w . config . xaxis . labels . formatter
87
- } else {
88
- w . globals . xLabelFormatter = function ( val ) {
89
- if ( Utils . isNumber ( val ) ) {
90
- // numeric xaxis may have smaller range, so defaulting to 1 decimal
91
- if ( w . config . xaxis . type === 'numeric' && w . globals . dataPoints < 50 ) {
92
- return val . toFixed ( 1 )
93
- }
94
- return val . toFixed ( 0 )
95
- }
96
- return val
97
- }
98
- }
99
-
100
104
// formatter function will always overwrite format property
101
105
w . config . yaxis . forEach ( ( yaxe , i ) => {
102
106
if ( yaxe . labels . formatter !== undefined ) {
0 commit comments