Skip to content

Commit

Permalink
update distribution files
Browse files Browse the repository at this point in the history
  • Loading branch information
SeBassTian23 committed Jan 9, 2020
1 parent 7098627 commit 72a5ab4
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 49 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery-calendar-heatmap",
"version": "1.0.0",
"version": "1.1.0",
"license": "MIT",
"authors": [
"Sebastian Kuhlgert <[email protected]>"
Expand Down
12 changes: 10 additions & 2 deletions dist/jquery.CalendarHeatmap.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* jquery-calendar-heatmap - v1.0.1
* jquery-calendar-heatmap - v1.1.0
* A simple Calendar Heatmap for jQuery.
* https://github.com/SeBassTian23/CalendarHeatmap
*
Expand All @@ -10,6 +10,14 @@
display: table !important;
clear: both;
}
.ch-rounded .ch-day,
.ch-rounded .ch-lvl {
border-radius: 35%;
}
.ch-circle .ch-day,
.ch-circle .ch-lvl {
border-radius: 100%;
}
.ch-month,
.ch-week-labels {
font-size: 0;
Expand Down Expand Up @@ -62,7 +70,7 @@
}
.ch-day.is-after-today,
.ch-lvl.is-after-today {
background-color: #d9e3ea;
background-color: #e9eff3;
}
.ch-day.lvl-1,
.ch-lvl.lvl-1 {
Expand Down
110 changes: 68 additions & 42 deletions dist/jquery.CalendarHeatmap.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* jquery-calendar-heatmap - v1.0.1
* jquery-calendar-heatmap - v1.1.0
* A simple Calendar Heatmap for jQuery.
* https://github.com/SeBassTian23/CalendarHeatmap
*
* Made by Sebastian Kuhlgert
* Under MIT License
*/
;( function( $, window, document, undefined ) {
;( function( $ ) {

"use strict";

Expand All @@ -27,6 +27,9 @@
monthLabels: null
}
},
tiles: {
shape: "square"
},
legend: {
show: true,
align: "right",
Expand All @@ -40,7 +43,7 @@
};

// The actual plugin constructor
function Plugin ( element, data, options ) {
function Plugin( element, data, options ) {
this.element = element;
this.data = data;
this.settings = $.extend( true, {}, defaults, options );
Expand All @@ -62,7 +65,7 @@
}
},
parse: function() {

var arr = [];
var type = $.type( this.data );
if ( [ "array", "object" ].indexOf( type ) === -1 ) {
console.log( "Invalid data source" );
Expand All @@ -72,33 +75,49 @@
var arrtype = $.type( this.data[ 0 ] );
if ( arrtype === "object" ) {
if ( this.data[ 0 ].date && this.data[ 0 ].count ) {
return this.data.slice( 0 );
arr = [];
for ( var h in this.data ) {
var objDate = this.data[ h ].date;
if ( $.isNumeric( this.data[ h ].date ) ) {
objDate = parseInt( this.data[ h ].date );
}
arr.push( {
"count": parseInt( this.data[ h ].count ),
"date": moment( objDate ).format( "YYYY-MM-DD" )
} );
}
return arr;
} else {
console.log( "Invalid Object format." );
return null;
}
} else if ( [ "string", "date" ].indexOf( arrtype ) > -1 ) {
} else if ( [ "string", "date", "number" ].indexOf( arrtype ) > -1 ) {
if ( moment( this.data[ 0 ] ).isValid() ) {
var obj = {};
for ( var i in this.data ) {
var d = moment( this.data[ i ] ).format( "YYYY-MM-DD" );
console.log( d );
if ( !obj[ d ] ) {
obj[ d ] = 1;
} else {
obj[ d ] += 1;
}
}
var arr = [];
console.log( obj );
arr = [];
for ( var j in obj ) {
arr.push( {
"count": obj[ j ],
"count": parseInt( obj[ j ] ),
"date": j
} );
}
return arr;
} else {
console.log( "Invalid Date format." );
return null;
}
} else {
console.log( "Invalid format." );
return null;
}
} else if ( type === "array" && this.data.length === 0 ) {
Expand All @@ -110,45 +129,40 @@
var data = [];
for ( var k in this.data ) {
data.push( {
"count": this.data[ k ],
"count": parseInt( this.data[ k ] ),
"date": moment( k ).format( "YYYY-MM-DD" )
} );
}
return data;
}
} else {
console.log( "Invalid Date format." );
return null;
}
} else {
return null;
}
}
},
index: function( data ) {
this.idx = {};
for ( var i in data ) {
this.idx[ data[ i ].date ] = i;
}
},
pad: function( str, max ) {
str = String( str );
return str.length < max ? this.pad( "0" + str, max ) : str;
},
calculateBins: function( events ) {

// Calculate bins for events
var arr = [];
var i;
var bins = this.settings.steps || 4;
var binlabels = [ "0" ];
var binlabelrange = [ [ 0, 0 ] ];
for ( i in events ) {
events[ i ].count = parseInt( events[ i ].count );
arr.push( events[ i ].count );
}
var firstStep = Math.min.apply( Math, arr );

var arr = events.map( function( x ) {
return parseInt( x.count );
} );

var minCount = Math.min.apply( Math, arr );
var maxCount = Math.max.apply( Math, arr );
var stepWidth = ( maxCount - firstStep ) / bins;
var stepWidth = ( maxCount - minCount ) / bins;

if ( stepWidth === 0 ) {
stepWidth = maxCount / bins;
Expand All @@ -159,7 +173,7 @@

// Generate bin labels
for ( i = 0; i < bins; i++ ) {
if ( !isFinite( firstStep ) ) {
if ( !isFinite( minCount ) ) {
binlabels.push( "" );
binlabelrange.push( [ null, null ] );
} else if ( maxCount < bins ) {
Expand All @@ -176,7 +190,7 @@
} else if ( maxCount === bins ) {
binlabels.push( String( ( i + 1 ) ) );
binlabelrange.push( [ ( i + 1 ), ( i + 1 ) ] );
} else if ( ( maxCount - 2 ) === bins ) {
} else if ( ( maxCount / 2 ) < bins ) {
if ( ( i + 1 ) === bins ) {
binlabels.push( String( ( i + 1 ) ) + "+" );
binlabelrange.push( [ ( i + 1 ), null ] );
Expand All @@ -185,9 +199,14 @@
binlabelrange.push( [ ( i + 1 ), ( i + 1 ) ] );
}
} else {
var l = Math.round( i * stepWidth ) + 1;
var ll = Math.round( i * stepWidth + stepWidth );
var l = Math.ceil( i * stepWidth ) + 1;
var ll = Math.ceil( i * stepWidth + stepWidth );
if ( i === ( bins - 1 ) ) {
ll = maxCount;
}
binlabelrange.push( [ l, ll ] );

// TODO: Fix counting issue: && ll < maxCount
if ( i === ( bins - 1 ) ) {
l += "+";
} else {
Expand All @@ -205,9 +224,9 @@

if ( events[ i ].count === 0 ) {
events[ i ].level = 0;
} else if ( events[ i ].count - firstStep === 0 ) {
} else if ( events[ i ].count - minCount === 0 ) {
events[ i ].level = 1;
} else if ( !isFinite( firstStep ) ) {
} else if ( !isFinite( minCount ) ) {
events[ i ].level = bins;
} else {
events[ i ].level = this.matchBin( binlabelrange, events[ i ].count );
Expand All @@ -225,12 +244,14 @@
return 0;
},
matchDate: function( obj, key ) {

if ( this.idx[ key ] ) {
return obj[ this.idx[ key ] ];
} else {
return null;
}
return obj.find( function( x ) {
return x.date === key;
} ) || null;
},
futureDate: function( str ) {
return moment( str ).diff( moment(), "days" ) >= 0 &&
moment( str ).format( "YYYY-MM-DD" ) !== moment().format( "YYYY-MM-DD" ) ?
true : false;
},
addWeekColumn: function( ) {
if ( this.settings.labels.days ) {
Expand All @@ -249,7 +270,7 @@
.append( "<div class=\"ch-month-label\">&nbsp;</div>" );
}

var swd = this.settings.weekStartDay || 1;
var swd = this.settings.weekStartDay;

for ( var i = 0; i < 7; i++ ) {

Expand Down Expand Up @@ -282,9 +303,6 @@
return;
}

// Generate lookup index
this.index( data );

var calc = this.calculateBins( data );
var events = calc.events;
var binLabels = calc.bins;
Expand Down Expand Up @@ -314,6 +332,11 @@
// Add labels
this.addWeekColumn();

// Adjust tile shape
if ( this.settings.tiles.shape && this.settings.tiles.shape !== "square" ) {
$( this.element ).addClass( " ch-" + this.settings.tiles.shape );
}

// Start building the months
for ( i = months; i > 0; i-- ) {

Expand All @@ -330,7 +353,7 @@
if ( this.settings.labels.custom.monthLabels ) {
if ( $.type( this.settings.labels.custom.monthLabels ) === "array" ) {
monthName = this.settings.labels.custom.monthLabels[ month ] || "";
}else {
} else {
monthName = moment().set( { "month": month, "year": year } )
.format( this.settings.labels.custom.monthLabels );
}
Expand Down Expand Up @@ -359,7 +382,10 @@
var str = year + "-" + this.pad( ( month + 1 ), 2 );
str += "-" + this.pad( ( j + 1 ), 2 );
var obj = this.matchDate( events, str );

var future = "";
if ( this.futureDate( str ) ) {
future = " is-after-today";
}
if ( obj ) {
var title = obj.count + " on ";
title += moment( obj.date ).format( "ll" );
Expand All @@ -380,7 +406,7 @@

} else {
$( "<div/>", {
"class": "ch-day"
"class": "ch-day" + future
} ).appendTo(
$( ".ch-month:last .ch-weeks .ch-week:last", this.element )
);
Expand Down Expand Up @@ -467,4 +493,4 @@
} );
};

} )( jQuery, window, document );
} )( jQuery );
4 changes: 2 additions & 2 deletions dist/jquery.CalendarHeatmap.min.css

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

Loading

0 comments on commit 72a5ab4

Please sign in to comment.