Changeset 3ac70ca in OpenWorkouts-current for ow/static/js/ow.js


Ignore:
Timestamp:
Mar 12, 2019, 9:29:22 PM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current
Children:
39dc0a6
Parents:
f2c9e20
Message:

(#7) Improved tooltip that shows per-day workout stats when hovering a day
on the calendar heatmap chart in the user profile page.

File:
1 edited

Legend:

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

    rf2c9e20 r3ac70ca  
    489489          the chart
    490490        */
     491
     492        // Hide the tooltip
     493        $('.js-calendar-heatmap-tooltip').hide()
     494
    491495        var chart = d3.select(chart_selector);
    492496
     
    541545                rows = calendar_rows(max_date);
    542546
     547            var find_day = function(day) {
     548                var found = data.find(function(d) {
     549                    return d.day == day;
     550                });
     551                return found;
     552            }
     553
    543554            // Build the svg image where the chart will be
    544555            var svg = chart.selectAll("svg")
     
    582593                .on("mouseover", function(d) {
    583594                    d3.select(this).classed('hover', true);
     595                    var day = find_day(d);
     596                    $('.js-ch-tooltip-date').html(titleFormat(new Date(d)));
     597                    if (day != undefined) {
     598                        $('.js-ch-tooltip-workouts').html(day.workouts);
     599                        $('.js-ch-tooltip-time').html(day.time_formatted);
     600                        $('.js-ch-tooltip-distance').html(day.distance_formatted);
     601                        $('.js-ch-tooltip-elevation').html(day.elevation_formatted);
     602                    }
     603                    else {
     604                        $('.js-ch-tooltip-workouts').html(' - ');
     605                        $('.js-ch-tooltip-time').html(' - ');
     606                        $('.js-ch-tooltip-distance').html(' - ');
     607                        $('.js-ch-tooltip-elevation').html(' - ');
     608                    }
     609                    $('.js-calendar-heatmap-tooltip').fadeIn('fast');
    584610                })
    585611                .on("mouseout", function(d) {
    586612                    d3.select(this).classed('hover', false);
     613                    $('.js-calendar-heatmap-tooltip').fadeOut('fast');
    587614                })
    588615                .datum(format);
     
    608635                });
    609636
    610             var find_day = function(day) {
    611                 var found = data.find(function(d) {
    612                     return d.day == day;
    613                 });
    614                 return found;
    615             }
    616 
    617637            var lookup = d3.nest()
    618638                .key(function(d) {
     
    655675                    // doSomething();
    656676                })
    657                 .select("title")
    658                 .text(function(d) {
    659                     // Update the title adding some more info
    660                     var day = find_day(d);
    661                     return titleFormat(new Date(d)) + ":  " + day.time_formatted; });
    662677        });
    663678
Note: See TracChangeset for help on using the changeset viewer.