File indexing completed on 2025-12-17 09:38:03
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
0025 enum type { e_highlight, e_associate_id, e_associate_info };
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 std::vector<svg::object> connect_action(
0043 std::vector<svg::object> &sources_, std::vector<svg::object> &targets_,
0044 const std::vector<std::vector<size_t>> &s_t_connections_, bool ls_ = true,
0045 const std::array<std::string, 2u> &on_off_ = {"mouseover", "mouseout"},
0046 const std::vector<connectors::type> &ct_ = {e_highlight, e_associate_info},
0047 const style::font &font_ = style::font());
0048
0049 struct name_extractor {
0050
0051 template <typename source_type>
0052 auto name(const source_type &s_) {
0053 return s_._name;
0054 }
0055 };
0056
0057 struct id_extractor {
0058
0059 template <typename source_type>
0060 auto name(const source_type &s_) {
0061 return s_._id;
0062 }
0063 };
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 template <typename source_objects_type,
0077 typename source_name_getter_type = name_extractor>
0078 void connect_action(const source_objects_type &sources_,
0079 std::vector<svg::object> &targets_,
0080 const std::vector<std::vector<size_t>> &s_t_connections_) {
0081
0082
0083 if (sources_.size() != s_t_connections_.size()) {
0084 return;
0085 }
0086
0087
0088 for (auto [is, s] : utils::enumerate(sources_)) {
0089
0090 std::string sid = source_name_getter_type{}.name(s);
0091
0092
0093 auto st_cs = s_t_connections_[is];
0094
0095 for (auto it : st_cs) {
0096
0097 if (it >= targets_.size()) {
0098 continue;
0099 }
0100
0101 svg::object &t = targets_[it];
0102 t._attribute_map["display"] = "none";
0103
0104
0105 svg::object on;
0106 on._tag = "animate";
0107 on._attribute_map["fill"] = "freeze";
0108 on._attribute_map["attributeName"] = "display";
0109 on._attribute_map["from"] = "none";
0110 on._attribute_map["to"] = "block";
0111 on._attribute_map["begin"] = sid + __d + "mouseout";
0112
0113 svg::object off;
0114
0115 off._tag = "animate";
0116 off._attribute_map["fill"] = "freeze";
0117 off._attribute_map["attributeName"] = "display";
0118 off._attribute_map["to"] = "none";
0119 off._attribute_map["from"] = "block";
0120 off._attribute_map["begin"] = sid + __d + "mouseover";
0121
0122
0123 t._sub_objects.push_back(off);
0124 t._sub_objects.push_back(on);
0125 }
0126 }
0127 }
0128
0129 }
0130 }