Skip to content

Commit 45bb580

Browse files
release: fixes
- Fixed custom format issue in ChartJS
2 parents 9c3a7d5 + 5dd2935 commit 45bb580

File tree

5 files changed

+95
-42
lines changed

5 files changed

+95
-42
lines changed

.github/workflows/test-e2e.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@ jobs:
4141
bash ./bin/run-e2e-tests-${{matrix.env}}.sh
4242
- name: Run ${{ matrix.env }} Cypress tests
4343
env:
44-
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
4544
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
4645
uses: cypress-io/github-action@v2
4746
with:
4847
env: host=localhost,port=8080
4948
browser: chrome
50-
record: true
5149
install: ${{ ! steps.npm-and-build-cache.outputs.cache-hit }}
5250
headless: true
5351
spec: cypress/integration/${{ matrix.env }}/**/*

classes/Visualizer/Render/Sidebar/Type/ChartJS/Pie.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,26 @@ protected function _renderChartTypeSettings() {
109109
esc_html__( 'If checked, the chart will be rendered as a donut chart.', 'visualizer' )
110110
);
111111

112+
self::_renderTextItem(
113+
esc_html__( 'Number Format', 'visualizer' ),
114+
'format',
115+
isset( $this->format ) ? $this->format : '',
116+
sprintf(
117+
'%s<br><br>%s<br><br>%s',
118+
esc_html__( 'Enter custom format pattern to apply to horizontal axis labels.', 'visualizer' ),
119+
sprintf(
120+
esc_html__( 'For number axis labels, this is a subset of the decimal formatting %1$sICU pattern set%2$s. For instance, $#,###.## will display values $1,234.56 for value 1234.56. Pay attention that if you use #&#37;&#37; percentage format then your values will be multiplied by 100.', 'visualizer' ),
121+
'<a href="http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details" target="_blank">',
122+
'</a>'
123+
),
124+
sprintf(
125+
esc_html__( 'For date axis labels, this is a subset of the date formatting %1$sICU date and time format%2$s.', 'visualizer' ),
126+
'<a href="https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax" target="_blank">',
127+
'</a>'
128+
)
129+
)
130+
);
131+
112132
self::_renderSectionEnd();
113133

114134
self::_renderGroupEnd();

composer.json

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
},
4949
"require-dev": {
5050
"wp-coding-standards/wpcs": "^2.3",
51-
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
51+
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
5252
"phpcompatibility/phpcompatibility-wp": "*"
5353
}
5454
}

composer.lock

100755100644
Lines changed: 44 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/render-chartjs.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,35 @@
118118
return;
119119
}
120120

121+
// Format series label.
122+
settings.plugins.tooltip = {
123+
callbacks: {
124+
label: function(context) {
125+
var label = '';
126+
if ( 'object' === typeof context.dataset.label ) {
127+
label = context.label || '';
128+
} else {
129+
label = context.dataset.label || '';
130+
}
131+
if ( label ) {
132+
label += ': ';
133+
}
134+
var format = context.dataset.format || '';
135+
if ( format ) {
136+
label += format_datum( context.formattedValue, format );
137+
} else {
138+
format = 'undefined' !== typeof context.chart.config._config.options.format ? context.chart.config._config.options.format : '';
139+
if ( format ) {
140+
label += format_datum( context.formattedValue, format );
141+
} else {
142+
label += context.formattedValue;
143+
}
144+
}
145+
return label;
146+
}
147+
}
148+
};
149+
121150
var chartjs = new Chart(context, {
122151
type: type,
123152
data: {
@@ -131,7 +160,7 @@
131160
if ( $( '#chart-img' ).length ) {
132161
$( '#chart-img' ).val( canvas.toDataURL() );
133162
}
134-
},
163+
}
135164
}],
136165
});
137166

0 commit comments

Comments
 (0)