コンテンツにスキップ

英文维基 | 中文维基 | 日文维基 | 草榴社区

モジュール:日本人口

モジュールの解説[作成]
local function create()
	local indexlist={}
	for i=0,100-1 do
		table.insert(indexlist,i)
	end
	return {
		width=1024,
		height=320,
		signals={
			{
				name="demo",
				init={
					require("Module:日本人口/data")
				},
				streams={
					{
						type="arc:click,arc:touchend",
						expr="if(datum.a.b.data==0,[demo[0],datum.z],if(datum.a.b.data==1,[demo[0],demo[1],datum.z],if(datum.a.b.data==2,[demo[0],demo[1],demo[2],datum.z],[demo[0],demo[1],demo[2],demo[3]])))"
					}
				}
			},
			{
				name="active",
				init=nil,
				streams={
					{
						type="arc:mouseover",
						expr="datum.z"
					},
					{
						type="arc:mouseout",
						expr="null"
					}
				}
			}
		},
		data={
			{
				name="i",
				values=indexlist
			},
			{
				name="base",
				values={0},
				transform={
					{
						type="cross",
						with="i"
					},
					{
						type="filter",
						test="datum.b.data<demo.length"
					},
					{
						type="formula",
						field="z",
						expr="demo[datum.b.data]"
					}
				}
			}
		},
		marks={
			{
				type="text",
				from={
					data="base"
				},
				properties={
					enter={
						align={
							value="center"
						},
						baseline={
							value="middle"
						},
						fill={
							value="black"
						},
						font={
							value="TakaoExGothic"
						},
						x={
							field="b.data",
							mult=256,
							offset=128
						},
						y={
							value=128*2+32
						},
						fontSize={
							value=24
						}
					},
					update={
						text={
							field="z.name"
						}
					}
				}
			},
			{
				type="text",
				from={
					data="base",
					transform={
						{
							type="formula",
							field="text",
							expr="replace(floor(datum.z.population/100000000)+'億'+slice('0000'+floor(datum.z.population/10000)%10000,-4)+'万'+slice('0000'+datum.z.population%10000,-4),regexp('^[0億万]+'),'')+'人'"
						}
					}
				},
				properties={
					enter={
						align={
							value="center"
						},
						baseline={
							value="middle"
						},
						fill={
							value="black"
						},
						font={
							value="TakaoExGothic"
						},
						x={
							field="b.data",
							mult=256,
							offset=128
						},
						y={
							value=128*2+32*2
						},
						fontSize={
							value=16
						}
					},
					update={
						text={
							field="text"
						}
					}
				}
			},
			{
				type="group",
				from={
					data="base",
					transform={
						{
							type="facet",
							groupby={"b.data"},
							transform={
								{
									type="cross",
									with="i"
								},
								{
									type="filter",
									test="datum.a.z.children!=null&&datum.b.data<datum.a.z.children.length"
								},
								{
									type="formula",
									field="z",
									expr="datum.a.z.children[datum.b.data]"
								},
								{
									type="pie",
									field="z.population",
									sort=true
								}
							}
						}
					}
				},
				properties={
					enter={
						x={
							field="key",
							mult=256
						},
						y={
							value=0
						},
						width={
							value=256
						},
						height={
							value=256
						}
					}
				},
				marks={
					{
						type="arc",
						from={
							transform={
								{
									type="formula",
									field="l",
									expr="if(datum.z==active,0.8,0.9)"
								},
								{
									type="formula",
									field="s",
									expr="if(demo[datum.a.b.data+1]==null||demo[datum.a.b.data+1]==datum.z,1,0.6)"
								}
							}
						},
						properties={
							enter={
								stroke={
									value="black"
								},
								strokeWidth={
									value=0.25
								}
							},
							update={
								fill={
									h={
										value=240
									},
									l={
										field="l"
									},
									s={
										field="s"
									}
								},
								x={
									value=128
								},
								y={
									value=128
								},
								startAngle={
									field="layout_end",
									mult=-1,
									offset=math.pi*2
								},
								endAngle={
									field="layout_start",
									mult=-1,
									offset=math.pi*2
								},
								innerRadius={
									value=32
								},
								outerRadius={
									value=128-8
								},
								cursor={
									value="pointer"
								}
							}
						}
					},
					{
						type="group",
						from={
							transform={
								{
									type="filter",
									test="datum.layout_end-datum.layout_start>PI/20||datum.z==active"
								},
								{
									type="cross",
									with="i"
								},
								{
									type="filter",
									test="datum.b.data<datum.a.z.name.length"
								},
								{
									type="formula",
									field="u",
									expr="datum.b.data-(datum.a.z.name.length-1)/2"
								},
								{
									type="formula",
									field="v",
									expr="if(floor((floor(datum.a.layout_mid/(PI/4))+1)/2)%2==1,[1,0],[0,1])"
								},
								{
									type="formula",
									field="size",
									expr="if(datum.a.z==active,16,12)"
								},
								{
									type="formula",
									field="p",
									expr="[-sin(datum.a.layout_mid)*80+128+datum.u*datum.v[0]*datum.size*1.1,-cos(datum.a.layout_mid)*80+128+datum.u*datum.v[1]*datum.size*1.1]"
								},
								{
									type="formula",
									field="c",
									expr="datum.a.z.name[datum.b.data]"
								},
								{
									type="facet"
								}
							}
						},
						marks={
							{
								type="text",
								interactive=false,
								properties={
									enter={
										align={
											value="center"
										},
										baseline={
											value="middle"
										},
										fill={
											value="black"
										},
										font={
											value="TakaoExGothic"
										}
									},
									update={
										x={
											field="p[0]"
										},
										y={
											field="p[1]"
										},
										text={
											field="c"
										},
										fontSize={
											field="size"
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
end
return {
	_=function(frame)
		return frame:extensionTag('graph',mw.text.jsonEncode(create()),{mode='interactive'})
	end
}