Extension:Graph/ja

グラフ拡張機能は タグを用いてデータの画像化をJSONで記述しレンダリングします. 棒グラフ、円グラフ、タイムテーブル（年表）やヒストグラム（demo）をVega宣言型プログラミングで生成します.

全般的な情報
グラフ拡張機能は強力なVega宣言型プログラムのグラフをウィキページに加えます. グラフは静的と動的のどちらの形式も扱います.

もっとも簡便にグラフを追加するには、既存のなどのテンプレートを使います. これらのテンプレートはVegaの複雑さを見ずに済みます. 熟練のユーザーならグラフ用サンドボックスでグラフが作成できます. グラフのサンドボックスではJSONとウィキのテンプレート・シンタックスが使えます.

有用なリンク

 * - ウィキでグラフを使う方法の標準的な推奨.
 * - ゼロから複雑でインタラクティブなグラフ完成まで、段階的に解説する説明書.
 * - サンプルや使用法のトリックを解説.
 * TechTalk Video - ウィキメディア財団技術部門の議論. グラフ拡張機能を取上げ、Lyra エディタをわかりやすくデモしている. （on labsも合わせてインストールする）.
 * 興味があれば、Vegaの将来的な機能の動画も参照できる（Jeffrey Heerの基調講演）.
 * 開発者のためのVega解説 - Vegaのリソースを探すならこちらが最適.
 * インタラクティブなVegaの紹介ビデオ
 * インタラクティブなVegaの紹介ビデオ

表の例
サンプルや使用法の裏技はを参照してください.

外部データ
HTTP(S)を使ってグラフのデータを取得することはできません. 代わりに や 等、固有のウィキ・プロトコルを使用してください.

Graphoidサービスとグラフ拡張機能は 設定を用いてプロトコルの解決を設定します.

既知のバグと制限

 * Graph extension bugs
 * Graphoid service bugs
 * Fails to implement ISO 8601 timescales so only Gregorian calendars can be used in timelines

Internals
When parsing, the Graph extension expands all template parameters/expressions, and stores the complete graph definitions in the  page property, using graph hashes for IDs. This means you can easily locate a wiki's graphs with either Special:PageWithProps or [//www.mediawiki.org/w/api.php?action=query&list=pageswithprop&continue=&formatversion=2&pwppropname=graph_specs the action API].

The graph extension adds HTML to the page where graphs should go, a containing an  tag. サンプル:

The tag's   attribute points to the #Graphoid service, which provides a [//www.mediawiki.org/api/rest_v1/page/graph/png/Extension%3AGraph%2FDemo/1686336/d243aa924db2f82926e0f317217fcce591fe8cd4.png static image of the graph].

If the Graph extension is configured for interactivity, and if the client browser has JavaScript enabled and is not a legacy browser to which ResourceLoader does not ship JavaScript, then the client browser renders graphs on the fly. The Graph extension adds an  ResourceLoader JavaScript module to the page that includes the Vega library, and puts the JSON of graph definitions into a JavaScript   variable named. Once the client has loaded this module, the Vega JavaScript library populates each with an HTML canvas and draws the graph in it, replacing the static image. , Wikimedia wikis only enable this interactive rendering for edit preview.

You can configure the Graph extension to always use just the tag, and not add the Vega libraries or graph definition JSON. This mode will not work during editing, since  do not get updated until after the save. Once saved, the Graphoid service will be able to access the new graph definition via the action API.

セキュリティ機能
can be configured to disallow referencing untrusted data sources (e.g. Wikimedia only allows data from the Wikimedia sites). It can also send extra headers whenever accessing external data, e.g.  header that MediaWiki uses to prevent CSRF attacks.

ライセンス
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.

wgGraphIsTrusted
If  (default), passes Treat-as-Untrusted:1 header with all graph data requests

wgGraphImgServiceUrl
A format string to form a backend service request URL for the &lt;img> tag. For example:

Would produce this URL:

//graphoid.wikimedia.org/mediawiki.org/v1/png/Extension:Graph/0/be66c7016b9de3188ef6a585950f10dc83239837.png /{domain}/v1/png/{title}/{revid}/{hash}.png

Parameters will be supplied in this order: 1=server, 2=title, 3=revid, 4=graph-hash-id. All parameters will be escaped with rawurlencode. If the value is  (default), no urls will be generated

wgGraphUrlBlacklist variable has been removed in 787d64a11 (7 Dec 2015), wgGraphDataDomains has been removed in e0813f85a (28 Jan 2016). Use a wgGraphAllowedDomains instead.

wgGraphUserServiceAlways variable has been removed in b735f63ff4b (30 Sep 2015).

グラフ名前空間の有効化
To store graph definitions as standalone pages in their own namespace, configure JsonConfig.

Graphoid サービス
Graphoid is a node.js  service that converts a graph definition into a static PNG image using the same Vega library code that runs in advanced browsers. The service is available on the Wikimedia cluster at graphoid.wikimedia.org.

You can install it yourself:

The service URLs contain the domain of the page (for example mediawiki.org), service version (v1), the title of the page with the graph (PageTitle), revision ID of the page (12345, but could be 0 for current), and a hash ID of the graph itself (also used in HTML page to identify graph definition), for example:

http://localhost:19000/mediawiki.org/v1/PageTitle/12345/a64b022a8fa5b7fc5e40a2c95cd0a114b2ae1174.png http://graphoid.wikimedia.org/mediawiki.org/v1/png/Extension:Graph/0/be66c7016b9de3188ef6a585950f10dc83239837.png You configure the Graph extension to use the Graphoid service in LocalSettings.php with a line like



You can further configure the service via its config file.

ビジュアルエディターのモジュール
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. 詳細は T89287 を参照してください.

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.

関連項目

 * Extension:GraphViz — エッジ（枝）で結ばれた複数のノード（頂点）のグラフを表示（このページで解説した拡張機能の表形式ではない）
 * Plotly — オープンソースのJavaScriptグラフ作成ライブラリ（3D作表も可能）
 * D3 — データ駆動型ドキュメント