Skip to content

Commit

Permalink
release: fixes
Browse files Browse the repository at this point in the history
- Fixed custom format issue in ChartJS
  • Loading branch information
vytisbulkevicius authored Mar 20, 2023
2 parents 9c3a7d5 + 5dd2935 commit 45bb580
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 42 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ jobs:
bash ./bin/run-e2e-tests-${{matrix.env}}.sh
- name: Run ${{ matrix.env }} Cypress tests
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
uses: cypress-io/github-action@v2
with:
env: host=localhost,port=8080
browser: chrome
record: true
install: ${{ ! steps.npm-and-build-cache.outputs.cache-hit }}
headless: true
spec: cypress/integration/${{ matrix.env }}/**/*
20 changes: 20 additions & 0 deletions classes/Visualizer/Render/Sidebar/Type/ChartJS/Pie.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,26 @@ protected function _renderChartTypeSettings() {
esc_html__( 'If checked, the chart will be rendered as a donut chart.', 'visualizer' )
);

self::_renderTextItem(
esc_html__( 'Number Format', 'visualizer' ),
'format',
isset( $this->format ) ? $this->format : '',
sprintf(
'%s<br><br>%s<br><br>%s',
esc_html__( 'Enter custom format pattern to apply to horizontal axis labels.', 'visualizer' ),
sprintf(
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' ),
'<a href="http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details" target="_blank">',
'</a>'
),
sprintf(
esc_html__( 'For date axis labels, this is a subset of the date formatting %1$sICU date and time format%2$s.', 'visualizer' ),
'<a href="https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax" target="_blank">',
'</a>'
)
)
);

self::_renderSectionEnd();

self::_renderGroupEnd();
Expand Down
2 changes: 1 addition & 1 deletion composer.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"require-dev": {
"wp-coding-standards/wpcs": "^2.3",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
"phpcompatibility/phpcompatibility-wp": "*"
}
}
82 changes: 44 additions & 38 deletions composer.lock
100755 → 100644

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 30 additions & 1 deletion js/render-chartjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,35 @@
return;
}

// Format series label.
settings.plugins.tooltip = {
callbacks: {
label: function(context) {
var label = '';
if ( 'object' === typeof context.dataset.label ) {
label = context.label || '';
} else {
label = context.dataset.label || '';
}
if ( label ) {
label += ': ';
}
var format = context.dataset.format || '';
if ( format ) {
label += format_datum( context.formattedValue, format );
} else {
format = 'undefined' !== typeof context.chart.config._config.options.format ? context.chart.config._config.options.format : '';
if ( format ) {
label += format_datum( context.formattedValue, format );
} else {
label += context.formattedValue;
}
}
return label;
}
}
};

var chartjs = new Chart(context, {
type: type,
data: {
Expand All @@ -131,7 +160,7 @@
if ( $( '#chart-img' ).length ) {
$( '#chart-img' ).val( canvas.toDataURL() );
}
},
}
}],
});

Expand Down

0 comments on commit 45bb580

Please sign in to comment.