模組:Graph:MultiChart/sandbox
外观
![]() | 这是Module:Graph:MultiChart(差异)的沙盒。 |
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 pairs(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