Line 3: |
Line 3: |
| | | |
| | | |
− | <!--T:1-->
| + | |
| This page shows some examples of what [[Extension:Graph | Graph extension]] can produce. | | This page shows some examples of what [[Extension:Graph | Graph extension]] can produce. |
| | | |
− | <!--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. | | Graphs use [<tvar|url1>http://vega.github.io/vega/</> Vega grammar] ([<tvar|url2>https://github.com/vega/vega/wiki</> documentation]) as underlying technology. |
| | | |
− | <!--T:3-->
| + | |
| Vega team is working on [<tvar|url>http://vega.github.io/</> other tools] to make Graphs easier to use. | | Vega team is working on [<tvar|url>http://vega.github.io/</> other tools] to make Graphs easier to use. |
| | | |
− | <!--T:4-->
| + | |
| For interactive graphs [<tvar|url>https://github.com/vega/vega/wiki/Tutorial</> this tutorial] will explain building graphs step by step. | | For interactive graphs [<tvar|url>https://github.com/vega/vega/wiki/Tutorial</> this tutorial] will explain building graphs step by step. |
| | | |
− | <!--T:5-->
| + | |
| For other graph ideas, see [<tvar|url>http://vega.github.io/vega-editor/?spec=bar</> Vega examples]. | | For other graph ideas, see [<tvar|url>http://vega.github.io/vega-editor/?spec=bar</> Vega examples]. |
| | | |
− | == Graph templates == <!--T:6--> | + | == Graph templates == |
| + | |
| | | |
− | <!--T:7-->
| |
| 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]]. | | 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]]. |
| | | |
− | <!--T:8-->
| + | |
| 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: |
| | | |
Line 48: |
Line 48: |
| | | |
| | | |
− | == Vega 2.0 interactive examples == <!--T:9--> | + | == Vega 2.0 interactive examples == |
| + | |
| | | |
− | <!--T:10-->
| |
| See [[Extension:Graph/Interactive Graph Tutorial|tutorial]] how to build this: | | See [[Extension:Graph/Interactive Graph Tutorial|tutorial]] how to build this: |
| {{Extension:Graph/Demo/HistoricalFertilityRates}} | | {{Extension:Graph/Demo/HistoricalFertilityRates}} |
Line 67: |
Line 67: |
| | | |
| | | |
− | == Using RESTBase API == <!--T:11--> | + | == Using RESTBase API == |
| + | |
| | | |
− | <!--T:12-->
| |
| Show pageview graphs for a range of dates, using pageview analytics API. | | Show pageview graphs for a range of dates, using pageview analytics API. |
| | | |
− | <!--T:13-->
| + | |
| See <tvar|1>{{ll|Template:Graph:PageViews}}</>. | | See <tvar|1>{{ll|Template:Graph:PageViews}}</>. |
| | | |
| | | |
− | '''<!--T:14--> Current page and en.wikipedia.org's main page for the last 30 days''' | + | ''' Current page and en.wikipedia.org's main page for the last 30 days''' |
| <pre> | | <pre> |
| {{Template:Graph:PageViews}} | | {{Template:Graph:PageViews}} |
Line 85: |
Line 85: |
| | | |
| | | |
− | <!--T:15-->
| + | |
| ''' Current page and en.wikipedia main page for the last 30 days - per type''' | | ''' 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}} |
Line 91: |
Line 91: |
| | | |
| | | |
− | == Using MediaWiki API == <!--T:16--> | + | == Using MediaWiki API == |
| + | |
| | | |
− | <!--T:17-->
| |
| This graph shows edit history for a wiki page. | | This graph shows edit history for a wiki page. |
| | | |
− | <!--T:18-->
| + | |
| See <tvar|1>{{template|Graph:PageHistory}}</>. | | See <tvar|1>{{template|Graph:PageHistory}}</>. |
| | | |
| {| | | {| |
− | ! <!--T:19--> Current Page | + | ! Current Page |
− | ! [[wikipedia:Albert Einstein|Albert Einstein]] <!--T:20--> from en.wikipedia.org | + | ! [[wikipedia:Albert Einstein|Albert Einstein]] from en.wikipedia.org |
| |- | | |- |
| | {{ Graph:PageHistory | width=500 | height=300 }} | | | {{ Graph:PageHistory | width=500 | height=300 }} |
Line 108: |
Line 108: |
| | | |
| | | |
− | <!--T:21-->
| + | |
| This graph shows the number of pages in each subcategory. | | This graph shows the number of pages in each subcategory. |
| | | |
− | <!--T:22-->
| + | |
| See [[<tvar|1>Special:MyLanguage/Extension:Graph/Demo/CategoryPie</>|graph source code]]. | | See [[<tvar|1>Special:MyLanguage/Extension:Graph/Demo/CategoryPie</>|graph source code]]. |
| | | |
| {| | | {| |
| ! [[:Category:Extensions by category|Category:'''Extensions by category''']]. | | ! [[:Category:Extensions by category|Category:'''Extensions by category''']]. |
− | ! [[:en:Category:People|Category:'''People''']] <!--T:23--> from en.wikipedia.org | + | ! [[:en:Category:People|Category:'''People''']] from en.wikipedia.org |
| |- | | |- |
| | {{Extension:Graph/Demo/CategoryPie|Extensions by category}} | | | {{Extension:Graph/Demo/CategoryPie|Extensions by category}} |
Line 123: |
Line 123: |
| | | |
| | | |
− | == Using Wikidata Query Service API == <!--T:24--> | + | == Using Wikidata Query Service API == |
| + | |
| | | |
− | <!--T:25-->
| |
| See [[Extension:Graph/Demo/Sparql|more examples]]. | | See [[Extension:Graph/Demo/Sparql|more examples]]. |
| | | |
Line 131: |
Line 131: |
| | | |
| | | |
− | == Trees == <!--T:26--> | + | == Trees == |
| | | |
− | === Cartesian tree === <!--T:27--> | + | === Cartesian tree === |
| | | |
| [[Extension:Graph/Demo/CartesianTree]] | | [[Extension:Graph/Demo/CartesianTree]] |
Line 140: |
Line 140: |
| | | |
| | | |
− | === Radial tree === <!--T:28--> | + | === Radial tree === |
| | | |
| [[Extension:Graph/Demo/RadialTree]] | | [[Extension:Graph/Demo/RadialTree]] |
Line 153: |
Line 153: |
| | | |
| | | |
− | ==Timeline / lifeline== <!--T:29--> | + | ==Timeline / lifeline== |
| | | |
| <graph> | | <graph> |
Line 283: |
Line 283: |
| | | |
| | | |
− | == More maps examples == <!--T:30--> | + | == More maps examples == |
| + | |
| | | |
− | <!--T:31-->
| |
| This transcludes the page <tvar|1>[[Extension:Graph/Demo/Map]]</>. | | This transcludes the page <tvar|1>[[Extension:Graph/Demo/Map]]</>. |
| | | |
− | <!--T:32-->
| + | |
| 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. | | 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. |
| | | |
− | <!--T:33-->
| + | |
| (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>: | | 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>: |
| | | |
Line 302: |
Line 302: |
| | | |
| | | |
− | <!--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: | | 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: |
| | | |
Line 308: |
Line 308: |
| | | |
| | | |
− | <!--T:36-->
| + | |
| The Lua function's output is data in Vega's format: | | The Lua function's output is data in Vega's format: |
| | | |
Line 319: |
Line 319: |
| | | |
| | | |
− | <!--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]). | | 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]). |
| | | |
− | <!--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. | | 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. |
| | | |
− | <!--T:39-->
| + | |
| Additional optional parameter specifies that it should be scaled to 80%. | | Additional optional parameter specifies that it should be scaled to 80%. |
| | | |
Line 334: |
Line 334: |
| | | |
| | | |
− | <!--T:40-->
| + | |
| Note how the legend it wrongly positioned. | | Note how the legend it wrongly positioned. |
| | | |
− | <!--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>. | | 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>. |
| | | |
− | <!--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. |
| | | |
Line 363: |
Line 363: |
| | | |
| | | |
− | === Using a template for repeated graphs === <!--T:46--> | + | === Using a template for repeated graphs === |
| + | |
| | | |
− | <!--T:47-->
| |
| 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]]. | | Falkensee graph sample, see [[Extension:Graph/Demo/falkensee|code]]. |
| | | |
Line 376: |
Line 376: |
| | | |
| | | |
− | == Embedded directly with <nowiki><graph></nowiki> == <!--T:50--> | + | == Embedded directly with <nowiki><graph></nowiki> == |
| + | |
| | | |
− | <!--T:51-->
| |
| 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. |
| | | |
Line 444: |
Line 444: |
| | | |
| | | |
− | == Horizontal bar graph == <!--T:52--> | + | == Horizontal bar graph == |
| | | |
| [[Extension:Graph/Demo/HorizontalBarGraphSample]] | | [[Extension:Graph/Demo/HorizontalBarGraphSample]] |
Line 451: |
Line 451: |
| | | |
| | | |
− | == Editing graph data == <!--T:53--> | + | == Editing graph data == |
| + | |
| | | |
− | <!--T:54-->
| |
| 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. |
| | | |
| | | |
| [[Category:Extension:Graph{{#translation:}}|Demo]] | | [[Category:Extension:Graph{{#translation:}}|Demo]] |