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

Method GetPosition

core/graphics/XChart.cpp:640–664  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

638}
639
640const util::Point XChart::GetPosition(const nlohmann::json &item) {
641 if(!canvasContext_ || !canvasContext_->IsValid() || scaleController_->Empty() || !item.is_object() || item.size() < 2) {
642 return util::Point{0, 0};
643 }
644
645 std::string xField = this->GetXScaleField();
646 std::vector<std::string> yFields = this->getYScaleFields();
647 std::string yField;
648 for(std::size_t index = 0; index < yFields.size(); ++index) {
649 const std::string &yFieldValue = yFields[index];
650 if (item.contains(yFieldValue)) {
651 yField = yFieldValue;
652 break;
653 }
654 }
655
656 if(!item.contains(xField) || yField.empty() || !item.contains(yField)) {
657 return util::Point{0, 0};
658 }
659
660 double x = this->GetScale(xField).Scale(item[xField]);
661 double y = this->GetScale(yField).Scale(item[yField]);
662 util::Point ret = this->GetCoord().ConvertPoint(util::Point{x, y});
663 return ret;
664}
665
666const nlohmann::json XChart::GetSelectedRecordsForGeom(const size_t index) {
667 if(!canvasContext_ || !canvasContext_->IsValid() || scaleController_->Empty()) {

Callers 1

ChartGetPositionFunction · 0.45

Calls 8

GetXScaleFieldMethod · 0.95
getYScaleFieldsMethod · 0.95
EmptyMethod · 0.80
IsValidMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
ScaleMethod · 0.45
ConvertPointMethod · 0.45

Tested by

no test coverage detected