cal_heatmap_rails 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +28 -0
- data/LICENSE_CALHEATMAP.txt +22 -0
- data/LICENSE_D3JS.txt +29 -0
- data/LICENSE_D3_RAILS.txt +28 -0
- data/README.md +57 -0
- data/Rakefile +1 -0
- data/cal_heatmap_rails.gemspec +23 -0
- data/lib/cal_heatmap_rails/engine.rb +4 -0
- data/lib/cal_heatmap_rails/version.rb +4 -0
- data/lib/cal_heatmap_rails.rb +5 -0
- data/vendor/assets/javascripts/cal-heatmap.js +2029 -0
- data/vendor/assets/javascripts/cal-heatmap.min.js +9 -0
- data/vendor/assets/javascripts/cal_heatmap_rails.js +2 -0
- data/vendor/assets/stylesheets/cal-heatmap.css +108 -0
- data/vendor/assets/stylesheets/cal_heatmap_rails.css +1 -0
- metadata +90 -0
@@ -0,0 +1,9 @@
|
|
1
|
+
/*! cal-heatmap v3.0.9 (Thu Aug 01 2013 18:58:34)
|
2
|
+
* ---------------------------------------------
|
3
|
+
* Cal-Heatmap is a javascript module to create calendar heatmap to visualize time series data, a la github contribution graph
|
4
|
+
* https://github.com/kamisama/cal-heatmap
|
5
|
+
* Licensed under the MIT license
|
6
|
+
* Copyright 2013 Wan Qi Chen
|
7
|
+
*/
|
8
|
+
function mergeRecursive(t,n){for(var e in n)try{t[e]=n[e].constructor===Object?mergeRecursive(t[e],n[e]):n[e]}catch(o){t[e]=n[e]}return t}var CalHeatMap=function(){"use strict";function t(){return n._domains=n.getDomain(n.options.start).map(function(t){return t.getTime()}),n.root=d3.select(n.options.itemSelector),n.root.append("svg").attr("class","graph"),n.options.paintOnLoad&&(n.paint(),n.options.nextSelector!==!1&&d3.select(n.options.nextSelector).on("click."+n.options.itemNamespace,function(){return d3.event.preventDefault(),n.loadNextDomain()}),n.options.previousSelector!==!1&&d3.select(n.options.previousSelector).on("click."+n.options.itemNamespace,function(){return d3.event.preventDefault(),n.loadPreviousDomain()}),n.options.displayLegend&&n.displayLegend(i.width-n.options.domainGutter-n.options.cellPadding),null!==n.options.afterLoad&&n.afterLoad(),n.options.loadOnInit?n.getDatas(n.options.data,new Date(n._domains[0]),n.getSubDomain(n._domains[n._domains.length-1]).pop(),function(t){n.fill(t,n.svg)}):n.onComplete()),!0}var n=this,e=["json","csv","tsv","txt"];this.options={itemSelector:"#cal-heatmap",paintOnLoad:!0,range:12,cellSize:10,cellPadding:2,cellRadius:0,domainGutter:2,domainMargin:[0,0,0,0],domain:"hour",subDomain:"min",weekStartOnMonday:!0,start:new Date,minDate:null,maxDate:null,data:"",dataType:e[0],considerMissingDataAsZero:!1,loadOnInit:!0,verticalOrientation:!1,domainDynamicDimension:!0,label:{position:"bottom",align:"center",offset:{x:0,y:0},rotate:null,width:100},legend:[10,20,30,40],displayLegend:!0,legendCellSize:10,legendCellPadding:2,legendMargin:[10,0,0,0],legendVerticalPosition:"bottom",legendHorizontalPosition:"left",highlight:[],itemName:["item","items"],domainLabelFormat:null,subDomainTitleFormat:{empty:"{date}",filled:"{count} {name} {connector} {date}"},subDomainDateFormat:null,subDomainTextFormat:null,legendTitleFormat:{lower:"less than {min} {name}",inner:"between {down} and {up} {name}",upper:"more than {max} {name}"},animationDuration:500,nextSelector:!1,previousSelector:!1,itemNamespace:"cal-heatmap",onClick:null,afterLoad:null,afterLoadNextDomain:function(){},afterLoadPreviousDomain:function(){},onComplete:null,afterLoadData:function(t){return t},onMaxDomainReached:function(){},onMinDomainReached:function(){}},this._domainType={min:{name:"minute",level:10,row:function(){return 10},column:function(){return 6},position:{x:function(t){return Math.floor(t.getMinutes()/n._domainType.min.row(t))},y:function(t){return t.getMinutes()%n._domainType.min.row(t)}},format:{date:"%H:%M, %A %B %-e, %Y",legend:"",connector:"at"},extractUnit:function(t){return t.getMinutes()}},hour:{name:"hour",level:20,row:function(){return 6},column:function(t){switch(n.options.domain){case"day":return 4;case"week":return 28;case"month":return 4*(n.options.domainDynamicDimension?n.getEndOfMonth(t).getDate():31)}},position:{x:function(t){return"month"===n.options.domain?Math.floor(t.getHours()/n._domainType.hour.row(t))+4*(t.getDate()-1):"week"===n.options.domain?Math.floor(t.getHours()/n._domainType.hour.row(t))+4*n.getWeekDay(t):Math.floor(t.getHours()/n._domainType.hour.row(t))},y:function(t){return t.getHours()%n._domainType.hour.row(t)}},format:{date:"%Hh, %A %B %-e, %Y",legend:"%H:00",connector:"at"},extractUnit:function(t){var e=d3.time.format("%H");return t.getFullYear()+""+n.getDayOfYear(t)+e(t)}},day:{name:"day",level:30,row:function(){return 7},column:function(t){switch(t=new Date(t),n.options.domain){case"year":return n.options.domainDynamicDimension?n.getWeekNumber(new Date(t.getFullYear(),11,31))-n.getWeekNumber(new Date(t.getFullYear(),0))+1:54;case"month":return n.options.verticalOrientation?6:n.options.domainDynamicDimension?n.getWeekNumber(new Date(t.getFullYear(),t.getMonth()+1,0))-n.getWeekNumber(t)+1:6;case"week":return 1}},position:{x:function(t){switch(n.options.domain){case"week":return 0;case"month":return n.getWeekNumber(t)-n.getWeekNumber(new Date(t.getFullYear(),t.getMonth()));case"year":return n.getWeekNumber(t)}},y:function(t){return n.getWeekDay(t)}},format:{date:"%A %B %-e, %Y",legend:"%e %b",connector:"on"},extractUnit:function(t){return t.getFullYear()+""+n.getDayOfYear(t)}},week:{name:"week",level:40,row:function(){return 1},column:function(t){switch(t=new Date(t),n.options.domain){case"year":return 54;case"month":return n.getWeekNumber(new Date(t.getFullYear(),t.getMonth()+1,0))-n.getWeekNumber(t);default:return 1}},position:{x:function(t){switch(n.options.domain){case"year":return n.getWeekNumber(t);case"month":return n.getWeekNumber(t)-n.getWeekNumber(new Date(t.getFullYear(),t.getMonth()))-1}},y:function(){return 0}},format:{date:"%B Week #%W",legend:"%B Week #%W",connector:"on"},extractUnit:function(t){return n.getWeekNumber(t)}},month:{name:"month",level:50,row:function(){return 1},column:function(){return 12},position:{x:function(t){return Math.floor(t.getMonth()/n._domainType.month.row(t))},y:function(t){return t.getMonth()%n._domainType.month.row(t)}},format:{date:"%B %Y",legend:"%B",connector:"on"},extractUnit:function(t){return t.getMonth()}},year:{name:"year",level:60,row:function(){return 1},column:function(){return 12},position:{x:function(t){return Math.floor(t.getFullYear()/this._domainType.year.row(t))},y:function(t){return t.getFullYear()%this._domainType.year.row(t)}},format:{date:"%Y",legend:"%Y",connector:"on"},extractUnit:function(t){return t.getFullYear()}}};for(var o in this._domainType)this._domainType["x_"+o]={},this._domainType["x_"+o].name="x_"+o,this._domainType["x_"+o].level=this._domainType[o].level,this._domainType["x_"+o].row=this._domainType[o].column,this._domainType["x_"+o].column=this._domainType[o].row,this._domainType["x_"+o].position={},this._domainType["x_"+o].position.x=this._domainType[o].position.y,this._domainType["x_"+o].position.y=this._domainType[o].position.x,this._domainType["x_"+o].format=this._domainType[o].format,this._domainType["x_"+o].extractUnit=this._domainType[o].extractUnit;this._domainType.x_day.row=function(t){switch(t=new Date(t),n.options.domain){case"year":return n.options.domainDynamicDimension?n.getWeekNumber(new Date(t.getFullYear(),11,31))-n.getWeekNumber(new Date(t.getFullYear(),0))+1:54;case"month":return n.options.verticalOrientation?n.options.domainDynamicDimension?n.getWeekNumber(new Date(t.getFullYear(),t.getMonth()+1,0))-n.getWeekNumber(t)+1:6:6;case"week":return 1}},this.svg=null,this._completed=!1,this._domains=[];var i={width:0,height:0};this.NAVIGATE_LEFT=1,this.NAVIGATE_RIGHT=2,this.root=null,this._maxDomainReached=!1,this._minDomainReached=!1,this.domainPosition=new DomainPosition,this.paint=function(t){function e(e,o,i,a){var r=0;switch(t){case!1:return e>0&&(r=o[i]),o[i]+=a,n.domainPosition.pushPosition(r),r;case n.NAVIGATE_RIGHT:return n.domainPosition.pushPosition(o[i]),h=a,c=n.domainPosition.getPosition(1),n.domainPosition.shiftRight(c),o[i];case n.NAVIGATE_LEFT:return r=-a,h=-r,c=o[i]-n.domainPosition.getLast(),n.domainPosition.unshiftPosition(r),n.domainPosition.shiftLeft(h),r}}function o(t){n.options.cellRadius>0&&t.attr("rx",n.options.cellRadius).attr("ry",n.options.cellRadius)}function a(t){switch(n.options.label.rotate){case"right":t.attr("transform",function(t){var e="rotate(90), ";switch(n.options.label.position){case"right":e+="translate(-"+u(t)+" , -"+u(t)+")";break;case"left":e+="translate(0, -"+l+")"}return e});break;case"left":t.attr("transform",function(t){var e="rotate(270), ";switch(n.options.label.position){case"right":e+="translate(-"+(u(t)+l)+" , "+u(t)+")";break;case"left":e+="translate(-"+l+" , "+l+")"}return e})}}t===void 0&&(t=!1);var r="top"===n.options.label.position||"bottom"===n.options.label.position,s=Math.max(25,2*n.options.cellSize),l=0;r||(s=0,l=n.options.label.width),"number"==typeof n.options.domainMargin&&(n.options.domainMargin=[n.options.domainMargin,n.options.domainMargin,n.options.domainMargin,n.options.domainMargin]);var u=function(t,e){var o=n.options.cellSize*n._domainType[n.options.subDomain].column(t)+n.options.cellPadding*n._domainType[n.options.subDomain].column(t);return e!==void 0&&e===!0?o+=l+n.options.domainGutter+n.options.domainMargin[1]+n.options.domainMargin[3]:o},m=function(t,e){var o=n.options.cellSize*n._domainType[n.options.subDomain].row(t)+n.options.cellPadding*n._domainType[n.options.subDomain].row(t);return e!==void 0&&e===!0&&(o+=n.options.domainGutter+s+n.options.domainMargin[0]+n.options.domainMargin[2]),o},p=n.root.select(".graph").selectAll(".graph-domain").data(n._domains,function(t){return t}),h=0,c=0,d=p.enter().append("svg").attr("width",function(t){return u(t,!0)}).attr("height",function(t){return m(t,!0)}).attr("x",function(t,o){return n.options.verticalOrientation?(i.width=u(t,!0),0):e(o,i,"width",u(t,!0))}).attr("y",function(t,o){return n.options.verticalOrientation?e(o,i,"height",m(t,!0)):(i.height=m(t,!0),0)}).attr("class",function(t){var e="graph-domain",o=new Date(t);switch(n.options.domain){case"hour":e+=" h_"+o.getHours();case"day":e+=" d_"+o.getDate()+" dy_"+o.getDay();case"week":e+=" w_"+n.getWeekNumber(o);case"month":e+=" m_"+(o.getMonth()+1);case"year":e+=" y_"+o.getFullYear()}return e});d.append("rect").attr("width",function(t){return u(t,!0)-n.options.domainGutter-n.options.cellPadding}).attr("height",function(t){return m(t,!0)-n.options.domainGutter-n.options.cellPadding}).attr("class","domain-background");var g=d.append("svg").attr("x",function(){switch(n.options.label.position){case"left":return l+n.options.domainMargin[3];default:return n.options.domainMargin[3]}}).attr("y",function(){switch(n.options.label.position){case"top":return s+n.options.domainMargin[0];default:return n.options.domainMargin[0]}}).attr("class","graph-subdomain-group"),f=g.selectAll("svg").data(function(t){return n.getSubDomain(t)}).enter().append("g");f.append("rect").attr("class",function(t){return"graph-rect"+n.getHighlightClassName(t)+(null!==n.options.onClick?" hover_cursor":"")}).attr("width",n.options.cellSize).attr("height",n.options.cellSize).attr("x",function(t){return n.positionSubDomainX(t)}).attr("y",function(t){return n.positionSubDomainY(t)}).on("click",function(t){return null!==n.options.onClick?n.onClick(t,null):void 0}).call(o),d.append("text").attr("class","graph-label").attr("y",function(t){var e=n.options.domainMargin[0];switch(n.options.label.position){case"top":e+=s/2;break;case"bottom":e+=m(t)+s/2}return e+n.options.label.offset.y*("right"===n.options.label.rotate&&"right"===n.options.label.position||"left"===n.options.label.rotate&&"left"===n.options.label.position?-1:1)}).attr("x",function(t){var e=n.options.domainMargin[3];switch(n.options.label.position){case"right":e+=u(t);break;case"bottom":case"top":e+=u(t)/2}return"right"===n.options.label.align?e+l-n.options.label.offset.x*("right"===n.options.label.rotate?-1:1):e+n.options.label.offset.x}).attr("text-anchor",function(){switch(n.options.label.align){case"start":case"left":return"start";case"end":case"right":return"end";default:return"middle"}}).attr("dominant-baseline",function(){return r?"middle":"top"}).text(function(t,e){return n.formatDate(new Date(n._domains[e]),n.options.domainLabelFormat)}).call(a),f.append("title").text(function(t){return n.formatDate(t,n.options.subDomainDateFormat)}),null!==n.options.subDomainTextFormat&&f.append("text").attr("class",function(t){return"subdomain-text"+n.getHighlightClassName(t)}).attr("x",function(t){return n.positionSubDomainX(t)+n.options.cellSize/2}).attr("y",function(t){return n.positionSubDomainY(t)+n.options.cellSize/2}).attr("text-anchor","middle").attr("dominant-baseline","central").text(function(t){return n.formatDate(t,n.options.subDomainTextFormat)}),t!==!1&&p.transition().duration(n.options.animationDuration).attr("x",function(t,e){return n.options.verticalOrientation?0:n.domainPosition.getPosition(e)}).attr("y",function(t,e){return n.options.verticalOrientation?n.domainPosition.getPosition(e):0});var D=i.width,y=i.height;n.options.verticalOrientation?i.height+=h-c:i.width+=h-c,p.exit().transition().duration(n.options.animationDuration).attr("x",function(e){if(n.options.verticalOrientation)return 0;switch(t){case n.NAVIGATE_LEFT:return Math.min(i.width,D);case n.NAVIGATE_RIGHT:return-u(e,!0)}}).attr("y",function(e){if(!n.options.verticalOrientation)return 0;switch(t){case n.NAVIGATE_LEFT:return Math.min(i.height,y);case n.NAVIGATE_RIGHT:return-m(e,!0)}}).remove(),n.root.select(".graph").transition().duration(n.options.animationDuration).attr("width",function(){return i.width-n.options.domainGutter-n.options.cellPadding}).attr("height",function(){return i.height-n.options.domainGutter-n.options.cellPadding}),n.svg=null===n.svg?d:n.root.select(".graph").selectAll("svg").data(n._domains,function(t){return t})},this.init=function(o){function i(t){return!(t instanceof Element)&&"string"!=typeof t||""===t}if(n.options=mergeRecursive(n.options,o),!this._domainType.hasOwnProperty(n.options.domain)||"min"===n.options.domain||"x_"===n.options.domain.substring(0,2))return console.log("The domain '"+n.options.domain+"' is not valid"),!1;if(!this._domainType.hasOwnProperty(n.options.subDomain)||"year"===n.options.subDomain)return console.log("The subDomain '"+n.options.subDomain+"' is not valid"),!1;if(this._domainType[n.options.domain].level<=this._domainType[n.options.subDomain].level)return console.log("'"+n.options.subDomain+"' is not a valid subDomain to '"+n.options.domain+"'"),!1;if(!o.hasOwnProperty("subDomain"))switch(n.options.domain){case"year":n.options.subDomain="month";break;case"month":n.options.subDomain="day";break;case"week":n.options.subDomain="day";break;case"day":n.options.subDomain="hour";break;default:n.options.subDomain="min"}if(0>e.indexOf(n.options.dataType))return console.log("The data type '"+n.options.dataType+"' is not valid data type"),!1;if(null===n.options.subDomainDateFormat&&(n.options.subDomainDateFormat=this._domainType[n.options.subDomain].format.date),null===n.options.domainLabelFormat&&(n.options.domainLabelFormat=this._domainType[n.options.domain].format.legend),!o.hasOwnProperty("label")||o.hasOwnProperty("label")&&!o.label.hasOwnProperty("align")){switch(n.options.label.position){case"left":n.options.label.align="right";break;case"right":n.options.label.align="left";break;default:n.options.label.align="center"}"left"===n.options.label.rotate?n.options.label.align="right":"right"===n.options.label.rotate&&(n.options.label.align="left")}if((!o.hasOwnProperty("label")||o.hasOwnProperty("label")&&!o.label.hasOwnProperty("offset"))&&("left"===n.options.label.position||"right"===n.options.label.position)&&(n.options.label.offset={x:10,y:15}),i(n.options.itemSelector))return console.log("The itemSelector is invalid"),!1;if(null===d3.select(n.options.itemSelector)[0][0])return console.log("The node specified in itemSelector does not exists"),!1;if(n.options.nextSelector!==!1&&i(n.options.nextSelector))return console.log("The nextSelector is invalid"),!1;if(n.options.previousSelector!==!1&&i(n.options.previousSelector))return console.log("The previousSelector is invalid"),!1;if(("string"!=typeof n.options.itemNamespace||""===n.options.itemNamespace)&&(console.log("itemNamespace can not be empty, falling back to cal-heatmap"),n.options.itemNamespace="cal-heatmap"),"number"==typeof n.options.domainMargin&&(n.options.domainMargin=[n.options.domainMargin,n.options.domainMargin,n.options.domainMargin,n.options.domainMargin]),Array.isArray(n.options.domainMargin))switch(n.options.domainMargin.length){case 0:n.options.domainMargin=[0,0,0,0];break;case 1:n.options.domainMargin=[n.options.domainMargin,n.options.domainMargin,n.options.domainMargin,n.options.domainMargin];break;case 2:n.options.domainMargin=[n.options.domainMargin[0],n.options.domainMargin[1],n.options.domainMargin[0],n.options.domainMargin[1]];break;case 3:n.options.domainMargin=[n.options.domainMargin[0],n.options.domainMargin[1],n.options.domainMargin[2],n.options.domainMargin[1]];break;case 4:n.options.domainMargin=n.options.domainMargin;break;default:n.options.domainMargin.splice(4)}"string"==typeof n.options.itemName?n.options.itemName=[n.options.itemName,n.options.itemName+"s"]:Array.isArray(n.options.itemName)&&1===n.options.itemName.length&&(n.options.itemName=[n.options.itemName[0],n.options.itemName[0]+"s"]);var a=["data","onComplete","onClick","afterLoad","afterLoadData","afterLoadPreviousDomain","afterLoadNextDomain"];for(var r in a)o.hasOwnProperty(a[r])&&(n.options[a[r]]=o[a[r]]);if("string"==typeof n.options.highlight)n.options.highlight="now"===n.options.highlight?[new Date]:[];else if(Array.isArray(n.options.highlight)){var s=n.options.highlight.indexOf("now");-1!==s&&(n.options.highlight.splice(s,1),n.options.highlight.push(new Date))}return t()}};CalHeatMap.prototype={onClick:function(t,n){return"function"==typeof this.options.onClick?this.options.onClick(t,n):(console.log("Provided callback for onClick is not a function."),!1)},afterLoad:function(){return"function"==typeof this.options.afterLoad?this.options.afterLoad():(console.log("Provided callback for afterLoad is not a function."),!1)},onComplete:function(){return null===this.options.onComplete||this._completed===!0?!0:(this._completed=!0,"function"==typeof this.options.onComplete?this.options.onComplete():(console.log("Provided callback for onComplete is not a function."),!1))},afterLoadPreviousDomain:function(t){if("function"==typeof this.options.afterLoadPreviousDomain){var n=this.getSubDomain(t);return this.options.afterLoadPreviousDomain(n.shift(),n.pop())}return console.log("Provided callback for afterLoadPreviousDomain is not a function."),!1},afterLoadNextDomain:function(t){if("function"==typeof this.options.afterLoadNextDomain){var n=this.getSubDomain(t);return this.options.afterLoadNextDomain(n.shift(),n.pop())}return console.log("Provided callback for afterLoadNextDomain is not a function."),!1},onMinDomainReached:function(t){return this._minDomainReached=t,"function"==typeof this.options.onMinDomainReached?this.options.onMinDomainReached(t):(console.log("Provided callback for onMinDomainReached is not a function."),!1)},onMaxDomainReached:function(t){return this._maxDomainReached=t,"function"==typeof this.options.onMaxDomainReached?this.options.onMaxDomainReached(t):(console.log("Provided callback for onMaxDomainReached is not a function."),!1)},formatNumber:d3.format(",g"),formatDate:function(t,n){if(n===void 0&&(n="title"),"function"==typeof n)return n(t);var e=d3.time.format(n);return e(t)},loadNextDomain:function(){var t=this.getNextDomain().getTime();if(this._maxDomainReached||this.maxDomainIsReached(t))return!1;var n=this;return this._domains.push(t),this._domains.shift(),this.paint(this.NAVIGATE_RIGHT),this.getDatas(this.options.data,new Date(this._domains[this._domains.length-1]),this.getSubDomain(this._domains[this._domains.length-1]).pop(),function(t){n.fill(t,n.svg)}),this.afterLoadNextDomain(new Date(this._domains[this._domains.length-1])),this.maxDomainIsReached(this.getNextDomain().getTime())&&this.onMaxDomainReached(!0),this._minDomainReached&&!this.minDomainIsReached(this._domains[0])&&this.onMinDomainReached(!1),!0},loadPreviousDomain:function(){if(this._minDomainReached||this.minDomainIsReached(this._domains[0]))return!1;var t=this.getPreviousDomain().getTime(),n=this;return this._domains.unshift(t),this._domains.pop(),this.paint(this.NAVIGATE_LEFT),this.getDatas(this.options.data,new Date(this._domains[0]),this.getSubDomain(this._domains[0]).pop(),function(t){n.fill(t,n.svg)}),this.afterLoadPreviousDomain(new Date(this._domains[0])),this.minDomainIsReached(t)&&this.onMinDomainReached(!0),this._maxDomainReached&&!this.maxDomainIsReached(this._domains[this._domains.length-1])&&this.onMaxDomainReached(!1),!0},maxDomainIsReached:function(t){return null!==this.options.maxDate&&t>this.options.maxDate.getTime()},minDomainIsReached:function(t){return null!==this.options.minDate&&this.options.minDate.getTime()>=t},displayLegend:function(t){var n=this,e=this.root;switch(this.options.legendVerticalPosition){case"top":e=e.insert("svg",".graph");break;default:e=e.append("svg")}var o=this.options.legendCellSize*(this.options.legend.length+1)+this.options.legendCellPadding*(this.options.legend.length+1)+this.options.legendMargin[3]+this.options.legendMargin[1];e=e.attr("class","graph-legend").attr("height",this.options.legendCellSize+this.options.legendMargin[0]+this.options.legendMargin[2]).attr("width",t).append("g").attr("transform",function(){switch(n.options.legendHorizontalPosition){case"right":return"translate("+(t-o)+")";case"middle":case"center":return"translate("+(t/2-o/2)+")";default:return"translate("+n.options.legendMargin[3]+")"}}).attr("y",this.options.legendMargin[0]).selectAll().data(d3.range(0,this.options.legend.length+1));var i=e.enter().append("rect").attr("width",this.options.legendCellSize).attr("height",this.options.legendCellSize).attr("class",function(t){return"graph-rect q"+(t+1)}).attr("x",function(t){return t*(n.options.legendCellSize+n.options.legendCellPadding)}).attr("y",this.options.legendMargin[0]).attr("fill-opacity",0);i.transition().delay(function(t,e){return n.options.animationDuration*e/10}).attr("fill-opacity",1),i.append("title").text(function(t){return n.options.legend[t+1],0===t?n.options.legendTitleFormat.lower.format({min:n.options.legend[t],name:n.options.itemName[1]}):t===n.options.legend.length?n.options.legendTitleFormat.upper.format({max:n.options.legend[t-1],name:n.options.itemName[1]}):n.options.legendTitleFormat.inner.format({down:n.options.legend[t-1],up:n.options.legend[t],name:n.options.itemName[1]})})},display:function(t,n){var e=this;return n.each(function(n){(t.hasOwnProperty(n)||e.options.considerMissingDataAsZero)&&(d3.select(this).selectAll(".graph-subdomain-group rect").attr("class",function(o){var i=e._domainType[e.options.subDomain].extractUnit(o),a="graph-rect"+e.getHighlightClassName(o);return t.hasOwnProperty(n)&&t[n].hasOwnProperty(i)?a+=" "+e.legend(t[n][i]):e.options.considerMissingDataAsZero&&(a+=" "+e.legend(0)),null!==e.options.onClick&&(a+=" hover_cursor"),a}).on("click",function(o){if(null!==e.options.onClick){var i=e._domainType[e.options.subDomain].extractUnit(o);return e.onClick(o,t[n].hasOwnProperty(i)||e.options.considerMissingDataAsZero?t[n][i]:null)}}),d3.select(this).selectAll(".graph-subdomain-group title").text(function(o){var i=e._domainType[e.options.subDomain].extractUnit(o);return t.hasOwnProperty(n)&&t[n].hasOwnProperty(i)&&null!==t[n][i]||e.options.considerMissingDataAsZero?(t.hasOwnProperty(n)&&t[n].hasOwnProperty(i)?value=t[n][i]:e.options.considerMissingDataAsZero&&(value=0),e.options.subDomainTitleFormat.filled.format({count:e.formatNumber(value),name:e.options.itemName[1!==value?1:0],connector:e._domainType[e.options.subDomain].format.connector,date:e.formatDate(o,e.options.subDomainDateFormat)})):e.options.subDomainTitleFormat.empty.format({date:e.formatDate(o,e.options.subDomainDateFormat)})}))}),!0},positionSubDomainX:function(t){var n=this._domainType[this.options.subDomain].position.x(t);return n*this.options.cellSize+n*this.options.cellPadding},positionSubDomainY:function(t){var n=this._domainType[this.options.subDomain].position.y(t);return n*this.options.cellSize+n*this.options.cellPadding},getHighlightClassName:function(t){if(this.options.highlight.length>0)for(var n in this.options.highlight)if(this.options.highlight[n]instanceof Date&&this.dateIsEqual(this.options.highlight[n],t))return" highlight"+(this.isNow(this.options.highlight[n])?" now":"");return""},isNow:function(t){return this.dateIsEqual(t,new Date)},dateIsEqual:function(t,n){switch(this.options.subDomain){case"x_min":case"min":return t.getFullYear()===n.getFullYear()&&t.getMonth()===n.getMonth()&&t.getDate()===n.getDate()&&t.getHours()===n.getHours()&&t.getMinutes()===n.getMinutes();case"x_hour":case"hour":return t.getFullYear()===n.getFullYear()&&t.getMonth()===n.getMonth()&&t.getDate()===n.getDate()&&t.getHours()===n.getHours();case"x_day":case"day":return t.getFullYear()===n.getFullYear()&&t.getMonth()===n.getMonth()&&t.getDate()===n.getDate();case"x_week":case"week":case"x_month":case"month":return t.getFullYear()===n.getFullYear()&&t.getMonth()===n.getMonth();default:return!1}},getDayOfYear:d3.time.format("%j"),getWeekNumber:function(t){var n=this.options.weekStartOnMonday===!0?d3.time.format("%W"):d3.time.format("%U");return n(t)},getWeekDay:function(t){return this.options.weekStartOnMonday===!1?t.getDay():0===t.getDay()?6:t.getDay()-1},getEndOfMonth:function(t){return"number"==typeof t&&(t=new Date(t)),new Date(t.getFullYear(),t.getMonth()+1,0)},getWeekDomain:function(t,n){var e;this.options.weekStartOnMonday===!1?e=new Date(t.getFullYear(),t.getMonth(),t.getDate()-t.getDay()):1===t.getDay()?e=new Date(t.getFullYear(),t.getMonth(),t.getDate()):0===t.getDay()?(e=new Date(t.getFullYear(),t.getMonth(),t.getDate()),e.setDate(e.getDate()-6)):e=new Date(t.getFullYear(),t.getMonth(),t.getDate()-t.getDay()+1);var o=new Date(e),i=new Date(o.setDate(o.getDate()+7*n));return this.options.weekStartOnMonday===!0?d3.time.mondays(Math.min(e,i),Math.max(e,i)):d3.time.sundays(Math.min(e,i),Math.max(e,i))},getYearDomain:function(t,n){var e=new Date(t.getFullYear(),0),o=new Date(t.getFullYear()+n,0);return d3.time.years(Math.min(e,o),Math.max(e,o))},getMinuteDomain:function(t,n){var e=new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours()),o=new Date(e.getTime()+6e4*n);return d3.time.minutes(Math.min(e,o),Math.max(e,o))},getHourDomain:function(t,n){var e=new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours()),o=n;return"number"==typeof n&&(o=new Date(e.getTime()+36e5*n)),d3.time.hours(Math.min(e,o),Math.max(e,o))},getDayDomain:function(t,n){var e=new Date(t.getFullYear(),t.getMonth(),t.getDate()),o=new Date(e);return o=new Date(o.setDate(o.getDate()+parseInt(n,10))),d3.time.days(Math.min(e,o),Math.max(e,o))},getMonthDomain:function(t,n){var e=new Date(t.getFullYear(),t.getMonth()),o=new Date(e);return o=o.setMonth(o.getMonth()+n),d3.time.months(Math.min(e,o),Math.max(e,o))},getDomain:function(t,n){switch("number"==typeof t&&(t=new Date(t)),n===void 0&&(n=this.options.range),this.options.domain){case"hour":return this.getHourDomain(t,n);case"day":return this.getDayDomain(t,n);case"week":return this.getWeekDomain(t,n);case"month":return this.getMonthDomain(t,n);case"year":return this.getYearDomain(t,n)}},getSubDomain:function(t){"number"==typeof t&&(t=new Date(t));var n=this,e=function(t,e){switch(e){case"year":return n.getDayOfYear(new Date(t.getFullYear()+1,0,0));case"month":var o=new Date(t.getFullYear(),t.getMonth()+1,0);return o.getDate();case"week":return 7}},o=function(t,n){switch(n){case"hour":return 60;case"day":return 1440;case"week":return 10080}},i=function(t,n){switch(n){case"day":return 24;case"week":return 168;case"month":var e=new Date(t.getFullYear(),t.getMonth()+1,0);return 24*e.getDate()}},a=function(t,e){if("month"===e){var o=new Date(t.getFullYear(),t.getMonth()+1,0),i=n.getWeekNumber(o),a=n.getWeekNumber(new Date(t.getFullYear(),t.getMonth()));return a>i&&(a=0,i++),i-a+1}return"year"===e?n.getWeekNumber(new Date(t.getFullYear(),11,31)):void 0};switch(this.options.subDomain){case"x_min":case"min":return this.getMinuteDomain(t,o(t,this.options.domain));case"x_hour":case"hour":return this.getHourDomain(t,i(t,this.options.domain));case"x_day":case"day":return this.getDayDomain(t,e(t,this.options.domain));case"week":return this.getWeekDomain(t,a(t,this.options.domain));case"x_month":case"month":return this.getMonthDomain(t,12)}},getNextDomain:function(){return this.getDomain(this._domains[this._domains.length-1],2).pop()},getPreviousDomain:function(){return this.getDomain(this._domains[0],-1)[0]},legend:function(t){if(isNaN(t))return"qi";if(null===t)return"";for(var n=0,e=this.options.legend.length-1;e>=n;n++){if(0===t&&this.options.legend[0]>0)return"";if(this.options.legend[0]>0&&0>t)return"qi";if(this.options.legend[n]>=t)return"q"+(n+1)}return"q"+(this.options.legend.length+1)},fill:function(t,n){var e=this.display(this.parseDatas(t),n);return this.onComplete(),e},getDatas:function(t,n,e,o){switch(typeof t){case"string":if(""===t)return this.onComplete(),!0;switch(this.options.dataType){case"json":d3.json(this.parseURI(t,n,e),o);break;case"csv":d3.csv(this.parseURI(t,n,e),o);break;case"tsv":d3.tsv(this.parseURI(t,n,e),o);break;case"text":d3.text(this.parseURI(t,n,e),"text/plain",o)}return!1;case"object":o(t)}return!0},parseDatas:function(t){var n={};if("function"!=typeof this.options.afterLoadData)return console.log("Provided callback for afterLoadData is not a function."),{};t=this.options.afterLoadData(t);for(var e in t){var o=new Date(1e3*e),i=this.getDomain(o)[0].getTime();if(!(0>this._domains.indexOf(i))){var a=this._domainType[this.options.subDomain].extractUnit(o);n[i]===void 0&&(n[i]={}),n[i][a]!==void 0?n[i][a]+=t[e]:n[i][a]=t[e]}}return n},parseURI:function(t,n,e){return t=t.replace(/\{\{t:start\}\}/g,n.getTime()/1e3),t=t.replace(/\{\{t:end\}\}/g,e.getTime()/1e3),t=t.replace(/\{\{d:start\}\}/g,n.toISOString()),t=t.replace(/\{\{d:end\}\}/g,e.toISOString())},next:function(){return this.loadNextDomain()},previous:function(){return this.loadPreviousDomain()},getSVG:function(){for(var t={".graph":{},".graph-rect":{},"rect.highlight":{},"rect.now":{},"text.highlight":{},"text.now":{},".domain-background":{},".graph-label":{},".subdomain-text":{},".qi":{}},n=0,e=this.options.legend.length;e>n;n++)t[".q"+n]={};var o=this.root,i=["stroke","stroke-width","stroke-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-miterlimit","fill","fill-opacity","fill-rule","marker","marker-start","marker-mid","marker-end","alignement-baseline","baseline-shift","dominant-baseline","glyph-orientation-horizontal","glyph-orientation-vertical","kerning","text-anchor","shape-rendering","text-transform","font-family","font","font-size","font-weight"],a=function(n,e,o){-1!==i.indexOf(e)&&(t[n][e]=o)},r=function(t){return o.select(t)[0][0]};for(var s in t){var l=r(s);if(null!==l)if("getComputedStyle"in window){var u=getComputedStyle(l,null);if(0!==u.length)for(var m=0;u.length>m;m++)a(s,u.item(m),u.getPropertyValue(u.item(m)));else for(var p in u)u.hasOwnProperty(p)&&a(s,p,u[p])}else if("currentStyle"in l){var h=l.currentStyle;for(var c in h)a(s,c,h[c])}}var d='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><style type="text/css"><![CDATA[ ';for(var g in t){d+=g+" {\n";for(var f in t[g])d+=" "+f+":"+t[g][f]+";\n";d+="}\n"}return d+="]]></style>",d+=(new XMLSerializer).serializeToString(this.root.selectAll("svg")[0][0]),d+=(new XMLSerializer).serializeToString(this.root.selectAll("svg")[0][1]),d+="</svg>"}};var DomainPosition=function(){this.positions=[]};DomainPosition.prototype.getPosition=function(t){return this.positions[t]},DomainPosition.prototype.getLast=function(){return this.positions[this.positions.length-1]},DomainPosition.prototype.pushPosition=function(t){this.positions.push(t)},DomainPosition.prototype.unshiftPosition=function(t){this.positions.unshift(t)},DomainPosition.prototype.shiftRight=function(t){for(var n in this.positions)this.positions[n]-=t;this.positions.shift()},DomainPosition.prototype.shiftLeft=function(t){for(var n in this.positions)this.positions[n]+=t;this.positions.pop()},String.prototype.format=function(){var t=this;for(var n in arguments[0]){var e=RegExp("\\{"+n+"\\}","gi");t=t.replace(e,arguments[0][n])}return t},"function"==typeof define&&define.amd&&define(["d3"],function(){return CalHeatMap});
|
9
|
+
//@ sourceMappingURL=cal-heatmap.source-map.js
|
@@ -0,0 +1,108 @@
|
|
1
|
+
/* Cal-HeatMap CSS */
|
2
|
+
|
3
|
+
|
4
|
+
.graph
|
5
|
+
{
|
6
|
+
clear: both;
|
7
|
+
display: block;
|
8
|
+
font-family: "Lucida Grande", Lucida, Verdana, sans-serif;
|
9
|
+
overflow: hidden;
|
10
|
+
}
|
11
|
+
|
12
|
+
.graph-label
|
13
|
+
{
|
14
|
+
fill: #999;
|
15
|
+
font-size: 10px
|
16
|
+
}
|
17
|
+
|
18
|
+
.graph-rect
|
19
|
+
{
|
20
|
+
fill: #ededed;
|
21
|
+
shape-rendering: crispedges
|
22
|
+
}
|
23
|
+
|
24
|
+
.graph-rect:hover
|
25
|
+
{
|
26
|
+
stroke: #000;
|
27
|
+
stroke-width: 1px
|
28
|
+
}
|
29
|
+
|
30
|
+
.subdomain-text {
|
31
|
+
font-size: 8px;
|
32
|
+
fill: #999;
|
33
|
+
pointer-events: none;
|
34
|
+
}
|
35
|
+
|
36
|
+
.hover_cursor:hover {
|
37
|
+
cursor: pointer;
|
38
|
+
}
|
39
|
+
|
40
|
+
.qi {
|
41
|
+
background-color: #999;
|
42
|
+
fill: #999;
|
43
|
+
}
|
44
|
+
|
45
|
+
.q0
|
46
|
+
{
|
47
|
+
background-color: #fff;
|
48
|
+
fill: #fff;
|
49
|
+
stroke: #ededed
|
50
|
+
}
|
51
|
+
|
52
|
+
.q1
|
53
|
+
{
|
54
|
+
background-color: #dae289;
|
55
|
+
fill: #dae289
|
56
|
+
}
|
57
|
+
|
58
|
+
.q2
|
59
|
+
{
|
60
|
+
background-color: #cedb9c;
|
61
|
+
fill: #9cc069
|
62
|
+
}
|
63
|
+
|
64
|
+
.q3
|
65
|
+
{
|
66
|
+
background-color: #b5cf6b;
|
67
|
+
fill: #669d45
|
68
|
+
}
|
69
|
+
|
70
|
+
.q4
|
71
|
+
{
|
72
|
+
background-color: #637939;
|
73
|
+
fill: #637939
|
74
|
+
}
|
75
|
+
|
76
|
+
.q5
|
77
|
+
{
|
78
|
+
background-color: #3b6427;
|
79
|
+
fill: #3b6427
|
80
|
+
}
|
81
|
+
|
82
|
+
rect.highlight
|
83
|
+
{
|
84
|
+
stroke:#444;
|
85
|
+
stroke-width:1;
|
86
|
+
}
|
87
|
+
|
88
|
+
text.highlight
|
89
|
+
{
|
90
|
+
fill: #444;
|
91
|
+
}
|
92
|
+
|
93
|
+
rect.now
|
94
|
+
{
|
95
|
+
stroke: red;
|
96
|
+
}
|
97
|
+
|
98
|
+
text.now
|
99
|
+
{
|
100
|
+
fill: red;
|
101
|
+
font-weight: 800;
|
102
|
+
}
|
103
|
+
|
104
|
+
.domain-background {
|
105
|
+
fill: none;
|
106
|
+
shape-rendering: crispedges;
|
107
|
+
}
|
108
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
*= require cal-heatmap
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cal_heatmap_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Everaldo Gomes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A gem to automate using cal-heatmap with Rails 4
|
42
|
+
email:
|
43
|
+
- everaldo.gomes@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- LICENSE_CALHEATMAP.txt
|
52
|
+
- LICENSE_D3JS.txt
|
53
|
+
- LICENSE_D3_RAILS.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- cal_heatmap_rails.gemspec
|
57
|
+
- lib/cal_heatmap_rails.rb
|
58
|
+
- lib/cal_heatmap_rails/engine.rb
|
59
|
+
- lib/cal_heatmap_rails/version.rb
|
60
|
+
- vendor/assets/javascripts/cal-heatmap.js
|
61
|
+
- vendor/assets/javascripts/cal-heatmap.min.js
|
62
|
+
- vendor/assets/javascripts/cal_heatmap_rails.js
|
63
|
+
- vendor/assets/stylesheets/cal-heatmap.css
|
64
|
+
- vendor/assets/stylesheets/cal_heatmap_rails.css
|
65
|
+
homepage: https://github.com/everaldo/cal_heatmap_rails
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.0.3
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: This gems packages cal-heatmap javascript and stylesheet files, allowing
|
89
|
+
inclusion through the Asset Pipeline
|
90
|
+
test_files: []
|