Changeset f2c9e20 in OpenWorkouts-current


Ignore:
Timestamp:
Mar 12, 2019, 6:39:46 PM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current
Children:
3ac70ca
Parents:
aedefa8
Message:

(#7) Show an empty calendar heatmap chart for months with 0 workout activity
in the user profile page.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/static/js/ow.js

    raedefa8 rf2c9e20  
    493493        d3.json(url, {credentials: "same-origin"}).then(function (data) {
    494494
    495             var min_date = d3.min(data, function(d) {
    496                 return new Date(d.day);
    497             });
    498 
    499             var max_date = d3.max(data, function(d) {
    500                 return new Date(d.day);
    501             });
     495            if (data.length == 0){
     496                // No data for this month, go on with an empty month.
     497                var url_year = url.match(/year=([^&]+)/);
     498                var url_month = url.match(/month=([^&]+)/);
     499                if (url_year != null && url_month != null) {
     500                    // if year/month has been passed in the url to retrieve
     501                    // workout data, use that to build the current month range.
     502                    //
     503                    // url_month is 1-12, while js Date() expects 0-11, so we use
     504                    // the currently selected month number as the next month and we
     505                    // use the previous number as the min date (start of the month)
     506                    var min_date = new Date(url_year[1], url_month[1] - 1);
     507                    var max_date = new Date(url_year[1], url_month[1])
     508                }
     509                else {
     510                    // otherwise, get the current month range
     511                    var min_date = new Date();
     512                    var max_date = new Date();
     513                    max_date.setDate(min_date.getDate() + 1);
     514                }
     515            }
     516            else {
     517                // We have got some workout data, build the min/max dates
     518                // from the workouts data, so we can build the proper month
     519                // range
     520                var min_date = d3.min(data, function(d) {
     521                    return new Date(d.day);
     522                });
     523
     524                var max_date = d3.max(data, function(d) {
     525                    return new Date(d.day);
     526                });
     527            }
    502528
    503529            // sunday-starting week:
Note: See TracChangeset for help on using the changeset viewer.