metripy 0.3.2__py3-none-any.whl → 0.3.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of metripy might be problematic. Click here for more details.

@@ -0,0 +1,313 @@
1
+ /**
2
+ * Charts JavaScript
3
+ * Handles Chart.js functionality for git commits visualization and other charts
4
+ */
5
+
6
+ class ChartManager {
7
+ constructor() {
8
+ this.charts = {};
9
+ this.data = {};
10
+ this.colors = {
11
+ primary: '#3b82f6',
12
+ primaryGradient: {
13
+ start: 'rgba(59, 130, 246, 0.8)',
14
+ end: 'rgba(59, 130, 246, 0.1)'
15
+ },
16
+ success: '#10b981',
17
+ warning: '#f59e0b',
18
+ danger: '#ef4444',
19
+ info: '#06b6d4',
20
+ text: '#1e293b',
21
+ textSecondary: '#64748b',
22
+ border: '#e2e8f0'
23
+ };
24
+ this.init();
25
+ }
26
+
27
+ init() {
28
+ this.setupChartDefaults();
29
+ this.initializeCharts();
30
+ }
31
+
32
+ setupChartDefaults() {
33
+ // Configure Chart.js global defaults
34
+ Chart.defaults.font.family = 'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';
35
+ Chart.defaults.font.size = 12;
36
+ Chart.defaults.color = this.colors.textSecondary;
37
+ Chart.defaults.borderColor = this.colors.border;
38
+ Chart.defaults.backgroundColor = this.colors.primary;
39
+
40
+ // Configure responsive defaults
41
+ Chart.defaults.responsive = true;
42
+ Chart.defaults.maintainAspectRatio = false;
43
+
44
+ // Configure animation defaults
45
+ /*
46
+ This had the consequence of hindering license chart rendering
47
+ Chart.defaults.animation = {
48
+ duration: 1000,
49
+ easing: 'easeOutQuart'
50
+ };
51
+ */
52
+ }
53
+
54
+ initializeCharts() {
55
+ // Wait for DOM to be ready and data to be available
56
+ this.waitForData().then(() => {
57
+ this.createGitCommitsChart();
58
+ // Add more chart initializations here as needed
59
+ });
60
+ }
61
+
62
+ waitForData() {
63
+ return new Promise((resolve) => {
64
+ const checkData = () => {
65
+ if (window.dashboard && window.dashboard.data && window.dashboard.data.gitCommits) {
66
+ this.data = window.dashboard.data;
67
+ console.log('Git commits data loaded:', this.data.gitCommits.length, 'months');
68
+ resolve();
69
+ } else {
70
+ setTimeout(checkData, 100);
71
+ }
72
+ };
73
+ checkData();
74
+ });
75
+ }
76
+
77
+ createGitCommitsChart() {
78
+ const canvas = document.getElementById('gitCommitsChart');
79
+ if (!canvas) {
80
+ console.warn('Git commits chart canvas not found');
81
+ return;
82
+ }
83
+
84
+ const ctx = canvas.getContext('2d');
85
+
86
+ // Prepare data for the chart
87
+ const chartData = this.prepareGitCommitsData();
88
+
89
+ // Create gradient
90
+ const gradient = ctx.createLinearGradient(0, 0, 0, 300);
91
+ gradient.addColorStop(0, this.colors.primaryGradient.start);
92
+ gradient.addColorStop(1, this.colors.primaryGradient.end);
93
+
94
+ this.charts.gitCommits = new Chart(ctx, {
95
+ type: 'line',
96
+ data: {
97
+ labels: chartData.labels,
98
+ datasets: [{
99
+ label: 'Commits',
100
+ data: chartData.values,
101
+ borderColor: this.colors.primary,
102
+ backgroundColor: gradient,
103
+ borderWidth: 3,
104
+ fill: true,
105
+ tension: 0.4,
106
+ pointBackgroundColor: this.colors.primary,
107
+ pointBorderColor: '#ffffff',
108
+ pointBorderWidth: 2,
109
+ pointRadius: 6,
110
+ pointHoverRadius: 8,
111
+ pointHoverBackgroundColor: this.colors.primary,
112
+ pointHoverBorderColor: '#ffffff',
113
+ pointHoverBorderWidth: 3
114
+ }]
115
+ },
116
+ options: {
117
+ responsive: true,
118
+ maintainAspectRatio: false,
119
+ interaction: {
120
+ intersect: false,
121
+ mode: 'index'
122
+ },
123
+ plugins: {
124
+ legend: {
125
+ display: false
126
+ },
127
+ tooltip: {
128
+ backgroundColor: 'rgba(0, 0, 0, 0.8)',
129
+ titleColor: '#ffffff',
130
+ bodyColor: '#ffffff',
131
+ borderColor: this.colors.primary,
132
+ borderWidth: 1,
133
+ cornerRadius: 8,
134
+ displayColors: false,
135
+ titleFont: {
136
+ size: 14,
137
+ weight: 'bold'
138
+ },
139
+ bodyFont: {
140
+ size: 13
141
+ },
142
+ padding: 12,
143
+ callbacks: {
144
+ title: (context) => {
145
+ return context[0].label;
146
+ },
147
+ label: (context) => {
148
+ const value = context.parsed.y;
149
+ const plural = value === 1 ? 'commit' : 'commits';
150
+ return `${value} ${plural}`;
151
+ }
152
+ }
153
+ }
154
+ },
155
+ scales: {
156
+ x: {
157
+ display: true,
158
+ grid: {
159
+ display: false
160
+ },
161
+ border: {
162
+ display: false
163
+ },
164
+ ticks: {
165
+ color: this.colors.textSecondary,
166
+ font: {
167
+ size: 11,
168
+ weight: '500'
169
+ },
170
+ maxRotation: 0,
171
+ padding: 10
172
+ }
173
+ },
174
+ y: {
175
+ display: true,
176
+ beginAtZero: true,
177
+ grid: {
178
+ color: this.colors.border,
179
+ drawBorder: false
180
+ },
181
+ border: {
182
+ display: false
183
+ },
184
+ ticks: {
185
+ color: this.colors.textSecondary,
186
+ font: {
187
+ size: 11,
188
+ weight: '500'
189
+ },
190
+ padding: 10,
191
+ callback: function(value) {
192
+ if (value === 0) return '0';
193
+ return value % 1 === 0 ? value : '';
194
+ }
195
+ }
196
+ }
197
+ },
198
+ animation: {
199
+ duration: 1500,
200
+ easing: 'easeOutQuint'
201
+ },
202
+ elements: {
203
+ point: {
204
+ hoverRadius: 8
205
+ }
206
+ }
207
+ }
208
+ });
209
+
210
+ // Add chart resize handler
211
+ this.addResizeHandler('gitCommits');
212
+ }
213
+
214
+ prepareGitCommitsData() {
215
+ if (!this.data.gitCommits) return { labels: [], values: [] };
216
+
217
+ const data = [...this.data.gitCommits];
218
+
219
+ return {
220
+ labels: data.map(item => item.month),
221
+ values: data.map(item => item.commits)
222
+ };
223
+ }
224
+
225
+
226
+ updateData(newData) {
227
+ this.data.gitCommits = newData;
228
+
229
+ if (this.charts.gitCommits) {
230
+ const chartData = this.prepareGitCommitsData();
231
+
232
+ this.charts.gitCommits.data.labels = chartData.labels;
233
+ this.charts.gitCommits.data.datasets[0].data = chartData.values;
234
+
235
+ this.charts.gitCommits.update('active');
236
+ }
237
+ }
238
+
239
+ addResizeHandler(chartName) {
240
+ if (!this.charts[chartName]) return;
241
+
242
+ const resizeObserver = new ResizeObserver(entries => {
243
+ this.charts[chartName].resize();
244
+ });
245
+
246
+ const canvas = this.charts[chartName].canvas;
247
+ if (canvas && canvas.parentElement) {
248
+ resizeObserver.observe(canvas.parentElement);
249
+ }
250
+ }
251
+
252
+ destroyChart(chartName) {
253
+ if (this.charts[chartName]) {
254
+ this.charts[chartName].destroy();
255
+ delete this.charts[chartName];
256
+ }
257
+ }
258
+
259
+ destroyAllCharts() {
260
+ Object.keys(this.charts).forEach(chartName => {
261
+ this.destroyChart(chartName);
262
+ });
263
+ }
264
+
265
+ // Utility methods
266
+ hexToRgba(hex, alpha = 1) {
267
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
268
+ if (!result) return null;
269
+
270
+ const r = parseInt(result[1], 16);
271
+ const g = parseInt(result[2], 16);
272
+ const b = parseInt(result[3], 16);
273
+
274
+ return `rgba(${r}, ${g}, ${b}, ${alpha})`;
275
+ }
276
+
277
+ formatNumber(num) {
278
+ if (num >= 1000000) {
279
+ return (num / 1000000).toFixed(1) + 'M';
280
+ } else if (num >= 1000) {
281
+ return (num / 1000).toFixed(1) + 'K';
282
+ }
283
+ return num.toString();
284
+ }
285
+ }
286
+
287
+ // Initialize chart manager when DOM is loaded
288
+ document.addEventListener('DOMContentLoaded', () => {
289
+ window.chartManager = new ChartManager();
290
+ });
291
+
292
+ // Handle page visibility changes to pause/resume animations
293
+ document.addEventListener('visibilitychange', () => {
294
+ if (window.chartManager) {
295
+ Object.values(window.chartManager.charts).forEach(chart => {
296
+ if (document.hidden) {
297
+ chart.stop();
298
+ } else {
299
+ chart.update('none');
300
+ }
301
+ });
302
+ }
303
+ });
304
+
305
+ // Handle window beforeunload to cleanup
306
+ window.addEventListener('beforeunload', () => {
307
+ if (window.chartManager) {
308
+ window.chartManager.destroyAllCharts();
309
+ }
310
+ });
311
+
312
+ // Export for global access
313
+ window.ChartManager = ChartManager;