Модуль:MetroMap
ХӀокху модулах лаьцна хааман Модуль:MetroMap/doc агӀо кхолла мега
local jsontable, data, size
local function setglobals(frame)
jsontable = mw.loadJsonData('Кеп:' .. frame.args[1] ..
' метрополитенан интержигара схема/data.json')
data = {}
for key,value in ipairs(jsontable.lines) do
if (value.article and value.name) then
data[value.article] = {undefined, value.name}
end
for key0, value0 in ipairs(value.stations or {}) do
if (value0.article) then
if (not data[value0.article] or
mw.ustring.find(value0.article, '(станция монорельса)', 1, true)) then
data[value0.article] = {value0.coords, value0.name}
end
end
end
end
size = ' ' .. (frame.args['size'] or '20') .. ' '
end
function buildnover(args)
local novertable = {nover = {}}
local formats = jsontable.nover
local novername, place
for key, value in pairs(formats) do
novername = args[key]
if (novername and novername ~= "") then
novertable.nover[novername] = value
end
end
for key, value in pairs(novertable.nover) do
place = key
end
if (formats[place]) then
local novertablecopy = deepcopy(novertable)
novertablecopy.nover[place] = formats[place][2 - (args.popup or 3)] or novertablecopy.nover[place]
return "'" .. mw.text.jsonEncode(novertablecopy) .. "'"
end
return "'" .. mw.text.jsonEncode(novertable) .. "'"
end
function buildhover(frame)
setglobals(frame)
local hovertable = {hover = {}, hoverblocks = {}}
local linename, lcolor, scolor
for key, value in pairs(jsontable.lines) do
for key0, value0 in pairs(value.stations or {}) do
if (value0.hover) then
hovertable.hover[value0.name or value0.article] = value0.hover
end
end
linename = value.name or value.article
lcolor = deepcopy(value.color)
lcolor.strokeStyle = lcolor.strokeStyle or 'rgb(0,0,0,0)'
scolor = deepcopy(value.color)
scolor.strokeStyle = scolor.strokeStyle or scolor.fillStyle
hovertable.hover[linename] = lcolor
if (value.article) then
table.insert(hovertable.hoverblocks, {value = scolor,
list = convertstations(value.stations, hovertable.hover)})
end
end
return mw.text.jsonEncode(hovertable)
end
function classes(station, line)
local ans = deepcopy(jsontable.classes)
ans[station] = ans.localstation
ans[station .. ' super'] = ans.localsuperstation
ans[line .. ' super'] = ans.localsuperline
ans.localstation = nil
ans.localsuperstation = nil
ans.localsuperline = nil
for key, value in pairs(jsontable.lines) do
if (value.future) then
ans[value.name or value.article] = ans.future .. ' ' .. value.classes .. ' ' .. ans.lines
else
ans[value.name or value.article] = value.classes .. ' ' .. ans.lines
end
if (value.remote) then
ans[value.name or value.article] = ans[value.name or value.article] .. ' remote'
else
ans[value.name or value.article] = ans[value.name or value.article] .. ' local'
end
for key0, value0 in pairs(value.stations or {}) do
if (value0.future) then
ans[removeparen(value0.article, value0.name, true)] = ans.default .. ' ' .. ans.future
end
end
end
ans.future = nil
return "'" .. mw.text.jsonEncode(ans) .. "'"
end
function removeparen(article, name, default)
local par
if (name) then
return name
end
par = mw.ustring.find(article, ' (', 1, true)
if (par) then
return mw.ustring.sub(article, 1, par-1)
end
if (default) then
return article
end
end
function convertstations(stations, blocks)
local ans = {}
for key, value in pairs(stations) do
ans[key] = removeparen(value.article, value.name, true)
end
table.sort(ans)
local removed = {}
for key,value in pairs(ans) do
if (blocks[value] or value == ans[key+1]) then
table.insert(removed, key)
end
end
for key = #removed, 1, -1 do
table.remove(ans, removed[key])
end
return ans
end
function deepcopy(original)
if (type(original) == 'nil') then
return nil
elseif (type(original) == 'number') then
return 0 + original
elseif (type(original) == 'string') then
return '' .. original
elseif (original == true) then
return true
elseif (original == false) then
return false
elseif (type(original) == 'function') then
return mw.clone(original)
elseif (type(original) ~= 'table') then
error('Unknown type: ' .. type(original))
end
local copy = {}
for key, value in pairs(original) do
copy[key] = deepcopy(value)
end
return copy
end
function imagemaptext()
local ans = ''
local linestable = jsontable.lines
local lineshapes = '# Lines\n'
local name, article
for key,value in ipairs(linestable) do
if (value.article) then
if (value.remote) then
article = ':ru:' .. value.article
else
article = value.article
end
ans = ans .. '# Line ' .. value.number .. '\nrect ' .. value.box .. ' [[' .. article
if (value.name) then
ans = ans .. '|' .. value.name
end
ans = ans .. ']]\n'
for key0, value0 in ipairs(value.stations) do
name = removeparen(value0.article, value0.name, false)
if (value0.remote) then
article = ':ru:' .. value0.article
else
article = value0.article
end
ans = ans .. 'circle ' .. value0.coords .. size .. '[[' .. article
if (name) then
ans = ans .. '|' .. name
end
ans = ans .. ']]\n'
end
end
if (value.shapes) then
for key0, value0 in ipairs(value.shapes) do
lineshapes = lineshapes .. value0
if (not value.hide) then
lineshapes = lineshapes .. ' [[' .. value.article
if (value.name) then
lineshapes = lineshapes .. '|' .. value.name
end
lineshapes = lineshapes .. ']]'
end
lineshapes = lineshapes .. '\n'
end
end
end
return ans .. terminals('Вокзалы') .. terminals('Аэропорты') .. lineshapes
end
function terminals(ttype)
local items = deepcopy(jsontable[ttype])
if (not items[1]) then
return ''
end
local link = items[1][1]
local left = '# ' .. ttype ..'\ncircle ' .. items[1][2] .. size .. link .. '\n'
local right = ''
table.remove(items, 1)
for key, value in pairs(items) do
left = left .. 'circle ' .. value[2] .. size .. value[1] .. '\n'
right = right .. 'circle ' .. value[2] .. size .. link .. '\n'
end
return left .. right
end
function miniimagemaptext()
local ans = '# Lines\n'
local linestable = jsontable.lines
local shapes, article
for key, value in ipairs(linestable) do
if (value.remote) then
article = ':ru:' .. value.article
else
article = value.article
end
shapes = value.minishapes or value.shapes
if (shapes) then
for key0, value0 in ipairs(shapes) do
ans = ans .. value0
if (not value.hide) then
ans = ans .. ' [[' .. article
if (value.name) then
ans = ans .. '|' .. value.name
end
ans = ans .. ']]'
end
ans = ans .. '\n'
end
end
end
return ans .. '\n'
end
function mobile(frame)
setglobals(frame)
local ans = ''
local linestable = jsontable.lines
local name, class, article
for key,value in ipairs(linestable) do
if (value.article) then
if (value.future) then
class = jsontable.classes.future .. ' ' .. value.classes .. ' ' .. jsontable.classes.lines
else
class = value.classes .. ' ' .. jsontable.classes.lines
end
if (value.remote) then
class = class .. ' remote'
article = ':ru:' .. value.article
else
class = class .. ' local'
article = value.article
end
ans = ans .. "<div class='" .. class .. "' style='text-align:center;white-space:nowrap'>'''[[" .. article
if (value.name) then
ans = ans .. '|' .. value.name
end
ans = ans .. "]]'''</div>\n"
for key0, value0 in ipairs(value.stations) do
name = removeparen(value0.article, value0.name, false)
if (value0.future) then
class = jsontable.classes.future
else
class = ''
end
if (value0.remote) then
class = class .. ' remote'
article = ':ru:' .. value0.article
else
class = class .. ' local'
article = value0.article
end
ans = ans .. "* <span class='" .. class .. "'>[[" .. article
if (name) then
ans = ans .. '|' .. name
end
ans = ans .. ']]</span>\n'
end
end
end
return ans
end
function popup0(frame)
setglobals(frame)
local stationname = ''
local linename = ''
local pagename = mw.title.getCurrentTitle().text
local name = (data[pagename] and data[pagename][2]) or
mw.ustring.gsub(pagename, ' %(.*%)', '')
local minimaptext = miniimagemaptext()
if (data[pagename] and data[pagename][1]) then
stationname = name
minimaptext = minimaptext .. '# Station\ncircle ' .. data[pagename][1] ..
' 25 [[' .. pagename
if (pagename ~= stationname) then
minimaptext = minimaptext .. '|' .. stationname
end
minimaptext = minimaptext .. ']]'
else
linename = name
end
return frame:expandTemplate{title = 'Суьртийн цхьанабараман карта', args = {
['файл'] = frame.args[2],
['тӀейаздар'] = frame:expandTemplate{title = ' ' ..
frame.args[1] .. ' метрополитенан интержигара схема/Куй'},
['тӀейаздар_лакхахь'] = 'хӀаъ',
['уллетаӀор'] = frame:getParent().args['уллетаӀор'] or 'центр',
['схьайелла'] = frame:expandTemplate{title = 'Мотт билгалбаккха', args = {
'йуьззинаэкранан схема хьажоргашца', 'full screen map with stations'
}},
['барам'] = frame:getParent().args['минимум'] or 270,
['иконка'] = 'none',
['класс'] = 'imgtogglemini',
version = frame.args[1],
query = mw.text.nowiki(mw.text.jsonEncode(jsontable.query)),
width = frame.args.mapwidth or 970,
textwidth = frame.args.textwidth or 250;
area = buildnover{['mini station local page'] = stationname, ['mini line local page'] = linename,
pagename = pagename, popup = 0},
areafile = '#invoke:MetroMap|buildhover|' .. frame.args[1],
list = classes(stationname, linename),
['карта'] = minimaptext
}}
end
function popup1(frame)
setglobals(frame)
local stationname = ''
local linename = ''
local pagename = frame.args.pagename
local shrink
local name = (data[pagename] and data[pagename][2]) or
mw.ustring.gsub(pagename, ' %(.*%)', '')
if (data[pagename] and data[pagename][1]) then
stationname = name
else
linename = name
end
if (frame.args.language == 'ce') then
shrink = 'схема дӀахьорчайе'
else
shrink = 'shrink map'
end
return frame:expandTemplate{title = 'Суьртийн цхьанабараман карта', args = {
['файл'] = frame.args[2],
['тӀейаздар'] = frame:expandTemplate{title = ' ' ..
frame.args[1] .. ' метрополитенан интержигара схема/Куй'},
['тӀейаздар_лакхахь'] = 'хӀаъ',
['уллетаӀор'] = 'центр',
['жимдан'] = shrink,
['барам'] = frame.args.width or 1000,
['иконка'] = 'none',
['класс'] = 'popupclass imgtogglefull',
version = 'opened-' .. frame.args[1],
links = frame.args.links,
area = buildnover{['station local page'] = stationname, ['line local page'] = linename,
pagename = pagename, popup = 1},
areafile = '#invoke:MetroMap|buildhover|' .. frame.args[1],
list = classes(stationname, linename),
['карта'] = imagemaptext()
}}
end
return {popup0 = popup0, popup1 = popup1, mobile = mobile, buildhover = buildhover}