-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchart.js
More file actions
639 lines (546 loc) · 21 KB
/
Copy pathchart.js
File metadata and controls
639 lines (546 loc) · 21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
import fs from 'fs';
import path from 'path';
import { JSDOM } from 'jsdom';
import * as d3 from 'd3';
//import { fileURLToPath } from 'url';
//import { dirname } from 'path';
import simpleGit from 'simple-git';
async function getRepoPath() {
const git = simpleGit();
const repoPath = await git.revparse(['--show-toplevel']);
return repoPath.trim(); // Đảm bảo loại bỏ khoảng trắng thừa
}
// Lấy đường dẫn đến repository hiện tại từ biến môi trường GITHUB_WORKSPACE
const __dirname = await getRepoPath();;
if (!__dirname) {
throw new Error('GITHUB_WORKSPACE environment variable is not set');
}
console.log(`Current repository path: ${__dirname}`);
// Sử dụng repoPath để xây dựng các đường dẫn tới các file hoặc thư mục trong repository
const dataFilePath = path.join(__dirname, './data.json');
export function generateCharts() {
fs.readFile(dataFilePath, "utf8", (err, jsonString) => {
if (err) {
console.log("File read failed:", err);
return;
}
try {
const data = JSON.parse(jsonString);
createChart(data);
createTotalCommitChart(data);
createTotalCommitBy6MonthChart(data);
createContributionsBy6MonthChart(data);
createMembersBy6MonthChart(data);
createLanguagesChart(data);
} catch (err) {
console.log("Error parsing JSON string:", err);
}
});
}
function createChart(data) {
const labels = ["Total Stars", "Total PRs", "Total Merged PRs", "Total Contributions"];
const values = [data.totalStars, data.totalPRs, data.totalMergedPRs, data.totalContributions];
const width = 600;
const height = 400;
const margin = { top: 20, right: 30, bottom: 40, left: 40 };
const dom = new JSDOM('<!DOCTYPE html><html><body><div id="container"></div></body></html>');
const body = d3.select(dom.window.document).select('body');
const svg = body.select('#container').append('svg')
.attr('xmlns', 'http://www.w3.org/2000/svg')
.style('background-color', '#f0f0f0') // Màu nền của biểu đồ
.attr('width', width)
.attr('height', height);
const x = d3.scaleBand()
.domain(labels)
.range([margin.left, width - margin.right])
.padding(0.1);
const y = d3.scaleLinear()
.domain([0, d3.max(values)]).nice()
.range([height - margin.bottom, margin.top]);
const bar = svg.selectAll('.bar')
.data(values)
.join('rect')
.attr('class', 'bar')
.attr('x', (d, i) => x(labels[i]))
.attr('y', d => y(d))
.attr('height', d => y(0) - y(d))
.attr('width', x.bandwidth())
.attr('fill', '#249324');
// Thêm giá trị vào từng cột
svg.selectAll('.text')
.data(values)
.join('text')
.attr('class', 'text')
.attr('x', (d, i) => x(labels[i]) + x.bandwidth() / 2)
.attr('y', d => y(d) - 5)
.attr('text-anchor', 'middle')
.style('fill', 'black')
.style('font-size', '12px')
.text(d => d);
svg.append('g')
.attr('class', 'x-axis')
.attr('transform', `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).tickSizeOuter(0))
.selectAll("text")
.attr("fill", "black");
svg.append('g')
.attr('class', 'y-axis')
.attr('transform', `translate(${margin.left},0)`)
.call(d3.axisLeft(y))
.selectAll("text")
.attr("fill", "black");
svg.append('text')
.attr('x', (width / 2))
.attr('y', margin.top)
.attr('text-anchor', 'middle')
.style('font-size', '20px')
.style('fill', 'black')
.text('Total Information');
// Tạo thư mục 'img' nếu chưa tồn tại
const imgDir = path.join(__dirname, './img');
if (!fs.existsSync(imgDir)) {
fs.mkdirSync(imgDir);
console.log('Created directory: img');
}
const svgString = body.select('#container').html();
fs.writeFileSync(path.join(__dirname, "./img", "Information.svg"), svgString);
console.log("The SVG file was created.");
}
function createTotalCommitChart(data) {
const totalMemberCommits = data.totalMemberCommits;
const diverseBoldColors = [
'#B20000', '#0073A5', '#B2B200', '#B200B2', '#483D8B',
'#CC8400', '#00008B', '#3B4B27', '#54586B', '#701C1C',
'#249324', '#167E7E', '#FF5733', '#33FF57', '#3357FF',
'#FF33A1', '#FFD700', '#8A2BE2', '#DC143C', '#FF8C00',
'#32CD32', '#8B0000', '#00CED1'
];
const margin = { top: 100, right: 50, bottom: 100, left: 50 };
const fullWidth = 800; // Độ rộng toàn bộ biểu đồ
const fullHeight = 600; // Độ cao toàn bộ biểu đồ
const chartWidth = fullWidth - margin.left - margin.right;
const chartHeight = fullHeight - margin.top - margin.bottom;
// Tạo một instance JSDOM và chọn body của document
const dom = new JSDOM('<!DOCTYPE html><html><body><div id="container"></div></body></html>');
const body = d3.select(dom.window.document).select('body');
// Tạo svg element để chứa biểu đồ
const svg = body.select('#container').append('svg')
.attr('xmlns', 'http://www.w3.org/2000/svg')
.style('background-color', '#f0f0f0') // Màu nền của biểu đồ
.attr('width', fullWidth)
.attr('height', fullHeight);
// Tạo group element để vẽ biểu đồ trong svg
const chart = svg.append('g')
.attr('transform', `translate(${margin.left},${margin.top})`);
// Định nghĩa scale cho trục x và y
const x = d3.scaleBand()
.domain(Object.keys(totalMemberCommits))
.range([0, chartWidth])
.padding(0.1);
const y = d3.scaleLinear()
.domain([0, d3.max(Object.values(totalMemberCommits))])
.nice()
.range([chartHeight, 0]);
// Vẽ trục x và y
chart.append('g')
.attr('class', 'x-axis')
.attr('transform', `translate(0,${chartHeight})`)
.call(d3.axisBottom(x))
.selectAll('text')
.style('text-anchor', 'end')
.attr('dx', '-.8em')
.attr('dy', '.15em')
.attr('transform', 'rotate(-45)')
.style('overflow', 'visible');
chart.append('g')
.attr('class', 'y-axis')
.call(d3.axisLeft(y).ticks(10));
// Vẽ các cột biểu đồ và thêm giá trị vào mỗi cột
chart.selectAll('.bar')
.data(Object.entries(totalMemberCommits))
.enter().append('rect')
.attr('class', 'bar')
.attr('x', d => x(d[0]))
.attr('y', d => y(d[1]))
.attr('width', x.bandwidth())
.attr('height', d => chartHeight - y(d[1]))
.attr('fill', (d, i) => diverseBoldColors[i % diverseBoldColors.length])
.append('title') // Thêm title element để hiển thị tooltip
.text(d => `${d[0]}: ${d[1]}`); // Hiển thị tên và giá trị của từng cột khi hover
// Thêm tiêu đề cho biểu đồ
chart.append('text')
.attr('x', chartWidth / 2)
.attr('y', -margin.top / 2)
.attr('text-anchor', 'middle')
.style('font-size', '20px')
.style('fill', 'black')
.text('Total Commits By Members');
// Tạo thư mục 'img' nếu chưa tồn tại
const imgDir = path.join(__dirname, './img');
if (!fs.existsSync(imgDir)) {
fs.mkdirSync(imgDir);
console.log('Created directory: img');
}
// Lưu biểu đồ thành file SVG
const svgString = body.select('#container').html();
fs.writeFileSync(path.join(__dirname, './img', 'TotalMembersCommit.svg'), svgString);
console.log('The SVG file was created.');
}
function createTotalCommitBy6MonthChart(data) {
const totalMemberCommits = data.by6month.summary;
const diverseBoldColors = [
'#B20000', '#0073A5', '#B2B200', '#B200B2', '#483D8B',
'#CC8400', '#00008B', '#3B4B27', '#54586B', '#701C1C',
'#249324', '#167E7E', '#FF5733', '#33FF57', '#3357FF',
'#FF33A1', '#FFD700', '#8A2BE2', '#DC143C', '#FF8C00',
'#32CD32', '#8B0000', '#00CED1'
];
const margin = { top: 100, right: 50, bottom: 100, left: 50 };
const fullWidth = 800; // Độ rộng toàn bộ biểu đồ
const fullHeight = 600; // Độ cao toàn bộ biểu đồ
const chartWidth = fullWidth - margin.left - margin.right;
const chartHeight = fullHeight - margin.top - margin.bottom;
// Tạo một instance JSDOM và chọn body của document
const dom = new JSDOM('<!DOCTYPE html><html><body><div id="container"></div></body></html>');
const body = d3.select(dom.window.document).select('body');
// Tạo svg element để chứa biểu đồ
const svg = body.select('#container').append('svg')
.attr('xmlns', 'http://www.w3.org/2000/svg')
.style('background-color', '#f0f0f0') // Màu nền của biểu đồ
.attr('width', fullWidth)
.attr('height', fullHeight);
// Tạo group element để vẽ biểu đồ trong svg
const chart = svg.append('g')
.attr('transform', `translate(${margin.left},${margin.top})`);
// Định nghĩa scale cho trục x và y
const x = d3.scaleBand()
.domain(Object.keys(totalMemberCommits))
.range([0, chartWidth])
.padding(0.1);
const y = d3.scaleLinear()
.domain([0, d3.max(Object.values(totalMemberCommits))])
.nice()
.range([chartHeight, 0]);
// Vẽ trục x và y
chart.append('g')
.attr('class', 'x-axis')
.attr('transform', `translate(0,${chartHeight})`)
.call(d3.axisBottom(x))
.selectAll('text')
.style('text-anchor', 'end')
.attr('dx', '-.8em')
.attr('dy', '.15em')
.attr('transform', 'rotate(-45)');
chart.append('g')
.attr('class', 'y-axis')
.call(d3.axisLeft(y).ticks(10));
// Vẽ các cột biểu đồ
chart.selectAll('.bar')
.data(Object.entries(totalMemberCommits))
.enter().append('rect')
.attr('class', 'bar')
.attr('x', d => x(d[0]))
.attr('y', d => y(d[1]))
.attr('width', x.bandwidth())
.attr('height', d => chartHeight - y(d[1]))
.attr('fill', (d, i) => diverseBoldColors[i % diverseBoldColors.length])
.append('title')
.text(d => `${d[0]}: ${d[1]}`); // Thêm title element để hiển thị tooltip
// Thêm tiêu đề cho biểu đồ
chart.append('text')
.attr('x', chartWidth / 2)
.attr('y', -margin.top / 2)
.attr('text-anchor', 'middle')
.style('font-size', '20px')
.style('fill', 'black')
.text('Total Commits By Members (Last 6 Months)');
// Tạo thư mục 'img' nếu chưa tồn tại
const imgDir = path.join(__dirname, './img');
if (!fs.existsSync(imgDir)) {
fs.mkdirSync(imgDir);
console.log('Created directory: img');
}
const svgString = body.select('#container').html();
fs.writeFileSync(path.join(__dirname, './img', 'TotalMembersCommitBy6Month.svg'), svgString);
console.log('The SVG file was created.');
}
function createContributionsBy6MonthChart(data) {
const by6month = data.by6month;
const months = Object.keys(by6month)
.filter(month => month !== 'summary')
.reverse();
const margin = { top: 50, right: 50, bottom: 50, left: 50 };
const fullWidth = 800; // Độ rộng toàn bộ biểu đồ
const fullHeight = 600; // Độ cao toàn bộ biểu đồ
const chartWidth = fullWidth - margin.left - margin.right;
const chartHeight = fullHeight - margin.top - margin.bottom;
// Tạo một instance JSDOM và chọn body của document
const dom = new JSDOM('<!DOCTYPE html><html><body><div id="container"></div></body></html>');
const body = d3.select(dom.window.document).select('body');
// Tạo svg element để chứa biểu đồ
const svg = body.select('#container').append('svg')
.attr('xmlns', 'http://www.w3.org/2000/svg')
.style('background-color', '#f0f0f0') // Màu nền của biểu đồ
.attr('width', fullWidth)
.attr('height', fullHeight);
// Tạo group element để vẽ biểu đồ trong svg
const chart = svg.append('g')
.attr('transform', `translate(${margin.left},${margin.top})`);
// Định nghĩa scale cho trục x và y
const x = d3.scaleBand()
.domain(months)
.range([0, chartWidth])
.padding(0.1);
const y = d3.scaleLinear()
.domain([0, d3.max(months.map(month => by6month[month].total))])
.nice()
.range([chartHeight, 0]);
// Vẽ lưới dọc
chart.append('g')
.attr('class', 'grid')
.call(d3.axisLeft(y)
.ticks(5)
.tickSize(-chartWidth)
.tickFormat('')
);
// Vẽ lưới ngang
chart.append('g')
.attr('class', 'grid')
.attr('transform', `translate(0,${chartHeight})`)
.call(d3.axisBottom(x)
.tickSize(-chartHeight)
.tickFormat('')
);
// Vẽ đường biểu đồ
chart.append('path')
.datum(months.map(month => ({ month, value: by6month[month].total })))
.attr('fill', 'none')
.attr('stroke', '#FF0000')
.attr('stroke-width', 2)
.attr('d', d3.line()
.x(d => x(d.month) + x.bandwidth() / 2)
.y(d => y(d.value))
.curve(d3.curveLinear)
);
// Hiển thị giá trị của từng điểm dữ liệu
chart.selectAll('.point')
.data(months.map(month => ({ month, value: by6month[month].total })))
.enter().append('circle')
.attr('class', 'point')
.attr('cx', d => x(d.month) + x.bandwidth() / 2)
.attr('cy', d => y(d.value))
.attr('r', 4)
.attr('fill', '#FF0000');
// Thêm nhãn cho các điểm dữ liệu
chart.selectAll('.label')
.data(months.map(month => ({ month, value: by6month[month].total })))
.enter().append('text')
.attr('class', 'label')
.attr('x', d => x(d.month) + x.bandwidth() / 2)
.attr('y', d => y(d.value) - 10)
.attr('text-anchor', 'middle')
.style('font-size', '12px')
.style('fill', '#333')
.text(d => d.value);
// Vẽ trục x và y
chart.append('g')
.attr('class', 'x-axis')
.attr('transform', `translate(0,${chartHeight})`)
.call(d3.axisBottom(x));
chart.append('g')
.attr('class', 'y-axis')
.call(d3.axisLeft(y).ticks(5));
// Thêm tiêu đề cho biểu đồ
chart.append('text')
.attr('x', chartWidth / 2)
.attr('y', -margin.top / 2)
.attr('text-anchor', 'middle')
.style('font-size', '20px')
.style('fill', 'black')
.text('Total Contributions By ORG (per month for the past 6 months)');
// Tạo thư mục 'img' nếu chưa tồn tại
const imgDir = path.join(__dirname, './img');
if (!fs.existsSync(imgDir)) {
fs.mkdirSync(imgDir);
console.log('Created directory: img');
}
const svgString = body.select('#container').html();
fs.writeFileSync(path.join(__dirname, './img', 'TotalContributionsBy6Month.svg'), svgString);
console.log('The SVG file was created.');
}
function createMembersBy6MonthChart(data) {
const diverseBoldColors = [
"#B20000", "#0073A5", "#B2B200", "#B200B2", "#483D8B",
"#CC8400", "#00008B", "#3B4B27", "#54586B", "#701C1C",
"#249324", "#167E7E", "#FF5733", "#33FF57", "#3357FF",
"#FF33A1", "#FFD700", "#8A2BE2", "#DC143C", "#FF8C00",
"#32CD32", "#8B0000", "#00CED1"
];
const margin = { top: 100, right: 100, bottom: 100, left: 80 };
const fullWidth = 800;
const fullHeight = 600;
const chartWidth = fullWidth - margin.left - margin.right;
const chartHeight = fullHeight - margin.top - margin.bottom;
// Tạo một instance JSDOM và chọn body của document
const dom = new JSDOM('<!DOCTYPE html><html><body><div id="container"></div></body></html>');
const body = d3.select(dom.window.document).select('body');
// Tạo svg element để chứa biểu đồ
const svg = body.select('#container').append('svg')
.attr('xmlns', 'http://www.w3.org/2000/svg')
.style('background-color', '#f0f0f0') // Màu nền của biểu đồ
.attr('width', fullWidth)
.attr('height', fullHeight);
// Tạo group element để vẽ biểu đồ trong svg
const chart = svg.append('g')
.attr('transform', `translate(${margin.left},${margin.top})`);
// Chuẩn bị dữ liệu cho biểu đồ cột xếp chồng
const months = Object.keys(data.by6month).filter(month => month !== "summary");
const teams = Object.keys(data.by6month[months[0]]).filter(team => team !== "total");
const stackedData = d3.stack().keys(teams)(months.map(month => ({
month,
...data.by6month[month]
})));
// Định nghĩa scale cho trục x và y
const x = d3.scaleBand()
.domain(months)
.range([0, chartWidth])
.padding(0.1);
const y = d3.scaleLinear()
.domain([0, d3.max(stackedData[stackedData.length - 1], d => d[1])])
.nice()
.range([chartHeight, 0]);
// Vẽ các cột biểu đồ
chart.selectAll('.bar')
.data(stackedData)
.enter().append('g')
.attr('fill', d => {
const index = teams.indexOf(d.key);
return diverseBoldColors[index % diverseBoldColors.length];
})
.selectAll('rect')
.data(d => d)
.enter().append('rect')
.attr('x', d => x(d.data.month))
.attr('y', d => y(d[1]))
.attr('height', d => y(d[0]) - y(d[1]))
.attr('width', x.bandwidth());
// Vẽ trục x và y
chart.append('g')
.attr('class', 'x-axis')
.attr('transform', `translate(0,${chartHeight})`)
.call(d3.axisBottom(x))
.selectAll('text')
.style('text-anchor', 'end')
.attr('dx', '-.8em')
.attr('dy', '.15em')
.attr('transform', 'rotate(-45)');
chart.append('g')
.attr('class', 'y-axis')
.call(d3.axisLeft(y).ticks(10));
// Thêm tiêu đề cho biểu đồ
chart.append('text')
.attr('x', chartWidth / 2)
.attr('y', -margin.top / 2)
.attr('text-anchor', 'middle')
.style('font-size', '20px')
.style('fill', 'black')
.text('Commits by Members (per month for the past 6 months)');
// Thêm chú thích về màu sắc
const legend = chart.append('g')
.attr('class', 'legend')
.attr('transform', `translate(0, ${chartHeight + margin.bottom / 2})`);
const legendItems = legend.selectAll('.legend-item')
.data(teams)
.enter().append('g')
.attr('class', 'legend-item')
.attr('transform', (d, i) => `translate(${i % 6 * 120},${Math.floor(i / 6) * 20})`);
legendItems.append('rect')
.attr('x', 0)
.attr('y', 0)
.attr('width', 10)
.attr('height', 10)
.attr('fill', (d, i) => diverseBoldColors[i % diverseBoldColors.length]);
legendItems.append('text')
.attr('x', 15)
.attr('y', 5)
.text(d => d)
.style('font-size', '12px')
.attr('alignment-baseline', 'middle');
// Tạo thư mục 'img' nếu chưa tồn tại
const imgDir = path.join(__dirname, './img');
if (!fs.existsSync(imgDir)) {
fs.mkdirSync(imgDir);
console.log('Created directory: img');
}
// Lưu biểu đồ thành file SVG
const svgString = body.select('#container').html();
fs.writeFileSync(path.join(__dirname, './img', 'MemberCommitBy6Month.svg'), svgString);
console.log('The SVG file was created.');
}
function createLanguagesChart(data) {
const dom = new JSDOM('<!DOCTYPE html><html><body><div id="container"></div></body></html>');
const body = d3.select(dom.window.document).select('body');
const totalLanguages = data.totalLanguages;
const totalLines = Object.values(totalLanguages).reduce((a, b) => a + b, 0);
const diverseBoldColors = [
"#B20000", "#0073A5", "#B2B200", "#B200B2", "#483D8B",
"#CC8400", "#00008B", "#3B4B27", "#54586B", "#701C1C",
"#249324", "#167E7E", "#FF5733", "#33FF57", "#3357FF",
"#FF33A1", "#FFD700", "#8A2BE2", "#DC143C", "#FF8C00",
"#32CD32", "#8B0000", "#00CED1"
];
const pie = d3.pie().sort(null).value(d => d[1]);
const arc = d3.arc().innerRadius(0).outerRadius(Math.min(300, 300) / 2 - 1);
const svg = body.select('#container').append('svg')
.attr('xmlns', 'http://www.w3.org/2000/svg')
.style('background-color', '#f0f0f0') // Màu nền của biểu đồ
.attr('width', 800)
.attr('height', 400)
.append('g')
.attr('transform', 'translate(300,200)');
const arcs = svg.selectAll('arc')
.data(pie(Object.entries(totalLanguages)))
.enter().append('g')
.attr('class', 'arc');
arcs.append('path')
.attr('d', arc)
.attr('fill', (d, i) => diverseBoldColors[i % diverseBoldColors.length]);
const legend = svg.append('g')
.attr('transform', `translate(200, -150)`);
const legendItems = legend.selectAll('.legend-item')
.data(Object.entries(totalLanguages))
.enter().append('g')
.attr('class', 'legend-item')
.attr('transform', (d, i) => `translate(0, ${i * 20})`);
legendItems.append('rect')
.attr('x', -20)
.attr('width', 10)
.attr('height', 10)
.attr('fill', (d, i) => diverseBoldColors[i % diverseBoldColors.length]);
legendItems.append('text')
.attr('x', 0)
.attr('y', 6)
.attr('dy', '.35em')
.style('text-anchor', 'start')
.text(d => `${d[0]}: ${((d[1] / totalLines) * 100).toFixed(2)}%`);
svg.append('text')
.attr('x', 0)
.attr('y', -180)
.attr('text-anchor', 'middle')
.style('font-size', '20px')
.style('fill', 'black')
.text('Total Languages');
// Tạo thư mục 'img' nếu chưa tồn tại
const imgDir = path.join(__dirname, './img');
if (!fs.existsSync(imgDir)) {
fs.mkdirSync(imgDir);
console.log('Created directory: img');
}
const svgString = body.select('#container').html();
const filePath = path.join(__dirname,"./img", 'TotalLanguages.svg');
fs.writeFileSync(filePath, svgString);
console.log(`The SVG file was created.`);
console.log(`${filePath}`);
}
export default generateCharts ;
//generateCharts();