Skip to content

Commit

Permalink
Separate image box from info box
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthijs Ridder committed Aug 28, 2024
1 parent dc672de commit bbd2e3c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
16 changes: 16 additions & 0 deletions core/include/actsvg/core/draw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,22 @@ svg::object connected_text(
const style::transform &transform_, const svg::object &object_,
const std::vector<std::string> &highlight_ = {"mouseover", "mouseout"});

/** Draw a image object - connected
*
* @param id_ is the image object id
* @param href_ is the image object href field
* @param object_ is the connected object
* @param highlight_ are the hightlighting options
* @param onerror_ is the image object onerror field
*
* @return an svg object with highlight connection
*
**/
svg::object image_box(
const std::string &id_, const std::string &href_, const svg::object &object_,
const std::vector<std::string> &highlight_, const std::string &onerror_);


/** Draw a text object - connected
*
* @param id_ is the text object id
Expand Down
37 changes: 31 additions & 6 deletions core/src/core/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,22 +445,51 @@ svg::object connected_text(const std::string &id_, const point2 &p_,
return t;
}

svg::object image_box(const std::string &id_, const std::string &href_) {
svg::object image_box(
const std::string &id_, const std::string &href_, const svg::object &object_,
const std::vector<std::string> &highlight_, const std::string &onerror_) {
svg::object i;

i._tag = "g";
i._id = id_;

// Image box object
svg::object imgb;
imgb._tag = "image";
imgb._attribute_map["href"] = href_;
imgb._attribute_map["height"] = "300";
imgb._attribute_map["width"] = "300";
imgb._attribute_map["x"] = "180";
imgb._attribute_map["y"] = "-26";
imgb._attribute_map["onerror"] = "this.onerror=null;this.href.baseVal='../../../../src/NoPull.png';";
imgb._attribute_map["onerror"] = onerror_;

i.add_object(imgb);
// Connect it
if (object_.is_defined()) {
i._attribute_map["display"] = "none";

svg::object on;
on._tag = "animate";
on._attribute_map["fill"] = "freeze";
on._attribute_map["attributeName"] = "display";
on._attribute_map["from"] = "none";
on._attribute_map["to"] = "block";
on._attribute_map["begin"] = object_._id + __d + highlight_[1];
on._attribute_map["fill-opacity"] = 1;

svg::object off;

off._tag = "animate";
off._attribute_map["fill"] = "freeze";
off._attribute_map["attributeName"] = "display";
off._attribute_map["to"] = "none";
off._attribute_map["from"] = "block";
off._attribute_map["begin"] = object_._id + __d + highlight_[0];

// Store the animation
i._sub_objects.push_back(on);
i._sub_objects.push_back(off);
}

return i;
}
Expand Down Expand Up @@ -514,10 +543,6 @@ svg::object connected_info_box(
text_, text_font_);
ib.add_object(te);


auto img = image_box(id_ + "pull_distr", "../../../css/img/" + id_ + ".png");
ib.add_object(img);

// Connect it
if (object_.is_defined()) {
ib._attribute_map["display"] = "none";
Expand Down
2 changes: 2 additions & 0 deletions python/src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ void add_core_module(context& ctx) {
/// Draw a connected info box
d.def("connected_info_box", &draw::connected_info_box);

d.def("image_box", &draw::image_box);

/// Draw a cartesian grid
d.def("cartesian_grid", &draw::cartesian_grid);

Expand Down

0 comments on commit bbd2e3c

Please sign in to comment.