function renderPodlingsEvolution()

in site/js/projects.js [1145:1230]


function renderPodlingsEvolution(obj) {
    var evo = {}; // 'year-month' -> { started: [], graduated: [], retired: [] }
    // init evo with empty content for the whole period
    var maxYear = new Date().getFullYear();
    for (var year = 2003; year <= maxYear; year++) {
        var maxMonth = (year < maxYear) ? 12 : (new Date().getMonth() + 1);
        for (var month = 1; month <= maxMonth; month++) {
            var key = year + '-' + (month < 10 ? '0':'') + month;
            evo[key] = { 'started': [], 'graduated': [], 'retired': [] };
        }
    }
    // add current podlings
    var p;
    for (p in podlings) {
        p = podlings[p];
        if (p['podling']) {
            evo[p.started]['started'].push(p);
        }
    }
    // add podlings history
    for (p in podlingsHistory) {
        p = podlingsHistory[p];
        evo[p.started]['started'].push(p);
        evo[p.ended][p.status].push(p);
    }
    // compute data
    var data = [];
    var cur = 0;
    var d;
    for (d in evo) {
        var started = evo[d]['started'];
        var graduated = evo[d]['graduated'];
        var retired = evo[d]['retired'];
        var startedDisplay = [];
        for (p in started) {
            p = started[p];
            startedDisplay.push(p.name + (p['ended'] ? ' (' + p.status + ' ' + p.ended + ')':''));
        }
        var graduatedDisplay = [];
        for (p in graduated) {
            p = graduated[p];
            graduatedDisplay.push(p.name + ' (started ' + p.started + ')');
        }
        var retiredDisplay = [];
        for (p in retired) {
            p = retired[p];
            retiredDisplay.push(p.name + ' (started ' + p.started + ')');
        }
        cur += started.length - graduated.length - retired.length;
        data.push([d, started.length, htmlListTooltip(d, 'new podling', startedDisplay),
            -1*graduated.length, htmlListTooltip(d, 'graduated podling', graduatedDisplay),
            -1*retired.length, htmlListTooltip(d, 'retired podling', retiredDisplay), cur]);
    }
    //narr.sort(function(a,b) { return (b[1] - a[1]) });
    var dataTable = new google.visualization.DataTable();
    dataTable.addColumn('string', 'Month');
    dataTable.addColumn('number', "New podlings");
    dataTable.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});
    dataTable.addColumn('number', "Graduated podlings");
    dataTable.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});
    dataTable.addColumn('number', "Retired podlings");
    dataTable.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});
    dataTable.addColumn('number', 'Current podlings');

    dataTable.addRows(data);

    var coptions = {
        title: "Incubating projects evolution",
        isStacked: true,
        height: 320,
        width: 1160,
        seriesType: "bars",
        backgroundColor: 'transparent',
        colors: ['#3366cc', '#109618', '#dc3912', '#ff9900'],
        series: {3: {type: "line", targetAxisIndex: 1}},
        tooltip: {isHtml: true},
        vAxes: [
            {title: 'Change in states', ticks: [-6,-3,0,3,6]},
            {title: 'Current number of podlings'}
        ]
    };
    var div = document.createElement('div');
    document.getElementById('details').appendChild(div);
    var chart = new google.visualization.ComboChart(div);
    chart.draw(dataTable, coptions);
}