Changes
removed debug sparqs
<includeonly>{{#tag:{{#if:{{{debug|}}}|syntaxhighlight|graph}}|</includeonly><noinclude>{{documentation}}<syntaxhighlight lang=html><graph></syntaxhighlight>{{#tag:syntaxhighlight|</noinclude>
{
//
// ATTENTION: This code is maintained at https://www.mediawiki.org/wiki/Template:Graph:Stacked
// Please do not modify it anywhere else, as it may get copied and override your changes.
// Suggestions can be made at https://www.mediawiki.org/wiki/Template:Graph:Stacked
//
// Template translation is in https://commons.wikimedia.org/wiki/Data:Original/Template:Graphs.tab
//
"version": 2,
"width": {{{width|550}}},
"height": {{{height|250}}},
"data": [{
"name": "chart",
{{#switch: {{{tabletype|tab}}}
|tab= "url": "tabular:///{{{table}}}",
|query= "url": "wikidatasparql:///?query={{urlencode:{{{table}}}|PATH}}",
}}
"format": {"type": "json"
{{#ifeq:{{{tabletype|tab}}}|tab|
, "property": "data"
}}
{{#ifeq:{{{type|}}}|time|
, "parse": {"{{{xField}}}": "date"}
}}
},
"transform": [
// Convert xField parameter into a field "_xfield"
{"type": "formula", "field": "_xfield", "expr":
{{#switch: {{{type|}}}
| year= "datetime(datum.{{{xField|year}}}, 0, 1)"
| "datum.{{{xField}}}"
}}
},
{"type": "sort", "by": ["_xfield"]},
{{#if:{{{series|}}}
| {"type": "fold", "fields": [{{{series}}}]},
}}
// For non-bar graph, ensure that all missing values still present as zeros to avoid area breaks
// We might need to allow other, non-0 values to be imputed.
{{#if:{{{barwidth|}}}||
{
"type": "impute",
"groupby": ["{{{group|key}}}"],
"orderby": ["_xfield"],
"field": "{{{value|value}}}",
"method": "value",
"value": 0
},
}}
]
},
{{#if:{{{series|}}}|{{#ifeq: {{{tabletype|tab}}} | tab |
{
"name": "labels",
"url": "tabular:///{{{table}}}",
"format": {"type": "json", "property": "fields"}
},
}}}}
{
"name": "stats",
"source": "chart",
"transform": [{
"type": "aggregate",
"groupby": ["_xfield"],
"summarize": [{"field": "{{{value|value}}}", "ops": ["sum"]}]
}]
}
],
"scales": [
{
"name": "x",
"type": {{#switch: {{{type|}}}
| year= "time"
| "{{{type}}}"
}},
"domain": {"data": "chart", "field": "_xfield"},
{{#if:{{{barwidth|}}}|{{#ifeq:{{{type|}}}|ordinal|"points": true,}}}}
"range": "width",
{{#if:{{{xZero|}}}|"zero": {{{xZero}}},}}
{{#if:{{{xMin|}}}|"domainMin": {{{xMin}}},}}
{{#if:{{{xMax|}}}|"domainMax": {{{xMax}}},}}
},
{
"name": "y",
"type": "linear",
"range": "height",
"domain": {"data": "stats", "field": "sum_{{{value|value}}}"},
{{#if:{{{yZero|}}}|"zero": {{{yZero}}},}}
{{#if:{{{yMin|}}}|"domainMin": {{{yMin}}},}}
{{#if:{{{yMax|}}}|"domainMax": {{{yMax}}},}}
},
{
"name": "color",
"type": "ordinal",
"domain": {"data": "chart", "field": "{{{group|key}}}"},
"range": {{{colors|"category10"}}}
},
{{#if:{{{series|}}}|
{
"name": "labels",
"type": "ordinal",
{{#ifeq: {{{tabletype|tab}}} | tab
| "domain": {"data": "labels", "field": "name"},
"range": {"data": "labels", "field": "title"},
| "domain": [{{{series|}}}],
"range": [{{{series|}}}],
}}
}
}}
],
{{#if:{{{legend|}}}|
"legends": [{
"fill": "color",
"stroke": "color",
{{#ifeq: {{{legend|}}}|-|| "title": "{{{legend|}}}", }}
{{#if:{{{series|}}}
| "properties": { "labels": { "text": {"scale": "labels", "field": "data"} } }
}}
}],
}}
"axes": [
{"scale": "x", "type": "x", "tickSizeEnd": 0
{{#ifeq:{{{xTicks|7}}}|-||, "ticks": {{{xTicks|7}}}}}
{{#if:{{{xAxis|}}}|, "title": "{{{xAxis}}}"}}
{{#if:{{{xGrid|}}}|, "grid": true}}
},
{"scale": "y", "type": "y", "tickSizeEnd": 0
// When drawing "type=year" bars with the given width, shift y axis left by half the width
{{#ifeq:{{{type|}}}|year|{{#ifeq:{{{barwidth|auto}}}|auto||,"offset":{{#expr:1+{{{barwidth}}}/2}}}}}}
{{#ifeq:{{{yTicks|-}}}|-||, "ticks": {{{yTicks}}}}}
{{#if:{{{yAxis|}}}|, "title": "{{{yAxis}}}"}}
{{#if:{{{yGrid|}}}|, "grid": true}}
}
],
"marks": [
// Group data by the "key", and draw lines, one line per key
{
{{#if:{{{barwidth|}}}
| "type": "rect",
"from": {
"data": "chart",
"transform": [
{"type": "stack", "groupby": ["_xfield"], "sortby": ["{{{group|key}}}"], "field": "{{{value|value}}}"}
]
},
"properties": {
"enter": {
"x": {"scale": "x", "field": "_xfield"
// When drawing "type=year" bars with the given width, shift them back by half the width
{{#ifeq:{{{type|}}}|year|{{#ifeq:{{{barwidth|auto}}}|auto||,"offset":{{#expr:{{{barwidth}}}/-2}}}}}}
},
{{#ifeq:{{{barwidth|}}}|auto|
{{#ifeq:{{{type|}}}|ordinal
| "width": {"scale": "x", "band": true, "offset": -1},
| "width": {"value": 3},
}}
| "width": {"value": {{{barwidth}}} },
}}
"y": {"scale": "y", "field": "layout_start"},
"y2": {"scale": "y", "field": "layout_end"},
"fill": {"scale": "color", "field": "{{{group|key}}}"}
}
}
| "type": "group",
"from": {
"data": "chart",
"transform": [
{"type": "stack", "groupby": ["_xfield"], "sortby": ["{{{group|key}}}"], "field": "{{{value|value}}}"},
{"type": "facet", "groupby": ["{{{group|key}}}"]}
]
},
"marks": [
{
"type": "area",
"properties": {
"enter": {
"x": {"scale": "x", "field": "_xfield"},
"y": {"scale": "y", "field": "layout_start"},
"y2": {"scale": "y", "field": "layout_end"},
"fill": {"scale": "color", "field": "{{{group|key}}}"},
"interpolate": {"value": "monotone"}
}
}
}
],
}}
}
{{#if:{{{title|}}}|
// Draw title at the top of the graph
, {
"type": "text",
"properties": {
"enter": {
"x": {"signal": "width", "mult": 0.5, "offset": 30},
"y": {"value": -15},
"text": {"value": "{{{title}}}"},
"fontWeight": {"value": "bold"},
"align": {"value": "center"},
"baseline": {"value": "bottom"},
"fill": {"value": "#000"}
}
}
}
}}
]
}
<includeonly>}}
<small>{{#switch: {{{tabletype|tab}}}
|tab= {{#invoke:TNT|msg|Original/Template:Graphs.tab|source-table|{{#invoke:TNT|link|{{{table}}}}}}}.
|query= {{#invoke:TNT|msg|Original/Template:Graphs.tab|source-wdqs|https://query.wikidata.org/#{{urlencode:{{{table}}}|PATH}}}}.
}}</small>
</includeonly><noinclude>|lang=javascript}}<syntaxhighlight lang=html></graph></syntaxhighlight></noinclude>
{
//
// ATTENTION: This code is maintained at https://www.mediawiki.org/wiki/Template:Graph:Stacked
// Please do not modify it anywhere else, as it may get copied and override your changes.
// Suggestions can be made at https://www.mediawiki.org/wiki/Template:Graph:Stacked
//
// Template translation is in https://commons.wikimedia.org/wiki/Data:Original/Template:Graphs.tab
//
"version": 2,
"width": {{{width|550}}},
"height": {{{height|250}}},
"data": [{
"name": "chart",
{{#switch: {{{tabletype|tab}}}
|tab= "url": "tabular:///{{{table}}}",
|query= "url": "wikidatasparql:///?query={{urlencode:{{{table}}}|PATH}}",
}}
"format": {"type": "json"
{{#ifeq:{{{tabletype|tab}}}|tab|
, "property": "data"
}}
{{#ifeq:{{{type|}}}|time|
, "parse": {"{{{xField}}}": "date"}
}}
},
"transform": [
// Convert xField parameter into a field "_xfield"
{"type": "formula", "field": "_xfield", "expr":
{{#switch: {{{type|}}}
| year= "datetime(datum.{{{xField|year}}}, 0, 1)"
| "datum.{{{xField}}}"
}}
},
{"type": "sort", "by": ["_xfield"]},
{{#if:{{{series|}}}
| {"type": "fold", "fields": [{{{series}}}]},
}}
// For non-bar graph, ensure that all missing values still present as zeros to avoid area breaks
// We might need to allow other, non-0 values to be imputed.
{{#if:{{{barwidth|}}}||
{
"type": "impute",
"groupby": ["{{{group|key}}}"],
"orderby": ["_xfield"],
"field": "{{{value|value}}}",
"method": "value",
"value": 0
},
}}
]
},
{{#if:{{{series|}}}|{{#ifeq: {{{tabletype|tab}}} | tab |
{
"name": "labels",
"url": "tabular:///{{{table}}}",
"format": {"type": "json", "property": "fields"}
},
}}}}
{
"name": "stats",
"source": "chart",
"transform": [{
"type": "aggregate",
"groupby": ["_xfield"],
"summarize": [{"field": "{{{value|value}}}", "ops": ["sum"]}]
}]
}
],
"scales": [
{
"name": "x",
"type": {{#switch: {{{type|}}}
| year= "time"
| "{{{type}}}"
}},
"domain": {"data": "chart", "field": "_xfield"},
{{#if:{{{barwidth|}}}|{{#ifeq:{{{type|}}}|ordinal|"points": true,}}}}
"range": "width",
{{#if:{{{xZero|}}}|"zero": {{{xZero}}},}}
{{#if:{{{xMin|}}}|"domainMin": {{{xMin}}},}}
{{#if:{{{xMax|}}}|"domainMax": {{{xMax}}},}}
},
{
"name": "y",
"type": "linear",
"range": "height",
"domain": {"data": "stats", "field": "sum_{{{value|value}}}"},
{{#if:{{{yZero|}}}|"zero": {{{yZero}}},}}
{{#if:{{{yMin|}}}|"domainMin": {{{yMin}}},}}
{{#if:{{{yMax|}}}|"domainMax": {{{yMax}}},}}
},
{
"name": "color",
"type": "ordinal",
"domain": {"data": "chart", "field": "{{{group|key}}}"},
"range": {{{colors|"category10"}}}
},
{{#if:{{{series|}}}|
{
"name": "labels",
"type": "ordinal",
{{#ifeq: {{{tabletype|tab}}} | tab
| "domain": {"data": "labels", "field": "name"},
"range": {"data": "labels", "field": "title"},
| "domain": [{{{series|}}}],
"range": [{{{series|}}}],
}}
}
}}
],
{{#if:{{{legend|}}}|
"legends": [{
"fill": "color",
"stroke": "color",
{{#ifeq: {{{legend|}}}|-|| "title": "{{{legend|}}}", }}
{{#if:{{{series|}}}
| "properties": { "labels": { "text": {"scale": "labels", "field": "data"} } }
}}
}],
}}
"axes": [
{"scale": "x", "type": "x", "tickSizeEnd": 0
{{#ifeq:{{{xTicks|7}}}|-||, "ticks": {{{xTicks|7}}}}}
{{#if:{{{xAxis|}}}|, "title": "{{{xAxis}}}"}}
{{#if:{{{xGrid|}}}|, "grid": true}}
},
{"scale": "y", "type": "y", "tickSizeEnd": 0
// When drawing "type=year" bars with the given width, shift y axis left by half the width
{{#ifeq:{{{type|}}}|year|{{#ifeq:{{{barwidth|auto}}}|auto||,"offset":{{#expr:1+{{{barwidth}}}/2}}}}}}
{{#ifeq:{{{yTicks|-}}}|-||, "ticks": {{{yTicks}}}}}
{{#if:{{{yAxis|}}}|, "title": "{{{yAxis}}}"}}
{{#if:{{{yGrid|}}}|, "grid": true}}
}
],
"marks": [
// Group data by the "key", and draw lines, one line per key
{
{{#if:{{{barwidth|}}}
| "type": "rect",
"from": {
"data": "chart",
"transform": [
{"type": "stack", "groupby": ["_xfield"], "sortby": ["{{{group|key}}}"], "field": "{{{value|value}}}"}
]
},
"properties": {
"enter": {
"x": {"scale": "x", "field": "_xfield"
// When drawing "type=year" bars with the given width, shift them back by half the width
{{#ifeq:{{{type|}}}|year|{{#ifeq:{{{barwidth|auto}}}|auto||,"offset":{{#expr:{{{barwidth}}}/-2}}}}}}
},
{{#ifeq:{{{barwidth|}}}|auto|
{{#ifeq:{{{type|}}}|ordinal
| "width": {"scale": "x", "band": true, "offset": -1},
| "width": {"value": 3},
}}
| "width": {"value": {{{barwidth}}} },
}}
"y": {"scale": "y", "field": "layout_start"},
"y2": {"scale": "y", "field": "layout_end"},
"fill": {"scale": "color", "field": "{{{group|key}}}"}
}
}
| "type": "group",
"from": {
"data": "chart",
"transform": [
{"type": "stack", "groupby": ["_xfield"], "sortby": ["{{{group|key}}}"], "field": "{{{value|value}}}"},
{"type": "facet", "groupby": ["{{{group|key}}}"]}
]
},
"marks": [
{
"type": "area",
"properties": {
"enter": {
"x": {"scale": "x", "field": "_xfield"},
"y": {"scale": "y", "field": "layout_start"},
"y2": {"scale": "y", "field": "layout_end"},
"fill": {"scale": "color", "field": "{{{group|key}}}"},
"interpolate": {"value": "monotone"}
}
}
}
],
}}
}
{{#if:{{{title|}}}|
// Draw title at the top of the graph
, {
"type": "text",
"properties": {
"enter": {
"x": {"signal": "width", "mult": 0.5, "offset": 30},
"y": {"value": -15},
"text": {"value": "{{{title}}}"},
"fontWeight": {"value": "bold"},
"align": {"value": "center"},
"baseline": {"value": "bottom"},
"fill": {"value": "#000"}
}
}
}
}}
]
}
<includeonly>}}
<small>{{#switch: {{{tabletype|tab}}}
|tab= {{#invoke:TNT|msg|Original/Template:Graphs.tab|source-table|{{#invoke:TNT|link|{{{table}}}}}}}.
|query= {{#invoke:TNT|msg|Original/Template:Graphs.tab|source-wdqs|https://query.wikidata.org/#{{urlencode:{{{table}}}|PATH}}}}.
}}</small>
</includeonly><noinclude>|lang=javascript}}<syntaxhighlight lang=html></graph></syntaxhighlight></noinclude>