| 18 | using namespace xg; |
| 19 | |
| 20 | void 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; |
nothing calls this directly
no test coverage detected