Modulo:Sandbox/moroboshi2

Versione del 26 ago 2015 alle 09:01 di Moroboshi (discussione | contributi) (test lettura anno)
    local p = {}
    local mWikidata = require('Modulo:Wikidata')
    local mChart = require('Modulo:Chart')
    local getArgs = require('Module:Arguments').getArgs


    function p.demograph(frame)
        local args = getArgs(frame)
        local raw_populations = mWikidata._getProperty({'P1082', from=args[1], rank='normal'}, true)
        local raw_year = mWikidata._getQualifier({'P1082', 'P585', from=args[1], rank='normal'}, true)
        local populations = {}
        local year_s = {}
        for i =1, #raw_populations do
            year_s[#raw_populations-i+1] = raw_year[i]
            populations[#raw_populations-i+1] = raw_populations[i]
        end
        if true then return mw.text.jsonEncode(raw_year, mw.text.JSON_PRETTY) .. "<br/>" .. mw.text.jsonEncode(year_s, mw.text.JSON_PRETTY) end
        local graph_args = {
            ygrid = true,
            xtitle = 'anni',
            ytitle = 'popolazione',
            y = { populations },
            x = { year_s },
            graph_type = 'rect',
            seriesTitles = {'Popolazione'},
            colors = {'#4682B4'}
        }
        local graph_json = mChart.chart_json(graph_args)
        --if true then return  graph_json end
        return  frame:extensionTag('graph', graph_json)
    end

    return p