PluginProbe
ElasticPress / 4.3.1
ElasticPress v4.3.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.3.1, at assets/js/stats.js

146 lines 3.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
104 const queriesTimeChart = document.getElementById('queriesTimeChart');
105 if (queriesTimeChart) {
106 new Chart(queriesTimeChart, {
107 type: 'pie',
108 data: {
109 labels: ['Avg indexing time in ms', 'Avg query time in ms'],
110 datasets: [
111 {
112 label: '',
113 backgroundColor: ['#9ea6c7', '#93b3d5'],
114 data: [epChartData.index_time_in_millis, epChartData.query_time_in_millis],
115 },
116 ],
117 },
118 options: {
119 responsive: false,
120 title: {
121 display: true,
122 },
123 legend: {
124 position: 'right',
125 },
126 tooltips: {
127 callbacks: {
128 /**
129 * Appends the string milliseconds after tooltip value
130 *
131 * @param {object} item Tooltip item
132 * @param {object} data Tooltip data
133 * @returns {string} current value in milliseconds
134 */
135 label(item, data) {
136 const dataset = data.datasets[item.datasetIndex];
137 const currentValue = dataset.data[item.index];
138
139 return `${+currentValue} milliseconds`;
140 },
141 },
142 },
143 },
144 });
145 }
146