Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
charts
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
charts
Commits
18f5597e
Commit
18f5597e
authored
11 years ago
by
Nathan Haug
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/charts_google/charts_google.inc
+18
-1
18 additions, 1 deletion
modules/charts_google/charts_google.inc
with
18 additions
and
1 deletion
modules/charts_google/charts_google.inc
+
18
−
1
View file @
18f5597e
...
...
@@ -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
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment