Skip to content

Commit

Permalink
IBX-6881: Upgrade chart.js to 4.4.0:
Browse files Browse the repository at this point in the history
  • Loading branch information
Gengar-i committed Nov 14, 2023
1 parent 9c89d0e commit 82f9505
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 45 deletions.
12 changes: 5 additions & 7 deletions src/bundle/Resources/public/js/scripts/core/bar.chart.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
(function (global, doc, ibexa) {
const barDefaultOptions = {
scales: {
xAxes: [
{
display: true,
gridLines: {
display: false,
},
x: {
display: true,
grid: {
display: false,
},
],
},
},
};

Expand Down
10 changes: 7 additions & 3 deletions src/bundle/Resources/public/js/scripts/core/base.chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
const defaultOptions = {
responsive: true,
maintainAspectRatio: false,
legend: {
display: false,
plugins: {
legend: {
display: false,
},
},
tooltips: {
enabled: true,
Expand Down Expand Up @@ -74,7 +76,9 @@
}

render() {
this.chart = new Chart(this.canvas.getContext('2d'), {
// console.log(window);
// console.log(this.labels, this.datasets);
this.chart = new Chart(this.canvas, {
type: this.getType(),
data: {
labels: this.labels,
Expand Down
15 changes: 15 additions & 0 deletions src/bundle/Resources/public/js/scripts/core/doughnut.chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(function (global, doc, ibexa) {
class DoughnutChart extends ibexa.core.BaseChart {
constructor(data) {
super(data);

this.type = 'doughnut';
}

getType() {
return this.type;
}
}

ibexa.addConfig('core.chart.Doughnut', DoughnutChart);
})(window, window.document, window.ibexa);
53 changes: 19 additions & 34 deletions src/bundle/Resources/public/js/scripts/core/line.chart.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function (global, doc, ibexa, Chart) {
(function (global, doc, ibexa, moment) {
const MAX_NUMBER_OF_LABELS = 16;
const lineDefaultOptions = {
elements: {
Expand All @@ -10,41 +10,26 @@
},
},
scales: {
xAxes: [
{
display: true,
gridLines: {
display: false,
},
ticks: {
maxRotation: 0,
autoSkip: false,
callback: (value, index, labels) => {
const labelsInterval = Math.max(Math.ceil(labels.length / MAX_NUMBER_OF_LABELS), 1);
const shouldDisplayLabel = !(index % labelsInterval);

return shouldDisplayLabel ? value : null;
},
},
x: {
display: true,
grid: {
display: false,
},
],
yAxes: [
{
display: true,
type: 'logarithmic',
ticks: {
callback: (...args) => {
const value = Chart.Ticks.formatters.logarithmic.call(this, ...args);

if (value.length) {
return Number(value).toLocaleString();
}

return value;
},
ticks: {
maxRotation: 0,
autoSkip: false,
callback: function (value, index, ticks) {
const label = this.getLabelForValue(value);
const labelsInterval = Math.max(Math.ceil(ticks.length / MAX_NUMBER_OF_LABELS), 1);
const shouldDisplayLabel = !(index % labelsInterval);

return shouldDisplayLabel ? label : null;
},
},
],
},
y: {
display: true,
},
},
};

Expand All @@ -70,4 +55,4 @@
}

ibexa.addConfig('core.chart.LineChart', LineChart);
})(window, window.document, window.ibexa, window.Chart);
})(window, window.document, window.ibexa, window.moment);
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<script src="{{ asset('bundles/ibexaadminuiassets/vendors/moment-timezone/builds/moment-timezone-with-data.min.js') }}"></script>
<script src="{{ asset('bundles/bazingajstranslation/js/translator.min.js') }}"></script>
<script src="{{ asset('assets/translations/config.js') }}"></script>
<script src="{{ asset('bundles/ibexaadminuiassets/vendors/chart-js/dist/Chart.min.js') }}"></script>
<script src="{{ asset('bundles/ibexaadminuiassets/vendors/chart-js/dist/chart.umd.js') }}"></script>
<script src="{{ asset('bundles/ibexaadminuiassets/vendors/js-md5/build/md5.min.js') }}"></script>
</head>
<body class="{% block body_class %}{% endblock %}">
Expand Down

0 comments on commit 82f9505

Please sign in to comment.