跳转到内容

模組:Graph:MultiChart/sandbox

维基百科,自由的百科全书

这是本页的一个历史版本,由A2569875留言 | 贡献2021年5月25日 (二) 04:56编辑。这可能和当前版本存在着巨大的差异。

local p={}
local lib_arg={}
--{{#invoke:沙盒/a2569875/Graph:MultiChart|mergeChart}}
function p.mergeChart(frame)
    local args = (type(frame) == type('')) and {frame} or ((type((frame or {}).args)==type({})) and frame.args or frame)
	local json, success = args['1'] or args[1], true
	if mw.text.trim(json) == '' then return '' end
	success, json = pcall(mw.text.jsonDecode, json, mw.text.JSON_TRY_FIXING )
	if not success then return '' end
	if type(json.data)==type({}) then json = {json} end
	if #json < 1 then return '' end
	local base_obj = {}
	local i=1
	for k,v in pairs(json[i]) do
		if type(v) == type({}) then
			local it = mw.clone(v)
			for id,data in it do
				if type(data.name) == type('') then
					it[id].name = data.name .. i
				end
				if type((data.from or {}).data) == type('') then
					it[id].from.data = data.from.data .. i
				end
				if type(data.type) == type('') then
					if(i~=1 and k=='axes' and data.type=='x') then it[id]=nil
					else

					end
				end
			end
			base_obj[k] = it
		else
			base_obj[k] = v
		end
	end
	
	return mw.dumpObject(base_obj)
end
return p