Skip to content

Commit 0b8a404

Browse files
committed
Make clicking on points bring you to commit ranges
So you can see what changes caused the performance change (probably).
1 parent 71155da commit 0b8a404

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

‎source/benchmarks/ruby-bench.html.haml‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,20 @@
7575
categories: graphElement.data('ruby-versions'),
7676
xAxisLabels: {
7777
formatter: function() {
78-
var date = Number(this.value);
79-
var sha = rubies[date];
80-
if (sha) {
81-
return '<a href="https://github.com/ruby/ruby/commit/' + sha + '">' + RubyBench.formatDate(date) + '</a>';
78+
var url = RubyBench.commitRangeUrl(rubies, this.axis.categories, this.pos);
79+
if (url) {
80+
return '<a href="' + url + '">' + RubyBench.formatDate(this.value) + '</a>';
8281
} else {
83-
return RubyBench.formatDate(date);
82+
return RubyBench.formatDate(this.value);
8483
}
8584
}
8685
},
86+
onPointClick: function() {
87+
var url = RubyBench.commitRangeUrl(rubies, this.series.xAxis.categories, this.x);
88+
if (url) {
89+
window.open(url, '_blank');
90+
}
91+
},
8792
tooltip: {
8893
formatter: function() {
8994
var date = Number(this.category);

‎source/javascripts/site.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ var RubyBench = (function() {
1111
return String(year) + '-' + String(month).padStart(2, '0') + '-' + String(day).padStart(2, '0');
1212
}
1313

14+
// GitHub URL showing the ruby/ruby changes that landed between the
15+
// previous charted day's commit and this day's commit. Falls back to the
16+
// single commit when there is no earlier sha to compare against.
17+
function commitRangeUrl(rubies, categories, index) {
18+
var sha = rubies[Number(categories[index])];
19+
if (!sha) {
20+
return null;
21+
}
22+
var prevSha = null;
23+
for (var i = index - 1; i >= 0 && !prevSha; i--) {
24+
prevSha = rubies[Number(categories[i])];
25+
}
26+
if (prevSha && prevSha !== sha) {
27+
return 'https://github.com/ruby/ruby/compare/' + prevSha + '...' + sha;
28+
}
29+
return 'https://github.com/ruby/ruby/commit/' + sha;
30+
}
31+
1432
// Initialize Highcharts defaults
1533
function initHighchartsDefaults() {
1634
Highcharts.setOptions({
@@ -65,6 +83,14 @@ var RubyBench = (function() {
6583
defaultConfig.legend = options.legend;
6684
}
6785

86+
// Make points clickable if a handler is provided
87+
if (options.onPointClick) {
88+
defaultConfig.plotOptions.series.cursor = 'pointer';
89+
defaultConfig.plotOptions.series.point = {
90+
events: { click: options.onPointClick }
91+
};
92+
}
93+
6894
// Add plot lines if provided
6995
if (options.yAxisPlotLines) {
7096
defaultConfig.yAxis.plotLines = options.yAxisPlotLines;
@@ -217,6 +243,7 @@ var RubyBench = (function() {
217243
// Public API
218244
return {
219245
formatDate: formatDate,
246+
commitRangeUrl: commitRangeUrl,
220247
initHighchartsDefaults: initHighchartsDefaults,
221248
createBaseChartConfig: createBaseChartConfig,
222249
plotChart: plotChart,

0 commit comments

Comments
 (0)