File indexing completed on 2025-11-23 09:33:26
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 Acts::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 = 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 = strokeWidth;
0059 str._hl_width = 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
0081
0082
0083
0084
0085 inline static actsvg::svg::object group(
0086 const std::vector<actsvg::svg::object>& objects, const std::string& name) {
0087 actsvg::svg::object gr;
0088 gr._tag = "g";
0089 gr._id = name;
0090 for (const auto& o : objects) {
0091 gr.add_object(o);
0092 }
0093 return gr;
0094 }
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104 inline static actsvg::svg::object measure(double xStart, double yStart,
0105 double xEnd, double yEnd,
0106 const std::string& variable = "",
0107 double value = 0.,
0108 const std::string& unit = "") {
0109 std::string mlabel = "";
0110 if (!variable.empty()) {
0111 mlabel = variable + " = ";
0112 }
0113 if (value != 0.) {
0114 mlabel += actsvg::utils::to_string(static_cast<actsvg::scalar>(value));
0115 }
0116 if (!unit.empty()) {
0117 mlabel += " ";
0118 mlabel += unit;
0119 }
0120 return actsvg::draw::measure(
0121 "measure",
0122 {static_cast<actsvg::scalar>(xStart),
0123 static_cast<actsvg::scalar>(yStart)},
0124 {static_cast<actsvg::scalar>(xEnd), static_cast<actsvg::scalar>(yEnd)},
0125 actsvg::style::stroke(), actsvg::style::marker({"o"}),
0126 actsvg::style::marker({"|<<"}), actsvg::style::font(), mlabel);
0127 }
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137 inline static actsvg::svg::object axesXY(double xMin, double xMax, double yMin,
0138 double yMax) {
0139 return actsvg::draw::x_y_axes(
0140 "x_y_axis",
0141 {static_cast<actsvg::scalar>(xMin), static_cast<actsvg::scalar>(xMax)},
0142 {static_cast<actsvg::scalar>(yMin), static_cast<actsvg::scalar>(yMax)});
0143 }
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156 inline static actsvg::svg::object infoBox(
0157 double xPos, double yPos, const std::string& title, const Style& titleStyle,
0158 const std::vector<std::string>& info, const Style& infoStyle,
0159 actsvg::svg::object& object,
0160 const std::vector<std::string>& highlights = {"mouseover", "mouseout"}) {
0161 auto [titleFill, titleStroke, titleFont] = titleStyle.fillStrokeFont();
0162 auto [infoFill, infoStroke, infoFont] = infoStyle.fillStrokeFont();
0163
0164 actsvg::style::stroke stroke;
0165
0166 return actsvg::draw::connected_info_box(
0167 object._id + "_infoBox",
0168 {static_cast<actsvg::scalar>(xPos), static_cast<actsvg::scalar>(yPos)},
0169 title, titleFill, titleFont, info, infoFill, infoFont, stroke, object,
0170 highlights);
0171 }
0172
0173
0174
0175
0176
0177
0178 inline static void toFile(const std::vector<actsvg::svg::object>& objects,
0179 const std::string& fileName) {
0180 actsvg::svg::file foutFile;
0181
0182 for (const auto& o : objects) {
0183 foutFile.add_object(o);
0184 }
0185
0186 std::ofstream fout;
0187 fout.open(fileName);
0188 fout << foutFile;
0189 fout.close();
0190 }
0191
0192 }