モジュール:高規格幹線道路

モジュールの解説[作成]
local function create(frame)
	local args=frame:getParent().args
	local name=args[2]
	local width=tonumber(args[3])
	local namehead="/"..name:gsub("(.+)自動車道.*","%1").."/"
	local pa
	if string.find("/北海道縦貫/北海道横断/日高/深川留萌/旭川紋別/帯広広尾/函館江差/",namehead) then
		pa={144.0,43.5,0.64,790000}
	elseif string.find("/東北横断/日本海沿岸東北/東北中央/津軽/三陸縦貫/八戸久慈/",namehead) then
		pa={140.6,39.2,2,280000}
	elseif string.find("/東関東/北関東/首都圏中央連絡/",namehead) then
		pa={139.6,35.9,1.23,240000}
	elseif string.find("/中国縦貫/山陽/中国横断/山陰/尾道福山/東広島呉/",namehead) then
		pa={132.7,35.1,0.82,370000}
	elseif string.find("/四国縦貫/四国横断/今治小松/高知東部/",namehead) then
		pa={133.4,33.6,0.88,280000}
	elseif string.find("/九州縦貫/九州横断/東九州/西九州/南九州西回り/",namehead) then
		pa={130.3,32.4,1.6,350000}
	end
	local projection=require("Module:地図/正射図法")({width,math.floor(width*pa[3])},math.floor(pa[4]/width),{pa[1],pa[2]})
	local size=projection.getSize()
	local reader=require("Module:地図/行政区域")(projection)
	local sc
	do
		local dp=projection.getDp()
		for _,ds in ipairs({1000000,500000,200000,100000,50000,20000,10000,5000,2000,1000,500,200,100}) do
			local m=math.floor(ds/dp)
			if m<size[1]/2 then
				sc={ds,m}
				break
			end
		end
	end
	local marks={}
	table.insert(marks,{
		type="path",
		interactive=false,
		properties={
			enter={
				path={
					value=reader.getCoast()
				},
				fill={
					value="white"
				}
			}
		}
	})
	for i=1,3 do
		local path=reader.getInnerPath(i)
		if #path>0 then
			table.insert(marks,{
				type="path",
				interactive=false,
				properties={
					enter={
						path={
							value=path
						},
						stroke={
							value="gray"
						},
						strokeWidth={
							value=i==1 and 1.5 or 0.25
						},
						strokeDash={
							value=i<=2 and {10,2,2,2} or {2,2}
						}
					}
				}
			})
		end
	end
	local pathlist={}
	for _,line in ipairs(require("Module:地図/高規格幹線道路")(projection)) do
		local path=line.getPath()
		if #path~=0 then
			local type=line.getType()*4+(line.getImcomplete() and 1 or 0)*2+(string.match(line.getName(1),"^"..name) and 1 or 0)
			if pathlist[type]==nil then
				pathlist[type]=""
			end
			pathlist[type]=pathlist[type]..line.getPath()
		end
	end
	for i,path in pairs(pathlist) do
		if i~=9*4+2 then
			local t=math.floor(i/4)
			table.insert(marks,{
				type="path",
				interactive=false,
				properties={
					enter={
						path={
							value=path
						},
						stroke={
							h={
								value=t==1 and 180 or (t==2 and 40 or (t==3 and 0 or (t==5 and 270 or 0)))
							},
							s={
								value=math.floor(i%2)==1 and 0.9 or (t~=9 and 0.7 or 0.2)
							},
							l={
								value=math.floor(i%2)==1 and 0.6 or 0.3
							}
						},
						strokeWidth={
							value=math.floor(i%2)==1 and 5 or (math.floor(i/2)%2==0 and t~=9) and 1.25 or 0.25
						}
					}
				}
			})
		end
	end
	table.insert(marks,{
		type="rect",
		interactive=false,
		properties={
			enter={
				fill={
					value="white"
				},
				fillOpacity={
					value=0.75
				},
				x={
					value=size[1]-sc[2]-8-4
				},
				y={
					value=size[2]-4-24
				},
				width={
					value=sc[2]+4*2
				},
				height={
					value=24
				}
			}
		}
	})
	table.insert(marks,{
		type="rect",
		interactive=false,
		properties={
			enter={
				fill={
					value="black"
				},
				x={
					value=size[1]-sc[2]-8
				},
				y={
					value=size[2]-4-8
				},
				width={
					value=sc[2]
				},
				height={
					value=4
				}
			}
		}
	})
	table.insert(marks,{
		type="text",
		interactive=false,
		properties={
			enter={
				fill={
					value="black"
				},
				align={
					value="center"
				},
				baseline={
					value="middle"
				},
				font={
					value="TakaoExGothic"
				},
				fontSize={
					value=12
				},
				text={
					value=sc[1]<1000 and (sc[1].."m") or ((sc[1]/1000).."km")
				},
				x={
					value=size[1]-sc[2]/2-8
				},
				y={
					value=size[2]-18
				}
			}
		}
	})
	return frame:extensionTag('templatestyles','',{src='Graph:Chart/styles.css'})..mw.text.tag("div",{style=""},
		frame:extensionTag('graph',mw.text.jsonEncode({
			version=2,
			width=size[1],
			height=size[2],
			background="gainsboro",
			marks={
				{
					type="group",
					properties={
						enter={
							clip={
								value=true
							},
							x={
								value=0
							},
							y={
								value=0
							},
							width={
								value=size[1]
							},
							height={
								value=size[2]
							}
						}
					},
					marks=marks
				}
			}
		}))
		..frame:extensionTag('ref','国土交通省 国土数値情報(行政区域・湖沼・高速道路時系列)を加工して作成')
		.."<br/>"
		..mw.text.tag("table",{style="font-size:60%;border-collapse:collapse;border:solid 1px lightgray;"},
			mw.text.tag("tr",{},mw.text.tag("td",{style="border:solid 1px lightgray;color:hsl(180,90%,60%);"},"■")..mw.text.tag("td",{style="border:solid 1px lightgray;color:hsl(180,70%,30%);"},"■")..mw.text.tag("td",{style="border:solid 1px lightgray;"},"[[高速自動車国道]](A路線)"))
			..mw.text.tag("tr",{},mw.text.tag("td",{style="border:solid 1px lightgray;color:hsl(40,90%,60%);"},"■")..mw.text.tag("td",{style="border:solid 1px lightgray;color:hsl(40,70%,30%);"},"■")..mw.text.tag("td",{style="border:solid 1px lightgray;"},"[[高速自動車国道に並行する一般国道自動車専用道路|高速自動車国道に並行する<br/>一般国道自動車専用道路]](A'路線)"))
			..mw.text.tag("tr",{},mw.text.tag("td",{style="border:solid 1px lightgray;color:hsl(0,90%,60%);"},"■")..mw.text.tag("td",{style="border:solid 1px lightgray;color:hsl(0,70%,30%);"},"■")..mw.text.tag("td",{style="border:solid 1px lightgray;"},"[[国土交通大臣指定に基づく高規格幹線道路(一般国道の自動車専用道路)|国土交通大臣指定に基づく高規格幹線道路<br/>(一般国道の自動車専用道路)]](B路線)"))
		)
	)
end
return {
	_=function(frame)
		return create(frame)
	end
}