App-Dochazka-WWW

 view release on metacpan or  search on metacpan

share/js/dochazka-www/svg-lib.js  view on Meta::CPAN

    var 
        absWidth = 870,

        dayViewerIntervals = function (date, obj, how) {
            // returns an SVG document for date, reflecting clocked and
            // scheduled intervals in obj; how is a boolean value "holiday or
            // weekend"
            var r = '',
                fill, i, intvl, begin, bo, end, eo, color;
            if (how) {
                fill = 'font-weight="bold" fill="transparent"';
            } else {
                fill = 'fill="black"';
            }
            r += '<svg width="' + absWidth + '" height="30" ' + svgBoilerPlate + '>';
            // draw base rectangle
            r += '<rect x="5" y="0" width="' + absWidth + '" height="30" fill="gray" stroke="transparent"/>';
            // draw attendance intervals
            for (i = 0; i < obj.clocked.length; i += 1) {
                intvl = obj.clocked[i];
                [begin, end] = intvl.iNtimerange.split('-');
                [bo, eo] = [timeToOffset(begin), timeToOffset(end)];
                color = appCaches.getActivityByAID(intvl.aid).color;
                r += '<rect x="' + bo + '" y="0" width="' + (eo - bo) + '" height="30" ' +
                     'fill="' + color + '" stroke="transparent"/>';
            }
            // draw schedule intervals
            for (i = 0; i < obj.scheduled.length; i += 1) {
                intvl = obj.scheduled[i];
                [begin, end] = intvl.split('-');
                [bo, eo] = [timeToOffset(begin), timeToOffset(end)];
                r += '<rect x="' + bo + '" y="0" width="' + (eo - bo) + '" height="15" ' +
                     'fill="black" fill-opacity="0.4" stroke="transparent"/>';
            }
            // draw date
            r += '<text font-size="24px" ' + fill + ' ' +
                 'stroke="black" stroke-width="1" x="7" y="26">' + date + ' ' + dt.dateToDay(date) + '</text>';
            r += '</svg>';
            return r;
        },

        dayViewerScale = function () {
            // returns svg document that draws a scale for the multi-day interval viewer
            var r = '',
                i, h, w;
            r += '<svg width="' + (absWidth + 1) + '" height="20" ' + svgBoilerPlate + '>';
            for (i = 0; i < 25; i += 1) {
                if (i < 10) {
                    h = String("0" + i);
                } else {
                    h = i;
                }
                w = timeToOffset(h + ":00");
                r += '<path d="M' + (w + 1) + ' 10 V 20" stroke="black" stroke-width=1 fill="transparent"/>';
                if (i < 24) {
                    r += '<text font-size="10px" x="' + w + '" y=8>' + String(h + "h") + '</text>';
                    r += '<path d="M' + (w + 19) + ' 15 V 20" stroke="black" stroke-width="1" fill="transparent"/>';
                }
            }
            r += '</svg>';
            return r;
        },

        svgBoilerPlate = 'version="1.1" xmlns="http://www.w3.org/2000/svg"',

        timeToOffset = function (t) {
            // given a time, return width offset for drawing



( run in 0.393 second using v1.01-cache-2.11-cpan-a1d94b6210f )