Skip to content

Commit 16ffaaf

Browse files
authored
Merge pull request ceph#53582 from rhcs-dashboard/chartjs-upgrade
mgr/dashboard: chartjs and ng2-charts version upgrade Reviewed-by: Nizamudeen A <[email protected]>
2 parents 34d5a7f + 14d2f0a commit 16ffaaf

23 files changed

+355
-372
lines changed

src/pybind/mgr/dashboard/frontend/angular.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@
9999
"node_modules/ngx-toastr/toastr.css",
100100
"src/styles.scss"
101101
],
102-
"scripts": [
103-
"node_modules/chart.js/dist/Chart.bundle.js"
104-
],
105102
"stylePreprocessorOptions": {
106103
"includePaths": [
107104
"src"

src/pybind/mgr/dashboard/frontend/package-lock.json

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

src/pybind/mgr/dashboard/frontend/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,16 @@
6262
"@types/file-saver": "2.0.1",
6363
"async-mutex": "0.2.4",
6464
"bootstrap": "5.2.3",
65-
"chart.js": "2.9.4",
65+
"chart.js": "4.4.0",
66+
"chartjs-adapter-moment": "1.0.1",
6667
"detect-browser": "5.2.0",
6768
"file-saver": "2.0.2",
6869
"fork-awesome": "1.1.7",
6970
"lodash": "4.17.21",
7071
"moment": "2.29.4",
7172
"ng-block-ui": "3.0.2",
7273
"ng-click-outside": "7.0.0",
73-
"ng2-charts": "2.4.2",
74+
"ng2-charts": "4.1.1",
7475
"ngx-pipe-function": "1.0.0",
7576
"ngx-toastr": "17.0.2",
7677
"rxjs": "6.6.3",

src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-configuration-list/rbd-configuration-list.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { RouterTestingModule } from '@angular/router/testing';
55

66
import { NgbDropdownModule, NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
77
import { NgxDatatableModule } from '@swimlane/ngx-datatable';
8-
import { ChartsModule } from 'ng2-charts';
8+
import { NgChartsModule } from 'ng2-charts';
99

1010
import { ComponentsModule } from '~/app/shared/components/components.module';
1111
import { RbdConfigurationEntry } from '~/app/shared/models/configuration';
@@ -27,7 +27,7 @@ describe('RbdConfigurationListComponent', () => {
2727
RouterTestingModule,
2828
ComponentsModule,
2929
NgbDropdownModule,
30-
ChartsModule,
30+
NgChartsModule,
3131
SharedModule,
3232
NgbTooltipModule
3333
],

src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-chart/cephfs-chart.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#chartCanvas
44
[datasets]="chart.datasets"
55
[options]="chart.options"
6-
[chartType]="chart.chartType">
6+
[type]="chart.chartType">
77
</canvas>
88
<div class="chartjs-tooltip"
99
#chartTooltip>

src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-chart/cephfs-chart.component.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22

3-
import { ChartsModule } from 'ng2-charts';
3+
import { NgChartsModule } from 'ng2-charts';
44

55
import { configureTestBed } from '~/testing/unit-test-helper';
66
import { CephfsChartComponent } from './cephfs-chart.component';
7+
import { ResizeObserver as ResizeObserverPolyfill } from '@juggle/resize-observer';
78

89
describe('CephfsChartComponent', () => {
910
let component: CephfsChartComponent;
@@ -17,7 +18,7 @@ describe('CephfsChartComponent', () => {
1718
];
1819

1920
configureTestBed({
20-
imports: [ChartsModule],
21+
imports: [NgChartsModule],
2122
declarations: [CephfsChartComponent]
2223
});
2324

@@ -29,6 +30,9 @@ describe('CephfsChartComponent', () => {
2930
'mds_mem.ino': counter,
3031
name: 'a'
3132
};
33+
if (typeof window !== 'undefined') {
34+
window.ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
35+
}
3236
fixture.detectChanges();
3337
});
3438

src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-chart/cephfs-chart.component.ts

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Component, ElementRef, Input, OnChanges, OnInit, ViewChild } from '@angular/core';
22

3-
import { ChartDataSets, ChartOptions, ChartPoint, ChartType } from 'chart.js';
43
import _ from 'lodash';
54
import moment from 'moment';
5+
import 'chartjs-adapter-moment';
66

77
import { ChartTooltip } from '~/app/shared/models/chart-tooltip';
88

@@ -24,78 +24,78 @@ export class CephfsChartComponent implements OnChanges, OnInit {
2424
rhsCounter = 'mds_server.handle_client_request';
2525

2626
chart: {
27-
datasets: ChartDataSets[];
28-
options: ChartOptions;
29-
chartType: ChartType;
27+
datasets: any[];
28+
options: any;
29+
chartType: any;
3030
} = {
3131
datasets: [
3232
{
3333
label: this.lhsCounter,
3434
yAxisID: 'LHS',
3535
data: [],
36-
lineTension: 0.1
36+
tension: 0.1,
37+
fill: {
38+
target: 'origin'
39+
}
3740
},
3841
{
3942
label: this.rhsCounter,
4043
yAxisID: 'RHS',
4144
data: [],
42-
lineTension: 0.1
45+
tension: 0.1,
46+
fill: {
47+
target: 'origin'
48+
}
4349
}
4450
],
4551
options: {
46-
title: {
47-
text: '',
48-
display: true
52+
plugins: {
53+
title: {
54+
text: '',
55+
display: true
56+
},
57+
tooltip: {
58+
enabled: false,
59+
mode: 'index',
60+
intersect: false,
61+
position: 'nearest',
62+
callbacks: {
63+
// Pick the Unix timestamp of the first tooltip item.
64+
title: (context: any): string => {
65+
let ts = '';
66+
if (context.length > 0) {
67+
ts = context[0].label;
68+
}
69+
return moment(ts).format('LTS');
70+
}
71+
}
72+
},
73+
legend: {
74+
position: 'top'
75+
}
4976
},
5077
responsive: true,
5178
maintainAspectRatio: false,
52-
legend: {
53-
position: 'top'
54-
},
5579
scales: {
56-
xAxes: [
57-
{
58-
position: 'top',
59-
type: 'time',
60-
time: {
61-
displayFormats: {
62-
quarter: 'MMM YYYY'
63-
}
64-
},
65-
ticks: {
66-
maxRotation: 0
80+
x: {
81+
position: 'top',
82+
type: 'time',
83+
time: {
84+
displayFormats: {
85+
quarter: 'MMM YYYY'
6786
}
68-
}
69-
],
70-
yAxes: [
71-
{
72-
id: 'LHS',
73-
type: 'linear',
74-
position: 'left'
7587
},
76-
{
77-
id: 'RHS',
78-
type: 'linear',
79-
position: 'right'
80-
}
81-
]
82-
},
83-
tooltips: {
84-
enabled: false,
85-
mode: 'index',
86-
intersect: false,
87-
position: 'nearest',
88-
callbacks: {
89-
// Pick the Unix timestamp of the first tooltip item.
90-
title: (tooltipItems, data): string => {
91-
let ts = 0;
92-
if (tooltipItems.length > 0) {
93-
const item = tooltipItems[0];
94-
const point = data.datasets[item.datasetIndex].data[item.index] as ChartPoint;
95-
ts = point.x as number;
96-
}
97-
return ts.toString();
88+
ticks: {
89+
maxRotation: 0
9890
}
91+
},
92+
LHS: {
93+
type: 'linear',
94+
position: 'left'
95+
},
96+
RHS: {
97+
type: 'linear',
98+
position: 'right'
9999
}
100100
}
101101
},
@@ -124,21 +124,20 @@ export class CephfsChartComponent implements OnChanges, OnInit {
124124
(tooltip: any) => tooltip.caretX + 'px',
125125
(tooltip: any) => tooltip.caretY - tooltip.height - 23 + 'px'
126126
);
127-
chartTooltip.getTitle = (ts) => moment(ts, 'x').format('LTS');
128127
chartTooltip.checkOffset = true;
129-
const chartOptions: ChartOptions = {
128+
const chartOptions: any = {
130129
title: {
131130
text: this.mdsCounter.name
132131
},
133-
tooltips: {
134-
custom: (tooltip) => chartTooltip.customTooltips(tooltip)
132+
tooltip: {
133+
external: (context: any) => chartTooltip.customTooltips(context)
135134
}
136135
};
137-
_.merge(this.chart, { options: chartOptions });
136+
_.merge(this.chart, { options: { plugins: chartOptions } });
138137
}
139138

140139
private updateChart() {
141-
const chartDataSets: ChartDataSets[] = [
140+
const chartDataset: any[] = [
142141
{
143142
data: this.convertTimeSeries(this.mdsCounter[this.lhsCounter])
144143
},
@@ -147,7 +146,7 @@ export class CephfsChartComponent implements OnChanges, OnInit {
147146
}
148147
];
149148
_.merge(this.chart, {
150-
datasets: chartDataSets
149+
datasets: chartDataset
151150
});
152151
this.chart.datasets = [...this.chart.datasets]; // Force angular to update
153152
}

0 commit comments

Comments
 (0)