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

Method Render

core/graphics/guide/Image.cpp:16–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14using namespace xg;
15
16void 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}

Callers

nothing calls this directly

Calls 11

GetNumberFunction · 0.85
GetStringFunction · 0.85
CreateCommandFunction · 0.85
GetXScaleFieldMethod · 0.80
getYScaleFieldsMethod · 0.80
GetDevicePixelRatioMethod · 0.80
RequestAnimationFrameMethod · 0.80
AddElementMethod · 0.80
GetPositionMethod · 0.45
emptyMethod · 0.45
OnLoadMethod · 0.45

Tested by

no test coverage detected