Skip to content

Commit 48cae51

Browse files
committed
small-and-fast: recreate the diagrams using chart.js
The diagrams showing just how much faster Git performs than Subversion were originally created using the Google Charts API, in b6d341c (first graphs and new services, 2012-04-30). In the meantime, the Google Charts API joined so many other things in the Google Graveyard (see https://killedbygoogle.com/ for more details). This means that the diagrams 404ed, and users were left wondering what should have been demonstrated on this page. But when a door closes, another door opens, and there are wonderful contenders in this time and age, and we do not even have to display static images, we can switch to proper, Javascript-backed charts where you can even hover over the chart and see the exact number! So let's do that. Based on https://www.chartjs.org/, reimplement those charts. That also offers a wildly improved readability of the entire thing, compared to the somewhat cryptic Google Chart URLs. This fixes #1862. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 205db72 commit 48cae51

File tree

4 files changed

+72
-12
lines changed

4 files changed

+72
-12
lines changed

assets/js/application.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ $(document).ready(function() {
3434
Forms.init();
3535
Downloads.init();
3636
DownloadBox.init();
37+
BarCharts.init();
3738
});
3839

3940
function onPopState(fn) {
@@ -540,6 +541,54 @@ var Downloads = {
540541
$('#relative-release-date').html(Downloads.postProcessReleaseDate);
541542
},
542543
}
544+
var BarCharts = {
545+
init: function() {
546+
BarCharts.render();
547+
},
548+
549+
render: function() {
550+
$('barchart').each(function() {
551+
const label = $(this).attr('x-data-title');
552+
const pairs = $(this).attr('x-data').split(',');
553+
const data = pairs.reduce((data, pair) => {
554+
const [label, amount] = pair.split(':');
555+
data[label] = parseFloat(amount);
556+
return data;
557+
}, {});
558+
const backgroundColor = pairs.map(pair => pair.startsWith('git') ? '#E09FA0' : '#E05F49');
559+
560+
const canvas = document.createElement('canvas');
561+
new Chart(canvas, {
562+
type: 'bar',
563+
data: {
564+
datasets: [{
565+
data,
566+
backgroundColor,
567+
}]
568+
},
569+
options: {
570+
maintainAspectRatio: false,
571+
scales: {
572+
y: {
573+
display: false,
574+
beginAtZero: true,
575+
}
576+
},
577+
plugins: {
578+
legend: {
579+
display: false
580+
},
581+
title: {
582+
display: true,
583+
text: label,
584+
}
585+
}
586+
}
587+
});
588+
$(this).append(canvas);
589+
});
590+
}
591+
}
543592

544593
// Scroll to Top
545594
$('#scrollToTop').removeClass('no-js');

assets/sass/typography.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,12 @@ div.more {
371371
.text-center {
372372
text-align: center;
373373
}
374+
375+
barchart {
376+
width: 90px;
377+
height: 125px;
378+
padding-right: 5px;
379+
padding-left: 5px;
380+
display: inline-block;
381+
background-color: #fcfcfa7f;
382+
}

content/about/small-and-fast.html

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
display_class: "two-line"
77
aliases:
88
- /about/small-and-fast/index.html
9+
needs_chartjs: true
910
---
1011
<section class="about" id="small-and-fast">
1112

@@ -31,42 +32,42 @@ <h3>Benchmarks</h3>
3132
<tbody>
3233
<tr>
3334
<td>
34-
<img src="https://chart.googleapis.com/chart?chxt=x&amp;cht=bvs&amp;chl=git|svn&amp;chd=t:0.649,2.6&amp;chds=0,2.6&amp;chs=100x125&amp;chco=E09FA0|E05F49&amp;chf=bg,s,fcfcfa&amp;chtt=Commit A" alt="init benchmarks">
35+
<barchart x-data="git:0.649,svn:2.6" x-data-title="Commit A" alt="init benchmarks" />
3536
</td>
3637
<td>
37-
<img src="https://chart.googleapis.com/chart?chxt=x&amp;cht=bvs&amp;chl=git|svn&amp;chd=t:1.53,24.7&amp;chds=0,24.7&amp;chs=100x125&amp;chco=E09FA0|E05F49&amp;chf=bg,s,fcfcfa&amp;chtt=Commit B" alt="init benchmarks">
38+
<barchart x-data="git:1.53,svn:24.7" x-data-title="Commit B" alt="init benchmarks" />
3839
</td>
3940
<td>
40-
<img src="https://chart.googleapis.com/chart?chxt=x&amp;cht=bvs&amp;chl=git|svn&amp;chd=t:0.257,1.09&amp;chds=0,1.09&amp;chs=100x125&amp;chco=E09FA0|E05F49&amp;chf=bg,s,fcfcfa&amp;chtt=Diff Curr" alt="init benchmarks">
41+
<barchart x-data="git:0.257,svn:1.09" x-data-title="Diff Curr" alt="init benchmarks" />
4142
</td>
4243
<td>
43-
<img src="https://chart.googleapis.com/chart?chxt=x&amp;cht=bvs&amp;chl=git|svn&amp;chd=t:0.248,3.99&amp;chds=0,3.99&amp;chs=100x125&amp;chco=E09FA0|E05F49&amp;chf=bg,s,fcfcfa&amp;chtt=Diff Rec" alt="init benchmarks">
44+
<barchart x-data="git:0.248,svn:3.99" x-data-title="Diff Rec" alt="init benchmarks" />
4445
</td>
4546
<td>
46-
<img src="https://chart.googleapis.com/chart?chxt=x&amp;cht=bvs&amp;chl=git|svn&amp;chd=t:1.17,83.57&amp;chds=0,83.57&amp;chs=100x125&amp;chco=E09FA0|E05F49&amp;chf=bg,s,fcfcfa&amp;chtt=Diff Tags" alt="init benchmarks">
47+
<barchart x-data="git:1.17,svn:83.57" x-data-title="Diff Tags" alt="init benchmarks" />
4748
</td>
4849
<td>
49-
<img src="https://chart.googleapis.com/chart?chxt=x&amp;cht=bvs&amp;chl=git*|git|svn&amp;chd=t:21.0,107.5,14.0&amp;chds=0,107.5&amp;chs=100x125&amp;chco=E09FA0|E09FA0|E05F49&amp;chf=bg,s,fcfcfa&amp;chtt=Clone" alt="init benchmarks">
50+
<barchart x-data="git*:21.0,git:107.5,svn:14.0" x-data-title="Clone" alt="init benchmarks" />
5051
</td>
5152
</tr>
5253
<tr>
5354
<td>
54-
<img src="https://chart.googleapis.com/chart?chxt=x&amp;cht=bvs&amp;chl=git|svn&amp;chd=t:0.012,0.381&amp;chds=0,0.381&amp;chs=100x125&amp;chco=E09FA0|E05F49&amp;chf=bg,s,fcfcfa&amp;chtt=Log (50)" alt="init benchmarks">
55+
<barchart x-data="git:0.012,svn:0.381" x-data-title="Log (50)" alt="init benchmarks" />
5556
</td>
5657
<td>
57-
<img src="https://chart.googleapis.com/chart?chxt=x&amp;cht=bvs&amp;chl=git|svn&amp;chd=t:0.519,169.197&amp;chds=0,169.197&amp;chs=100x125&amp;chco=E09FA0|E05F49&amp;chf=bg,s,fcfcfa&amp;chtt=Log (All)" alt="init benchmarks">
58+
<barchart x-data="git:0.519,svn:169.197" x-data-title="Log (All)" alt="init benchmarks" />
5859
</td>
5960
<td>
60-
<img src="https://chart.googleapis.com/chart?chxt=x&amp;cht=bvs&amp;chl=git|svn&amp;chd=t:0.601,82.843&amp;chds=0,82.843&amp;chs=100x125&amp;chco=E09FA0|E05F49&amp;chf=bg,s,fcfcfa&amp;chtt=Log (File)" alt="init benchmarks">
61+
<barchart x-data="git:0.601,svn:82.843" x-data-title="Log (File)" alt="init benchmarks" />
6162
</td>
6263
<td>
63-
<img src="https://chart.googleapis.com/chart?chxt=x&amp;cht=bvs&amp;chl=git|svn&amp;chd=t:0.896,2.816&amp;chds=0,2.816&amp;chs=100x125&amp;chco=E09FA0|E05F49&amp;chf=bg,s,fcfcfa&amp;chtt=Update" alt="init benchmarks">
64+
<barchart x-data="git:0.896,svn:2.816" x-data-title="Update" alt="init benchmarks" />
6465
</td>
6566
<td>
66-
<img src="https://chart.googleapis.com/chart?chxt=x&amp;cht=bvs&amp;chl=git|svn&amp;chd=t:1.91,3.04&amp;chds=0,3.04&amp;chs=100x125&amp;chco=E09FA0|E05F49&amp;chf=bg,s,fcfcfa&amp;chtt=Blame" alt="init benchmarks">
67+
<barchart x-data="git:1.91,svn:3.04" x-data-title="Blame" alt="init benchmarks" />
6768
</td>
6869
<td>
69-
<img src="https://chart.googleapis.com/chart?chxt=x&amp;cht=bvs&amp;chl=git|svn&amp;chd=t:181,132&amp;chds=0,181&amp;chs=100x125&amp;chco=E09FA0|E05F49&amp;chf=bg,s,fcfcfa&amp;chtt=Size" alt="init benchmarks">
70+
<barchart x-data="git:181,svn:132" x-data-title="Size" alt="init benchmarks" />
7071
</td>
7172
</tr>
7273
</tbody>

layouts/partials/footer.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
<script src="{{ relURL "js/jquery.defaultvalue.js" }}"></script>
1717
<script src="{{ relURL "js/session.min.js" }}"></script>
1818
{{ if eq (.Scratch.Get "section") "search" }}<script src="{{ relURL "pagefind/pagefind-ui.js" }}"></script>{{ end }}
19+
{{ if eq .Page.Params.needs_chartjs true }}<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>{{ end }}
1920
{{ $js := resources.Get "js/application.js" | resources.ExecuteAsTemplate "js/application.js" . | resources.Minify }}
2021
<script src="{{ $js.RelPermalink }}"></script>

0 commit comments

Comments
 (0)