File indexing completed on 2025-01-30 09:32:36
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <cmath>
0012 #include <fstream>
0013 #include <map>
0014 #include <vector>
0015
0016 #include "draw.hpp"
0017 #include "svg.hpp"
0018 #include "utils.hpp"
0019
0020 namespace actsvg {
0021
0022 namespace connectors {
0023
0024 enum type { e_highlight, e_associate_id, e_associate_info };
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 static inline std::vector<svg::object> connect_action(
0042 std::vector<svg::object> &sources_, std::vector<svg::object> &targets_,
0043 const std::vector<std::vector<size_t> > &s_t_connections_, bool ls_ = true,
0044 const std::array<std::string, 2u> &on_off_ = {"mouseover", "mouseout"},
0045 const std::vector<connectors::type> &ct_ = {e_highlight, e_associate_info},
0046 const style::font &font_ = style::font()) {
0047
0048 std::vector<svg::object> additional_connections;
0049
0050 for (auto [s, ts] : utils::enumerate(s_t_connections_)) {
0051 if (s < sources_.size()) {
0052
0053 auto &sog = sources_[s];
0054
0055 std::vector<std::string> id_assoc_text;
0056 std::vector<std::string> info_assoc_text;
0057
0058 if (sog._id.empty()) {
0059 continue;
0060 }
0061
0062 if (ls_) {
0063 id_assoc_text.push_back("Source: ");
0064 id_assoc_text.push_back("* " + sog._id);
0065
0066 info_assoc_text.push_back("Source: ");
0067 for (const auto &sai : sog._aux_info) {
0068 info_assoc_text.push_back(sai);
0069 }
0070 }
0071
0072 for (auto [it, t] : utils::enumerate(ts)) {
0073 if (t < targets_.size()) {
0074
0075 auto &tog = targets_[t];
0076
0077 if (it == 0) {
0078 id_assoc_text.push_back("Target:");
0079 info_assoc_text.push_back("Target:");
0080 }
0081 id_assoc_text.push_back("* " + tog._id);
0082 for (const auto &tai : tog._aux_info) {
0083 info_assoc_text.push_back(tai);
0084 }
0085
0086 if (std::find(ct_.begin(), ct_.end(), e_highlight) !=
0087 ct_.end()) {
0088 svg::object on_off;
0089 on_off._tag = "set";
0090 on_off._attribute_map["attributeName"] = "fill";
0091 on_off._attribute_map["begin"] =
0092 sog._id + __d + on_off_[0];
0093 on_off._attribute_map["end"] =
0094 sog._id + __d + on_off_[1];
0095
0096 on_off._stroke._sterile = true;
0097 on_off._fill._sterile = true;
0098
0099
0100 bool connection_done = false;
0101 for (auto &sob_tog : tog._sub_objects) {
0102 if (sob_tog._tag == "use") {
0103 on_off._attribute_map["to"] =
0104 style::rgb_attr(sob_tog._fill._fc._hl_rgb);
0105 sob_tog._sub_objects.push_back(on_off);
0106 connection_done = true;
0107 break;
0108 }
0109 }
0110
0111 if (not connection_done) {
0112 on_off._attribute_map["to"] =
0113 style::rgb_attr(tog._fill._fc._hl_rgb);
0114 tog._sub_objects.push_back(on_off);
0115 }
0116 }
0117 }
0118 }
0119
0120 if (std::find(ct_.begin(), ct_.end(), e_associate_id) !=
0121 ct_.end()) {
0122
0123 auto c_text = draw::connected_text(
0124 sog._id + "_id_associations",
0125 {sog._barycenter[0], sog._barycenter[1]}, id_assoc_text,
0126 font_, style::transform(), sog);
0127 additional_connections.push_back(c_text);
0128 } else if (std::find(ct_.begin(), ct_.end(), e_associate_info) !=
0129 ct_.end()) {
0130
0131 auto c_text = draw::connected_text(
0132 sog._id + "_info_associations",
0133 {sog._barycenter[0], sog._barycenter[1]}, info_assoc_text,
0134 font_, style::transform(), sog);
0135 additional_connections.push_back(c_text);
0136 }
0137 }
0138 }
0139 return additional_connections;
0140 }
0141 }
0142 }