תבנית:עוגת קטגוריות
מתוך ויקיפדיה, האנציקלופדיה החופשית
פעולות נוספות
תבנית זו מקבלת שם של קטגוריה ומייצרת ממנה גרף של תתי קטגוריות לפי הגודל שלהן.
דוגמה עריכה
קוד: {{עוגת קטגוריות|ישראל}}
תוצאה: <graph> {
"version": 2,
"width": 300,
"height": 300,
"data": [
{
"name": "table",
"url": "wikiapi:///?generator=categorymembers&gcmtitle=Category:%D7%99%D7%A9%D7%A8%D7%90%D7%9C&gcmtype=subcat&action=query&gcmlimit=max&prop=categoryinfo&formatversion=2&format=json",
"format": {"property": "query.pages","type": "json"},
"transform": [
{"type": "sort","by": "-categoryinfo.size"},
{"type": "pie","field": "categoryinfo.size"}
]
}
],
"scales": [
{
"name": "color",
"domain": {"data": "table","field": "title"},
"range": "category10",
"type": "ordinal"
}
],
"marks": [
{
"from": {"data": "table"},
"type": "arc",
"properties": {
"enter": {
"fill": {"scale": "color","field": "title"},
"outerRadius": {"value": 200},
"startAngle": {"field": "layout_start"},
"endAngle": {"field": "layout_end"},
"stroke": {"value": "white"},
"strokeWidth": {"value": 1}
}
}
},
{
"from": {
"data": "table",
"transform": [
{ "type": "formula", "field": "sliceSize", "expr": "(datum.layout_end - datum.layout_start)*180/PI" },
{ "type": "filter", "test": "datum.sliceSize > 2" },
{ "type": "formula", "field": "title", "expr": "substring(datum.title, 1+indexof(datum.title,':'), 40)" },
{ "type": "formula", "field": "invert", "expr": "datum.layout_mid*180/PI < 180 ? 1 : -1" },
{ "type": "formula", "field": "align", "expr": "datum.invert < 0 ? 'left' : 'right'" },
{ "type": "formula", "field": "angle", "expr": "(datum.layout_mid*180/PI)-90*datum.invert" },
{ "type": "formula", "field": "fontSize", "expr": "datum.sliceSize > 20 ? 15 : (datum.sliceSize > 10 ? 14 : 10)" },
{ "type": "formula", "field": "fontWeight", "expr": "datum.sliceSize > 15 ? 'bold' : 'normal'" }
]
},
"type": "text",
"properties": {
"enter": {
"align": {"field": "align"},
"angle": {"field": "angle"},
"baseline": {"value": "middle"},
"fill": {"value": "black"},
"fontSize": {"field": "fontSize"},
"fontWeight": {"field": "fontWeight"},
"radius": {"value": 270},
"text": {"field": "title"},
"theta": {"field": "layout_mid"}
}
}
}
]
} </graph>