From e0b1ec3600c1948d61c4584249452a36fc885700 Mon Sep 17 00:00:00 2001 From: Globegitter Date: Sun, 15 Mar 2015 23:23:57 +0000 Subject: [PATCH] Fixed currency support. --- bower.json | 2 +- dist/chartist-plugin-tooltip.js | 2 +- dist/chartist-plugin-tooltip.min.js | 4 ++-- dist/chartist-plugin-tooltip.min.js.map | 2 +- package.json | 2 +- src/scripts/chartist-plugin-tooltip.js | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bower.json b/bower.json index 02e5a9e..be1b1cf 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "chartist-plugin-tooltip", - "version": "0.0.5", + "version": "0.0.6", "main": [ "./dist/chartist-plugin-tooltip.min.js" ], diff --git a/dist/chartist-plugin-tooltip.js b/dist/chartist-plugin-tooltip.js index 4d814e5..bb5fde0 100644 --- a/dist/chartist-plugin-tooltip.js +++ b/dist/chartist-plugin-tooltip.js @@ -60,7 +60,7 @@ var value = $point.attr('ct:value'); if (options.currency) { - value = options.currency + value.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,'); + value = options.currency + value.replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,"); } tooltipText += value; diff --git a/dist/chartist-plugin-tooltip.min.js b/dist/chartist-plugin-tooltip.min.js index 4e4d1f1..be286f2 100644 --- a/dist/chartist-plugin-tooltip.min.js +++ b/dist/chartist-plugin-tooltip.min.js @@ -1,8 +1,8 @@ -/* chartist-plugin-pointlabels 0.0.4 +/* chartist-plugin-pointlabels 0.0.5 * Copyright © 2015 Gion Kunz * Free to use under the WTFPL license. * http://www.wtfpl.net/ */ -!function(a,b){"function"==typeof define&&define.amd?define([],function(){return a.returnExportsGlobal=b()}):"object"==typeof exports?module.exports=b():a["Chartist.plugins.tooltips"]=b()}(this,function(){return function(a,b,c){"use strict";var d={currency:null};c.plugins=c.plugins||{},c.plugins.tooltip=function(a){return a=c.extend({},d,a),function(b){var d=".ct-point";b instanceof c.Bar&&(d=".ct-bar");var e=$(b.container),f=e.append('
').find(".tooltip").hide();e.on("mouseenter",d,function(){var b=Ember.$(this),c="";b.attr("ct:meta")&&(c+=b.attr("ct:meta")+"
");var d=b.attr("ct:value");a.currency&&(d=a.currency+d.toFixed(2).replace(/\d(?=(\d{3})+\.)/g,"$&,")),c+=d,f.html(c).show()}),e.on("mouseleave",d,function(){f.hide()}),e.on("mousemove",function(a){f.css({left:(a.offsetX||a.originalEvent.layerX)-f.width()/2-10,top:(a.offsetY||a.originalEvent.layerY)-f.height()-40})})}}}(window,document,Chartist),Chartist.plugins.tooltips}); +!function(a,b){"function"==typeof define&&define.amd?define([],function(){return a.returnExportsGlobal=b()}):"object"==typeof exports?module.exports=b():a["Chartist.plugins.tooltips"]=b()}(this,function(){return function(a,b,c){"use strict";var d={currency:null};c.plugins=c.plugins||{},c.plugins.tooltip=function(a){return a=c.extend({},d,a),function(b){var d=".ct-point";b instanceof c.Bar&&(d=".ct-bar");var e=$(b.container),f=e.append('
').find(".tooltip").hide();e.on("mouseenter",d,function(){var b=Ember.$(this),c="";b.attr("ct:meta")&&(c+=b.attr("ct:meta")+"
");var d=b.attr("ct:value");a.currency&&(d=a.currency+d.replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g,"$1,")),c+=d,f.html(c).show()}),e.on("mouseleave",d,function(){f.hide()}),e.on("mousemove",function(a){f.css({left:(a.offsetX||a.originalEvent.layerX)-f.width()/2-10,top:(a.offsetY||a.originalEvent.layerY)-f.height()-40})})}}}(window,document,Chartist),Chartist.plugins.tooltips}); //# sourceMappingURL=chartist-plugin-tooltip.min.js.map \ No newline at end of file diff --git a/dist/chartist-plugin-tooltip.min.js.map b/dist/chartist-plugin-tooltip.min.js.map index 86f7de1..f4964c8 100644 --- a/dist/chartist-plugin-tooltip.min.js.map +++ b/dist/chartist-plugin-tooltip.min.js.map @@ -1 +1 @@ -{"version":3,"file":"chartist-plugin-tooltip.min.js","sources":["chartist-plugin-tooltip.js"],"names":["root","factory","define","amd","returnExportsGlobal","exports","module","this","window","document","Chartist","defaultOptions","currency","plugins","tooltip","options","extend","chart","tooltipSelector","Bar","$chart","$","container","$toolTip","append","find","hide","on","$point","Ember","tooltipText","attr","value","toFixed","replace","html","show","event","css","left","offsetX","originalEvent","layerX","width","top","offsetY","layerY","height","tooltips"],"mappings":";;;;;;CAAC,SAAUA,EAAMC,GACO,kBAAXC,SAAyBA,OAAOC,IAEzCD,UAAW,WACT,MAAQF,GAAKI,oBAAsBH,MAET,gBAAZI,SAIhBC,OAAOD,QAAUJ,IAEjBD,EAAK,6BAA+BC,KAEtCM,KAAM,WAsEN,MA/DC,UAASC,EAAQC,EAAUC,GAC1B,YAEA,IAAIC,IACFC,SAAU,KAWZF,GAASG,QAAUH,EAASG,YAC5BH,EAASG,QAAQC,QAAU,SAASC,GAIlC,MAFAA,GAAUL,EAASM,UAAWL,EAAgBI,GAEvC,SAAiBE,GACtB,GAAIC,GAAkB,WAClBD,aAAiBP,GAASS,MAC5BD,EAAkB,UAEpB,IAAIE,GAASC,EAAEJ,EAAMK,WACjBC,EAAWH,EACdI,OAAO,+BACPC,KAAK,YACLC,MAEDN,GAAOO,GAAG,aAAcT,EAAiB,WACvC,GAAIU,GAASC,MAAMR,EAAEd,MACjBuB,EAAc,EAEdF,GAAOG,KAAK,aACdD,GAAeF,EAAOG,KAAK,WAAa,OAG1C,IAAIC,GAAQJ,EAAOG,KAAK,WACpBhB,GAAQH,WACVoB,EAAQjB,EAAQH,SAAWoB,EAAMC,QAAQ,GAAGC,QAAQ,oBAAqB,QAE3EJ,GAAeE,EAEfT,EAASY,KAAKL,GAAaM,SAG7BhB,EAAOO,GAAG,aAAcT,EAAiB,WACvCK,EAASG,SAGXN,EAAOO,GAAG,YAAa,SAASU,GAC9Bd,EAASe,KACPC,MAAOF,EAAMG,SAAWH,EAAMI,cAAcC,QAAUnB,EAASoB,QAAU,EAAI,GAC7EC,KAAMP,EAAMQ,SAAWR,EAAMI,cAAcK,QAAUvB,EAASwB,SAAW,UAMjFvC,OAAQC,SAAUC,UAEbA,SAASG,QAAQmC","sourcesContent":["(function (root, factory) {\n if (typeof define === 'function' && define.amd) {\n // AMD. Register as an anonymous module.\n define([], function () {\n return (root.returnExportsGlobal = factory());\n });\n } else if (typeof exports === 'object') {\n // Node. Does not work with strict CommonJS, but\n // only CommonJS-like enviroments that support module.exports,\n // like Node.\n module.exports = factory();\n } else {\n root['Chartist.plugins.tooltips'] = factory();\n }\n}(this, function () {\n\n /**\n * Chartist.js plugin to display a data label on top of the points in a line chart.\n *\n */\n /* global Chartist */\n (function(window, document, Chartist) {\n 'use strict';\n\n var defaultOptions = {\n currency: null\n // showTooltips: true,\n // tooltipEvents: ['mousemove', 'touchstart', 'touchmove'],\n // labelClass: 'ct-label',\n // labelOffset: {\n // x: 0,\n // y: -10\n // },\n // textAnchor: 'middle'\n };\n\n Chartist.plugins = Chartist.plugins || {};\n Chartist.plugins.tooltip = function(options) {\n\n options = Chartist.extend({}, defaultOptions, options);\n\n return function tooltip(chart) {\n var tooltipSelector = '.ct-point';\n if (chart instanceof Chartist.Bar) {\n tooltipSelector = '.ct-bar';\n }\n var $chart = $(chart.container);\n var $toolTip = $chart\n .append('
')\n .find('.tooltip')\n .hide();\n\n $chart.on('mouseenter', tooltipSelector, function() {\n var $point = Ember.$(this);\n var tooltipText = '';\n\n if ($point.attr('ct:meta')) {\n tooltipText += $point.attr('ct:meta') + '
';\n }\n\n var value = $point.attr('ct:value');\n if (options.currency) {\n value = options.currency + value.toFixed(2).replace(/\\d(?=(\\d{3})+\\.)/g, '$&,');\n }\n tooltipText += value;\n\n $toolTip.html(tooltipText).show();\n });\n\n $chart.on('mouseleave', tooltipSelector, function() {\n $toolTip.hide();\n });\n\n $chart.on('mousemove', function(event) {\n $toolTip.css({\n left: (event.offsetX || event.originalEvent.layerX) - $toolTip.width() / 2 - 10,\n top: (event.offsetY || event.originalEvent.layerY) - $toolTip.height() - 40\n });\n });\n }\n };\n\n }(window, document, Chartist));\n\n return Chartist.plugins.tooltips;\n\n}));\n"]} \ No newline at end of file +{"version":3,"file":"chartist-plugin-tooltip.min.js","sources":["chartist-plugin-tooltip.js"],"names":["root","factory","define","amd","returnExportsGlobal","exports","module","this","window","document","Chartist","defaultOptions","currency","plugins","tooltip","options","extend","chart","tooltipSelector","Bar","$chart","$","container","$toolTip","append","find","hide","on","$point","Ember","tooltipText","attr","value","replace","html","show","event","css","left","offsetX","originalEvent","layerX","width","top","offsetY","layerY","height","tooltips"],"mappings":";;;;;;CAAC,SAAUA,EAAMC,GACO,kBAAXC,SAAyBA,OAAOC,IAEzCD,UAAW,WACT,MAAQF,GAAKI,oBAAsBH,MAET,gBAAZI,SAIhBC,OAAOD,QAAUJ,IAEjBD,EAAK,6BAA+BC,KAEtCM,KAAM,WAsEN,MA/DC,UAASC,EAAQC,EAAUC,GAC1B,YAEA,IAAIC,IACFC,SAAU,KAWZF,GAASG,QAAUH,EAASG,YAC5BH,EAASG,QAAQC,QAAU,SAASC,GAIlC,MAFAA,GAAUL,EAASM,UAAWL,EAAgBI,GAEvC,SAAiBE,GACtB,GAAIC,GAAkB,WAClBD,aAAiBP,GAASS,MAC5BD,EAAkB,UAEpB,IAAIE,GAASC,EAAEJ,EAAMK,WACjBC,EAAWH,EACdI,OAAO,+BACPC,KAAK,YACLC,MAEDN,GAAOO,GAAG,aAAcT,EAAiB,WACvC,GAAIU,GAASC,MAAMR,EAAEd,MACjBuB,EAAc,EAEdF,GAAOG,KAAK,aACdD,GAAeF,EAAOG,KAAK,WAAa,OAG1C,IAAIC,GAAQJ,EAAOG,KAAK,WACpBhB,GAAQH,WACVoB,EAAQjB,EAAQH,SAAWoB,EAAMC,QAAQ,+BAAgC,QAE3EH,GAAeE,EAEfT,EAASW,KAAKJ,GAAaK,SAG7Bf,EAAOO,GAAG,aAAcT,EAAiB,WACvCK,EAASG,SAGXN,EAAOO,GAAG,YAAa,SAASS,GAC9Bb,EAASc,KACPC,MAAOF,EAAMG,SAAWH,EAAMI,cAAcC,QAAUlB,EAASmB,QAAU,EAAI,GAC7EC,KAAMP,EAAMQ,SAAWR,EAAMI,cAAcK,QAAUtB,EAASuB,SAAW,UAMjFtC,OAAQC,SAAUC,UAEbA,SAASG,QAAQkC","sourcesContent":["(function (root, factory) {\n if (typeof define === 'function' && define.amd) {\n // AMD. Register as an anonymous module.\n define([], function () {\n return (root.returnExportsGlobal = factory());\n });\n } else if (typeof exports === 'object') {\n // Node. Does not work with strict CommonJS, but\n // only CommonJS-like enviroments that support module.exports,\n // like Node.\n module.exports = factory();\n } else {\n root['Chartist.plugins.tooltips'] = factory();\n }\n}(this, function () {\n\n /**\n * Chartist.js plugin to display a data label on top of the points in a line chart.\n *\n */\n /* global Chartist */\n (function(window, document, Chartist) {\n 'use strict';\n\n var defaultOptions = {\n currency: null\n // showTooltips: true,\n // tooltipEvents: ['mousemove', 'touchstart', 'touchmove'],\n // labelClass: 'ct-label',\n // labelOffset: {\n // x: 0,\n // y: -10\n // },\n // textAnchor: 'middle'\n };\n\n Chartist.plugins = Chartist.plugins || {};\n Chartist.plugins.tooltip = function(options) {\n\n options = Chartist.extend({}, defaultOptions, options);\n\n return function tooltip(chart) {\n var tooltipSelector = '.ct-point';\n if (chart instanceof Chartist.Bar) {\n tooltipSelector = '.ct-bar';\n }\n var $chart = $(chart.container);\n var $toolTip = $chart\n .append('
')\n .find('.tooltip')\n .hide();\n\n $chart.on('mouseenter', tooltipSelector, function() {\n var $point = Ember.$(this);\n var tooltipText = '';\n\n if ($point.attr('ct:meta')) {\n tooltipText += $point.attr('ct:meta') + '
';\n }\n\n var value = $point.attr('ct:value');\n if (options.currency) {\n value = options.currency + value.replace(/(\\d)(?=(\\d{3})+(?:\\.\\d+)?$)/g, \"$1,\");\n }\n tooltipText += value;\n\n $toolTip.html(tooltipText).show();\n });\n\n $chart.on('mouseleave', tooltipSelector, function() {\n $toolTip.hide();\n });\n\n $chart.on('mousemove', function(event) {\n $toolTip.css({\n left: (event.offsetX || event.originalEvent.layerX) - $toolTip.width() / 2 - 10,\n top: (event.offsetY || event.originalEvent.layerY) - $toolTip.height() - 40\n });\n });\n }\n };\n\n }(window, document, Chartist));\n\n return Chartist.plugins.tooltips;\n\n}));\n"]} \ No newline at end of file diff --git a/package.json b/package.json index 68045ed..17275d7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "chartist-plugin-tooltip", "description": "Point Labels Plugin for Chartist.js", - "version": "0.0.5", + "version": "0.0.6", "author": "Markus Padourek", "homepage": "https://github.com/Globegitter/chartist-plugin-tooltip", "repository": { diff --git a/src/scripts/chartist-plugin-tooltip.js b/src/scripts/chartist-plugin-tooltip.js index ac51d54..451bfe9 100644 --- a/src/scripts/chartist-plugin-tooltip.js +++ b/src/scripts/chartist-plugin-tooltip.js @@ -44,7 +44,7 @@ var value = $point.attr('ct:value'); if (options.currency) { - value = options.currency + value.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,'); + value = options.currency + value.replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,"); } tooltipText += value;