1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Graph: Support version 2 graphs

This commit is contained in:
gnosygnu
2018-03-03 08:52:14 -05:00
parent 54d74b0acd
commit 93bac15244
23 changed files with 240 additions and 53 deletions

View File

@@ -16,11 +16,12 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
package gplx.xowa.xtns.graphs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
import gplx.xowa.htmls.heads.*;
import gplx.langs.jsons.*;
public class Graph_xnde implements Xox_xnde {
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {}
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_bgn);
ctx.Page().Html_data().Head_mgr().Itm__graph().Enabled_y_();
boolean log_wkr_enabled = Log_wkr != Xop_log_basic_wkr.Null; if (log_wkr_enabled) Log_wkr.Log_end_xnde(ctx.Page(), Xop_log_basic_wkr.Tid_graph, src, xnde);
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end);
}
@@ -30,14 +31,26 @@ public class Graph_xnde implements Xox_xnde {
Bry_bfr tmp_bfr = Bry_bfr_.New();
json = Json_fmtr.clean(tmp_bfr, json);
// enable graph
Xoh_head_itm__graph itm_graph = ctx.Page().Html_data().Head_mgr().Itm__graph();
itm_graph.Enabled_y_();
// get version; NOTE: default is 2; REF: https://noc.wikimedia.org/conf/InitialiseSettings.php.txt and 'wgGraphDefaultVegaVer' => ['default' => 2]; also, extension.json and "GraphDefaultVegaVer": 2
Json_doc jdoc = app.Utl__json_parser().Parse(json);
int version = jdoc.Get_val_as_int_or(Bry_.new_a7("version"), 2);
itm_graph.Version_(wpg.Url(), version);
// add to bfr
bfr.Add(Html__div_bgn);
bfr.Add(Html__div_lhs_bgn);
bfr.Add_int_fixed(version, 1);
bfr.Add(Html__div_lhs_end);
bfr.Add(json);
bfr.Add(Html__div_end);
bfr.Add(Html__div_rhs);
}
public static Xop_log_basic_wkr Log_wkr = Xop_log_basic_wkr.Null;
private static final byte[]
Html__div_bgn = Bry_.new_a7("<div class='mw-wiki-graph'>\n")
, Html__div_end = Bry_.new_a7("</div>\n")
Html__div_lhs_bgn = Bry_.new_a7("<div class='mw-graph' xo-graph-version=")
, Html__div_lhs_end = Bry_.new_a7(">\n")
, Html__div_rhs = Bry_.new_a7("</div>\n")
;
}