From 0a6d0fa44d2afb701c748e05b7d18e05e67feb3a Mon Sep 17 00:00:00 2001 From: Alan Schio Date: Fri, 15 Jun 2018 16:57:15 -0400 Subject: [PATCH] Update morris.js Add support for valueFormatter to show in Line and Bar mouse hover tooltip the value formated --- morris.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/morris.js b/morris.js index 35ad207..f97bfa9 100644 --- a/morris.js +++ b/morris.js @@ -236,7 +236,16 @@ Licensed under the BSD-2-Clause License. ret.label = new Date(ret.label).toString(); } } else { - ret.x = index; + if(this.options.valueFormatter) { + ret.src.formated = [] + for(var ykey in this.options.ykeys) { + var value = ret.src[this.options.ykeys[ykey]]; + ret.src.formated[this.options.ykeys[ykey]] = this.options.valueFormatter(value); + } + } + ret.x = index; + + if (this.options.xLabelFormat) { ret.label = this.options.xLabelFormat(ret); } @@ -950,7 +959,7 @@ Licensed under the BSD-2-Clause License. if (this.options.labels[j] === false) { continue; } - content += "
\n " + this.options.labels[j] + ":\n " + (this.yLabelFormat(y, j)) + "\n
"; + content += "
\n " + this.options.labels[j] + ":\n " + ( this.options.valueFormatter?this.options.valueFormatter (y): this.yLabelFormat(y, j)) + "\n
"; } if (typeof this.options.hoverCallback === 'function') { content = this.options.hoverCallback(index, this.options, content, row.src); @@ -1806,7 +1815,7 @@ Licensed under the BSD-2-Clause License. if (this.options.labels[j] === false) { continue; } - content += "
\n " + this.options.labels[j] + ":\n " + (this.yLabelFormat(y, j)) + "\n
"; + content += "
\n " + this.options.labels[j] + ":\n " + (this.options.valueFormatter?this.options.valueFormatter (y):this.yLabelFormat(y, j)) + "\n
"; } if (typeof this.options.hoverCallback === 'function') { content = this.options.hoverCallback(index, this.options, content, row.src);