MCPcopy Create free account
hub / github.com/antvis/F2Native / InvokeMethod

Method InvokeMethod

core/bridge/ChartBridge.cpp:18–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16}
17
18bool ChartBridge::InvokeMethod(const std::string &methodName,
19 const std::string &params,
20 BridgeCallback callback) {
21 if (!callback) {
22 //没有callback 打印一个日志
23 chart_->GetLogTracer()->trace("callback is nullptr");
24 return false;
25 }
26
27 if (!railing_) {
28 CallbackError(methodName, callback, "railing is nullptr");
29 return false;
30 }
31
32 commonFunction_ = BridgeChannel::Callback([callback, this](const std::string &functionId,
33 const std::string &params) -> const std::string {
34 //回调渲染动画
35 if (functionId == chart_->GetRequestFrameFuncId()) {
36 railing_->PlayAnimation(params);
37 return params;
38 }
39 //内部回调方法
40 else if (callbackFunctions_.find(functionId) != callbackFunctions_.end()) {
41 auto &function = callbackFunctions_[functionId];
42 return function.Execute(functionId, params);
43 }
44 //直接通过bridge回调出去
45 else {
46 nlohmann::json ret = {{"method","render"}, {"renderCallback", {{"functionId", functionId}, {"param", params}}}};
47 callback(ret.dump());
48 return params;
49 }
50 });
51 chart_->SetCanvasContext(railing_->GetCanvasContext());
52
53 if (methodName == "render") {
54 auto chartConfig = json::ParseString(params);
55 if (!chartConfig.is_object()) {
56 chart_->GetLogTracer()->trace("dsl is not object %s " , params.c_str());
57 CallbackError(methodName, callback, "dsl is not object");
58 return false;
59 }
60
61 if (!chartConfig.contains("chartConfig")) {
62 chart_->GetLogTracer()->trace("dsl is not contains chartConfig %s " , params.c_str());
63 CallbackError(methodName, callback, "dsl is not contains chartConfig key");
64 return false;
65 }
66
67 auto position = json::GetObject(chartConfig, "getPosition");
68 if (chartConfig["chartConfig"].is_object()) {
69 return InvokeRender(json::GetObject(chartConfig, "chartConfig"),
70 position,
71 callback);
72 } else {
73 const auto &dsl = json::ParseString(json::GetString(chartConfig, "chartConfig"));
74 return InvokeRender(dsl, position, callback);
75 }

Callers 3

nChartBridgeInvokeMethodFunction · 0.80
InitMethod · 0.80
RenderMethod · 0.80

Calls 14

ParseStringFunction · 0.85
GetStringFunction · 0.85
traceMethod · 0.80
GetLogTracerMethod · 0.80
GetRequestFrameFuncIdMethod · 0.80
PlayAnimationMethod · 0.80
findMethod · 0.80
endMethod · 0.80
dumpMethod · 0.80
GetScaleTicksMethod · 0.80
ExecuteMethod · 0.45
SetCanvasContextMethod · 0.45

Tested by

no test coverage detected