Extension:图表
此扩展目前不再活跃维护! 尽管它可能仍然工作,但任何错误报告或功能请求将很可能被忽略。 如果您对承担开发与维护该扩展的任务工作感兴趣,您可以请求自己的存储库。 As a courtesy, you may want to contact the author. 或者您应移除该模板,并在页面的{{Extension }}信息框中将您自己列为扩展的维护人员。 |
Graph 发行状态: 不再維護 |
|
---|---|
实现 | 标签 , ContentHandler |
描述 | 数据驱动的图表 |
作者 | |
MediaWiki | >= 1.43 |
许可协议 | MIT授權條款 |
下載 | |
|
|
季度下載量 | 26 (Ranked 110th) |
正在使用的公开wiki数 | 884 (Ranked 281st) |
前往translatewiki.net翻譯Graph扩展 | |
問題 | 开启的任务 · 报告错误 |
图表扩展可以讓<graph>
标签以JSON格式描述数据可视化内容,例如条形图,饼图,时间线和直方图(示范),该JSON格式呈现基於Vega的图表。
基本信息
圖表擴展允許将基於Vega的圖表加入至Wiki頁面中。 圖表可以是互動式的。
插入圖表最簡單的方法就是使用預先製作的模板,如利用{{Graph:Chart}}製作長條圖。 這些模板隱藏了所有Vega複雜的部份。 高级用户可藉由圖表沙盒開發圖表。 除了JSON格式,圖表沙盒也支援維基語法。 该扩展集成VisualEditor ,提供了一个简单的工具/向导,可直接在编辑器中输入数值,生成基本的图表。
外部链接
- Vega2文档 – 在nyurik/vega/wiki恢复了Vega2的文档页面。
- 導覽 - 在Wiki中使用圖表的建議。
- 互動式圖表教程 - 說明如何從頭開始構建複雜的互動式圖表。
- 範例 - 一些範例和使用技巧。
- TechTalk 影片 - WMF技術講座上圖表擴展的討論,包括Lyra編輯器很棒的範例。(實驗室也有安裝)
- Vega未來功能。(Jeffrey Heer的專題演講)
- Vega - 所有Vega資源的聚集地。
- 有關Vega 2.0
- 介紹Vega互動式圖表的影片
安裝
- 需要JsonConfig 擴展
- 下载文件,并将解压后的
Graph
文件夹移动到extensions/
目录中。
开发者和代码贡献人员应从Git安装扩展,输入:cd extensions/
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/Graph - 将下列代码放置在您的LocalSettings.php 的底部:
wfLoadExtension( 'Graph' );
- 完成 – 在您的wiki上导航至Special:Version,以验证已成功安装扩展。
使用Vagrant安装:
- 如果使用Vagrant ,请通过
vagrant roles enable graph --provision
安装
Additional config setup
If you are looking to replicate a production environment like en.wiki you will need to complete the following steps:
- Install Scribunto , Imagemap and TemplateStyles , and enable SVG uploads
- If you use vagrant, you can use
vagrant roles enable --provision scribunto imagemap templatestyles svg
- If you use vagrant, you can use
- Import mediawiki.org's Module:Graph, Module:Graph/doc, Template:Nowrap and Template:Nowrap/styles.css (export link)
- Import enwiki's Module:Chart and Module:Chart/Default colors (export link)
- Import the file File:Circle_frame.svg
Debugging graphs and porting graphs from Vega 2 to Vega 5
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
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.
圖表範例
參考範例頁面 獲得更多範例及使用技巧。
User defined fallback
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}}
外部数据
HTTPS無法為圖表取得數據。
但是可使用自定義的維基傳輸安全協議如wikiraw:
或wikiapi:
:
圖表擴展利用GraphAllowedDomains
設定解析這些協議。
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開頭)
# 允許訪問的網域,子網域也允許訪問。
# 自定義的協議如'wikiraw'利用$gad來確認使用哪種協議。
# 這樣一來wikiraw://en.wikipedia.org/Page 將會對https://en.wikipedia.org/w/api.php?action=query&titles=Page&... 請求API。
'https' => [ 'wikipedia.org', 'wikimedia.org', ... ],
'http' => [ 'wmflabs.org', ... ],
# 下方列出所有wikirawupload:協議允許訪問的網域:
# wikirawupload:協議要求完全吻合,不允許子網域的訪問。
'wikirawupload' => [ 'upload.wikimedia.org' ],
# Wikidata Sparql 可供查詢的網域:
'wikidatasparql' => [ 'query.wikidata.org' ],
];
內部事務
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.
例子:
<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.
安全功能
<graph>
can be configured to disallow referencing untrusted data sources (e.g. Wikimedia only allows data from the Wikimedia sites).
许可协议
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 |
配置
wgGraphAllowedDomains
See the section on external data.
VisualEditor module
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. 有关更多详细信息,请参见phab: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.
Troubleshooting broken graphs
Errors with graphs will be logged in the developer console.
Error: Bad constructor arguments (phab:T277906)
To fix: Replace filepath:Earthmap1000x500compac.jpg with filepath:Earthmap1000x500.jpg
例子。
TypeError: undefined is not an object (evaluating 'datum.firstYear.value')
To fix: Make sure you have not set default as null
例子。
參見
- Diagram extensions
- Plotly — The open source JavaScript graphing library (with 3d charting capabilities)
- D3 — Data-Driven Documents
此扩展在以下wiki农场/托管网站和/或软件包中提供: 這不是一份權威名單。 即使某些wiki农场/托管网站和/或软件包未在这里列出,它们也可能提供此扩展。 请检查你的wiki农场/托管网站或软件包以确认提供情况。 |
- Pages with disabled graphs
- Extensions with XSS vulnerabilities/zh
- Unmaintained extensions/zh
- Tag extensions/zh
- ContentHandler extensions/zh
- MIT licensed extensions/zh
- Extensions in Wikimedia version control/zh
- OutputPageParserOutput extensions/zh
- ParserFirstCallInit extensions/zh
- All extensions/zh
- Pages using deprecated NoteTA template
- Extensions included in Canasta/zh
- Extensions included in WikiForge/zh
- Graph extensions/zh
- Extensions with VisualEditor support/zh
- Discovery/zh