Skip to content

Commit 203c00b

Browse files
authored
[DOCS] Update chart js to v4 port to 2024 (#23018)
port from #23008
1 parent b54f753 commit 203c00b

File tree

2 files changed

+16
-29
lines changed

2 files changed

+16
-29
lines changed

docs/sphinx_setup/_static/js/graphs.js

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ $(document).ready(function () {
821821

822822
// Text
823823
const textContainer = document.createElement('p');
824-
textContainer.style.color = item.fontColor;
824+
textContainer.style.color = '#666';
825825
textContainer.style.margin = 0;
826826
textContainer.style.padding = 0;
827827
textContainer.style.fontSize = '0.6rem';
@@ -838,40 +838,39 @@ $(document).ready(function () {
838838
}
839839
};
840840

841-
// ====================================================
842-
843841
function getChartOptions(title, containerId) {
844842
return {
845843
responsive: true,
844+
indexAxis: 'y',
846845
maintainAspectRatio: false,
847-
legend: {display: false},
848846
title: {
849847
display: false,
850848
text: title
851849
},
852850
scales: {
853-
xAxes: [{
851+
x: {
854852
ticks: {
855853
beginAtZero: true
856854
}
857-
}],
858-
yAxes: [{
855+
},
856+
y: {
859857
ticks: {
860-
display: false, //this will remove only the label
858+
display: false,
861859
beginAtZero: true
862860
}
863-
}]
861+
}
864862
},
865863
plugins: {
864+
legend: {
865+
display: false
866+
},
866867
htmlLegend: {
867-
// ID of the container to put the legend in
868868
containerID: containerId,
869869
}
870870
}
871871
}
872872
}
873873

874-
// params: string[], Datasets[]
875874
function getChartDataNew(labels, datasets) {
876875
return {
877876
labels: labels,
@@ -948,24 +947,13 @@ $(document).ready(function () {
948947
var graphConfigs = kpis.map((str) => {
949948
var kpi = str.toLowerCase();
950949
var groupUnit = model[0];
951-
if (kpi === 'throughput') {
952-
var throughputData = Graph.getDatabyKPI(model, kpi);
953-
var config = Graph.getGraphConfig(kpi, groupUnit, precisions);
954-
precisions.forEach((prec, index) => {
955-
config.datasets[index].data = throughputData.map(tData => tData[prec]);
956-
});
957-
return config;
958-
//to fix
959-
// return removeEmptyLabel(config);
960-
}
961-
else if(kpi === 'latency'){
962-
var latencyData = Graph.getDatabyKPI(model, kpi);
950+
if (kpi === 'throughput' || kpi === 'latency') {
951+
var kpiData = Graph.getDatabyKPI(model, kpi);
963952
var config = Graph.getGraphConfig(kpi, groupUnit, precisions);
964953
precisions.forEach((prec, index) => {
965-
config.datasets[index].data = latencyData.map(tData => tData[prec]);
954+
config.datasets[index].data = kpiData.map(tData => tData[prec]);
966955
});
967-
return config;
968-
// return removeEmptyLabel(config);
956+
return removeEmptyLabel(config);
969957
}
970958
var config = Graph.getGraphConfig(kpi, groupUnit);
971959
config.datasets[0].data = Graph.getDatabyKPI(model, kpi);
@@ -1040,7 +1028,6 @@ $(document).ready(function () {
10401028
sorted.forEach((index)=>{
10411029
config.datasets.splice(index,1);
10421030
})
1043-
console.log(config);
10441031
return config;
10451032
}
10461033

@@ -1062,7 +1049,7 @@ $(document).ready(function () {
10621049
context.canvas.height = heightRatio;
10631050
window.setTimeout(() => {
10641051
new Chart(context, {
1065-
type: 'horizontalBar',
1052+
type: 'bar',
10661053
data: getChartDataNew(labels, datasets),
10671054
options: getChartOptions(chartTitle, containerId),
10681055
plugins: [htmlLegendPlugin]

docs/sphinx_setup/_templates/layout.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<link rel="stylesheet" href="{{ pathto('_static/css/banner.css', 1) }}" type="text/css" />
1414
<link rel="stylesheet" href="{{ pathto('_static/css/coveo_custom.css', 1) }}" type="text/css" />
1515

16-
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.3/dist/Chart.min.js"></script>
16+
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js"></script>
1717
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels"></script>
1818
<script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-annotation/0.5.7/chartjs-plugin-annotation.min.js"></script>
1919
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/Plugin.Barchart.Background.min.js"></script>

0 commit comments

Comments
 (0)