Changeset d0fc76b in OpenWorkouts-current for ow/static


Ignore:
Timestamp:
Jan 25, 2019, 1:49:34 PM (5 years ago)
Author:
Segundo Fdez <segun.2@…>
Branches:
current, feature/docs, master
Children:
1fe89ea
Parents:
4dcf28d (diff), 26220ba (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into feature/ui

Location:
ow/static
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ow/static/______css/__openworkouts.css

    r4dcf28d rd0fc76b  
    1212    background-color: #eeeeee;
    1313}
     14
     15/* dashboard, weekly stats */
     16
     17span.week_totals_left {
     18    padding-right: 5px;
     19    border-right: 1px solid #e1e1e1;
     20}
     21
     22span.week_totals_right {
     23    padding-left: 5px;
     24}
     25
     26.x-axis path, .x-axis line {
     27    fill: none;
     28    stroke: none;
     29}
     30
     31.bar {
     32    fill: #f8b5be;
     33}
     34
     35.bar:hover {
     36    fill: #ee4056;
     37}
     38
     39.current {
     40    fill: #ee4056;
     41}
     42
     43text.label {
     44    font-size: 0.6em;
     45    text-anchor: middle;
     46}
  • ow/static/js/ow.js

    r4dcf28d rd0fc76b  
    123123
    124124};
     125
     126
     127owjs.week_chart = function(spec) {
     128
     129    "use strict";
     130
     131    // parameters provided when creating an "instance" of the chart
     132    var chart_selector = spec.chart_selector,
     133        url = spec.url,
     134        current_day_name = spec.current_day_name
     135
     136    // Helpers
     137    function select_x_axis_label(d) {
     138        /* Given a value, return the label associated with it */
     139        return d3.select('.x-axis')
     140            .selectAll('text')
     141            .filter(function(x) { return x == d.name; });
     142    }
     143
     144    // Methods
     145    var render = function render() {
     146        /*
     147           Build a d3 bar chart, populated with data from the given url.
     148         */
     149        var chart = d3.select("svg"),
     150            margin = {top: 20, right: 20, bottom: 30, left: 50},
     151            width = +chart.attr("width") - margin.left - margin.right,
     152            height = +chart.attr("height") - margin.top - margin.bottom,
     153            g = chart.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")"),
     154            x = d3.scaleBand().rangeRound([0, width]).padding(0.1),
     155            y = d3.scaleLinear().rangeRound([height, 0]);
     156
     157        d3.json(url).then(function (data) {
     158            x.domain(data.map(function (d) {
     159                return d.name;
     160            }));
     161
     162            y.domain([0, d3.max(data, function (d) {
     163                return Number(d.distance);
     164            })]);
     165
     166            g.append("g")
     167                .attr('class', 'x-axis')
     168                .attr("transform", "translate(0," + height + ")")
     169                .call(d3.axisBottom(x))
     170
     171            g.selectAll(".bar")
     172                .data(data)
     173                .enter().append("rect")
     174                .attr("class", function(d) {
     175                    if (d.name == current_day_name){
     176                        select_x_axis_label(d).attr('style', "font-weight: bold;");
     177                        return 'bar current'
     178                    }
     179                    else {
     180                        return 'bar'
     181                    }
     182                })
     183                .attr("x", function (d) {
     184                    return x(d.name);
     185                })
     186                .attr("y", function (d) {
     187                    return y(Number(d.distance));
     188                })
     189                .attr("width", x.bandwidth())
     190                .attr("height", function (d) {
     191                    return height - y(Number(d.distance));
     192                })
     193                .on('mouseover', function(d) {
     194                    if (d.name != current_day_name){
     195                        select_x_axis_label(d).attr('style', "font-weight: bold;");
     196                    }
     197                })
     198                .on('mouseout', function(d) {
     199                    if (d.name != current_day_name){
     200                        select_x_axis_label(d).attr('style', "font-weight: regular;");
     201                    }
     202                });
     203
     204            g.selectAll(".text")
     205                .data(data)
     206                .enter()
     207                .append("text")
     208                .attr("class","label")
     209                .attr("x", function (d) {
     210                    return x(d.name) + x.bandwidth()/2;
     211                })
     212                .attr("y", function (d) {
     213                    return y(Number(d.distance) + 5);
     214                })
     215                .text(function(d) {
     216                    if (Number(d.distance) > 0) {
     217                        return d.distance;
     218                    }
     219                });
     220
     221        });
     222    };
     223
     224    var that = {}
     225    that.render = render;
     226    return that
     227
     228};
Note: See TracChangeset for help on using the changeset viewer.