Graph test

De dieudo.fr
Aller à la navigation Aller à la recherche

<languages/>

<translate> This page shows some examples of what Graph extension can produce. Graphs use Vega grammar (documentation) as underlying technology. Vega team is working on other tools to make Graphs easier to use. For interactive graphs this tutorial will explain building graphs step by step. For other graph ideas, see 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:</translate>

{{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}}

<translate>

Vega 2.0 interactive examples

See tutorial how to build this:</translate>

/Dimpvis Graph test/Dimpvis

/Airports Graph test/Airports

/OverviewDetail Graph test/OverviewDetail

/IndexChart Graph test/IndexChart

<translate>

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</translate>

{{Template:Graph:PageViews}}
{{Template:Graph:PageViews|30|Main Page|en.wikipedia.org}}

Modèle:Graph:PageViews Modèle:Graph:PageViews

<translate> Current page and en.wikipedia main page for the last 30 days - per type</translate> Graph test/Pageviews2 Graph test/Pageviews2

<translate>

Using MediaWiki API

This graph shows edit history for a wiki page. See Modèle:Template.</translate>

<translate>Current Page</translate> Albert Einstein <translate>from en.wikipedia.org</translate>
Modèle:Graph:PageHistory Modèle:Graph:PageHistory

<translate> This graph shows the number of pages in each subcategory. See graph source code.</translate>

Category:Extensions by category. Category:People <translate>from en.wikipedia.org</translate>
Graph test/CategoryPie Graph test/CategoryPie

<translate>

Using Wikidata Query Service API

See more examples.</translate>

Graph test/Sparql/Largest disasters

<translate>

Trees

Cartesian tree

</translate> /CartesianTree

Graph test/CartesianTree

<translate>

Radial tree

</translate> /RadialTree

Graph test/RadialTree

Dendrogram

<translate>

Timeline / lifeline

</translate>

<translate>

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":</translate>

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

<translate> 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:</translate>

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

<translate> The Lua function's output is data in Vega's format:</translate>

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

Graph test/Map

<translate> 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%.</translate>

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

Graph test/MapTemplate

Note how the legend it wrongly positioned. That won't happen at lower scales.

<translate>

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.</translate>

{{/TemplateSample}}
{{/TemplateSample | blue}}
{{/TemplateSample | #f00dee}}

Graph test/TemplateSample Graph test/TemplateSample Graph test/TemplateSample

<translate>

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.</translate>

Graph test/falkensee

<translate>

Embedded directly with <graph>

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

<translate>

Horizontal bar graph

</translate> /HorizontalBarGraphSample

Graph test/HorizontalBarGraphSample

<translate>

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. </translate>