Line 2: |
Line 2: |
| __TOC__ | | __TOC__ |
| | | |
− | <translate>
| + | |
| <!--T:1--> | | <!--T:1--> |
| This page shows some examples of what [[Extension:Graph | Graph extension]] can produce.</translate> | | This page shows some examples of what [[Extension:Graph | Graph extension]] can produce.</translate> |
− | <translate>
| + | |
| <!--T:2--> | | <!--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> | | 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--> | | <!--T:3--> |
| Vega team is working on [<tvar|url>http://vega.github.io/</> other tools] to make Graphs easier to use.</translate> | | Vega team is working on [<tvar|url>http://vega.github.io/</> other tools] to make Graphs easier to use.</translate> |
− | <translate>
| + | |
| <!--T:4--> | | <!--T:4--> |
| For interactive graphs [<tvar|url>https://github.com/vega/vega/wiki/Tutorial</> this tutorial] will explain building graphs step by step.</translate> | | 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--> | | <!--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]. |
Line 22: |
Line 22: |
| <!--T:7--> | | <!--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]].</translate> | | 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--> | | <!--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 47: |
Line 47: |
| |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--> | | == Vega 2.0 interactive examples == <!--T:9--> |
| | | |
Line 66: |
Line 66: |
| {{Extension:Graph/Demo/IndexChart}} | | {{Extension:Graph/Demo/IndexChart}} |
| | | |
− | <translate>
| + | |
| == Using RESTBase API == <!--T:11--> | | == Using RESTBase API == <!--T:11--> |
| | | |
| <!--T:12--> | | <!--T:12--> |
| Show pageview graphs for a range of dates, using pageview analytics API.</translate> | | Show pageview graphs for a range of dates, using pageview analytics API.</translate> |
− | <translate>
| + | |
| <!--T:13--> | | <!--T:13--> |
| See <tvar|1>{{ll|Template:Graph:PageViews}}</>. | | See <tvar|1>{{ll|Template:Graph:PageViews}}</>. |
| </translate> | | </translate> |
| | | |
− | '''<translate><!--T:14--> Current page and en.wikipedia.org's main page for the last 30 days</translate>''' | + | '''<!--T:14--> Current page and en.wikipedia.org's main page for the last 30 days</translate>''' |
| <pre> | | <pre> |
| {{Template:Graph:PageViews}} | | {{Template:Graph:PageViews}} |
Line 84: |
Line 84: |
| {{Template:Graph:PageViews|30|Main Page|en.wikipedia.org}} | | {{Template:Graph:PageViews|30|Main Page|en.wikipedia.org}} |
| | | |
− | <translate>
| + | |
| <!--T:15--> | | <!--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'''</translate> |
Line 90: |
Line 90: |
| {{Extension:Graph/Demo/Pageviews2|en.wikipedia|Main Page|30}} | | {{Extension:Graph/Demo/Pageviews2|en.wikipedia|Main Page|30}} |
| | | |
− | <translate>
| + | |
| == Using MediaWiki API == <!--T:16--> | | == Using MediaWiki API == <!--T:16--> |
| | | |
| <!--T:17--> | | <!--T:17--> |
| This graph shows edit history for a wiki page.</translate> | | This graph shows edit history for a wiki page.</translate> |
− | <translate>
| + | |
| <!--T:18--> | | <!--T:18--> |
| See <tvar|1>{{template|Graph:PageHistory}}</>. | | See <tvar|1>{{template|Graph:PageHistory}}</>. |
| </translate> | | </translate> |
| {| | | {| |
− | ! <translate><!--T:19--> Current Page</translate> | + | ! <!--T:19--> Current Page</translate> |
− | ! [[wikipedia:Albert Einstein|Albert Einstein]] <translate><!--T:20--> from en.wikipedia.org</translate> | + | ! [[wikipedia:Albert Einstein|Albert Einstein]] <!--T:20--> from en.wikipedia.org</translate> |
| |- | | |- |
| | {{ Graph:PageHistory | width=500 | height=300 }} | | | {{ Graph:PageHistory | width=500 | height=300 }} |
Line 107: |
Line 107: |
| |} | | |} |
| | | |
− | <translate>
| + | |
| <!--T:21--> | | <!--T:21--> |
| This graph shows the number of pages in each subcategory.</translate> | | This graph shows the number of pages in each subcategory.</translate> |
− | <translate>
| + | |
| <!--T:22--> | | <!--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]]. |
Line 116: |
Line 116: |
| {| | | {| |
| ! [[: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> | + | ! [[:en:Category:People|Category:'''People''']] <!--T:23--> from en.wikipedia.org</translate> |
| |- | | |- |
| | {{Extension:Graph/Demo/CategoryPie|Extensions by category}} | | | {{Extension:Graph/Demo/CategoryPie|Extensions by category}} |
Line 122: |
Line 122: |
| |} | | |} |
| | | |
− | <translate>
| + | |
| == Using Wikidata Query Service API == <!--T:24--> | | == Using Wikidata Query Service API == <!--T:24--> |
| | | |
Line 130: |
Line 130: |
| {{Extension:Graph/Demo/Sparql/Largest disasters}} | | {{Extension:Graph/Demo/Sparql/Largest disasters}} |
| | | |
− | <translate>
| + | |
| == Trees == <!--T:26--> | | == Trees == <!--T:26--> |
| | | |
Line 139: |
Line 139: |
| {{Extension:Graph/Demo/CartesianTree}} | | {{Extension:Graph/Demo/CartesianTree}} |
| | | |
− | <translate>
| + | |
| === Radial tree === <!--T:28--> | | === Radial tree === <!--T:28--> |
| </translate> | | </translate> |
Line 152: |
Line 152: |
| {{Extension:Graph/Demo/Dendrogram}} | | {{Extension:Graph/Demo/Dendrogram}} |
| | | |
− | <translate>
| + | |
| ==Timeline / lifeline== <!--T:29--> | | ==Timeline / lifeline== <!--T:29--> |
| </translate> | | </translate> |
Line 282: |
Line 282: |
| }</graph> | | }</graph> |
| | | |
− | <translate>
| + | |
| == More maps examples == <!--T:30--> | | == More maps examples == <!--T:30--> |
| | | |
| <!--T:31--> | | <!--T:31--> |
| This transcludes the page <tvar|1>[[Extension:Graph/Demo/Map]]</>.</translate> | | This transcludes the page <tvar|1>[[Extension:Graph/Demo/Map]]</>.</translate> |
− | <translate>
| + | |
| <!--T:32--> | | <!--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.</translate> | | 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--> | | <!--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.) |
Line 301: |
Line 301: |
| </source> | | </source> |
| | | |
− | <translate>
| + | |
| <!--T:35--> | | <!--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:</translate> |
Line 307: |
Line 307: |
| <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--> | | <!--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:</translate> |
Line 318: |
Line 318: |
| {{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--> | | <!--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> |
− | <translate>
| + | |
| <!--T:38--> | | <!--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> |
− | <translate>
| + | |
| <!--T:39--> | | <!--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 333: |
Line 333: |
| {{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--> | | <!--T:40--> |
| Note how the legend it wrongly positioned.</translate> | | Note how the legend it wrongly positioned.</translate> |
− | <translate>
| + | |
| <!--T:41--> | | <!--T:41--> |
| That won't happen at lower scales. | | That won't happen at lower scales. |
Line 347: |
Line 347: |
| <!--T:44--> | | <!--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> |
− | <translate>
| + | |
| <!--T:45--> | | <!--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 362: |
Line 362: |
| {{Extension:Graph/Demo/TemplateSample |#f00dee}} | | {{Extension:Graph/Demo/TemplateSample |#f00dee}} |
| | | |
− | <translate>
| + | |
| === Using a template for repeated graphs === <!--T:46--> | | === Using a template for repeated graphs === <!--T:46--> |
| | | |
Line 375: |
Line 375: |
| {{Extension:Graph/Demo/falkensee}} | | {{Extension:Graph/Demo/falkensee}} |
| | | |
− | <translate>
| + | |
| == Embedded directly with <nowiki><graph></nowiki> == <!--T:50--> | | == Embedded directly with <nowiki><graph></nowiki> == <!--T:50--> |
| | | |
Line 443: |
Line 443: |
| }</graph> | | }</graph> |
| | | |
− | <translate>
| + | |
| == Horizontal bar graph == <!--T:52--> | | == Horizontal bar graph == <!--T:52--> |
| </translate> | | </translate> |
Line 450: |
Line 450: |
| {{Extension:Graph/Demo/HorizontalBarGraphSample}} | | {{Extension:Graph/Demo/HorizontalBarGraphSample}} |
| | | |
− | <translate>
| + | |
| == Editing graph data == <!--T:53--> | | == Editing graph data == <!--T:53--> |
| | | |