Skip to content

Commit

Permalink
[GRM] Check individually if x and y labels are defined in the tree
Browse files Browse the repository at this point in the history
  • Loading branch information
IngoMeyer441 committed Jul 21, 2024
1 parent 5307cd3 commit 8328f78
Showing 1 changed file with 30 additions and 43 deletions.
73 changes: 30 additions & 43 deletions lib/grm/src/grm/interaction.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1300,36 +1300,31 @@ err_t get_tooltips(int mouse_x, int mouse_y, err_t (*tooltip_callback)(int, int,
auto coordinate_system = subplot_element->querySelectors("coordinate_system");
auto left_side_region = subplot_element->querySelectors("side_region[location=\"left\"]");
auto bottom_side_region = subplot_element->querySelectors("side_region[location=\"bottom\"]");
std::vector<std::shared_ptr<GRM::Element>> label_vec;
struct
{
std::shared_ptr<GRM::Element> x, y;
} label_elements{};

if (bottom_side_region && bottom_side_region->hasAttribute("text_content")) label_vec.push_back(bottom_side_region);
if (left_side_region && left_side_region->hasAttribute("text_content")) label_vec.push_back(left_side_region);
if (bottom_side_region && bottom_side_region->hasAttribute("text_content")) label_elements.x = bottom_side_region;
if (left_side_region && left_side_region->hasAttribute("text_content")) label_elements.y = left_side_region;

if (label_vec.empty())
if (label_elements.x && label_elements.x->hasAttribute("text_content"))
{
static auto xlabel = static_cast<std::string>(label_elements.x->getAttribute("text_content"));
info->xlabel = (char *)xlabel.c_str();
}
else
{
info->xlabel = (char *)"x";
info->ylabel = (char *)"y";
}
if (label_elements.y && label_elements.y->hasAttribute("text_content"))
{
static auto ylabel = static_cast<std::string>(label_elements.y->getAttribute("text_content"));
info->ylabel = (char *)ylabel.c_str();
}
else
{
if (!label_vec[0]->hasAttribute("text_content"))
{
info->xlabel = (char *)"x";
}
else
{
static auto xlabel = static_cast<std::string>(label_vec[0]->getAttribute("text_content"));
info->xlabel = (char *)xlabel.c_str();
}
if (!label_vec[1]->hasAttribute("text_content"))
{
info->ylabel = (char *)"y";
}
else
{
static auto ylabel = static_cast<std::string>(label_vec[1]->getAttribute("text_content"));
info->ylabel = (char *)ylabel.c_str();
}
info->ylabel = (char *)"y";
}

x_range_min = (double)(mouse_x - 50) / max_width_height;
Expand Down Expand Up @@ -1690,31 +1685,23 @@ err_t get_tooltips(int mouse_x, int mouse_y, err_t (*tooltip_callback)(int, int,
info->y_px = -1;
info->x = 0;
info->y = 0;
if (label_vec.empty())
if (label_elements.x && label_elements.x->hasAttribute("text_content"))
{
static auto xlabel = static_cast<std::string>(label_elements.x->getAttribute("text_content"));
info->xlabel = (char *)xlabel.c_str();
}
else
{
info->xlabel = (char *)"x";
info->ylabel = (char *)"y";
}
if (label_elements.y && label_elements.y->hasAttribute("text_content"))
{
static auto ylabel = static_cast<std::string>(label_elements.y->getAttribute("text_content"));
info->ylabel = (char *)ylabel.c_str();
}
else
{
if (!label_vec[0]->hasAttribute("text_content"))
{
info->xlabel = (char *)"x";
}
else
{
static auto xlabel = static_cast<std::string>(label_vec[0]->getAttribute("text_content"));
info->xlabel = (char *)xlabel.c_str();
}
if (!label_vec[1]->hasAttribute("text_content"))
{
info->ylabel = (char *)"y";
}
else
{
static auto ylabel = static_cast<std::string>(label_vec[1]->getAttribute("text_content"));
info->ylabel = (char *)ylabel.c_str();
}
info->ylabel = (char *)"y";
}
info->label = (char *)"";
return_error_if(info == nullptr, ERROR_MALLOC);
Expand Down

0 comments on commit 8328f78

Please sign in to comment.