Skip to content
Snippets Groups Projects
Commit 18f5597e authored by Nathan Haug's avatar Nathan Haug
Browse files

Issue #2052727: "%" Value Suffix in Google charts causes unexpected formatting.

parent 9c53211f
No related branches found
No related tags found
No related merge requests found
......@@ -217,7 +217,9 @@ function _charts_google_populate_chart_data(&$chart, $chart_definition) {
// These properties are not real Google Charts properties. They are
// utilized by the formatter in charts_google.js.
$decimal_count = $chart[$key]['#decimal_count'] ? '.' . str_repeat('0', $chart[$key]['#decimal_count']) : '';
$format = $chart[$key]['#prefix'] . '#' . $decimal_count . $chart[$key]['#suffix'];
$prefix = _charts_google_escape_icu_characters($chart[$key]['#prefix']);
$suffix = _charts_google_escape_icu_characters($chart[$key]['#suffix']);
$format = $prefix . '#' . $decimal_count . $suffix;
$series['_format']['format'] = $format;
// TODO: Convert this from PHP's date format to ICU format.
......@@ -292,3 +294,18 @@ function _charts_google_populate_chart_data(&$chart, $chart_definition) {
return $chart_definition;
}
/**
* Utility to escape special characters in ICU number formats.
*
* Google will use the ICU format to auto-adjust numbers based on special
* characters that are used in the format. This function escapes these special
* characters so they just show up as the character specified.
*
* The format string is a subset of the ICU pattern set. For instance,
* {pattern:'#,###%'} will result in output values "1,000%", "750%", and "50%"
* for values 10, 7.5, and 0.5.
*/
function _charts_google_escape_icu_characters($string) {
return preg_replace('/([0-9@#\.\-,E\+;%\'\*])/', "'$1'", $string);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment