diff --git a/UPGRADE-1.7.md b/UPGRADE-1.7.md index 793fbad61f..2894b9052d 100644 --- a/UPGRADE-1.7.md +++ b/UPGRADE-1.7.md @@ -6,12 +6,13 @@ Require upgraded Sylius version using Composer: composer require sylius/sylius:~1.7.0 ``` -Update your `package.json` in order to add `slick-carousel` : +Update your `package.json` in order to add `chart.js` and `slick-carousel` : ```diff { "dependencies": { "babel-polyfill": "^6.26.0", ++ "chart.js": "^2.9.3", "jquery": "^3.4.0", "jquery.dirtyforms": "^2.0.0", "lightbox2": "^2.9.0", diff --git a/package.json b/package.json index 122e0f3ee7..8880db7b88 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "dependencies": { "babel-polyfill": "^6.26.0", + "chart.js": "^2.9.3", "jquery": "^3.4.0", "jquery.dirtyforms": "^2.0.0", "lightbox2": "^2.9.0", diff --git a/src/Sylius/Bundle/AdminBundle/Resources/private/js/app.js b/src/Sylius/Bundle/AdminBundle/Resources/private/js/app.js index 0de66761b4..5f22addf42 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/private/js/app.js +++ b/src/Sylius/Bundle/AdminBundle/Resources/private/js/app.js @@ -25,6 +25,7 @@ import './sylius-notification'; import './sylius-product-images-preview'; import './sylius-product-slug'; import './sylius-taxon-slug'; +import './sylius-chart'; import SyliusTaxonomyTree from './sylius-taxon-tree'; import formsList from './sylius-forms-list'; diff --git a/src/Sylius/Bundle/AdminBundle/Resources/private/js/sylius-chart.js b/src/Sylius/Bundle/AdminBundle/Resources/private/js/sylius-chart.js new file mode 100644 index 0000000000..a66a595081 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/private/js/sylius-chart.js @@ -0,0 +1,43 @@ +import 'chart.js/dist/Chart.min'; + +const drawChart = function drawChart(canvas) { + const labels = canvas.getAttribute('data-labels'); + const values = canvas.getAttribute('data-values'); + + const chartElement = new Chart(canvas, { + type: 'bar', + data: { + labels: JSON.parse(labels), + datasets: [{ + data: JSON.parse(values), + backgroundColor: 'rgba(26, 187, 156, 0.3)', + borderColor: 'rgba(26, 187, 156, 1)', + borderWidth: 1, + }], + }, + options: { + scales: { + yAxes: [{ + ticks: { + beginAtZero: true, + }, + }], + xAxes: [{ + gridLines: { + display: false, + }, + }], + }, + responsive: true, + maintainAspectRatio: false, + legend: { + display: false, + }, + }, + }); +}; + +const canvas = document.getElementById('dashboard-chart'); +if (canvas) { + drawChart(canvas); +} diff --git a/src/Sylius/Bundle/AdminBundle/Resources/translations/messages.en.yml b/src/Sylius/Bundle/AdminBundle/Resources/translations/messages.en.yml index 0d09f8e1d4..cabfdd99c2 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/translations/messages.en.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/translations/messages.en.yml @@ -46,3 +46,4 @@ sylius: ui: gateway: no_sca_support_notice: The chosen payment gateway does not support SCA. + sales_summary: Sales summary diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Dashboard/_chart.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Dashboard/_chart.html.twig new file mode 100644 index 0000000000..d6f9431880 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Dashboard/_chart.html.twig @@ -0,0 +1,15 @@ +{% set labels, values = + ['02.19', '03.19', '04.19', '05.19', '06.19', '07.19', '08.19', '09.19', '10.19', '11.19', '12.19', '01.20'], + [399, 1200, 199, 788, 399, 1100, 199, 23, 399, 999, 199, 567] +%} + +{% if labels and values %} +