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

Method Render

core/graphics/guide/RefLine.cpp:20–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18using namespace xg;
19
20void guide::RefLine::Render(XChart &chart, shape::Group *container, canvas::CanvasContext &context, const std::vector<util::Rect> &dangerRects) {
21 const std::string &xField = chart.GetXScaleField();
22 std::vector<std::string> yFields = chart.getYScaleFields();
23 const std::string yField = yFields[0];
24
25
26 for (auto it = chart.GetGeoms().begin(); it != chart.GetGeoms().end(); ++it) {
27 auto &dataArray = (*it)->GetDataArray();
28 long dataArraySize = dataArray.size();
29 const std::string &geomType = (*it)->GetType();
30 const Group *group = (*it)->GetContainer();
31 if (group == nullptr) {
32 continue;
33 }
34
35 long dataRatio = group->children_.size() / dataArraySize;
36 if (dataRatio == 0) {
37 return;
38 }
39
40 for (int index = 0; index < group->children_.size(); index++) {
41 auto &rect = group->children_[index];
42
43 bool shouldDrawRefLine = false;
44 std:string content = "";
45 float textSize = 30.f;
46 const std::string &contentKey = "content";
47 const std::string &textColorKey = "textColor";
48 const std::string &textSizeKey = "textSize";
49 canvas::CanvasFillStrokeStyle refColorStyle = CanvasFillStrokeStyle("#000000");
50
51 if (this->config_.contains("refLines") && this->config_["refLines"].is_array()) {
52 for(const auto &oneRefLine : this->config_["refLines"]) {
53 std::string key = oneRefLine.contains("recordIndex") ? "recordIndex" : "dataArrayIndex";
54 if(json::GetIntNumber(oneRefLine, key, -1) == index / dataRatio) {
55 //dataArrayIndex与data的index匹配,开始校验数据是否valid
56 //标题
57 if (oneRefLine.contains(contentKey) && oneRefLine[contentKey].is_string()) {
58 content = oneRefLine[contentKey];
59 }
60 //字颜色
61 if (oneRefLine.contains(textColorKey) && oneRefLine[textColorKey].is_string()) {
62 refColorStyle = CanvasFillStrokeStyle(oneRefLine[textColorKey]);
63 }
64 //字大小
65 if (oneRefLine.contains(textSizeKey) && oneRefLine[textSizeKey].is_number()) {
66 textSize = oneRefLine[textSizeKey].get<float>();
67 }
68 shouldDrawRefLine = true;
69 }
70 }
71 }
72
73 if (!shouldDrawRefLine) {
74 continue;
75 }
76
77 double r0 = 0.f;

Callers

nothing calls this directly

Calls 15

GetIntNumberFunction · 0.85
GetStringFunction · 0.85
GetNumberFunction · 0.85
GetXScaleFieldMethod · 0.80
getYScaleFieldsMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
GetContainerMethod · 0.80
GetDevicePixelRatioMethod · 0.80
SetStorkStyleMethod · 0.80
AddElementMethod · 0.80

Tested by

no test coverage detected