| 3 | #include "graphics/shape/Polygon.h" |
| 4 | |
| 5 | void xg::guide::Background::Render(XChart &chart, shape::Group *container, canvas::CanvasContext &context, const std::vector<util::Rect> &dangerRects) { |
| 6 | const std::string &xField = chart.GetXScaleField(); |
| 7 | std::vector<std::string> yFields = chart.getYScaleFields(); |
| 8 | const std::string yField = yFields[0]; |
| 9 | |
| 10 | std::string shape = json::GetString(this->config_, "shape", "rect"); |
| 11 | if (shape == "polygon") { |
| 12 | std::vector<util::Point> points; |
| 13 | const auto &pointsJson = json::GetArray(this->config_, "points"); |
| 14 | for_each(pointsJson.begin(), pointsJson.end(), [&](auto &pointJson) -> void { |
| 15 | util::Point point = this->GetPosition(chart, pointJson, xField, yField); |
| 16 | points.push_back(point); |
| 17 | }); |
| 18 | canvas::CanvasFillStrokeStyle colorStyle = util::ColorParser(this->config_, "fixedColor"); |
| 19 | auto p = xg::make_unique<xg::shape::Polygon>(1, points, colorStyle, colorStyle, false); |
| 20 | xg::util::BBox bbox = p->GetBBox(context); |
| 21 | canvas::CanvasFillStrokeStyle newColorStyle = util::ColorParser(this->config_, "fixedColor", &bbox); |
| 22 | p->SetFillStyle(newColorStyle); |
| 23 | // 此处简易实现,后续需要区分stroke和fill |
| 24 | p->SetStorkStyle(newColorStyle); |
| 25 | container->AddElement(std::move(p)); |
| 26 | } else if (shape == "rect") { |
| 27 | util::Point leftBottom = this->GetPosition(chart, json::Get(this->config_, "leftBottom"), xField, yField); |
| 28 | util::Point rightTop = this->GetPosition(chart, json::Get(this->config_, "rightTop"), xField, yField); |
| 29 | |
| 30 | std::string color = json::Get(this->config_, "color"); |
| 31 | util::Point p = {leftBottom.x, rightTop.y}; |
| 32 | |
| 33 | auto rect = xg::make_unique<xg::shape::Rect>(p, util::Size{fabs(rightTop.x - leftBottom.x), fabs(rightTop.y - leftBottom.y)}); |
| 34 | float fillOpacity = json::GetNumber(config_, "fillOpacity", 1); |
| 35 | rect->SetFillOpacity(fillOpacity); |
| 36 | rect->SetFillColor(color); |
| 37 | container->AddElement(std::move(rect)); |
| 38 | } |
| 39 | } |
nothing calls this directly
no test coverage detected