| 14 | using namespace xg; |
| 15 | |
| 16 | void guide::Image::Render(XChart &chart, shape::Group *container, canvas::CanvasContext &context, const std::vector<util::Rect> &dangerRects) { |
| 17 | const std::string &xField = chart.GetXScaleField(); |
| 18 | std::vector<std::string> yFields = chart.getYScaleFields(); |
| 19 | const std::string &yField = yFields[0]; |
| 20 | |
| 21 | util::Point position = this->GetPosition(chart, json::GetArray(this->config_, "position"), xField, yField); |
| 22 | const nlohmann::json &margin = config_["margin"]; |
| 23 | std::array<float, 2> _margin = margin; |
| 24 | |
| 25 | double width = json::GetNumber(config_, "width", 12) * context.GetDevicePixelRatio(); |
| 26 | double height = json::GetNumber(config_, "height", 12) * context.GetDevicePixelRatio(); |
| 27 | if (width <= 0 || height <= 0) { |
| 28 | return; |
| 29 | } |
| 30 | const std::string &src = json::GetString(config_, "src"); |
| 31 | if (src.empty()) { |
| 32 | return; |
| 33 | } |
| 34 | float marginLeft = _margin[0] * context.GetDevicePixelRatio(); |
| 35 | float marginTop = _margin[1] * context.GetDevicePixelRatio(); |
| 36 | // 显示image的位置点的上方居中,因此x偏移x/2,y偏移y |
| 37 | position.x = position.x - width / 2 - marginLeft; |
| 38 | position.y = position.y - height - marginTop; |
| 39 | auto image = xg::make_unique<shape::Image>(src, position, util::Size {width, height}); |
| 40 | |
| 41 | //上屏 |
| 42 | image->OnLoad([&] () { |
| 43 | func::Command *cmd = func::CreateCommand([this]() -> void {}); |
| 44 | //立刻上屏 |
| 45 | chart.RequestAnimationFrame(cmd, 0); |
| 46 | }); |
| 47 | container->AddElement(std::move(image)); |
| 48 | |
| 49 | } |
nothing calls this directly
no test coverage detected