Template:Graph:Lines: Difference between revisions

From IxWiki
Jump to navigation Jump to search
wp>Timbaaa
 
m 1 revision imported
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<includeonly>{{safesubst:#tag:templatestyles||src="Graph:Chart/styles.css"}}{{#tag:graph|
{{#tag:templatestyles||src="Graph:Chart/styles.css"}}{{#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}}}.}}}}}}}}
{
{{#switch: {{{tabletype|tab}}}{{{hideSource|}}}
  //
|tab= {{#invoke:TNT|msg|Original/Template:Graphs.tab|source-table|{{#invoke:TNT|link|{{{table}}}}}}}.
  // ATTENTION: This code is maintained at https://www.mediawiki.org/wiki/Template:Graph:Lines
|query= {{#invoke:TNT|msg|Original/Template:Graphs.tab|source-wdqs|https://query.wikidata.org/#{{urlencode:{{{table}}}|PATH}}}}.
  //            Please do not modify it anywhere else, as it may get copied and override your changes.
}}{{#if:{{{thumb|{{{1|}}}}}}|</div>|</small>}}</div></div>{{#ifeq:{{{align|{{{2|}}}}}}|center|</div>}}<noinclude>
  //            Suggestions can be made at https://www.mediawiki.org/wiki/Template_talk:Graph:Lines
{{clear}}
  //
{{ombox| type = content | image = [[File:Test Template Info-Icon - Version (2).svg|40px]]
  // Template translation is in https://commons.wikimedia.org/wiki/Data:Original/Template:Graphs.tab
| 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|400}}},
  "height": {{{height|300}}},
  "padding": "strict",
 
  "signals": [{"name": "rightwidth", "expr": "width + padding.right"}],
  "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}}}
| year= "datetime(datum.{{{xField|year}}}, 0, 1)"
| "datum.{{{xField}}}"
}}
      }
      , {"type": "sort", "by": ["_xfield"]}
{{#if:{{{series|}}}
|     , {"type": "fold", "fields": [{{{series}}}]}
}}
{{#if:{{{replaceZerosWith|}}}
|   , {"type": "formula", "field": "_yfield", "expr": "max(datum.{{#if:{{{series|}}}|value|{{{value|value}}}}}, {{{replaceZerosWith}}})" }
|  , {"type": "formula", "field": "_yfield", "expr": "datum.{{#if:{{{series|}}}|value|{{{value|value}}}}}" }
}}
{{#ifeq:{{{yScale|}}}|log
|   , {"type": "filter", "test": "datum._yfield != 0"}
}}
    ]
  },
{{#if:{{{series|}}}|{{#ifeq: {{{tabletype|tab}}} | tab |
  {
    "name": "labels",
    "url": "tabular:///{{{table}}}",
    "format": {"type": "json", "property": "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": "{{{yScale|linear}}}",
      "range": "height",
      "domain": {"data": "chart", "field": "_yfield"},
{{#if:{{{yZero|}}}|"zero": {{{yZero}}},}}
{{#if:{{{yMin|}}}|"domainMin": {{{yMin}}},}}
{{#if:{{{yMax|}}}|"domainMax": {{{yMax}}},}}
    },
    {
      "name": "color",
      "type": "ordinal",
      "domain": {"data": "chart", "field": "{{{group|key}}}"},
      "range": "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
{{#ifeq:{{{yTicks|-}}}|-||, "ticks": {{{yTicks}}}}}
{{#if:{{{yAxis|}}}|, "title": "{{{yAxis}}}"}}
{{#if:{{{yGrid|}}}|, "grid": true}}
}
  ],
 
  "marks": [
    // Group data by the group parameter or "key", and draw lines, one line per group
    {
      "type": "group",
      "from": {
        "data": "chart",
        "transform": [{"type": "facet", "groupby": ["{{{group|key}}}"]}]
      },
      "marks": [
        {
          "type": "line",
          "properties": {
            "enter": {
              "y": {"scale": "y", "field": "_yfield"},
              "x": {"scale": "x", "field": "_xfield"},
              "stroke": {"scale": "color", "field": "{{{group|key}}}"},
              "interpolate": {"value": "monotone"},
              "strokeWidth": {"value": 2.5}
            }
          }
        }
      ],
    }
 
{{#if:{{{title|}}}|
    // Draw title at the top of the graph
,  {
      "type": "text",
      "properties": {
        "enter": {
          "x": {"signal": "rightwidth", "mult": 0.5},
          "y": {"value": -15},
          "text": {"value": "{{{title}}}"},
          "fontWeight": {"value": "bold"},
          "align": {"value": "center"},
          "baseline": {"value": "bottom"},
          "fill": {"value": "#000"}
        }
      }
    }
}}
  ]
}
}}
<small>{{#switch: {{{tabletype|tab}}}
|tab= {{#invoke:TNT|msg|I18n/Template:Graphs.tab|source_table|{{#invoke:TNT|link|{{{table}}}}}}}.
|query= {{#invoke:TNT|msg|I18n/Template:Graphs.tab|source_wdqs|https://query.wikidata.org/#{{urlencode:{{{table}}}|PATH}}}}.
}}</small>
</includeonly><noinclude>{{doc}}</noinclude>

Latest revision as of 13:51, 10 March 2022

Lua error: bad argument #1 to "get" (not a valid title)..