Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
Add hash-based permalink support and add zoom states to history.
Browse files Browse the repository at this point in the history
This goes through the AB.history object for zooming and hiding/showing operations.
  • Loading branch information
antifuchs committed May 3, 2011
1 parent f2992a0 commit e72452d
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 26 deletions.
103 changes: 84 additions & 19 deletions ht/public/javascript/autobench.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,68 @@
if (!AB) var AB = {};

AB.history = (function() {
function nonElementPart(str) {
return str.split(';')[1];
}

function elementPart(str) {
var elt = str.split(';')[0];
if (elt) return elt.substring(1);
}

function destructureImplReleaseSpec(spec) {
var implSpecAndVersion = spec.split('/');
if (implSpecAndVersion) {
var implSpec = implSpecAndVersion[0].split(',');
return [implSpecAndVersion[1], implSpec];
}
}

return {
changedTo: function(hash) {
var eltPart = elementPart(hash);
var elt;
if (eltPart) elt = AB.plot.benchmark_element[elementPart(hash)];
if (elt) {
$.scrollTo(elt.parent().parent());
}

var zoomConfig = nonElementPart(hash);
if (zoomConfig) {
if (!AB.plot.initialized) AB.plot.skipInit = true;
var releaseSpec = destructureImplReleaseSpec(zoomConfig);
AB.plot.zoomIn(releaseSpec[1], releaseSpec[0]);
} else if (AB.plot.zoomed) {
AB.plot.zoomOut();
}

return false;
},

zoomInWithHistory: function(series, version) {
var eltPart = elementPart(location.hash);
if (!eltPart) eltPart = '';
location.hash = eltPart + ';' + AB.plot.version_by_series[series] + '/' + version;
},

zoomOutWithHistory: function() {
var eltPart = elementPart(location.hash);
if (!eltPart) eltPart = '';
location.hash = eltPart;
},

jumpToBenchmark: function(benchmarkName) {
var versionSpec = nonElementPart(location.hash);
location.hash = benchmarkName + ';' + versionSpec;
},

clearCurrentBenchmark: function() {
var versionSpec = nonElementPart(location.hash);
location.hash = ';' + versionSpec;
}
};
})();

AB.mouse = (function() {
function showTooltip(x, y, id, contents) {
$('<div id="'+id+'" class="tooltip">' + contents + '</div>').css( {
Expand Down Expand Up @@ -87,7 +150,7 @@ AB.mouse = (function() {
gitlink = '<li><a onclick="window.open(this.href); return false;" href="http://git.boinkor.net/gitweb/sbcl.git?a=commit;h='+sha1+'">commit</a></li>';
}
if (!AB.plot.zoomed && canZoom(item.seriesIndex, item.datapoint[0])) {
zoomlink = '<li><a title="show minor revisions after this release" href="javascript:AB.plot.zoomIn(\''+item.seriesIndex+'\', \''+getVersion(item.seriesIndex, item.datapoint[0])+'\')">zoom</a></li>';
zoomlink = '<li><a title="show minor revisions after this release" href="javascript:AB.history.zoomInWithHistory(\''+item.seriesIndex+'\', \''+getVersion(item.seriesIndex, item.datapoint[0])+'\')">zoom</a></li>';
}
showTooltip(item.pageX, item.pageY, 'clicktip',
'<h4><span class="impl">'+getImplName(item.seriesIndex) + '</span><span class="version">' + getVersion(item.seriesIndex, item.datapoint[0]) + "</span></h4>"+
Expand All @@ -112,6 +175,10 @@ AB.plot = (function(){
};

return {
skipInit: false,

initialized: false,

zoomed: false,

// [benchmark] -> element containing the graph of that benchmark
Expand Down Expand Up @@ -143,23 +210,24 @@ AB.plot = (function(){
},

init: function() {
AB.plot.waitbox('Fetching data...');
$("input.impl").each(function(i, elt){
if (elt.checked){
AB.plot.fetch(destructureImplSpec(elt.id));
}
});
if (!AB.plot.skipInit) {
AB.plot.waitbox('Fetching data...');
$("input.impl").each(function(i, elt){
if (elt.checked){
AB.plot.fetch(destructureImplSpec(elt.id));
}
});
}
AB.plot.skipInit = false;
AB.plot.initialized = true;
},

zoomIn: function(series, release) {
zoomIn: function(implspec, release) {
if (AB.plot.zoomed)
return false;

AB.mouse.clear();
var implspec = AB.plot.version_by_series[series];
AB.plot.zoomed = {errors: AB.plot.errors,
versions: AB.plot.versions,
dataset: AB.plot.dataset};
AB.plot.zoomed = true;
AB.plot.errors = {}; AB.plot.versions = {}; AB.plot.dataset = {};
AB.plot.waitbox('Zooming in on release ' + release + '...');
$('#zoom-release-spec').text(release);
Expand All @@ -173,14 +241,10 @@ AB.plot = (function(){
return false;

AB.mouse.clear();
$.each(AB.plot.zoomed, function(key, val){
AB.plot[key] = AB.plot.zoomed[key];
});
$('#impl-selector').show();
$('body').removeClass('zoomed');
AB.plot.init();
AB.plot.zoomed = false;
AB.plot.waitbox('Zooming out...');
AB.plot.draw();
},

selectionChanged: function() {
Expand Down Expand Up @@ -337,7 +401,7 @@ AB.userPrefs = (function(){
$(elt).removeClass('hidden');
$('ul#hidden-benchmarks li a[class='+$(elt).attr('id')+']').parent().remove();
AB.plot.drawOne($(elt).attr('id'));
window.location.hash = $(elt).attr('id');
AB.history.jumpToBenchmark($(elt).attr('id'));
},

updateHideCookieValue: function(){
Expand All @@ -352,6 +416,7 @@ AB.userPrefs = (function(){
hideBenchmark: function(elt) {
AB.userPrefs.removeFromDisplay(elt);
AB.userPrefs.updateHideCookieValue();
AB.history.clearCurrentBenchmark();
},

showBenchmark: function(elt) {
Expand Down
121 changes: 121 additions & 0 deletions ht/public/javascript/jquery.hashchange-1.0.0.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/**
* jQuery hashchange 1.0.0
*
* (based on jquery.history)
*
* Copyright (c) 2008 Chris Leishman (chrisleishman.com)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*/
(function($) {

$.fn.extend({
hashchange: function(callback) { this.bind('hashchange', callback) },
openOnClick: function(href) {
if (href === undefined || href.length == 0)
href = '#';
return this.click(function(ev) {
if (href && href.charAt(0) == '#') {
// execute load in separate call stack
window.setTimeout(function() { $.locationHash(href) }, 0);
} else {
window.location(href);
}
ev.stopPropagation();
return false;
});
}
});

// IE 8 introduces the hashchange event natively - so nothing more to do
if ($.browser.msie && document.documentMode && document.documentMode >= 8) {
$.extend({
locationHash: function(hash) {
if (!hash) hash = '#';
else if (hash.charAt(0) != '#') hash = '#' + hash;
location.hash = hash;
}
});
return;
}

var curHash;
// hidden iframe for IE (earlier than 8)
var iframe;

$.extend({
locationHash: function(hash) {
if (curHash === undefined) return;

if (!hash) hash = '#';
else if (hash.charAt(0) != '#') hash = '#' + hash;

location.hash = hash;

if (curHash == hash) return;
curHash = hash;

if ($.browser.msie) updateIEFrame(hash);
$.event.trigger('hashchange');
}
});

$(document).ready(function() {
curHash = location.hash;
if ($.browser.msie) {
// stop the callback firing twice during init if no hash present
if (curHash == '') curHash = '#';
// add hidden iframe for IE
iframe = $('<iframe />').hide().get(0);
$('body').prepend(iframe);
updateIEFrame(location.hash);
setInterval(checkHashIE, 100);
} else {
setInterval(checkHash, 100);
}
});
$(window).unload(function() { iframe = null });

function checkHash() {
var hash = location.hash;
if (hash != curHash) {
curHash = hash;
$.event.trigger('hashchange');
}
}

if ($.browser.msie) {
// Attach a live handler for any anchor links
$('a[href^=#]').live('click', function() {
var hash = $(this).attr('href');
// Don't intercept the click if there is an existing anchor on the page
// that matches this hash
if ($(hash).length == 0 && $('a[name='+hash.slice(1)+']').length == 0) {
$.locationHash(hash);
return false;
}
});
}

function checkHashIE() {
// On IE, check for location.hash of iframe
var idoc = iframe.contentDocument || iframe.contentWindow.document;
var hash = idoc.location.hash;
if (hash == '') hash = '#';

if (hash != curHash) {
if (location.hash != hash) location.hash = hash;
curHash = hash;
$.event.trigger('hashchange');
}
}

function updateIEFrame(hash) {
if (hash == '#') hash = '';
var idoc = iframe.contentWindow.document;
idoc.open();
idoc.close();
if (idoc.location.hash != hash) idoc.location.hash = hash;
}

})(jQuery);
11 changes: 11 additions & 0 deletions ht/public/javascript/jquery.scrollTo-1.4.2-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 13 additions & 7 deletions ht/views/boinkmarks/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
<script src="/javascript/jquery-1.3.2.min.js"></script>
<script language="javascript" type="text/javascript" src="/javascript/autobench.js"></script>
<script language="javascript" type="text/javascript" src="/javascript/jquery.modaldialog.js"></script>
<script language="javascript" type="text/javascript" src="/javascript/jquery.cookies.2.0.1.min.js"></script>
<script language="javascript" type="text/javascript" src="/javascript/jquery.json-1.3.min.js"></script>
<script language="javascript" type="text/javascript" src="/javascript/jquery.hashchange-1.0.0.js"></script>
<script language="javascript" type="text/javascript" src="/javascript/jquery.scrollTo-1.4.2-min.js"></script>
<script language="javascript" type="text/javascript" src="/javascript/jquery.cookies.2.0.1.min.js"></script>
<script language="javascript" type="text/javascript" src="/javascript/jquery.json-1.3.min.js"></script>
<script language="javascript" type="text/javascript" src="/javascript/jquery.flot.js"></script>
<!--[if IE]><script language="javascript" type="text/javascript" src="/javascript/excanvas.min.js"></script><![endif]-->
</head>
Expand Down Expand Up @@ -44,7 +46,7 @@ <h1>Boinkmarks: Automated CL benchmarks</h1>
</div>
<div id="zoom-box" class="box">
<div class="box-head"><h3>Showing release <span id="zoom-release-spec"></span></h3></div>
<div class="box-body"><button id="zoom-out" onclick="AB.plot.zoomOut();return false;">Zoom out</button></div>
<div class="box-body"><button id="zoom-out" onclick="AB.history.zoomOutWithHistory();return false;">Zoom out</button></div>
</div>
<div id="hidden-benchmarks-box" class="box">
<div class="box-head"><h3>Hidden benchmarks</h3></div>
Expand All @@ -57,7 +59,7 @@ <h1>Boinkmarks: Automated CL benchmarks</h1>
<!-- TMPL_LOOP benchmarks -->
<div id="<!-- tmpl_var benchmark -->" class="graph shown">
<div class="graph-title">
<a name="<!-- TMPL_VAR benchmark -->"></a>
<a rel="anchor" name="<!-- TMPL_VAR benchmark -->"></a>
<a href="#<!-- TMPL_VAR benchmark -->">
<h3><!-- TMPL_VAR benchmark --></h3>
</a>
Expand All @@ -79,9 +81,13 @@ <h3><!-- TMPL_VAR benchmark --></h3>
<!-- /TMPL_LOOP -->
</div>
<script type="text/javascript" defer="defer">
$.cookies.setOptions({hoursToLive: 8544});
AB.userPrefs.init();
AB.plot.init();
$(document).ready(function(){
$(window).hashchange(function(){AB.history.changedTo(location.hash)});
AB.history.changedTo(location.hash);
$.cookies.setOptions({hoursToLive: 8544});
AB.userPrefs.init();
AB.plot.init();
});
</script>
</body>
</html>

0 comments on commit e72452d

Please sign in to comment.