PluginProbe
ElasticPress / 5.3.5
ElasticPress v5.3.5
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
elasticpress / assets / js / stats.js

stats.js in ElasticPress 5.3.5, at assets/js/stats.js

109 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* eslint-disable no-new */
2
3 import Chart from 'chart.js/auto';
4
5 const { epChartData } = window;
6
7 /**
8 * Generates a random string representing a color.
9 *
10 * @returns {string} Random color
11 */
12 function getRandomColor() {
13 const letters = '0123456789ABCDEF';
14 let color = '#';
15
16 for (let i = 0; i < 6; i += 1) {
17 color += letters[Math.floor(Math.random() * 16)];
18 }
19
20 return color;
21 }
22
23 const barData = Object.entries(epChartData.indices_data);
24 const barLabels = [];
25 const barDocs = [];
26 const barColors = [];
27
28 barData.forEach(function (data) {
29 barLabels.push(data[1].name);
30 barDocs.push(data[1].docs);
31 barColors.push(getRandomColor());
32 });
33
34 const documentChart = document.getElementById('documentChart');
35 if (documentChart) {
36 new Chart(documentChart, {
37 type: 'bar',
38 data: {
39 labels: barLabels,
40 datasets: [
41 {
42 label: 'Documents',
43 backgroundColor: barColors,
44 data: barDocs,
45 },
46 ],
47 },
48 options: {
49 indexAxis: 'y',
50 plugins: {
51 legend: {
52 display: false,
53 },
54 },
55 title: {
56 display: true,
57 },
58 },
59 });
60 }
61
62 const queriesTotalChart = document.getElementById('queriesTotalChart');
63 if (queriesTotalChart) {
64 new Chart(document.getElementById('queriesTotalChart'), {
65 type: 'pie',
66 data: {
67 labels: ['Indexing operations', 'Total Query operations'],
68 datasets: [
69 {
70 label: '',
71 backgroundColor: ['#5ba9a7', '#2e7875', '#a980a4'],
72 data: [epChartData.index_total, epChartData.query_total],
73 },
74 ],
75 },
76 options: {
77 responsive: false,
78 title: {
79 display: true,
80 },
81 plugins: {
82 legend: {
83 position: 'right',
84 labels: {
85 usePointStyle: true,
86 },
87 },
88 },
89 tooltips: {
90 callbacks: {
91 /**
92 * Appends the string operations before tooltip value
93 *
94 * @param {object} item Chat item
95 * @param {object} data Data
96 * @returns {string} Operations
97 */
98 label(item, data) {
99 const dataset = data.datasets[item.datasetIndex];
100 const currentValue = dataset.data[item.index];
101
102 return `Operations: ${currentValue}`;
103 },
104 },
105 },
106 },
107 });
108 }
109