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

Method Render

core/graphics/guide/Text.cpp:9–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7using namespace xg;
8
9void guide::Text::Render(XChart &chart, shape::Group *container, canvas::CanvasContext &context, const std::vector<util::Rect> &dangerRects) {
10 const std::string &xField = chart.GetXScaleField();
11 std::vector<std::string> yFields = chart.getYScaleFields();
12 const std::string yField = yFields[0];
13
14 util::Point position = this->GetPosition(chart, json::Get(this->config_, "position"), xField, yField);
15
16 std::string textColor = json::GetString(config_, "textColor");
17 std::string content = json::GetString(config_, "content");
18 std::string textAlign = json::GetString(config_, "textAlign");
19 std::string textBaseLine = json::GetString(config_, "textBaseline");
20
21 float textSize = config_["textSize"];
22 textSize *= context.GetDevicePixelRatio();
23
24 nlohmann::json margin = config_["margin"];
25
26 std::array<float, 2> _margin = margin;
27 position.x = position.x - _margin[0] * context.GetDevicePixelRatio();
28 position.y = position.y - _margin[1] * context.GetDevicePixelRatio();
29
30 auto text = xg::make_unique<shape::Text>(content, position, textSize, "", textColor);
31
32 if (config_.contains("font")){
33 nlohmann::json font = json::GetObject(config_, "font");
34 if (!font.is_null()){
35 std::string fontStyle = json::GetString(font, "fontStyle", "");
36 std::string fontVariant = json::GetString(font, "fontVariant", "");
37 std::string fontWeight = json::GetString(font, "fontWeight", "");
38 std::string fontFamily = json::GetString(font, "fontFamily", "");
39 text->SetTextFont(fontStyle, fontVariant, fontWeight, fontFamily);
40 }
41 }
42
43 float fillOpacity = json::GetNumber(config_, "fillOpacity", 1);
44 text->SetFillOpacity(fillOpacity);
45 text->SetTextAlign(textAlign);
46 text->SetTextBaseline(textBaseLine);
47 bbox_ = text->GetBBox(context);
48 container->AddElement(std::move(text));
49}

Callers

nothing calls this directly

Calls 13

GetFunction · 0.85
GetStringFunction · 0.85
GetNumberFunction · 0.85
GetXScaleFieldMethod · 0.80
getYScaleFieldsMethod · 0.80
GetDevicePixelRatioMethod · 0.80
SetTextFontMethod · 0.80
SetFillOpacityMethod · 0.80
AddElementMethod · 0.80
GetPositionMethod · 0.45
SetTextAlignMethod · 0.45
SetTextBaselineMethod · 0.45

Tested by

no test coverage detected