PluginProbe
ElasticPress / 4.7.1
ElasticPress v4.7.1
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 4.7.1, at assets/js/stats.js

103 lines 2.0 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';
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 Chart.defaults.global.legend.labels.usePointStyle = true;
29
30 barData.forEach(function (data) {
31 barLabels.push(data[1].name);
32 barDocs.push(data[1].docs);
33 barColors.push(getRandomColor());
34 });
35
36 const documentChart = document.getElementById('documentChart');
37 if (documentChart) {
38 new Chart(documentChart, {
39 type: 'horizontalBar',
40 data: {
41 labels: barLabels,
42 datasets: [
43 {
44 label: 'Documents',
45 backgroundColor: barColors,
46 data: barDocs,
47 },
48 ],
49 },
50 options: {
51 legend: {
52 display: false,
53 },
54 title: {
55 display: true,
56 },
57 },
58 });
59 }
60
61 const queriesTotalChart = document.getElementById('queriesTotalChart');
62 if (queriesTotalChart) {
63 new Chart(document.getElementById('queriesTotalChart'), {
64 type: 'pie',
65 data: {
66 labels: ['Indexing operations', 'Total Query operations'],
67 datasets: [
68 {
69 label: '',
70 backgroundColor: ['#5ba9a7', '#2e7875', '#a980a4'],
71 data: [epChartData.index_total, epChartData.query_total],
72 },
73 ],
74 },
75 options: {
76 responsive: false,
77 title: {
78 display: true,
79 },
80 legend: {
81 position: 'right',
82 },
83 tooltips: {
84 callbacks: {
85 /**
86 * Appends the string operations before tooltip value
87 *
88 * @param {object} item Chat item
89 * @param {object} data Data
90 * @returns {string} Operations
91 */
92 label(item, data) {
93 const dataset = data.datasets[item.datasetIndex];
94 const currentValue = dataset.data[item.index];
95
96 return `Operations: ${currentValue}`;
97 },
98 },
99 },
100 },
101 });
102 }
103