Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsgiehl <stefan@piwik.org>2015-10-11 00:31:17 +0300
committersgiehl <stefan@piwik.org>2015-10-11 15:46:00 +0300
commit253271f772ce996b3b9543b71b262144cf78b38d (patch)
tree29e99316d3c42f9f23b52e217fa5c38daec2deff /plugins/CoreVisualizations
parent0dd0926c012f54d9a2a43249e0d11ff38394cdc7 (diff)
refactored js number formatter to own object to make it better usable
Diffstat (limited to 'plugins/CoreVisualizations')
-rw-r--r--plugins/CoreVisualizations/javascripts/jqplot.js95
-rw-r--r--plugins/CoreVisualizations/javascripts/jqplotBarGraph.js2
-rw-r--r--plugins/CoreVisualizations/javascripts/jqplotPieGraph.js2
3 files changed, 4 insertions, 95 deletions
diff --git a/plugins/CoreVisualizations/javascripts/jqplot.js b/plugins/CoreVisualizations/javascripts/jqplot.js
index fac656f5ae..6e5d2135d1 100644
--- a/plugins/CoreVisualizations/javascripts/jqplot.js
+++ b/plugins/CoreVisualizations/javascripts/jqplot.js
@@ -749,106 +749,15 @@ RowEvolutionSeriesToggle.prototype.beforeReplot = function () {
// ------------------------------------------------------------
// PIWIK NUMBERFORMATTER PLUGIN FOR JQPLOT
-// Handle number formats for piwik...
// ------------------------------------------------------------
(function($){
- function replaceSymbols(value) {
- var replacements = {
- '.': piwik.numbers.symbolDecimal,
- ',': piwik.numbers.symbolGroup,
- '+': piwik.numbers.symbolPlus,
- '-': piwik.numbers.symbolMinus,
- '%': piwik.numbers.symbolPercent
- };
-
- var newValue = '';
- var valueParts = value.split('');
-
- $.each(valueParts, function(index, value) {
- $.each(replacements, function(char, replacement) {
- if (value.indexOf(char) != -1) {
- value = value.replace(char, replacement);
- return false;
- }
- });
- newValue += value;
- });
-
- return newValue;
- }
-
- var minimumFractionDigits = 0;
- var maximumFractionDigits = 2;
-
- $.jqplot.NumberFormatter = function (format, value, pattern) {
+ $.jqplot.NumberFormatter = function (format, value) {
if (!$.isNumeric(value)) {
return format.replace(/%s/, value);
}
- pattern = pattern || piwik.numbers.patternNumber;
-
- var patterns = pattern.split(';');
- if (patterns.length == 1) {
- // No explicit negative pattern was provided, construct it.
- patterns.push('-' + patterns[0])
- }
-
- // Ensure that the value is positive and has the right number of digits.
- var negative = value < 0;
- pattern = negative ? patterns[1] : patterns[0];
-
- var usesGrouping = (pattern.indexOf(',') != -1);
- // if pattern has number groups, parse them.
- if (usesGrouping) {
- var primaryGroupMatches = pattern.match(/#+0/);
- var primaryGroupSize = primaryGroupMatches[0].length;
- var secondaryGroupSize = primaryGroupMatches[0].length;
- var numberGroups = pattern.split(',');
- // check for distinct secondary group size.
- if (numberGroups.length > 2) {
- secondaryGroupSize = numberGroups[1].length;
- }
- }
-
- var signMultiplier = negative ? '-1' : '1';
- value = value * signMultiplier;
- // Split the number into major and minor digits.
- var valueParts = value.toString().split('.');
- var majorDigits = valueParts[0];
- // Account for maximumFractionDigits = 0, where the number won't
- // have a decimal point, and $valueParts[1] won't be set.
- minorDigits = valueParts[1] || '';
- if (usesGrouping) {
- // Reverse the major digits, since they are grouped from the right.
- majorDigits = majorDigits.split('').reverse();
- // Group the major digits.
- var groups = [];
- groups.push(majorDigits.splice(0, primaryGroupSize).reverse().join(''));
- while (majorDigits.length) {
- groups.push(majorDigits.splice(0, secondaryGroupSize).reverse().join(''));
- }
- // Reverse the groups and the digits inside of them.
- groups = groups.reverse();
- // Reconstruct the major digits.
- majorDigits = groups.join(',');
- }
- if (minimumFractionDigits < maximumFractionDigits) {
- // Strip any trailing zeroes.
- var minorDigits = minorDigits.replace(/0+$/,'');
- if (minorDigits.length < minimumFractionDigits) {
- // Now there are too few digits, re-add trailing zeroes
- // until the desired length is reached.
- var neededZeroes = minimumFractionDigits - minorDigits.length;
- minorDigits += (new Array(neededZeroes+1)).join('0');
- }
- }
- // Assemble the final number and insert it into the pattern.
- value = minorDigits ? majorDigits + '.' + minorDigits : majorDigits;
- value = pattern.replace(/#(?:[\.,]#+)*0(?:[,\.][0#]+)*/, value);
- // Localize the number.
- value = replaceSymbols(value);
- return format.replace(/%s/, value);
+ return format.replace(/%s/, NumberFormatter.formatNumber(value));
}
})(jQuery);
diff --git a/plugins/CoreVisualizations/javascripts/jqplotBarGraph.js b/plugins/CoreVisualizations/javascripts/jqplotBarGraph.js
index 70598be192..cd21308f73 100644
--- a/plugins/CoreVisualizations/javascripts/jqplotBarGraph.js
+++ b/plugins/CoreVisualizations/javascripts/jqplotBarGraph.js
@@ -62,7 +62,7 @@
var percentage = '';
if (typeof this.tooltip.percentages != 'undefined') {
percentage = this.tooltip.percentages[seriesIndex][valueIndex];
- percentage = ' (' + $.jqplot.NumberFormatter('%s', percentage, piwik.numbers.patternPercent) + ')';
+ percentage = ' (' + NumberFormatter.formatPercent(percentage) + ')';
}
var label = this.jqplotParams.axes.xaxis.labels[valueIndex];
diff --git a/plugins/CoreVisualizations/javascripts/jqplotPieGraph.js b/plugins/CoreVisualizations/javascripts/jqplotPieGraph.js
index 3c9d6c730f..7169e32af4 100644
--- a/plugins/CoreVisualizations/javascripts/jqplotPieGraph.js
+++ b/plugins/CoreVisualizations/javascripts/jqplotPieGraph.js
@@ -67,7 +67,7 @@
var label = this.data[0][valueIndex][0];
- var text = '<strong>' + $.jqplot.NumberFormatter('%s', percentage, piwik.numbers.patternPercent) + '</strong> (' + value + ' ' + series + ')';
+ var text = '<strong>' + NumberFormatter.formatPercent(percentage) + '</strong> (' + value + ' ' + series + ')';
$(element).tooltip({
track: true,
items: '*',