Graph Test: Difference between revisions
From wikiluntti
| Line 194: | Line 194: | ||
=== Horizontal Bar Chart === | === Horizontal Bar Chart === | ||
https://www.mediawiki.org/wiki/Extension:Graph/Demo/HorizontalBarGraphSample | |||
<graph> | <graph> | ||
Revision as of 17:35, 14 June 2021
Introduction
https://www.mediawiki.org/wiki/Extension:Graph/Guide
Methods
Graph
<graph> {
"width": 600,
"height": 150,
"background": "#ffffff",
"data": [
{
"name": "tree",
"values": [
{"A": "Luukalat","B": "Viuhkaeväiset","C": "Cladistia" },
{"A": "Luukalat","B": "Viuhkaeväiset","C": "Rustokiillesuomuiset" },
{"A": "Luukalat","B": "Viuhkaeväiset","C": "Luukiillesuomuiset" },
{"A": "Luukalat","B": "Viuhkaeväiset","C": "Teleosteomorpa" },
{"A": "Luukalat","B": "Varsieväiset","C": "Latimeriat" },
{"A": "Luukalat","B": "Varsieväiset","C": "Keuhkokalat"},
{"A": "Luukalat","B": "Varsieväiset","C": "Nelijalkaiset"},
{"A": "Rustokalat","B": "Hait","C": ""},
{"A": "Rustokalat","B": "Rauskut","C": ""},
{"A": "Rustokalat","B": "Sillikuningaskalat","C": ""},
{"A": "Leuattomat selkärankaiset","B": "Ympyräsuiset","C": "Nahkiaiset"},
{"A": "Leuattomat selkärankaiset","B": "Alkukalat","C": "Pteraspidomorphi"},
{"A": "Leuattomat selkärankaiset","B": "Alkukalat","C": "Thelodonti"},
{"A": "Leuattomat selkärankaiset","B": "Alkukalat","C": "Cephalaspidomorphi"}
],
"transform": [
{
"type": "treeify",
"groupby": ["A","B"]
},
{
"type": "hierarchy",
"mode": "cluster",
"nodesize": [20,100]
},
{
"type": "formula",
"field": "align",
"expr": "'right'"
},
{
"type": "formula",
"field": "offset",
"expr": "-10"
}
]
}
],
"marks": [
{
"type": "path",
"from": {
"data": "tree",
"transform": [
{"type": "filter","test": "datum.parent"},
{
"type": "linkpath",
"sourceX": "parent.layout_y",
"sourceY": "parent.layout_x",
"targetX": "layout_y",
"targetY": "layout_x",
"shape": "cornerX"
}
]
},
"properties": {
"enter": {
"path": {"field": "layout_path"},
"strokeWidth": {"value": 2},
"stroke": {"value": "#000000"}
}
}
},
{
"type": "text",
"from": {
"data": "tree",
"transform": [
{
"type": "formula",
"field": "ff_node_label",
"expr": "if(datum.layout_depth == 0, 'Selkärankaiset', if(datum.layout_depth == 1, datum.A, if(datum.layout_depth == 2, datum.B, if(datum.layout_depth == 3, datum.C, ))))"
}
]
},
"properties": {
"enter": {
"x": {"field": "layout_y"},
"dx": {"field": "offset"},
"y": {"field": "layout_x"},
"dy": {"value": -8},
"font": {"value": "Arial"},
"fontSize": {"value": 16},
"align": {"field": "align"},
"baseline": {"value": "middle"},
"fill": {"value": "#0000ff"},
"text": {"field": "ff_node_label"}
}
}
}
]
} </graph>
Line Chart
Tutorial: https://en.wikipedia.org/wiki/Template:Graph:Chart
<graph> Template:Graph:Chart </graph>
Line graphs
https://www.mediawiki.org/wiki/Extension:Graph/Demo
<graph>
{
"version": 2,
"width": 550,
"height": 400,
"data": [
{
"name": "tree",
"url": "https://cod3v.info/index.php?title=Extension:Graph/data/flare-json",
"format": {"type": "treejson"},
"transform": [
{"type": "hierarchy", "field": "size", "size": [400, 500]}
]
}
],
"marks": [
{
"type": "path",
"from": {
"data": "tree",
"transform": [
{
"type": "filter", "test": "datum.parent"
},
{
"type": "linkpath",
"sourceX": "parent.layout_y",
"sourceY": "parent.layout_x",
"targetX": "layout_y",
"targetY": "layout_x",
"shape": "diagonalX"
}
]
},
"properties": {
"enter": {
"path": {"field": "layout_path"},
"stroke": {"value": "#ddd"}
}
}
},
{
"type": "text",
"from": {"data": "tree"},
"properties": {
"enter": {
"x": {"field": "layout_y", "offset": -10},
"y": {"field": "layout_x"},
"font": {"value": "Helvetica Neue"},
"fontSize": {"value": 10},
"align": {"value": "left"},
"baseline": {"value": "middle"},
"fill": {"value": "#000"},
"text": {"field": "name"}
}
}
}
]
}
</graph>
Horizontal Bar Chart
https://www.mediawiki.org/wiki/Extension:Graph/Demo/HorizontalBarGraphSample
<graph> {
"version": 2, "width": 400, "height": 400,
"padding": {"top": 10, "left": 30, "bottom": 30, "right": 10},
"data": [
{
"name": "table",
"values": [
{"t": "a", "v": 28}, {"t": "b", "v": 55},
{"t": "c", "v": 43}, {"t": "d", "v": 91},
{"t": "e", "v": 81}, {"t": "f", "v": 53},
{"t": "g", "v": 19}, {"t": "h", "v": 87},
{"t": "i", "v": 52}, {"t": "j", "v": 48},
{"t": "k", "v": 24}, {"t": "l", "v": 49},
{"t": "m", "v": 87}, {"t": "n", "v": 66},
{"t": "o", "v": 17}, {"t": "p", "v": 27},
{"t": "q", "v": 68}, {"t": "r", "v": 16},
{"t": "s", "v": 49}, {"t": "t", "v": 15}
]
}
],
"scales": [
{
"name": "x",
"range": "width",
"domain": {"data": "table", "field": "v"}
},
{
"name": "y",
"range": "height",
"type": "ordinal",
"domain": {"data": "table", "field": "t"}
}
],
"axes": [
{"type": "x", "scale": "x"},
{"type": "y", "scale": "y"}
],
"marks": [
{
"type": "rect",
"from": {"data": "table"},
"properties": {
"enter": {
"y": {"scale": "y", "field": "t"},
"height": {"scale": "y", "band": true, "offset": -1},
"x": {"scale": "x", "value": 0},
"x2": {"scale": "x", "field": "v"}
},
"update": {
"fill": {"value": "steelblue"}
},
"hover": {
"fill": {"value": "red"}
}
}
}
]
} </graph>
Bar chart from Vega Tutorials
https://vega.github.io/vega/tutorials/bar-chart/
<graph> {
"$schema": "https://vega.github.io/schema/vega/v5.json", "version": 2, "width": 400, "height": 200, "padding": 5,
"data": [
{
"name": "table",
"values": [
{"category": "A", "amount": 28},
{"category": "B", "amount": 55},
{"category": "C", "amount": 43},
{"category": "D", "amount": 91},
{"category": "E", "amount": 81},
{"category": "F", "amount": 53},
{"category": "G", "amount": 19},
{"category": "H", "amount": 87}
]
}
],
"signals": [
{
"name": "tooltip",
"value": {},
"on": [
{"events": "rect:mouseover", "update": "datum"},
{"events": "rect:mouseout", "update": "{}"}
]
}
],
"scales": [
{
"name": "xscale",
"type": "band",
"domain": {"data": "table", "field": "category"},
"range": "width",
"padding": 0.05,
"round": true
},
{
"name": "yscale",
"domain": {"data": "table", "field": "amount"},
"nice": true,
"range": "height"
}
],
"axes": [
{ "orient": "bottom", "scale": "xscale" },
{ "orient": "left", "scale": "yscale" }
],
"marks": [
{
"type": "rect",
"from": {"data":"table"},
"encode": {
"enter": {
"x": {"scale": "xscale", "field": "category"},
"width": {"scale": "xscale", "band": 1},
"y": {"scale": "yscale", "field": "amount"},
"y2": {"scale": "yscale", "value": 0}
},
"update": {
"fill": {"value": "steelblue"}
},
"hover": {
"fill": {"value": "red"}
}
}
},
{
"type": "text",
"encode": {
"enter": {
"align": {"value": "center"},
"baseline": {"value": "bottom"},
"fill": {"value": "#333"}
},
"update": {
"x": {"scale": "xscale", "signal": "tooltip.category", "band": 0.5},
"y": {"scale": "yscale", "signal": "tooltip.amount", "offset": -2},
"text": {"signal": "tooltip.amount"},
"fillOpacity": [
{"test": "isNaN(tooltip.amount)", "value": 0},
{"value": 1}
]
}
}
}
]
} </graph>