16#ifndef MiL_SVG_RENDER_BASICS_H
17#define MiL_SVG_RENDER_BASICS_H 1
28 const double pi(22/7);
29 double a1 = radius * radius * pi;
30 double ap = a1 * weight;
31 double rpa = std::sqrt(ap/pi);
39 double rpr = radius * weight;
48 auto [ x, y ] = origin;
73 auto [ x, y ] = origin;
89 auto [ x, y ] = origin;
105 auto [ x, y ] = origin;
106 auto [ rx, ry ] = rorigin;
122 auto [ x, y ] = origin;
134 while ((pos = uriconv.find(
'&', pos)) != std::string::npos)
136 uriconv.replace(pos, 1,
"&");
140 string astart =
"<a href=";
145 astart += k::newline;
150 string afinish =
"</a>";
151 afinish += k::newline;
159 const string text,
const int tx,
const int ty)
174 const string text,
const int tx,
const int ty,
const double deg)
191 auto [ x, y ] = origin;
193 string textcut(
text);
194 while (textcut.size() > maxlen)
197 auto sppos = textcut.find_last_of(k::space, maxlen);
198 if (sppos == string::npos)
206 string namesubs = textcut.substr(0, sppos);
208 textcut = textcut.substr(sppos);
220 const uint lettingsz = 0)
222 const auto [ x, y ] = origin;
223 const double line_max = std::ceil(
double(
text.size()) / maxlen);
224 const uint lines(line_max);
227 string textcut(
text);
230 while (linen < lines)
234 auto xp = x - ((sz + lettingsz) * (lines - linen - 1));
237 if (textcut.size() < maxlen)
238 epos = textcut.size();
242 auto sppos = textcut.find_last_of(k::space, maxlen);
243 if (sppos == string::npos)
253 string namesubs = textcut.substr(0, epos);
255 textcut = textcut.substr(epos);
257 xmin = std::min(xmin,
uint(xp));
266 const string dasharray =
"")
268 auto [ xo, yo ] = origin;
269 auto [ xe, ye ] = end;
284 const string dasharray =
"")
296 polyline_element pl(points);
308 const string filterstr =
"")
310 auto [ width, height ] = a;
311 auto [ x, y ] = origin;
320 if (!filterstr.empty())
330 const string filterstr =
"")
332 auto [ width, height ] = a;
333 auto [ x, y ] = origin;
346 double width = 4,
double height = 4,
347 const string filterstr =
"")
357 double width = 4,
double height = 4,
358 const string filterstr =
"")
368 const space_type r = 4,
const string xform =
"")
371 auto [ x, y ] = origin;
384 const space_type r = 4,
const string xform =
"")
397 const space_type radius,
const double blurspace,
400 const double opacity = 1)
402 using atype =
decltype(obj.
_M_area)::atype;
404 auto [ xd, yd ] = origin;
409 const double oring = radius + blurspace;
412 const double iring = radius - blurspace;
415 std::ostringstream oss;
416 oss <<
"x" << std::to_string(x) << k::hyphen
417 <<
"y" << std::to_string(y) << k::hyphen
418 <<
"r" << std::to_string(radius) << k::hyphen
419 <<
"blurspace" << std::to_string(blurspace);
420 const string mangle(oss.str());
425 const string rgrado_name(
string(
"radialout") + k::hyphen + mangle);
445 const string rgradi_name(
string(
"radialin") + k::hyphen + mangle);
449 rgradi.
stop(
"100%", klr, opacity);
469 using atype =
decltype(obj.
_M_area)::atype;
473 static std::mt19937_64 rg(std::random_device{}());
474 auto distr = std::uniform_real_distribution<>(0.0, 2 * 22/7);
475 auto disti = std::uniform_int_distribution<>(-3, 3);
477 for (
uint i = 0; i < nrays; ++i)
479 double theta = distr(rg);
480 double rvary = disti(rg);
482 atype xe = x + (r + rvary) * std::cos(theta);
483 atype ye = y + (r + rvary) * std::sin(theta);
499 const string id =
"")
501 using atype =
decltype(obj.
_M_area)::atype;
503 auto [xo, yo] = origin;
504 auto [xc, yc] = circump;
525 auto [ cx, cy ] = origin;
526 double x(cx + (r * std::cos(angler)));
527 double y(cy - (r * std::sin(angler)));
528 return std::make_tuple(x, y);
537 double angler = (k::pi / 180.0) * ad;
547 angled = 360 - angled;
573 std::ostringstream ossa;
574 for (
uint i = 0; i < lpoints.size(); ++i)
576 auto [x, y ] = lpoints[i];
581 ossa <<
"M" << k::space;
583 ossa <<
"L" << k::space;
596 const bool selfclosingtagp =
true,
const string xattr =
"")
623 const double r = 4,
const double angle = 120,
624 const bool selfclosingtagp =
true,
const string xattr =
"")
631 vrange pointz = { p1, p2, p3, p1 };
643 const double r = 4,
const double angle = 120)
655 const double r = 4,
const uint pointsn = 8)
658 const double angle(360.0/8);
663 for (
uint i = 0; i < pointsn; ++i)
670 pointz.push_back(pointz.front());
673 const string id =
"octogon-" + std::to_string(r);
694 const int sweepflag = 1)
698 std::ostringstream oss;
699 oss <<
"M" << k::space <<
to_string(start) << k::space;
700 oss <<
"A" << k::space;
701 oss << std::to_string(r) << k::space << std::to_string(r) << k::space;
702 oss << 0 << k::space << arcflag << k::space << sweepflag << k::space;
713 const int arcflag = 0,
const int sweepflag = 0)
722 std::ostringstream oss;
723 oss <<
"M" << k::space <<
to_string(origin) << k::space;
724 oss <<
"L" << k::space <<
to_string(start) << k::space;
725 oss <<
"A" << k::space;
726 oss << std::to_string(r) << k::space << std::to_string(r) << k::space;
727 oss << 0 << k::space << arcflag << k::space << sweepflag << k::space;
729 oss <<
"L" << k::space <<
to_string(origin) << k::space;
739 const int arcflag = 0,
const int sweepflag = 0)
750 const int len,
const int width)
754 const auto [ xo, yo ] = origin;
757 const double whalf(width / 2);
758 const int lenw = len - whalf;
759 const auto x = xo - whalf;
760 const auto y = yo - whalf;
762 std::ostringstream oss;
763 oss <<
"M" << k::space << x << k::comma << y << k::space;
766 oss <<
"H" << k::space << x - lenw << k::space;
767 oss <<
"V" << k::space << y + width << k::space;
768 oss <<
"H" << k::space << x << k::space;
771 oss <<
"V" << k::space << y + lenw + width << k::space;
772 oss <<
"H" << k::space << x + width << k::space;
773 oss <<
"V" << k::space << y + width << k::space;
776 oss <<
"H" << k::space << x + lenw + width << k::space;
777 oss <<
"V" << k::space << y << k::space;
778 oss <<
"H" << k::space << x + width << k::space;
781 oss <<
"V" << k::space << y - lenw << k::space;
782 oss <<
"H" << k::space << x << k::space;
783 oss <<
"V" << k::space << y << k::space;
785 const string pathdata = oss.str();
787 string id(
"center-mark-");
788 string attr(std::to_string(width) +
"-" + std::to_string(len));
799 const double radius,
const double tiltd = 0.0)
813 std::ostringstream oss;
824 const style& styl,
const int radius,
825 const double tiltd = 0.0)
838 const auto [ awidth, aheight ] = a;
854 svg_element obj(
"color_qis_" + std::to_string(klrs.size()) +
"_palette",
858 auto x = rwidth, y = rheight;
860 for (
const auto& klr : klrs)
863 const style s = { klr, 1.0, klr, 0.0, 2 };
869 x + xoffset, y - rheight / 2 + rspace, 90);
871 if (xoffset + rwidth + rspace < awidth - rwidth - rspace)
872 xoffset += rwidth + rspace;
876 y += (rheight + rspace + rspace);
void add_filter(const string id)
void add_data(const data &d)
Either serialize immediately (as below), or create data structure that adds data to data_vec and then...
void add_style(const style &sty)
void add_data(const data &d, const string dasharray="")
const string offset_percentage(const ssize_type numer, const ssize_type denom)
void add_data(const data &d, string trans="")
void add_data(const data &d)
Either serialize immediately (as below), or create data structure that adds data to data_vec and then...
void stop(const string off, const color &klr, const double opacity=1.0)
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...
void add_raw(const string &raw)
void add_fill(const string id)
void start(const string &desc="")
void add_element(const element_base &e)
static constexpr string finish_tag_hard
Abstract base class for all SVG Elements.
Circular gradients https://developer.mozilla.org/en-US/docs/Web/SVG/Element/radialGradient.
constexpr char space(' ')
Formatting character constants.
double zero_angle_north_ccw(double angled)
Zero degrees is top, going clockwise (cw).
double scale_proportional_to_area(double radius, double weight)
circle_element make_circle(const point_2t origin, style s, const space_type r=4, const string xform="")
Make circle element.
line_element make_line(const point_2t origin, const point_2t end, style s, const string dasharray="")
Line primitive.
void point_to_ring_halo(svg_element &obj, const point_2t origin, const space_type radius, const double blurspace, const svg::color klr, const svg::color fadeklr=color::none, const double opacity=1)
Draws a ring centered at origin of radius r, with outer and inner radial gradient of blurspace in eac...
color
Color enumerated as types.
text_element style_text(const string text, const point_2t origin, const typography typo)
Text elemetn at.
void sized_text_r(element_base &obj, svg::typography typo, const int sz, const string text, const int tx, const int ty, const double deg)
Text at size, with a transformation=rotation.
void point_to_circle(svg_element &obj, const point_2t origin, style s, const space_type r=4, const string xform="")
Draws a circle around a point (x,y), of style (s), of radius (r).
uint text_line_n(svg_element &obj, const point_2t origin, const string text, const svg::typography typo, const int sz, const uint maxlen)
Text of maxlen length, overflow goes on line below.
string make_path_data_from_points(const vrange &lpoints)
Make single path segment.
path_element make_path_center_mark(const point_2t &origin, const style styl, const int len, const int width)
Plus or x tilt mark as closed path that can be filled.
path_element make_path(const string &pathda, const style &styl, const string id="", const bool selfclosingtagp=true, const string xattr="")
Draw path given serialized path data. Can be used to make pinstripes, ie top and bottom line layers....
const string to_string(const unit e)
double zero_angle_north_cw(double angled)
Zero degrees is top, going clockwise (cw).
void point_to_octogon(svg_element &obj, const point_2t origin, const style s, const double r=4)
Center an octogon at this point.
double space_type
Base floating point type.
void place_ray_at_angle(svg_element &obj, const point_2t &origin, const point_2t &circump, const style &s, const string id="")
void points_to_line(svg_element &obj, const style s, const point_2t origin, const point_2t end, const string dasharray="")
Line between two points.
void point_to_crossed_lines(svg_element &obj, const point_2t origin, const style &styl, const int radius, const double tiltd=0.0)
Point to center mark as crossed lines. Default is a plus sign at origin, but.
path_element make_path_triangle(const point_2t origin, const style styl, const double r=4, const double angle=120, const bool selfclosingtagp=true, const string xattr="")
Center a triangle at this point.
void styled_text(element_base &obj, const string text, const point_2t origin, const typography typo)
Text at.
svg_element display_color_qis(const auto &klrs, const area<> a, const typography &typobase)
Make grid palette for display. NB.
void point_2d_to_ray(svg_element &obj, double x, double y, style s, space_type r=4, const uint nrays=10)
Lines radiating from center point (x,y).
rect_element make_rect_centered(const point_2t origin, const style s, const area<> a, const string filterstr="")
Create rect_element centered at origin.
void styled_text_link(element_base &obj, const string text, const point_2t origin, const typography typo, const string uri)
XXX Text at.
string make_path_arc_closed(const point_2t &origin, const point_2t &start, const point_2t &end, const space_type r, const int arcflag=0, const int sweepflag=0)
Make closed path between two points and the center of a circle of radius r. Points like: get_circumfe...
std::vector< point_2t > vrange
void point_to_rect_centered(element_base &obj, const point_2t origin, style s, double width=4, double height=4, const string filterstr="")
Center a rectangle at this point.
rect_element make_rect(const point_2t origin, const style s, const area<> a, const string filterstr="")
Create rect_element at origin.
point_2t get_circumference_point_d(const double ad, const double r, const point_2t origin)
Angle in degrees.
string make_crossed_lines(const point_2t origin, const style s, const double radius, const double tiltd=0.0)
Crossed lines, no fill. X marks the ....
void sized_text(element_base &obj, svg::typography typo, const int sz, const string text, const int tx, const int ty)
Text at size.
string make_path_arc_circumference(const point_2t &start, const point_2t &end, const space_type r, const int arcflag=0, const int sweepflag=1)
Make path segment between two points on a circumference of radius r. Points like: get_circumference_p...
void point_to_rect(element_base &obj, const point_2t origin, style s, double width=4, double height=4, const string filterstr="")
Rectangle at this point.
void styled_text_r(element_base &obj, const string text, const point_2t origin, const typography typo, const double deg)
Text at.
uint text_line_n_r(svg_element &obj, const point_2t origin, const string text, const svg::typography typo, const uint sz, const uint maxlen, const uint lettingsz=0)
Text of maxlen length rotated, overflow goes on line below.
polyline_element make_polyline(const vrange &points, const style s, const stroke_style sstyle={ })
Polyline primitive.
double scale_proportional_to_weight(double radius, double weight)
point_2t get_circumference_point_r(const double angler, const double r, const point_2t origin)
Angle in radians.
std::tuple< space_type, space_type > point_2t
Point (x,y) in 2D space.
path_element make_path_octogon(const point_2t origin, const style styl, const double r=4, const uint pointsn=8)
Center an octogon at this point. radius 4 is pixels to draw out from center point....
void point_to_triangle(svg_element &obj, const point_2t origin, const style s, const double r=4, const double angle=120)
Center a triangle at this point.
Additional path/line/polyline stroke styles.
Datum consolidating style preferences.
@ central
For rotated text.
@ left
Left-most part of text block.
@ start
Start the text block at point.