16#ifndef MiL_SVG_ELEMENTS_H
17#define MiL_SVG_ELEMENTS_H 1
75 _M_sstream <<
"url(#" <<
id <<
")" << k::quote;
83 _M_sstream <<
"url(#" <<
id <<
")" << k::quote;
102 std::ostringstream oss;
103 oss << k::space <<
"transform=" << k::quote << s << k::quote;
145 {
return string(
"</g>") + k::newline; }
167 _M_sstream <<
"<g id=" << k::quote << name << k::quote << k::space;
176 _M_sstream <<
"<g id=" << k::quote << name << k::quote;
213 {
return "</defs>"; }
257 _M_sstream <<
"href=" << k::quote << url << k::quote;
267 add_data(
const string& url,
const string relt,
const string ast,
268 const string cors =
"anonymous")
270 _M_sstream <<
"rel=" << k::quote << relt << k::quote << k::space;
271 _M_sstream <<
"href=" << k::quote << url << k::quote << k::space;
272 _M_sstream <<
"as=" << k::quote << ast << k::quote << k::space;
273 _M_sstream <<
"crossorigin=" << k::quote << cors << k::quote << k::space;
274 _M_sstream <<
"referrerpolicy=" << k::quote <<
"no-referrer" << k::quote;
314 _M_sstream <<
"<filter id=" << k::quote <<
id << k::quote <<
">"
323 auto [ width, height ] = blur_area;
325 _M_sstream <<
"<filter id=" << k::quote <<
id << k::quote << k::space
326 <<
"x=" << k::quote << x << k::quote << k::space
327 <<
"y=" << k::quote << y << k::quote << k::space
328 <<
"width=" << k::quote << width << k::quote << k::space
329 <<
"height=" << k::quote << height << k::quote
349 stream <<
"<feGaussianBlur in=";
350 stream << k::quote <<
in << k::quote << k::space;
351 stream <<
"stdDeviation=" << k::quote << dev << k::quote << k::space;
397 stop(
const string off,
const color& klr,
const double opacity = 1.0)
399 _M_sstream <<
"<stop offset=" << k::quote << off << k::quote << k::space
400 <<
"stop-color=" << k::quote <<
to_string(klr) << k::quote;
404 <<
"stop-opacity=" << k::quote << opacity << k::quote;
414 const double ratio =
static_cast<double>(numer)/
static_cast<double>(denom);
416 return std::to_string(perc) +
"%";
433 _M_sstream <<
"<radialGradient id=" << k::quote <<
"default" << k::quote;
444 _M_sstream <<
"<radialGradient id=" << k::quote <<
id << k::quote;
447 _M_sstream << k::space <<
"r=" << k::quote << radius << k::quote;
448 _M_sstream << k::space <<
"cx=" << k::quote << cx << k::quote;
449 _M_sstream << k::space <<
"cy=" << k::quote << cy << k::quote;
463 _M_sstream <<
"<radialGradient id=" << k::quote <<
id << k::quote
464 << k::space <<
"r=" << k::quote << radius << k::quote;
465 _M_sstream << k::space <<
"cx=" << k::quote << cx << k::quote;
466 _M_sstream << k::space <<
"cy=" << k::quote << cy << k::quote;
469 _M_sstream << k::space <<
"fx=" << k::quote << fx << k::quote;
470 _M_sstream << k::space <<
"fy=" << k::quote << fy << k::quote;
471 _M_sstream << k::space <<
"fr=" << k::quote << fr << k::quote;
483 _M_sstream <<
"</radialGradient>" << k::newline;
496 _M_sstream <<
"<linearGradient id=" << k::quote <<
"default" << k::quote;
507 _M_sstream <<
"</linearGradient>" << k::newline;
535 _M_sstream <<
"<marker id=" << k::quote <<
id << k::quote << k::space
536 <<
"markerWidth=" << k::quote << w << k::quote << k::space
537 <<
"markerHeight=" << k::quote << h << k::quote << k::space
538 <<
"refX=" << k::quote << x << k::quote << k::space
539 <<
"refY=" << k::quote << y << k::quote <<
" >"
599 {
_M_sstream <<
"<desc>" << k::newline << dsc << k::newline; }
635 const string x(
"__x");
636 const string y(
"__y");
637 const string attr(
"__attr");
638 const string style(
"__style");
640 string strip = R
"_delimiter_(x="__x" y="__y" __attr __style)_delimiter_";
668 const string x(
"__x");
669 const string dys(
"__dy");
670 string strip = R
"_delimiter_(<tspan x="__x" dy="__dy">)_delimiter_";
686 const string x(
"__x");
687 const string dxs(
"__dx");
688 string strip = R
"_delimiter_(<tspan x="__x" dx="__dx">)_delimiter_";
700 {
return "</tspan>"; }
714 for (
uint i = 0; i < s.size(); ++i)
722 if (i < s.size() - 1)
760 const string x(
"__x");
761 const string y(
"__y");
762 const string w(
"__w");
763 const string h(
"__h");
765 string strip = R
"_delimiter_(x="__x" y="__y" width="__w" height="__h"
816 const string x(
"__x");
817 const string y(
"__y");
818 const string r(
"__r");
820 string strip = R
"_delimiter_(cx="__x" cy="__y" r="__r")_delimiter_";
867 const string x1(
"__x1");
868 const string x2(
"__x2");
869 const string y1(
"__y1");
870 const string y2(
"__y2");
871 const string dash(
"__darray");
873 const bool dashp = !dasharray.empty();
875 R
"_delimiter_(x1="__x1" y1="__y1" x2="__x2" y2="__y2")_delimiter_";
877 R
"_delimiter_(x1="__x1" y1="__y1" x2="__x2" y2="__y2" stroke-dasharray="__darray")_delimiter_";
879 string strip = dashp ? stript : stripf;
896 {
_M_sstream <<
"<line id=" << k::quote << name << k::quote << k::space; }
942 _M_sstream <<
"stroke-dasharray=" << k::quote;
947 _M_sstream <<
"stroke-dashoffset=" << k::quote;
964 _M_sstream <<
"marker-mid=" << mkr << k::space;
965 _M_sstream <<
"marker-end=" << mkr << k::space;
976 {
_M_sstream <<
"<polyline id=" << k::quote << name << k::quote << k::space; }
1012 const string pathd(
"__d");
1013 const string len(
"__l");
1015 string strip = R
"_delimiter_(d="__d")_delimiter_";
1028 {
_M_sstream <<
"<path id=" << k::quote << name << k::quote << k::space; }
1058 const string off =
"",
const string whichside =
"")
1066 << k::quote <<
'#' <<
path_name << k::quote;
1069 << k::quote <<
offset << k::quote;
1072 << k::quote <<
side << k::quote;
1108 const string simg =
"<image";
1111 _M_sstream <<
"id=" << k::quote <<
id << k::quote << k::space;
1126 const string x(
"__x");
1127 const string y(
"__y");
1128 const string w(
"__w");
1129 const string h(
"__h");
1130 const string ref(
"__ref");
1132 string strip = R
"_delimiter_(href="__ref" x="__x" y="__y" width="__w" height="__h")_delimiter_";
1149 const string display =
"")
1154 _M_sstream <<
"crossorigin=" << k::quote << cors << k::quote << k::space;
1156 _M_sstream <<
"visibility=" << k::quote << vattr << k::quote << k::space;
1157 if (!display.empty())
1158 _M_sstream <<
"display=" << k::quote << display << k::quote << k::space;
1211 const auto [ scalex, scaley ] =
scale;
1212 const auto [ ox, oy ] = origin;
1218 const auto [ vwidth, vheight ] = av;
1233 string strip = R
"(<foreignObject x="XXX" y="YYY" width="WWW" height="HHH">)";
1247{
_M_sstream <<
" </foreignObject></g></g>" << k::newline; }
1261 const string svideo = R
"(<video xmlns="http://www.w3.org/1999/xhtml" )";
1264 _M_sstream <<
"id=" << k::quote <<
id << k::quote << k::space;
1284 const string attr = R
"(autoplay="true" loop="true" muted="true")")
1286 string strip = R
"(width="WWW" height="HHH" )";
1294 _M_sstream <<
"<source src=" << k::quote << src << k::quote << k::space;
1295 _M_sstream <<
"type=" << k::quote << mtype << k::quote;
1319 const string siframe = R
"(<iframe xmlns="http://www.w3.org/1999/xhtml" )";
1322 _M_sstream <<
"id=" << k::quote <<
id << k::quote << k::space;
1335 const string attr = R
"(sandbox="allow-scripts allow-same-origin")")
1337 string strip = R
"(width="WWW" height="HHH" )";
1347 _M_sstream <<
"<source src=" << k::quote << src << k::quote << k::space;
1348 _M_sstream <<
"type=" << k::quote << mtype << k::quote << k::space;
1373 const string sobject = R
"(<object xmlns="http://www.w3.org/1999/xhtml" )";
1376 _M_sstream <<
"id=" << k::quote <<
id << k::quote << k::space;
1390 const string attr = R
"(sandbox="allow-scripts allow-same-origin")")
1392 string strip = R
"(width="WWW" height="HHH" )";
1397 _M_sstream <<
"data=" << k::quote << src << k::quote << k::space;
1398 _M_sstream <<
"type=" << k::quote << mtype << k::quote << k::space;
1427 const string shead = R
"(<script type="text/javascript" crossorigin="anonymous")";
1430 _M_sstream <<
"id=" << k::quote <<
id << k::quote << k::space;
1441 static const string&
1444 static string js_show_element = R
"(
1445 function showTooltip(event, tooltipId) {
1446 const tooltipimg = document.getElementById(tooltipId);
1448 const ge = tooltipimg.parentElement;
1449 const svge = ge.parentElement;
1450 const brect = ge.getBoundingClientRect();
1451 const bx = brect.left;
1452 const by = brect.top;
1454 tooltipimg.setAttribute('x', event.x + bx);
1455 tooltipimg.setAttribute('y', event.y + by);
1457 tooltipimg.setAttribute('visibility', 'visible');
1459 console.error(`Element with ID "${tooltipId}" not found.`);
1463 static string js_show_document = R
"(
1464 function showTooltip(event, tooltipId) {
1465 const tooltipimg = document.getElementById(tooltipId);
1467 //tooltipimg.onload = function() {
1468 const ge = tooltipimg.parentElement;
1469 const svge = ge.parentElement;
1470 const brect = ge.getBoundingClientRect();
1471 const bx = brect.left;
1472 const by = brect.top;
1474 //const iheight = 150;
1475 const iheight = tooltipimg.offsetHeight; //!isNaN(iheight)
1476 tooltipimg.setAttribute('x', event.pageX - bx);
1477 tooltipimg.setAttribute('y', event.pageY - by - iheight);
1478 tooltipimg.setAttribute('visibility', 'visible');
1479 //tooltipimg.setAttribute('display', 'inline');
1481 console.error(`Element with ID "${tooltipId}" not found.`);
1485 static string js_hide = R
"(
1486 function hideTooltip(tooltipId) {
1487 const tooltipimg = document.getElementById(tooltipId);
1488 tooltipimg.setAttribute('visibility', 'hidden');
1489 //tooltipimg.setAttribute('display', 'none');
1494 js = js_show_element + k::newline + js_hide;
1496 js = js_show_document + k::newline + js_hide;
1504 const string toolr(
"__toolt");
1505 string strip1 = R
"_delimiter_(onmouseover="showTooltip(event, '__toolt')" )_delimiter_";
1506 string strip2 = R
"_delimiter_(onmouseout="hideTooltip('__toolt')" )_delimiter_";
1509 return k::space + strip1 + k::space + strip2;
1559 const bool lifetime =
true,
1570 const bool lifetime =
true)
1592 {
return _M_area.center_point(); }
1599 const style& sty = k::no_style);
void start_element(const string dsc)
static string start_tspan_x(uint xpos, uint dx)
void add_data(const string &url)
void start_element(string name, const string ts, const style &sty=k::no_style)
void add_data(const stroke_style &sstyl)
string gaussian_blur(string in, string dev)
static constexpr const char * pair_open_tag
void add_filter(const string id)
void start_element(const string id, const ssize_type radius=0, const ssize_type cx=0, const ssize_type cy=0)
void add_data(const data &d)
Either serialize immediately (as below), or create data structure that adds data to data_vec and then...
stream_type _M_sstream
Virtual, only one buffer.
void start_element(const string &id)
void start_element(const string id, const ssize_type radius, const ssize_type cx, const ssize_type cy, const ssize_type fr, const ssize_type fx, const ssize_type fy)
static const script_element tooltip_script(const scope context)
void add_style(const style &sty)
virtual void add_text(string txt)
void str(const string &s)
void start_element(const string id)
void add_data(const data &d, const string dasharray="")
svg_element(const string __title, const area &__cv, const bool lifetime=true, const unit u=svg::unit::pixel, const typography &__typo=k::smono_typo)
void add_data(const string fltr)
void add_data(const area<> a, const string src, const string mtype="image/jpeg", const string attr=R"(sandbox="allow-scripts allow-same-origin")")
iframe. a is width and height of video as embedded in page r is the foreign object,...
const string offset_percentage(const ssize_type numer, const ssize_type denom)
void start_element(const string id, const area<> blur_area, const point_2t p)
static const string & tooltip_javascript(const scope context)
showTooltip(id) hideTooltip(id) event.x vs. event.pageX, event.y vs. event.pageY
void start_element(const point_2t origin, const area<> av, const area<>, const point_2t scale=std::make_tuple(1.0, 1.0))
void add_desc(const string desc)
text_path_element(const string name, const string off="", const string whichside="")
void add_data(const area<> a, const string src, const string mtype="image/jpeg", const string attr=R"(sandbox="allow-scripts allow-same-origin")")
Add resource to object.
static string finish_tspan()
void start_element(const string &id)
void add_data(const data &d, string trans="")
void add_transform(const string s)
void start_element()
For groups of elements that have the same name.
void start_element(string name)
static string finish_defs()
static constexpr const char * pair_finish_tag
static string finish_group()
const point_2t center_point()
void add_data(const area<> a, const string src, const string mtype="video/mp4", const string attr=R"(autoplay="true" loop="true" muted="true")")
Video. a is width and height of video as embedded in page r is the foreign object,...
static constexpr const char * self_finish_tag
void add_data(const string scriptstr)
Add string with script source.
void add_title(const string &t)
void add_data(const data &d)
Either serialize immediately (as below), or create data structure that adds data to data_vec and then...
void start_element(string name, const style &sty)
void start_element()
SVG element beginning boilerplate for outermost (containing) svg_element. Variable: unit,...
void stop(const string off, const color &klr, const double opacity=1.0)
static string start_defs()
string gaussian_blur(string dev)
static const string tooltip_attribute(const string &id)
void start_element(const point_2t p, const area destarea, const style &sty=k::no_style)
static constexpr const char * finish_tag
static string start_tspan_y(uint xpos, string dy)
For text list output, use tspan for line breaks. This span creates a new horizontal line for every ts...
void add_data(const data &d, const string trans="", const unit utype=svg::unit::point)
Either serialize immediately (as below), or create data structure that adds data to data_vec and then...
static string start_tspan_y(uint xpos, uint dy)
static constexpr const char * pair_finish_tag
virtual void start_element()=0
void start_element(const string &id)
svg_element(const string __title, const string desc, const area &__cv, const bool lifetime=true)
static string start_group(const string name)
void start_element(string name)
void add_data(const data &d, const string cors, const string vattr, const string display="")
Visibility and other HTML/img attributes.
static string start_tspan_x(uint xpos, string dx)
For text list output, use tspan for line breaks. This span creates a new vertical line space for ever...
std::ostringstream stream_type
static constexpr const char * pair_finish_tag
void add_data(const data &d)
Either serialize immediately (as below), or create data structure that adds data to data_vec and then...
void start_element(const string &id)
const typography & _M_typo
void add_raw(const string &raw)
void start_element(const string name)
scope
Where is the script element placed? On/within the element itself, or at the document (global)?...
virtual void finish_element()=0
bool empty()
Empty when the output buffer is.
void add_fill(const string id)
void start_element(const string id, const area<> a, const point_2t p)
void add_data(const string &url, const string relt, const string ast, const string cors="anonymous")
Overload for rel=x form. https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/rel/p...
void start(const string &desc="")
void add_element(const element_base &e)
void start_element(const string t)
string make_transform_attribute(const string s)
Common transforms include rotate(180)
void finish(const bool writep=true)
static constexpr const char * pair_open_tag
void start_element(const string &id)
static constexpr string finish_tag_hard
polyline_element(const vrange &points)
svg_element(const svg_element &other)
void start_element(string name)
string make_tspan_y_from_string_by_token(string s, uint xpos, const char token=' ')
Make text span.
void store_element(const element_base &e)
Abstract base class for all SVG Elements.
iframe HTML object embedded in SVG container. NB: HTML elements video/audio/iframe/canvas can be used...
Linear gradients https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient.
HTML object embedded in SVG container. Unlike image_elements, object_elements are not locked down for...
Circular gradients https://developer.mozilla.org/en-US/docs/Web/SVG/Element/radialGradient.
video HTML object embedded in SVG container. NB: HTML elements video/audio/iframe/canvas can be used ...
color
Color enumerated as types.
unit
Measurement abstraction for absolute (not relative) measurements.
@ pt
Point where 1 pixel x 1/72 dpi x 96 PPI = .26 mm.
const string to_string(const unit e)
void string_replace(std::string &target, const std::string &match, const std::string &replace)
double space_type
Base floating point type.
std::vector< point_2t > vrange
std::tuple< space_type, space_type > point_2t
Point (x,y) in 2D space, space_type defaults to double.
Color quantified as integral RGB components in the range [0,255]. aka like Scalar in OpenCV.
Additional path/line/polyline stroke styles.
Datum consolidating style preferences.
const std::string add_attribute(const svg::unit utype=svg::unit::pixel) const