Skip to content

Instantly share code, notes, and snippets.

@syui
Last active June 3, 2016 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syui/6738a7c2885b4e90eeb9be2dd8f38277 to your computer and use it in GitHub Desktop.
Save syui/6738a7c2885b4e90eeb9be2dd8f38277 to your computer and use it in GitHub Desktop.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="../static/js/jquery.xdomainajax.js"></script>
<script src="../static/bower_components/d3/d3.min.js" charset="utf-8"></script>
<script src="../static/bower_components/cal-heatmap/cal-heatmap.min.js"></script>
<link rel="stylesheet" href="../static/bower_components/cal-heatmap/cal-heatmap.css" />
<!--<script src="https://raw.githubusercontent.com/syui/jquery.fn/master/cross-domain-ajax/jquery.xdomainajax.js"></script>-->
<!--diff : https://github.com/syui/jquery.fn/blob/master/cross-domain-ajax/jquery.xdomainajax.js#L62 -->
<h3>Calendar Activities</h3>
<div id="cal-heatmap"></div>
<div id="example-heatmap"></div>
<script>
jQuery(function ($) {
var json;
$.ajax({
type: 'GET',
url: 'https://gitlab.com/u/syui/calendar',
dataType: 'html',
async: false,
cache: false,
success: function(data) {
var content = $(data.responseText).find('script').html();
var tmp = content.replace("<![CDATA[", "").replace("]]>", "");
var s = tmp.indexOf( "{" );
var e = tmp.indexOf( "}" );
json = tmp.substring( s, e+1 );
$('#gitlab-calendar-activities').text(json);
}
});
setTimeout( $('#example-heatmap').each(function () {
//setTimeout( function() {
if( json != null ){
var obj = $.parseJSON(json);
var now = new Date();
new CalHeatMap().init({
data: obj,
domain: 'month',
domainLabelFormat: '%Y-%m',
itemSelector: '#example-heatmap',
legend: [1, 3, 5, 7],
legendColors: {
min: "#efefef",
max: "steelblue",
empty: "#efefef"
},
tooltip: true,
start: new Date(now.getFullYear(), now.getMonth() - 9)
});
} else {
setTimeout( arguments.callee, 100 );
}
}));
});
</script>
<div id="gitlab-calendar-activities" style="display:none;"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment