Jump to content

Template:Graph:Lines: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
+embed.html
 
(22 intermediate revisions by 11 users not shown)
Line 1: Line 1:
{{#ifeq:{{{align|{{{2|}}}}}}|center|<div class="center">}}{{#if:{{{thumb|{{{1|}}}}}}|<div class="thumb {{#switch:{{{align|{{{2|}}}}}}|center|none=tnone|left=tleft|right|#default=tright}}"><div class="thumbinner" style="width: fit-content;"><div class="thumbimage">|<div class="{{#switch:{{{align|{{{2|}}}}}}|right=floatright|left=floatleft|#default=floatnone}}">}}<includeonly>{{#invoke:Template wrapper|wrap|_template=Graph:Lines/core|_exclude=thumb, align, caption, 1, 2, 3|hideSource=true}}</includeonly><noinclude>[[File:Template-Graph-Lines example.png]]</noinclude>{{#if:{{{thumb|{{{1|}}}}}}|</div><div class="thumbcaption">|<div><small>}}{{{caption|{{{3|{{#if:{{{title|}}}|{{{title}}}.}}}}}}}}
<includeonly>{{#tag:{{#if:{{{debug|}}}|syntaxhighlight|graph}}|</includeonly><noinclude><!--
{{#switch: {{{tabletype|tab}}}{{{hideSource|}}}
Insert /doc page if available, otherwise insert itself-->{{#ifexist:{{FULLPAGENAME}}/doc|{{documentation}}|{{ :{{FULLPAGENAME}}}}}}<syntaxhighlight lang=html><graph></syntaxhighlight>{{#tag:syntaxhighlight|</noinclude>
|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/embed.html#{{urlencode:{{{table}}}|PATH}}}}.
//
}}{{#if:{{{thumb|{{{1|}}}}}}|</div>|</small>}}</div></div>{{#ifeq:{{{align|{{{2|}}}}}}|center|</div>}}<noinclude>
// ATTENTION: This code is maintained at https://www.mediawiki.org/wiki/Template:Graph:Lines
{{clear}}
// Please do not modify it anywhere else, as it may get copied and override your changes.
{{ombox| type = content | image = [[File:Test Template Info-Icon - Version (2).svg|40px]]
// Suggestions can be made at https://www.mediawiki.org/wiki/Template_talk:Graph:Lines
| text = This is a wrapper template for [[Template:Graph:Lines/core]], whose source is maintained at [[:mw:Template:Graph:Lines]]. This wrapper implements Wikipedia-specific styles on top of the original template.}}
//
{{documentation}}

</noinclude>
"version": 2,
"width": {{{width|300}}},
"height": {{{height|200}}},

"data": [{
"name": "chart",
"url": "tabular:///{{{table|}}}",
"format": {"type": "json", "property": "data"
{{#ifeq:{{{type|}}}|time|
, "parse": {"{{{xField}}}": "date"}
}}
},
"transform": [
// Convert xField parameter into a field "_xfield"
{"type": "formula", "field": "_xfield", "expr":
{{#switch: {{{type|year}}}
| year= "datetime(datum.{{{xField|year}}}, 0, 1)"
| "datum.{{{xField}}}"
}}
},
{"type": "fold", "fields": [{{{series}}}]}
]
},
{
"name": "labels",
"url": "tabular:///{{{table|}}}",
"format": {"type": "json", "property": "schema.fields"}
}],
"scales": [
{
"name": "x",
"type": {{#switch: {{{type|year}}}
| year= "time"
| "{{{type}}}"
}},
"domain": {"data": "chart", "field": "_xfield"},
"range": "width",
{{#if:{{{xZero|}}}|"zero": {{{xZero}}},}}
{{#if:{{{xMin|}}}|"domainMin": {{{xMin}}},}}
{{#if:{{{xMax|}}}|"domainMax": {{{xMax}}},}}
},
{
"name": "y",
"type": "linear",
"range": "height",
"domain": {"data": "chart", "field": "value"},
{{#if:{{{yZero|}}}|"zero": {{{yZero}}},}}
{{#if:{{{yMin|}}}|"domainMin": {{{yMin}}},}}
{{#if:{{{yMax|}}}|"domainMax": {{{yMax}}},}}
},
{
"name": "color",
"type": "ordinal",
"domain": {"data": "chart", "field": "key"},
"range": "category10"
},
{
"name": "labels",
"type": "ordinal",
"domain": {"data": "labels", "field": "name"},
"range": {"data": "labels", "field": "title"},
}
],
{{#if:{{{legend|}}}|
"legends": [{
"fill": "color",
"stroke": "color",
"title": "{{{legend|}}}",
"properties": {
"labels": { "text": {"scale": "labels", "field": "data"} }
}
}],
}}
"axes": [
{"scale": "x", "type": "x", "ticks": 7
{{#if:{{{xAxis|}}}|, "title": "{{{xAxis|}}}"}}
{{#if:{{{xGrid|}}}|, "grid": true}}
},
{"scale": "y", "type": "y"
{{#if:{{{yAxis|}}}|, "title": "{{{yAxis|}}}"}}
{{#if:{{{yGrid|}}}|, "grid": true}}
}
],

"marks": [
// Group data by the "key", and draw lines, one line per key
{
"type": "group",
"from": {
"data": "chart",
"transform": [{"groupby": ["key"], "type": "facet"}]
},
"marks": [
{
"type": "line",
"properties": {
"enter": {
"y": {"scale": "y", "field": "value"},
"x": {"scale": "x", "field": "_xfield"},
"stroke": {"scale": "color", "field": "key"},
"interpolate": {"value": "monotone"},
"strokeWidth": {"value": 2.5}
}
}
}
],
}

{{#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>See or edit [[commons:data:{{{table|}}}|raw graph data]].</small>
</includeonly><noinclude>|lang=javascript}}<syntaxhighlight lang=html></graph></syntaxhighlight></noinclude>

Latest revision as of 12:49, 10 August 2023

See or edit [[c:Data:{{{table}}}|source data]].