File indexing completed on 2025-12-11 09:40:21
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include <actsvg/meta.hpp>
0013
0014 #include <array>
0015 #include <fstream>
0016 #include <string>
0017 #include <tuple>
0018 #include <vector>
0019
0020 namespace ActsPlugins::Svg {
0021
0022
0023 struct Style {
0024
0025 std::array<int, 3> fillColor = {255, 255, 255};
0026 double fillOpacity = 1.;
0027
0028
0029 std::array<int, 3> highlightColor = {0, 0, 0};
0030 std::vector<std::string> highlights = {};
0031
0032 double strokeWidth = 0.5;
0033 std::array<int, 3> strokeColor = {0, 0, 0};
0034
0035 double highlightStrokeWidth = 2;
0036 std::array<int, 3> highlightStrokeColor = {0, 0, 0};
0037
0038 std::vector<int> strokeDasharray = {};
0039
0040 unsigned int fontSize = 14u;
0041 std::array<int, 3> fontColor = {0};
0042
0043
0044 unsigned int quarterSegments = 72u;
0045
0046
0047
0048 std::tuple<actsvg::style::fill, actsvg::style::stroke> fillAndStroke() const {
0049 actsvg::style::fill fll;
0050 fll._fc._rgb = fillColor;
0051 fll._fc._opacity = static_cast<actsvg::scalar>(fillOpacity);
0052 fll._fc._hl_rgb = highlightColor;
0053 fll._fc._highlight = highlights;
0054
0055 actsvg::style::stroke str;
0056 str._sc._rgb = strokeColor;
0057 str._sc._hl_rgb = highlightStrokeColor;
0058 str._width = static_cast<actsvg::scalar>(strokeWidth);
0059 str._hl_width = static_cast<actsvg::scalar>(highlightStrokeWidth);
0060 str._dasharray = strokeDasharray;
0061
0062 return {fll, str};
0063 }
0064
0065
0066
0067 std::tuple<actsvg::style::fill, actsvg::style::stroke, actsvg::style::font>
0068 fillStrokeFont() const {
0069 auto [fll, str] = fillAndStroke();
0070
0071 actsvg::style::font fnt;
0072 fnt._size = fontSize;
0073 fnt._fc._rgb = fontColor;
0074
0075 return std::tie(fll, str, fnt);
0076 }
0077 };
0078
0079
0080 inline static const Style defaultSensitiveStyle{{66, 166, 245},
0081 0.85,
0082 {245, 166, 66},
0083 {"mouseover", "mouseout"},
0084 0.25,
0085 {0, 0, 0},
0086 2.,
0087 {0, 0, 0},
0088 {},
0089 14u,
0090 {0},
0091 72u};
0092
0093
0094 inline static const Style defaultGridStyle{{0, 0, 0},
0095 0.0,
0096 {100, 100, 100},
0097 {"mouseover", "mouseout"},
0098 0.25,
0099 {0, 0, 0},
0100 3.,
0101 {0, 0, 0},
0102 {},
0103 14u,
0104 {0},
0105 72u};
0106
0107
0108
0109
0110
0111
0112
0113 inline static actsvg::svg::object group(
0114 const std::vector<actsvg::svg::object>& objects, const std::string& name) {
0115 actsvg::svg::object gr;
0116 gr._tag = "g";
0117 gr._id = name;
0118 for (const auto& o : objects) {
0119 gr.add_object(o);
0120 }
0121 return gr;
0122 }
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132 inline static actsvg::svg::object measure(double xStart, double yStart,
0133 double xEnd, double yEnd,
0134 const std::string& variable = "",
0135 double value = 0.,
0136 const std::string& unit = "") {
0137 std::string mlabel = "";
0138 if (!variable.empty()) {
0139 mlabel = variable + " = ";
0140 }
0141 if (value != 0.) {
0142 mlabel += actsvg::utils::to_string(static_cast<actsvg::scalar>(value));
0143 }
0144 if (!unit.empty()) {
0145 mlabel += " ";
0146 mlabel += unit;
0147 }
0148 return actsvg::draw::measure(
0149 "measure",
0150 {static_cast<actsvg::scalar>(xStart),
0151 static_cast<actsvg::scalar>(yStart)},
0152 {static_cast<actsvg::scalar>(xEnd), static_cast<actsvg::scalar>(yEnd)},
0153 actsvg::style::stroke(), actsvg::style::marker({"o"}),
0154 actsvg::style::marker({"|<<"}), actsvg::style::font(), mlabel);
0155 }
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 inline static actsvg::svg::object axesXY(double xMin, double xMax, double yMin,
0166 double yMax) {
0167 return actsvg::draw::x_y_axes(
0168 "x_y_axis",
0169 {static_cast<actsvg::scalar>(xMin), static_cast<actsvg::scalar>(xMax)},
0170 {static_cast<actsvg::scalar>(yMin), static_cast<actsvg::scalar>(yMax)});
0171 }
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184 inline static actsvg::svg::object infoBox(
0185 double xPos, double yPos, const std::string& title, const Style& titleStyle,
0186 const std::vector<std::string>& info, const Style& infoStyle,
0187 const actsvg::svg::object& object,
0188 const std::vector<std::string>& highlights = {"mouseover", "mouseout"}) {
0189 auto [titleFill, titleStroke, titleFont] = titleStyle.fillStrokeFont();
0190 auto [infoFill, infoStroke, infoFont] = infoStyle.fillStrokeFont();
0191
0192 actsvg::style::stroke stroke;
0193
0194 return actsvg::draw::connected_info_box(
0195 object._id + "_infoBox",
0196 {static_cast<actsvg::scalar>(xPos), static_cast<actsvg::scalar>(yPos)},
0197 title, titleFill, titleFont, info, infoFill, infoFont, stroke, object,
0198 highlights);
0199 }
0200
0201
0202
0203
0204
0205
0206 inline static void toFile(const std::vector<actsvg::svg::object>& objects,
0207 const std::string& fileName) {
0208 actsvg::svg::file foutFile;
0209
0210 for (const auto& o : objects) {
0211 foutFile.add_object(o);
0212 }
0213
0214 std::ofstream fout;
0215 fout.open(fileName);
0216 fout << foutFile;
0217 fout.close();
0218 }
0219
0220 }