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

Method ParseObject

core/graphics/XChart.cpp:94–303  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92}
93
94bool XChart::ParseObject(const nlohmann::json &dsl) {
95 //线上已经使用了data作为key,这里兼容下
96 const std::string sourceKey = dsl.contains("data") ? "data" :"source";
97 if (!dsl.contains(sourceKey)) {
98 this->logTracer_->trace("#Parse source key is not include");
99 return false;
100 }
101 if (dsl[sourceKey].is_array()) {
102 const auto &data = json::GetArray(dsl, sourceKey);
103 SourceObject(data);
104 }
105 //线上的老代码data部分是string
106 else if(dsl[sourceKey].is_string()) {
107 const auto &dataStr = json::GetString(dsl, sourceKey);
108 const auto data = json::ParseString(dataStr);
109 SourceObject(data);
110 }
111
112 if (!data_.is_array() || (data_.is_array() && data_.size() == 0)) {
113 this->logTracer_->trace("#Parse data json is invalid");
114 return false;
115 }
116
117 const auto &name = json::GetString(dsl, "name");
118 SetName(name);
119
120 const auto &padding = json::GetArray(dsl, "padding");
121 const auto &margin = json::GetArray(dsl, "margin");
122 if (padding.is_array() && padding.size() >= 4) {
123 Padding(padding[0], padding[1], padding[2], padding[3]);
124 }
125
126 if (margin.is_array() && margin.size() >= 4) {
127 Margin(margin[0], margin[1], margin[2], margin[3]);
128 }
129
130 const auto &coord = json::GetObject(dsl, "coord");
131 CoordObject(coord);
132
133 //一个chart只有一个legend
134 const auto &legend = json::GetObject(dsl, "legend");
135 LegendObject(json::GetString(legend, "field"), legend);
136
137 //可能是bool, 可能是object
138 const auto &animate = json::Get(dsl, "animate");
139 AnimateObject(animate);
140
141 const auto &axises = json::GetArray(dsl, "axises");
142 for (auto it = axises.begin(); it != axises.end(); ++it) {
143 const auto &config = json::GetObject(*it, "config");
144 const auto &selection = json::GetObject(*it, "selection");
145
146 //ougu todo 坐标轴动画配置
147 const auto &animate = json::GetObject(*it, "animate");
148
149 //兼容线上老的代码
150 if (config.is_object()) {
151 AxisObject(json::GetString(*it, "field"), config, selection);

Callers 1

InvokeRenderMethod · 0.80

Calls 15

GetStringFunction · 0.85
ParseStringFunction · 0.85
GetFunction · 0.85
GetNumberFunction · 0.85
traceMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
PositionMethod · 0.80
ColorMethod · 0.80
AdjustMethod · 0.80
LineObjectMethod · 0.80
TextObjectMethod · 0.80

Tested by

no test coverage detected