Jump to content

Extension:Graph: Difference between revisions

From mediawiki.org
Content deleted Content added
text editing
m Copy edit.
 
(43 intermediate revisions by 17 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
{{XSS alert|extra_problem= <translate><!--T:164--> See <tvar name=1>{{phab|T334940}}</tvar> for more information.</translate>}}
{{Extension|templatemode =
{{Extension
|status = stable
|status = unmaintained
|type1 = tag
|type1 = tag
|type2 = contenthandler
|type2 = contenthandler
Line 28: Line 29:


== General info == <!--T:3-->
== General info == <!--T:3-->

<!--T:4-->
Graph extension allows powerful [<tvar name=url>http://vega.github.io/</tvar> Vega] based graphs to be added to the wiki pages. Graphs can be interactive.
</translate>
</translate>
<translate><!--T:4--> Graph extension allows powerful [<tvar name=url>http://vega.github.io/</tvar> Vega] based graphs to be added to the wiki pages.</translate>
<translate><!--T:165--> Graphs can be interactive.</translate>


<translate><!--T:5--> The easiest way to add a graph is to use a ready-made template such as {{template|Graph:Chart}}.</translate>
<translate><!--T:5--> The easiest way to add a graph is to use a ready-made template such as {{template|Graph:Chart}}.</translate>
Line 38: Line 38:
<translate><!--T:8--> Graph sandbox allows wiki template syntax in addition to JSON.</translate>
<translate><!--T:8--> Graph sandbox allows wiki template syntax in addition to JSON.</translate>
<translate><!--T:141--> The extension integrates with <tvar name=1>[[Special:MyLanguage/VisualEditor|VisualEditor]]</tvar>, providing a simple tool/wizard which generates basic graphs, by entering values directly to the editor.</translate>
<translate><!--T:141--> The extension integrates with <tvar name=1>[[Special:MyLanguage/VisualEditor|VisualEditor]]</tvar>, providing a simple tool/wizard which generates basic graphs, by entering values directly to the editor.</translate>

<translate>
<translate>

== Useful links == <!--T:9-->
== Useful links == <!--T:9-->
</translate>
</translate>
* [https://github.com/nyurik/vega/wiki <translate><!--T:91--> Vega 2 documentation</translate>] - <translate><!--T:92--> restored Vega 2 documentation pages on <tvar name=1>nyurik/vega/wiki</tvar>.</translate>
* [https://github.com/nyurik/vega/wiki <translate><!--T:91--> Vega 2 documentation</translate>] <translate><!--T:92--> restored Vega 2 documentation pages on <tvar name=1>nyurik/vega/wiki</tvar>.</translate>
<translate>
<translate>
<!--T:77-->
<!--T:77-->
* {{<tvar name=1>ll|Extension:Graph/Guide</tvar>|Guide}} - General recommendations on how to use graphs in wiki.</translate>
* {{<tvar name=1>ll|Extension:Graph/Guide</tvar>|Guide}} General recommendations on how to use graphs in wiki.</translate>
<translate>
<translate>
<!--T:93-->
<!--T:93-->
* {{<tvar name=1>ll|Extension:Graph/Interactive Graph Tutorial</tvar>|Interactive Tutorial}} - step by step instructions how to build a complex interactive graph from scratch</translate>
* {{<tvar name=1>ll|Extension:Graph/Interactive Graph Tutorial</tvar>|Interactive Tutorial}} step by step instructions how to build a complex interactive graph from scratch</translate>
<translate>
<translate>
<!--T:94-->
<!--T:94-->
* {{<tvar name=1>ll|Extension:Graph/Demo</tvar>|Demo page}} - for many samples and usage tricks.</translate>
* {{<tvar name=1>ll|Extension:Graph/Demo</tvar>|Demo page}} for many samples and usage tricks.</translate>
<translate>
<translate>
<!--T:95-->
<!--T:95-->
* [<tvar name=url>https://www.youtube.com/watch?v=j7DTn9jHnI0</tvar> TechTalk Video] - a WMF tech talk discussing the Graph extension, including a great demo of the [<tvar name=url2>http://idl.cs.washington.edu/projects/lyra</tvar> Lyra editor] (also installed [<tvar name=url3>http://lyra.wmflabs.org/</tvar> on labs]).</translate>
* [<tvar name=url>https://www.youtube.com/watch?v=j7DTn9jHnI0</tvar> TechTalk Video] a WMF tech talk discussing the Graph extension, including a great demo of the [<tvar name=url2>http://idl.cs.washington.edu/projects/lyra</tvar> Lyra editor] (also installed [<tvar name=url3>http://lyra.wmflabs.org/</tvar> on labs]).</translate>
<translate>
<translate>
<!--T:96-->
<!--T:96-->
Line 71: Line 71:


<translate>
<translate>

== Installation == <!--T:10-->
== Installation == <!--T:10-->
</translate>
</translate>
Line 88: Line 87:
</translate>
</translate>


* <translate><!--T:147--> Install <tvar name=1>{{ll|Extension:Scribunto|Scribunto}}</tvar>, <tvar name=2>{{ll|Extension:Imagemap|Imagemap}}</tvar> and <tvar name=3>{{ll|Extension:TemplateStyles|TemplateStyles}}</tvar>, and [[<tvar name=4>Special:MyLanguage/Manual:Image_administration#SVG</tvar>|enable SVG uploads]]</translate>
<translate><!--T:102--> Roles</translate>
<translate><!--T:127--> (only if you decided to use Vagrant)</translate>
** <translate><!--T:148--> If you use vagrant, you can use <tvar name=1><code>vagrant roles enable --provision scribunto imagemap templatestyles svg</code></tvar></translate>
* <translate><!--T:149--> Import mediawiki.org's <tvar name=1>[[Module:Graph]]</tvar>, <tvar name=2>[[Module:Graph/doc]]</tvar>, <tvar name=3>{{ll|Template:Nowrap}}</tvar> and <tvar name=4>[[Template:Nowrap/styles.css]]</tvar> ([<tvar name=url>https://www.mediawiki.org/wiki/Special:Export?nsindex=all&pages=Module:Graph%0AModule:Graph/doc%0ATemplate:Nowrap%0ATemplate:Nowrap/styles.css&curonly=1&templates=1&wpDownload=1</tvar> export link])</translate>
* <translate><!--T:150--> Import enwiki's <tvar name=1>[[w:Module:Chart|Module:Chart]]</tvar> and <tvar name=2>[[w:Module:Chart/Default colors|Module:Chart/Default colors]]</tvar> ([<tvar name=url>https://en.wikipedia.org/wiki/Special:Export?pages=Module:Chart%0AModule:Chart/Default_colors&curonly=1&templates=1&wpDownload=1</tvar> export link])</translate>
* <translate><!--T:151--> Import the file <tvar name=1>[[:File:Circle_frame.svg]]</tvar></translate>


<translate>
<translate>
== Debugging graphs and porting graphs from Vega 2 to Vega 5== <!--T:152-->
<!--T:103-->
* Enable graphs role</translate>
</translate>
<translate><!--T:153--> A sandbox is provided at <tvar name=1>[[Special:GraphSandbox]]</tvar> that works similar to the [<tvar name=url>https://vega.github.io/editor/#/edited</tvar> Vega graph editor].</translate>
<translate><!--T:154--> The MediaWiki tool includes compatibility code that maps older Vega schemas to the currently enabled version.</translate>
<translate><!--T:155--> Inserting an old schema in the main text area will print a modified and modernized schema underneath the graph where possible.</translate>

<translate><!--T:156--> Similar to <tvar name=url>vega.github.io/editor</tvar>, the Vega object can be inspected via the <tvar name=1><code>VEGA_DEBUG</code></tvar> JavaScript global.</translate>
<translate><!--T:157--> See Vega's [<tvar name=url>https://vega.github.io/vega/docs/api/debugging/</tvar> debugging guide] on how to use it.</translate>

<translate>
<translate>
=== Migrating schemas from older Vega versions === <!--T:158-->
<!--T:104-->
* Enable scribunto role</translate>
</translate>
<translate><!--T:159--> Previously Graph supported Vega 2.</translate>
<translate>
<translate><!--T:160--> You can paste the JSON of graphs in <tvar name=url>http://vega.github.io/vega-editor/?mode=vega</tvar> to see how they previously rendered for comparison with Vega 5.</translate>
<!--T:105-->
* Enable imagemap role


<translate><!--T:161--> <tvar name=1>[[Special:GraphSandbox]]</tvar> (for latest code see [<tvar name=url>https://en.wikipedia.beta.wmflabs.org/wiki/Special:GraphSandbox</tvar> the beta cluster version of the sandbox]) can be used to map older schemas to new schemas.</translate>
<!--T:106-->
<translate><!--T:162--> Copy the old schema into the main textarea and the updated schema will appear in the text area below the graph.</translate>
Templates and Lua Modules
<translate><!--T:163--> Copy the new schema into your code.</translate>


<!--T:107-->
* Copy <tvar name=1>[[Module:Graph]]</tvar> locally</translate>
<translate>
<translate>
<!--T:108-->
* Copy <tvar name=1>[[Module:Graph/doc]]</tvar> locally</translate>
<translate>
<!--T:109-->
* Copy <tvar name=1>[[Template:Nowrap]]</tvar> locally</translate>
<translate><!--T:142--> * Copy [[Template:Nowrap/styles.css]] locally</translate>
<translate>
<!--T:110-->
* Copy <tvar name=1>[[w:Module:Chart|Module:Chart]]</tvar> locally</translate>
<translate>
<!--T:111-->
* Copy <tvar name=1>[[w:Module:Chart/Default_colors|Module:Chart/Default_colors]]</tvar> locally.</translate>
<translate>
<!--T:126-->
* Copy <tvar name=1>[[:File:Circle_frame.svg]]</tvar> locally

== Charts examples == <!--T:73-->
== Charts examples == <!--T:73-->


Line 151: Line 142:


<!--T:116-->
<!--T:116-->
Fallback images have two variables <tvar name=1><code>fallback</code></tvar> and <tvar name=2><code>fallbackWidth</code></tvar>.
Fallback images have two variables: <tvar name=1><code>fallback</code></tvar> and <tvar name=2><code>fallbackWidth</code></tvar>.


<!--T:117-->
<!--T:117-->
Line 170: Line 161:
<translate><!--T:121--> If <tvar name=1>{{ll|Template:Graph:Chart}}</tvar> were adapted, it would look like this:</translate>
<translate><!--T:121--> If <tvar name=1>{{ll|Template:Graph:Chart}}</tvar> were adapted, it would look like this:</translate>


<syntaxhighlight lang="moin">
<syntaxhighlight lang="mediawiki">
{{safesubst:#tag:graph|{{safesubst:#invoke:Graph|chartWrapper}} | fallback = {{{fallback|''}}} | fallbackWidth= {{{fallbackWidth|''}}} }}
{{safesubst:#tag:graph|{{safesubst:#invoke:Graph|chartWrapper}} | fallback = {{{fallback|''}}} | fallbackWidth= {{{fallbackWidth|''}}} }}
</syntaxhighlight>
</syntaxhighlight>
Line 179: Line 170:
</translate>
</translate>


<syntaxhighlight lang="moin">
<syntaxhighlight lang="mediawiki">
{{Graph:Chart|width=400|height=100|xAxisTitle=X|yAxisTitle=Y
{{Graph:Chart|width=400|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|fallback=Graph test seddon.png|fallbackWidth=450}}
|type=rect|x=1,2,3,4,5,6,7,8|y=10,12,6,14,2,10,7,9|fallback=Graph test seddon.png|fallbackWidth=450}}
Line 187: Line 178:
<translate><!--T:124--> The reason for this is there is frequently a difference in the rendered image width and the actual image width.</translate>
<translate><!--T:124--> The reason for this is there is frequently a difference in the rendered image width and the actual image width.</translate>


<syntaxhighlight lang="moin">
<syntaxhighlight lang="mediawiki">
{{Graph:Chart|width=400|height=100|xAxisTitle=X|yAxisTitle=Y
{{Graph:Chart|width=400|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|fallback=Graph test seddon.png}}
|type=rect|x=1,2,3,4,5,6,7,8|y=10,12,6,14,2,10,7,9|fallback=Graph test seddon.png}}
Line 193: Line 184:


<translate>
<translate>

== External data == <!--T:12-->
== External data == <!--T:12-->
</translate>
</translate>
<translate><!--T:13--> HTTP(S) protocol cannot be used to get data for the graph.</translate>
<translate><!--T:13--> HTTP(S) protocol cannot be used to get data for the graph.</translate>
<translate><!--T:14--> Instead, use one of the custom [[<tvar name=guide>Special:MyLanguage/Extension:Graph/Guide#External_Data</tvar>|wiki protocols]] like <tvar name="1"><code>wikiraw:</code></tvar>, <tvar name="2"><code>wikiapi:</code></tvar>, and others.</translate>
<translate><!--T:14--> Instead, use one of the custom [[<tvar name=1>Special:MyLanguage/Extension:Graph/Guide#External_Data</tvar>|wiki protocols]] like <tvar name=2><code>wikiraw:</code></tvar>, <tvar name=3><code>wikiapi:</code></tvar>, and others.</translate>


<translate>
<translate>
Line 222: Line 214:
];
];
</syntaxhighlight>
</syntaxhighlight>

<translate>

== Known bugs & limitations == <!--T:23-->
</translate>
* [[phab:tag/graph]] - <translate><!--T:78--> Graph extension bugs</translate>
* <translate><!--T:136--> Fails to implement ISO 8601 timescales so only Gregorian calendars can be used in timelines</translate>


<translate>
<translate>
Line 240: Line 225:
<translate><!--T:28--> Sample:</translate>
<translate><!--T:28--> Sample:</translate>


<syntaxhighlight lang="html5">
<syntaxhighlight lang="html">
<div class="mw-graph" data-graph-id="72edc224f0a10b343c1e84f63dbfc97cac9bc957">
<div class="mw-graph" data-graph-id="72edc224f0a10b343c1e84f63dbfc97cac9bc957">
</div>
</div>
Line 250: Line 235:
<translate>
<translate>
== Security features == <!--T:37-->
== Security features == <!--T:37-->
</translate>
<translate><!--T:38--> <tvar name=1>{{tag|graph|open}}</tvar> can be configured to disallow referencing untrusted data sources (e.g. Wikimedia only allows data from the Wikimedia sites).</translate>


<!--T:38-->
<translate>
<tvar name=1>{{tag|graph|open}}</tvar> can be configured to disallow referencing untrusted data sources (e.g. Wikimedia only allows data from the Wikimedia sites).

== License == <!--T:40-->
== License == <!--T:40-->


Line 280: Line 265:
See the section on [[<tvar name=1>Special:MyLanguage/Extension:Graph/Guide#External Data</tvar>|external data]].
See the section on [[<tvar name=1>Special:MyLanguage/Extension:Graph/Guide#External Data</tvar>|external data]].


=== Other variables === <!--T:88-->
</translate>
* {{date|2015|12|7}} - <translate><!--T:79--> <tvar name=1>'''wgGraphUrlBlacklist'''</tvar> has been removed in <tvar name=url>[https://github.com/wikimedia/mediawiki-extensions-Graph/commit/787d64a118b72f8b26c8f4ded9597a0e5531763e 787d64a11]</tvar>.</translate>
* {{date|2016|1|28}} - <translate><!--T:89--> <tvar name=1>'''wgGraphDataDomains'''</tvar> has been removed in <tvar name=url>[https://github.com/wikimedia/mediawiki-extensions-Graph/commit/e0813f85a3aa27234c98b02b4073bb9336b2cb47 e0813f85a]</tvar>.</translate> <translate><!--T:140--> Use <tvar name=1>'''wgGraphAllowedDomains'''</tvar> instead.</translate>
* {{date|2015|9|30}} - <translate><!--T:80--> <tvar name=1>'''wgGraphUserServiceAlways'''</tvar> has been removed in <tvar name=url>[https://github.com/wikimedia/mediawiki-extensions-Graph/commit/b735f63ff4b673eef44f7851bafa7e377e79c1cc b735f63ff4b]</tvar>.</translate>
* {{date|2019|7|17}} - <translate><!--T:138--> <tvar name=1>'''wgGraphIsTrusted'''</tvar> has been removed in <tvar name=url>[https://github.com/wikimedia/mediawiki-extensions-Graph/commit/cf80f43e156f2ad01ed20cd7d4d08c10518d1e45 cf80f43e15]</tvar>.</translate>
* {{date|2020|6}} - <translate><!--T:139--> <tvar name=1>'''$wgGraphImgServiceUrl'''</tvar> was deprecated.</translate>

<translate>
== VisualEditor module == <!--T:64-->
== VisualEditor module == <!--T:64-->


Line 306: Line 282:
<!--T:71-->
<!--T:71-->
This first step serves as a stepping stone for many possibilities with graph editing within VisualEditor, and there are a lot of ways in which the module can be improved and expanded.
This first step serves as a stepping stone for many possibilities with graph editing within VisualEditor, and there are a lot of ways in which the module can be improved and expanded.
</translate>
{{OnWikimedia}}


<translate>
== Troubleshooting broken graphs == <!--T:128-->
== Troubleshooting broken graphs == <!--T:128-->


Line 326: Line 299:
=== TypeError: undefined is not an object (evaluating 'datum.firstYear.value') ===
=== TypeError: undefined is not an object (evaluating 'datum.firstYear.value') ===


<translate><!--T:145--> To fix: Make sure you have not set default as null</translate>
<translate>
<!--T:145-->
To fix: Make sure you have not set default as null


<!--T:146-->
<translate><!--T:146--> [<tvar name=url>https://sv.m.wikipedia.org/w/index.php?title=Special:Mobil_diff/49114054&type=revision</tvar> Example].</translate>
[<tvar name=url>https://sv.m.wikipedia.org/w/index.php?title=Special:Mobil_diff/49114054&type=revision</tvar> Example].


<translate>
== See also == <!--T:72-->
== See also == <!--T:72-->
</translate>
</translate>
* {{Ll|Diagram extensions}}
* {{ll|Extension:GraphViz}} — <translate><!--T:81--> for displaying [[w:Graph (discrete mathematics)|graphs]] of sets of vertices connected by edges (i.e. not charts, like this extension)</translate>
* [https://plot.ly/javascript/ Plotly] — <translate><!--T:133--> The open source JavaScript graphing library (with 3d charting capabilities)</translate>
* [https://plot.ly/javascript/ Plotly] — <translate><!--T:133--> The open source JavaScript graphing library (with 3d charting capabilities)</translate>
* [https://d3js.org/ D3] — <translate><!--T:134--> Data-Driven Documents</translate>
* [https://d3js.org/ D3] — <translate><!--T:134--> Data-Driven Documents</translate>


{{Used by|canasta=1|miraheze=1}}
{{Used by}}


[[Category:Graph extensions{{#translation:}}]]
[[Category:Graph extensions{{#translation:}}]]

Latest revision as of 09:55, 5 August 2024

MediaWiki extensions manual
Graph
Release status: unmaintained
Implementation Tag , ContentHandler
Description Data-driven graphs
Author(s)
  • Yuri Astrakhan (Yurik talk),
  • Dan Andreescu,
  • Frédéric Bolduc
MediaWiki >= 1.43
License MIT License
Download
  • $wgGraphDefaultVegaVer
  • $wgGraphAllowHttp
  • $wgGraphAllowedDomains
Quarterly downloads 26 (Ranked 108th)
Public wikis using 884 (Ranked 281st)
Translate the Graph extension if it is available at translatewiki.net
Issues Open tasks · Report a bug

The Graph extension allows a ‎<graph> tag to describe data visualizations such as bar charts, pie charts, timelines, and histograms (demo) in a JSON format that renders a Vega-based graph.

General info

[edit]

Graph extension allows powerful Vega based graphs to be added to the wiki pages. Graphs can be interactive.

The easiest way to add a graph is to use a ready-made template such as {{Graph:Chart}}. These templates hide all Vega complexities. Power users can use the Graph Sandbox to develop graphs. Graph sandbox allows wiki template syntax in addition to JSON. The extension integrates with VisualEditor, providing a simple tool/wizard which generates basic graphs, by entering values directly to the editor.

[edit]

Installation

[edit]
  • Requires JsonConfig extension
  • Download and move the extracted Graph folder to your extensions/ directory.
    Developers and code contributors should install the extension from Git instead, using:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/Graph
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'Graph' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.


Vagrant installation:

  • If using Vagrant , install with vagrant roles enable graph --provision

Additional config setup

[edit]

If you are looking to replicate a production environment like en.wiki you will need to complete the following steps:

Debugging graphs and porting graphs from Vega 2 to Vega 5

[edit]

A sandbox is provided at Special:GraphSandbox that works similar to the Vega graph editor. The MediaWiki tool includes compatibility code that maps older Vega schemas to the currently enabled version. Inserting an old schema in the main text area will print a modified and modernized schema underneath the graph where possible.

Similar to vega.github.io/editor, the Vega object can be inspected via the VEGA_DEBUG JavaScript global. See Vega's debugging guide on how to use it.

Migrating schemas from older Vega versions

[edit]

Previously Graph supported Vega 2. You can paste the JSON of graphs in http://vega.github.io/vega-editor/?mode=vega to see how they previously rendered for comparison with Vega 5.

Special:GraphSandbox (for latest code see the beta cluster version of the sandbox) can be used to map older schemas to new schemas. Copy the old schema into the main textarea and the updated schema will appear in the text area below the graph. Copy the new schema into your code.

Charts examples

[edit]

See Demo page for many samples and usage tricks.


User defined fallback

[edit]

When using client side rendering, it is possible to use Wikimedia Commons to provide a static fallback image to noscript users. This is a temporary solution until a new service is put in place to provide server side rendering.

The user must first upload the static graph to Wikimedia Commons.

Fallback images have two variables: fallback and fallbackWidth.

fallback relates to a Wikimedia Commons filename.

fallbackWidth is the fallback images width in pixels.

These variables are pass through the graph in the following way:

<graph fallback="Graph test seddon.png" fallbackWidth=450>

Where lua modules are used such as Module:Graph then these variables can be provided via the tag function. If Template:Graph:Chart were adapted, it would look like this:

{{safesubst:#tag:graph|{{safesubst:#invoke:Graph|chartWrapper}} | fallback = {{{fallback|''}}} |  fallbackWidth= {{{fallbackWidth|''}}} }}

It would then be utilised in a template in the following manner:

{{Graph:Chart|width=400|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|fallback=Graph test seddon.png|fallbackWidth=450}}

If a fallbackWidth isn't provided but an image is defined then the extension will derive the width from the provided graph width. The reason for this is there is frequently a difference in the rendered image width and the actual image width.

{{Graph:Chart|width=400|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|fallback=Graph test seddon.png}}


External data

[edit]

HTTP(S) protocol cannot be used to get data for the graph. Instead, use one of the custom wiki protocols like wikiraw:, wikiapi:, and others.

Graph extension uses the GraphAllowedDomains setting to control how these protocols are resolved: Note that because queries rely on the structure of wikibase items, they may suddenly stop working if the underlying data is edited and changes, as it may yield incomplete, empty or invalid data that can't be used to create a graph. In these cases the graph will end up empty (see phab:T168601).

$wgGraphAllowedDomains = [
    # http + https keys lists all of the domains allowed for the external data access.
    # Any domain listed here automatically permits all subdomains as well.
    # Custom protocols like 'wikiraw' use it to determine which protocol to use.
    # This way wikiraw://en.wikipedia.org/Page will be an api request to https://en.wikipedia.org/w/api.php?action=query&titles=Page&...
    'https' => [ 'wikipedia.org', 'wikimedia.org', ... ],
    'http' => [ 'wmflabs.org', ... ],
    
    # list of domains allowed for the wikirawupload: protocol access.
    # Exact match only, no subdomains.
    'wikirawupload' => [ 'upload.wikimedia.org' ],
    
    # same as wikirawupload but for Wikidata Sparql queries
    'wikidatasparql' => [ 'query.wikidata.org' ],
];

Internals

[edit]

When parsing, the Graph extension expands all template parameters/expressions, and stores the complete graph definitions in the ParserOutput, using graph hashes for IDs.

The graph extension adds HTML to the page where graphs should go, a ‎<div> with a graph-id as the attribute. Sample:

<div class="mw-graph" data-graph-id="72edc224f0a10b343c1e84f63dbfc97cac9bc957">
</div>

The Graph extension adds an ext.graph ResourceLoader JavaScript module to the page that includes the Vega library, and puts the JSON of graph definitions into a JavaScript mediawiki.config variable named wgGraphSpecs. Once the client has loaded this module, the Vega JavaScript library populates each ‎<div> with an HTML canvas and draws the graph in it, replacing the static image.

Security features

[edit]

‎<graph> can be configured to disallow referencing untrusted data sources (e.g. Wikimedia only allows data from the Wikimedia sites).

License

[edit]

Vega library is distributed under a modified BSD license acceptable under for us to use.

This appears to be a copy of the BSD license, with some minor (acceptable) modifications. It's not a problem for us to use it, although ideally they would not make changes like this to the license. It's better if people do not make these changes to their license, to avoid confusion (like this) about whether the license is safe for open-source use.

—Stephen LaPorte

Configuration

[edit]

wgGraphAllowedDomains

[edit]

See the section on external data.

VisualEditor module

[edit]

Since summer 2015, the Graph extension also comes with a module (ext.graph.VisualEditor) which enables graph editing within VisualEditor.

This module was a result of a Google Summer of Code 2015 project. See phab:T89287 for more details.

This module allows users to see graphs within VisualEditor, as opposed to alien extension nodes. Furthermore, users can open up a dialog to edit a graph's type, data and padding. The UI also offers a way to edit a graph's raw JSON specification within VE without having to switch to the classic wikitext editor, in case more advanced users want to tweak settings not supported by the UI.

This first step serves as a stepping stone for many possibilities with graph editing within VisualEditor, and there are a lot of ways in which the module can be improved and expanded.

Troubleshooting broken graphs

[edit]

Errors with graphs will be logged in the developer console.

Error: Bad constructor arguments (phab:T277906)

[edit]

To fix: Replace filepath:Earthmap1000x500compac.jpg with filepath:Earthmap1000x500.jpg

Example.

TypeError: undefined is not an object (evaluating 'datum.firstYear.value')

[edit]

To fix: Make sure you have not set default as null

Example.

See also

[edit]