Difference between revisions of "Extension:Graph/Demo"

From RobotX
Jump to navigation Jump to search
(Created page with "<languages/> __TOC__ <translate> <!--T:1--> This page shows some examples of what Graph extension can produce.</translate> <translate> <!--T:2--> Graphs...")
 
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
<languages/>
 
 
__TOC__
 
__TOC__
  
<translate>
 
<!--T:1-->
 
This page shows some examples of what [[Extension:Graph | Graph extension]] can produce.</translate>
 
<translate>
 
<!--T:2-->
 
Graphs use [<tvar|url1>http://vega.github.io/vega/</> Vega grammar] ([<tvar|url2>https://github.com/vega/vega/wiki</> documentation]) as underlying technology.</translate>
 
<translate>
 
<!--T:3-->
 
Vega team is working on [<tvar|url>http://vega.github.io/</> other tools] to make Graphs easier to use.</translate>
 
<translate>
 
<!--T:4-->
 
For interactive graphs [<tvar|url>https://github.com/vega/vega/wiki/Tutorial</> this tutorial] will explain building graphs step by step.</translate>
 
<translate>
 
<!--T:5-->
 
For other graph ideas, see [<tvar|url>http://vega.github.io/vega-editor/?spec=bar</> Vega examples].
 
  
== Graph templates == <!--T:6-->
 
  
<!--T:7-->
+
This page shows some examples of what [[Extension:Graph | Graph extension]] can produce.
The easiest way to use graphs is via pre-built templates such as the [[:en:Template:Graph:Chart|Graph:Chart]] (available on many Wikipedias), or more specialized [[:en:Template:Graph:PieChart|PieChart]].</translate>
+
 
<translate>
+
 
<!--T:8-->
+
Graphs use [<tvar|url1>http://vega.github.io/vega/ Vega grammar] ([<tvar|url2>https://github.com/vega/vega/wiki documentation]) as underlying technology.
 +
 
 +
 
 +
Vega team is working on [<tvar|url>http://vega.github.io/ other tools] to make Graphs easier to use.
 +
 
 +
 
 +
For interactive graphs [<tvar|url>https://github.com/vega/vega/wiki/Tutorial this tutorial] will explain building graphs step by step.
 +
 
 +
 
 +
For other graph ideas, see [<tvar|url>http://vega.github.io/vega-editor/?spec=bar Vega examples].
 +
 
 +
== Graph templates ==
 +
 
 +
 
 +
The easiest way to use graphs is via pre-built templates such as the [[:en:Template:Graph:Chart|Graph:Chart]] (available on many Wikipedias), or more specialized [[:en:Template:Graph:PieChart|PieChart]].
 +
 
 +
 
 
Graph:Chart supports many common graph types such as line, area, and pie charts:
 
Graph:Chart supports many common graph types such as line, area, and pie charts:
</translate>
+
 
  
 
<pre style="font-size:90%;">{{Graph:Chart|width=600|height=100|xAxisTitle=X|yAxisTitle=Y
 
<pre style="font-size:90%;">{{Graph:Chart|width=600|height=100|xAxisTitle=X|yAxisTitle=Y
Line 47: Line 46:
 
  |y2=2,4,6,8,13,11|interpolate=monotone|colors=seagreen,orchid}}
 
  |y2=2,4,6,8,13,11|interpolate=monotone|colors=seagreen,orchid}}
  
<translate>
 
== Vega 2.0 interactive examples == <!--T:9-->
 
  
<!--T:10-->
+
== Vega 2.0 interactive examples ==
See [[Extension:Graph/Interactive Graph Tutorial|tutorial]] how to build this:</translate>
+
 
 +
 
 +
See [[Extension:Graph/Interactive Graph Tutorial|tutorial]] how to build this:
 
{{Extension:Graph/Demo/HistoricalFertilityRates}}
 
{{Extension:Graph/Demo/HistoricalFertilityRates}}
  
Line 66: Line 65:
 
{{Extension:Graph/Demo/IndexChart}}
 
{{Extension:Graph/Demo/IndexChart}}
  
<translate>
 
== Using RESTBase API == <!--T:11-->
 
  
<!--T:12-->
+
== Using RESTBase API ==
Show pageview graphs for a range of dates, using pageview analytics API.</translate>
 
<translate>
 
<!--T:13-->
 
See <tvar|1>{{ll|Template:Graph:PageViews}}</>.
 
</translate>
 
  
'''<translate><!--T:14--> Current page and en.wikipedia.org's main page for the last 30 days</translate>'''
+
 
 +
Show pageview graphs for a range of dates, using pageview analytics API.
 +
 
 +
 
 +
See {{ll|Template:Graph:PageViews}}.
 +
 
 +
 
 +
''' Current page and en.wikipedia.org's main page for the last 30 days'''
 
<pre>
 
<pre>
 
{{Template:Graph:PageViews}}
 
{{Template:Graph:PageViews}}
{{Template:Graph:PageViews|30|Main Page|en.wikipedia.org}}
 
 
</pre>
 
</pre>
 
{{Template:Graph:PageViews}}
 
{{Template:Graph:PageViews}}
{{Template:Graph:PageViews|30|Main Page|en.wikipedia.org}}
 
  
<translate>
+
 
<!--T:15-->
+
 
''' Current page and en.wikipedia main page for the last 30 days - per type'''</translate>
+
 
 +
''' Current page and en.wikipedia main page for the last 30 days - per type'''
 
{{Extension:Graph/Demo/Pageviews2|mediawiki|{{FULLPAGENAME}}|30}}
 
{{Extension:Graph/Demo/Pageviews2|mediawiki|{{FULLPAGENAME}}|30}}
{{Extension:Graph/Demo/Pageviews2|en.wikipedia|Main Page|30}}
 
  
<translate>
+
== Using MediaWiki API ==  
== Using MediaWiki API == <!--T:16-->
+
 
 +
 
 +
This graph shows edit history for a wiki page.
 +
 
 +
 
 +
See {{template|Graph:PageHistory}}.
  
<!--T:17-->
 
This graph shows edit history for a wiki page.</translate>
 
<translate>
 
<!--T:18-->
 
See <tvar|1>{{template|Graph:PageHistory}}</>.
 
</translate>
 
 
{|
 
{|
! <translate><!--T:19--> Current Page</translate>
+
! Current Page
! [[wikipedia:Albert Einstein|Albert Einstein]] <translate><!--T:20--> from en.wikipedia.org</translate>
 
 
|-
 
|-
 
| {{ Graph:PageHistory | width=500 | height=300 }}
 
| {{ Graph:PageHistory | width=500 | height=300 }}
| {{ Graph:PageHistory | Albert Einstein | wiki=en.wikipedia.org | width=500 | height=300 }}
 
 
|}
 
|}
  
<translate>
+
 
<!--T:21-->
+
 
This graph shows the number of pages in each subcategory.</translate>
+
This graph shows the number of pages in each subcategory.
<translate>
+
 
<!--T:22-->
+
 
See [[<tvar|1>Special:MyLanguage/Extension:Graph/Demo/CategoryPie</>|graph source code]].
+
See [[Special:MyLanguage/Extension:Graph/Demo/CategoryPie|graph source code]].
</translate>
+
 
 
{|
 
{|
 
! [[:Category:Extensions by category|Category:'''Extensions by category''']].
 
! [[:Category:Extensions by category|Category:'''Extensions by category''']].
! [[:en:Category:People|Category:'''People''']] <translate><!--T:23--> from en.wikipedia.org</translate>
 
 
|-
 
|-
 
| {{Extension:Graph/Demo/CategoryPie|Extensions by category}}
 
| {{Extension:Graph/Demo/CategoryPie|Extensions by category}}
| {{Extension:Graph/Demo/CategoryPie|People|en.wikipedia.org}}
 
 
|}
 
|}
  
<translate>
+
== Using Wikidata Query Service API ==  
== Using Wikidata Query Service API == <!--T:24-->
 
  
<!--T:25-->
+
 
See [[Extension:Graph/Demo/Sparql|more examples]].</translate>
+
See [[Extension:Graph/Demo/Sparql|more examples]].
  
 
{{Extension:Graph/Demo/Sparql/Largest disasters}}
 
{{Extension:Graph/Demo/Sparql/Largest disasters}}
  
<translate>
 
== Trees == <!--T:26-->
 
  
=== Cartesian tree === <!--T:27-->
+
== Trees ==
</translate>
+
 
 +
=== Cartesian tree ===  
 +
 
 
[[Extension:Graph/Demo/CartesianTree]]
 
[[Extension:Graph/Demo/CartesianTree]]
  
 
{{Extension:Graph/Demo/CartesianTree}}
 
{{Extension:Graph/Demo/CartesianTree}}
  
<translate>
+
 
=== Radial tree === <!--T:28-->
+
=== Radial tree ===  
</translate>
+
 
 
[[Extension:Graph/Demo/RadialTree]]
 
[[Extension:Graph/Demo/RadialTree]]
  
Line 152: Line 143:
 
{{Extension:Graph/Demo/Dendrogram}}
 
{{Extension:Graph/Demo/Dendrogram}}
  
<translate>
+
 
==Timeline / lifeline== <!--T:29-->
+
==Timeline / lifeline==  
</translate>
+
 
 
<graph>
 
<graph>
 
{
 
{
Line 282: Line 273:
 
}</graph>
 
}</graph>
  
<translate>
 
== More maps examples == <!--T:30-->
 
  
<!--T:31-->
+
== More maps examples ==
This transcludes the page <tvar|1>[[Extension:Graph/Demo/Map]]</>.</translate>
+
 
<translate>
+
 
<!--T:32-->
+
This transcludes the page [[Extension:Graph/Demo/Map]].
The <code><nowiki><graph></nowiki></code> tag's JSON data on that page specifies that its <code>countries</code> data comes from a separate URL, [[Extension:Graph/Demo/RawData:WorldMap-iso2-json]], that contains map data in JSON format.</translate>
+
 
<translate>
+
 
<!--T:33-->
+
The <code><nowiki><graph></nowiki></code> tag's JSON data on that page specifies that its <code>countries</code> data comes from a separate URL, [[Extension:Graph/Demo/RawData:WorldMap-iso2-json]], that contains map data in JSON format.
 +
 
 +
 
 
(MediaWiki doesn't know this wiki page should be formatted as JSON yet, it will eventually use a JSON content handler.)
 
(MediaWiki doesn't know this wiki page should be formatted as JSON yet, it will eventually use a JSON content handler.)
  
<!--T:34-->
+
 
One of the elements in the <code><nowiki><graph></nowiki></code> tag's JSON data specifies a highlight color for each country, in the format <code>"''country-code''":"''highlight-color''"</code>:</translate>
+
One of the elements in the <code><nowiki><graph></nowiki></code> tag's JSON data specifies a highlight color for each country, in the format <code>"''country-code''":"''highlight-color''"</code>:
  
 
<source lang="javascript">
 
<source lang="javascript">
Line 301: Line 292:
 
</source>
 
</source>
  
<translate>
+
 
<!--T:35-->
+
 
Vega usually works with data in the format <source lang="javascript" inline>[{"id":"country-code", "v":"highlight-color"}, ...]</source>, so I created a helper Lua function to convert the data:</translate>
+
Vega usually works with data in the format <source lang="javascript" inline>[{"id":"country-code", "v":"highlight-color"}, ...]</source>, so I created a helper Lua function to convert the data:
  
 
<pre>{{#invoke:Graph:Utils|expandDict|{"BR":"pink","US":"blue","CN":"red","DZ":"green","AU":"purple"} }}</pre>
 
<pre>{{#invoke:Graph:Utils|expandDict|{"BR":"pink","US":"blue","CN":"red","DZ":"green","AU":"purple"} }}</pre>
  
<translate>
+
 
<!--T:36-->
+
 
The Lua function's output is data in Vega's format:</translate>
+
The Lua function's output is data in Vega's format:
  
 
{{#tag:source|
 
{{#tag:source|
Line 318: Line 309:
 
{{Extension:Graph/Demo/Map|{{#invoke:Graph:Utils|expandDict|{"BR":"pink","US":"blue","CN":"red","DZ":"green","AU":"purple"} }} | scale=90}}
 
{{Extension:Graph/Demo/Map|{{#invoke:Graph:Utils|expandDict|{"BR":"pink","US":"blue","CN":"red","DZ":"green","AU":"purple"} }} | scale=90}}
  
<translate>
+
 
<!--T:37-->
+
 
Here is a more complex data processing example: [[Extension:Graph/Demo/MapTemplate|MapTemplate]] is expanded with the data from Lua which takes it from the 2010 population distribution in the world (data based on [http://esa.un.org/wpp/ UN data]).</translate>
+
Here is a more complex data processing example: [[Extension:Graph/Demo/MapTemplate|MapTemplate]] is expanded with the data from Lua which takes it from the 2010 population distribution in the world (data based on [http://esa.un.org/wpp/ UN data]).
<translate>
+
 
<!--T:38-->
+
 
To generate this graph, I use Lua module [[:Module:Graph:Utils|Graph:Utils]]'s function <code>parseCsv</code> to extract the year 2010 column from the [[Extension:Graph/Demo/RawData:PopulationByCountryHistoric-csv]] page (in csv format), and pass that data as the first unnamed parameter to the [[Extension:Graph/Demo/MapTemplate|MapTemplate]] graph.</translate>
+
To generate this graph, I use Lua module [[:Module:Graph:Utils|Graph:Utils]]'s function <code>parseCsv</code> to extract the year 2010 column from the [[Extension:Graph/Demo/RawData:PopulationByCountryHistoric-csv]] page (in csv format), and pass that data as the first unnamed parameter to the [[Extension:Graph/Demo/MapTemplate|MapTemplate]] graph.
<translate>
+
 
<!--T:39-->
+
 
 
Additional optional parameter specifies that it should be scaled to 80%.
 
Additional optional parameter specifies that it should be scaled to 80%.
</translate>
+
 
  
 
<pre style="font-size:90%;">{{Extension:Graph/Demo/MapTemplate|{{#invoke:Graph:Utils|parseCsv|Extension:Graph/Demo/RawData:PopulationByCountryHistoric-csv|2010}}|scale=180}}</pre>
 
<pre style="font-size:90%;">{{Extension:Graph/Demo/MapTemplate|{{#invoke:Graph:Utils|parseCsv|Extension:Graph/Demo/RawData:PopulationByCountryHistoric-csv|2010}}|scale=180}}</pre>
Line 333: Line 324:
 
{{Extension:Graph/Demo/MapTemplate|type=sqrt|colors=["#ffff65","#cb0000"]|scale=180}}
 
{{Extension:Graph/Demo/MapTemplate|type=sqrt|colors=["#ffff65","#cb0000"]|scale=180}}
  
<translate>
+
 
<!--T:40-->
+
 
Note how the legend it wrongly positioned.</translate>
+
Note how the legend it wrongly positioned.
<translate>
+
 
<!--T:41-->
+
 
 
That won't happen at lower scales.
 
That won't happen at lower scales.
  
== Passing MediaWiki template parameters == <!--T:42-->
+
== Passing MediaWiki template parameters ==  
 +
 
  
<!--T:43-->
 
 
If you're using a wiki page as a template, you can pass [[Help:Templates#Parameters|parameters]] to it, like any other MediaWiki template.
 
If you're using a wiki page as a template, you can pass [[Help:Templates#Parameters|parameters]] to it, like any other MediaWiki template.
  
<!--T:44-->
+
 
As an example, the graph specification in [[Extension:Graph/Demo/TemplateSample|TemplateSample]] does not hardcode a fill color for <code>marks.properties.update.fill.value</code>; instead it sets the fill color to <code><nowiki>{{{1|#ccc}}}</nowiki></code>.</translate>
+
As an example, the graph specification in [[Extension:Graph/Demo/TemplateSample|TemplateSample]] does not hardcode a fill color for <code>marks.properties.update.fill.value</code>; instead it sets the fill color to <code><nowiki>{{{1|#ccc}}}</nowiki></code>.
<translate>
+
 
<!--T:45-->
+
 
 
So if you visit that page or transclude it with no parameter, the graph  fills with color <code style="background-color:#ccc">#ccc</code>; but if you transclude that page you can specify the fill color as the first template parameter.
 
So if you visit that page or transclude it with no parameter, the graph  fills with color <code style="background-color:#ccc">#ccc</code>; but if you transclude that page you can specify the fill color as the first template parameter.
</translate>
+
 
  
 
<pre style="font-size:90%;">
 
<pre style="font-size:90%;">
Line 362: Line 353:
 
{{Extension:Graph/Demo/TemplateSample |#f00dee}}
 
{{Extension:Graph/Demo/TemplateSample |#f00dee}}
  
<translate>
 
=== Using a template for repeated graphs === <!--T:46-->
 
  
<!--T:47-->
+
=== Using a template for repeated graphs ===
 +
 
 +
 
 
This is very useful if you have multiple graphs of the same form: you can put the verbose graph JSON and additional repetive wikitext in a template and only pass the parameters to it that vary, such as title and values.  [[Talk:MediaWiki Developer Summit 2015/Lessons learned#Template_test | See a sample of this approach]].
 
This is very useful if you have multiple graphs of the same form: you can put the verbose graph JSON and additional repetive wikitext in a template and only pass the parameters to it that vary, such as title and values.  [[Talk:MediaWiki Developer Summit 2015/Lessons learned#Template_test | See a sample of this approach]].
  
== Overlaying two types of data == <!--T:48-->
+
== Overlaying two types of data ==  
  
<!--T:49-->
+
 
Falkensee graph sample, see [[Extension:Graph/Demo/falkensee|code]].</translate>
+
Falkensee graph sample, see [[Extension:Graph/Demo/falkensee|code]].
  
 
{{Extension:Graph/Demo/falkensee}}
 
{{Extension:Graph/Demo/falkensee}}
  
<translate>
 
== Embedded directly with <nowiki><graph></nowiki> == <!--T:50-->
 
  
<!--T:51-->
+
== Embedded directly with <nowiki><graph></nowiki> ==
 +
 
 +
 
 
This example is a <code><nowiki><graph></nowiki></code> tag containing the graph JSON inside the current page.
 
This example is a <code><nowiki><graph></nowiki></code> tag containing the graph JSON inside the current page.
</translate>
+
 
  
 
<graph>
 
<graph>
Line 443: Line 434:
 
}</graph>
 
}</graph>
  
<translate>
+
 
== Horizontal bar graph == <!--T:52-->
+
== Horizontal bar graph ==  
</translate>
+
 
 
[[Extension:Graph/Demo/HorizontalBarGraphSample]]
 
[[Extension:Graph/Demo/HorizontalBarGraphSample]]
  
 
{{Extension:Graph/Demo/HorizontalBarGraphSample}}
 
{{Extension:Graph/Demo/HorizontalBarGraphSample}}
  
<translate>
 
== Editing graph data == <!--T:53-->
 
  
<!--T:54-->
+
== Editing graph data ==
 +
 
 +
 
 
Editing JSON by hand is fiddly and prone to error. so you should use a JSON checker such as [http://jsonlint.com/ JSONLint] or a JSON editor such as the [http://vega.github.io/vega-editor/ Vega Live Editor] to edit JSON before you copy and paste it into the wiki page. If the <code><nowiki><graph></nowiki></code> tag's data is directly embedded in the page such as the example above, then if you use VisualEditor to edit the page you can directly edit graph data.
 
Editing JSON by hand is fiddly and prone to error. so you should use a JSON checker such as [http://jsonlint.com/ JSONLint] or a JSON editor such as the [http://vega.github.io/vega-editor/ Vega Live Editor] to edit JSON before you copy and paste it into the wiki page. If the <code><nowiki><graph></nowiki></code> tag's data is directly embedded in the page such as the example above, then if you use VisualEditor to edit the page you can directly edit graph data.
</translate>
 
  
[[Category:Extension:Graph{{#translation:}}|Demo]]
+
 
 +
[[Category:Extension:Graph|Demo]]

Latest revision as of 19:16, 31 October 2020


This page shows some examples of what Graph extension can produce.


Graphs use [<tvar|url1>http://vega.github.io/vega/ Vega grammar] ([<tvar|url2>https://github.com/vega/vega/wiki documentation]) as underlying technology.


Vega team is working on [<tvar|url>http://vega.github.io/ other tools] to make Graphs easier to use.


For interactive graphs [<tvar|url>https://github.com/vega/vega/wiki/Tutorial this tutorial] will explain building graphs step by step.


For other graph ideas, see [<tvar|url>http://vega.github.io/vega-editor/?spec=bar Vega examples].

Graph templates

The easiest way to use graphs is via pre-built templates such as the Graph:Chart (available on many Wikipedias), or more specialized PieChart.


Graph:Chart supports many common graph types such as line, area, and pie charts:


{{Graph:Chart|width=600|height=100|xAxisTitle=X|yAxisTitle=Y
 |type=rect|x=1,2,3,4,5,6,7,8|y=10,12,6,14,2,10,7,9}}

{{Graph:Chart|width=100|height=100|type=pie|legend=Legende
 |x=A,B,C,D,E,F,G,H,I|y1=100,200,150,300,100,100,150,50,200
 |y2=7,8,9,8,8,9,10,9,5|showValues=}}

{{Graph:Chart|width=400|height=100|xAxisTitle=X|yAxisTitle=Y
 |legend=Legend|type=stackedarea|x=1,2,3,4,5,6|y1=10,12,6,14,2,10
 |y2=2,4,6,8,13,11|interpolate=monotone|colors=seagreen,orchid}}


Vega 2.0 interactive examples

See tutorial how to build this: Template:Extension:Graph/Demo/HistoricalFertilityRates

Extension:Graph/Demo/Dimpvis Template:Extension:Graph/Demo/Dimpvis

Extension:Graph/Demo/Airports Template:Extension:Graph/Demo/Airports

Extension:Graph/Demo/OverviewDetail Template:Extension:Graph/Demo/OverviewDetail

Extension:Graph/Demo/IndexChart Template:Extension:Graph/Demo/IndexChart


Using RESTBase API

Show pageview graphs for a range of dates, using pageview analytics API.


See Template:Graph:PageViews .


Current page and en.wikipedia.org's main page for the last 30 days

{{Template:Graph:PageViews}}



Current page and en.wikipedia main page for the last 30 days - per type Template:Extension:Graph/Demo/Pageviews2

Using MediaWiki API

This graph shows edit history for a wiki page.


See

  1. REDIRECT Template:Template link expanded

.

Current Page


This graph shows the number of pages in each subcategory.


See graph source code.

Category:Extensions by category.
Template:Extension:Graph/Demo/CategoryPie

Using Wikidata Query Service API

See more examples.

Template:Extension:Graph/Demo/Sparql/Largest disasters


Trees

Cartesian tree

Extension:Graph/Demo/CartesianTree

Template:Extension:Graph/Demo/CartesianTree


Radial tree

Extension:Graph/Demo/RadialTree

Template:Extension:Graph/Demo/RadialTree


Dendrogram

Extension:Graph/Demo/Dendrogram

Template:Extension:Graph/Demo/Dendrogram


Timeline / lifeline


More maps examples

This transcludes the page Extension:Graph/Demo/Map.


The <graph> tag's JSON data on that page specifies that its countries data comes from a separate URL, Extension:Graph/Demo/RawData:WorldMap-iso2-json, that contains map data in JSON format.


(MediaWiki doesn't know this wiki page should be formatted as JSON yet, it will eventually use a JSON content handler.)


One of the elements in the <graph> tag's JSON data specifies a highlight color for each country, in the format "country-code":"highlight-color":

{"BR":"pink","US":"blue","CN":"red","DZ":"green","AU":"purple"}


Vega usually works with data in the format [{"id":"country-code", "v":"highlight-color"}, ...], so I created a helper Lua function to convert the data:

{{#invoke:Graph:Utils|expandDict|{"BR":"pink","US":"blue","CN":"red","DZ":"green","AU":"purple"} }}


The Lua function's output is data in Vega's format:

[{"id":"US","v":"blue"},{"id":"AU","v":"purple"},{"id":"CN","v":"red"},{"id":"BR","v":"pink"},{"id":"DZ","v":"green"}]

Template:Extension:Graph/Demo/Map


Here is a more complex data processing example: MapTemplate is expanded with the data from Lua which takes it from the 2010 population distribution in the world (data based on UN data).


To generate this graph, I use Lua module Graph:Utils's function parseCsv to extract the year 2010 column from the Extension:Graph/Demo/RawData:PopulationByCountryHistoric-csv page (in csv format), and pass that data as the first unnamed parameter to the MapTemplate graph.


Additional optional parameter specifies that it should be scaled to 80%.


{{Extension:Graph/Demo/MapTemplate|{{#invoke:Graph:Utils|parseCsv|Extension:Graph/Demo/RawData:PopulationByCountryHistoric-csv|2010}}|scale=180}}

Template:Extension:Graph/Demo/MapTemplate


Note how the legend it wrongly positioned.


That won't happen at lower scales.

Passing MediaWiki template parameters

If you're using a wiki page as a template, you can pass parameters to it, like any other MediaWiki template.


As an example, the graph specification in TemplateSample does not hardcode a fill color for marks.properties.update.fill.value; instead it sets the fill color to {{{1|#ccc}}}.


So if you visit that page or transclude it with no parameter, the graph fills with color #ccc; but if you transclude that page you can specify the fill color as the first template parameter.


{{Extension:Graph/Demo/TemplateSample}}
{{Extension:Graph/Demo/TemplateSample | blue}}
{{Extension:Graph/Demo/TemplateSample | #f00dee}}

Template:Extension:Graph/Demo/TemplateSample Template:Extension:Graph/Demo/TemplateSample Template:Extension:Graph/Demo/TemplateSample


Using a template for repeated graphs

This is very useful if you have multiple graphs of the same form: you can put the verbose graph JSON and additional repetive wikitext in a template and only pass the parameters to it that vary, such as title and values. See a sample of this approach.

Overlaying two types of data

Falkensee graph sample, see code.

Template:Extension:Graph/Demo/falkensee


Embedded directly with <graph>

This example is a <graph> tag containing the graph JSON inside the current page.



Horizontal bar graph

Extension:Graph/Demo/HorizontalBarGraphSample

Template:Extension:Graph/Demo/HorizontalBarGraphSample


Editing graph data

Editing JSON by hand is fiddly and prone to error. so you should use a JSON checker such as JSONLint or a JSON editor such as the Vega Live Editor to edit JSON before you copy and paste it into the wiki page. If the <graph> tag's data is directly embedded in the page such as the example above, then if you use VisualEditor to edit the page you can directly edit graph data.