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 using atype =
decltype(obj.
_M_area)::atype;
74 auto [ x, y ] = origin;
90 using atype =
decltype(obj.
_M_area)::atype;
91 auto [ x, y ] = origin;
107 using atype =
decltype(obj.
_M_area)::atype;
108 auto [ x, y ] = origin;
109 auto [ rx, ry ] = rorigin;
125 using atype =
decltype(obj.
_M_area)::atype;
126 auto [ x, y ] = origin;
138 while ((pos = uriconv.find(
'&', pos)) != std::string::npos)
140 uriconv.replace(pos, 1,
"&");
144 string astart =
"<a href=";
149 astart += k::newline;
154 string afinish =
"</a>";
155 afinish += k::newline;
163 const string text,
const int tx,
const int ty)
165 using atype =
decltype(obj.
_M_area)::atype;
179 const string text,
const int tx,
const int ty,
const double deg)
181 using atype =
decltype(obj.
_M_area)::atype;
197 auto [ x, y ] = origin;
199 string textcut(
text);
200 while (textcut.size() > maxlen)
203 auto sppos = textcut.find_last_of(k::space, maxlen);
204 if (sppos == string::npos)
212 string namesubs = textcut.substr(0, sppos);
214 textcut = textcut.substr(sppos);
226 const uint lettingsz = 0)
228 const auto [ x, y ] = origin;
229 const double line_max = std::ceil(
double(
text.size()) / maxlen);
230 const uint lines(line_max);
233 string textcut(
text);
236 while (linen < lines)
240 auto xp = x - ((sz + lettingsz) * (lines - linen - 1));
243 if (textcut.size() < maxlen)
244 epos = textcut.size();
248 auto sppos = textcut.find_last_of(k::space, maxlen);
249 if (sppos == string::npos)
259 string namesubs = textcut.substr(0, epos);
261 textcut = textcut.substr(epos);
263 xmin = std::min(xmin,
uint(xp));
272 const string dasharray =
"")
274 auto [ xo, yo ] = origin;
275 auto [ xe, ye ] = end;
290 const string dasharray =
"")
302 polyline_element pl(points);
314 const string filterstr =
"")
316 auto [ width, height ] = a;
317 auto [ x, y ] = origin;
326 if (!filterstr.empty())
336 const string filterstr =
"")
338 auto [ width, height ] = a;
339 auto [ x, y ] = origin;
352 double width = 4,
double height = 4,
353 const string filterstr =
"")
364 double width = 4,
double height = 4,
365 const string filterstr =
"")
375 const space_type r = 4,
const string xform =
"")
378 auto [ x, y ] = origin;
391 const space_type r = 4,
const string xform =
"")
404 const space_type radius,
const double blurspace,
407 const double opacity = 1)
409 using atype =
decltype(obj.
_M_area)::atype;
411 auto [ xd, yd ] = origin;
416 const double oring = radius + blurspace;
419 const double iring = radius - blurspace;
422 std::ostringstream oss;
423 oss <<
"x" << std::to_string(x) << k::hyphen
424 <<
"y" << std::to_string(y) << k::hyphen
425 <<
"r" << std::to_string(radius) << k::hyphen
426 <<
"blurspace" << std::to_string(blurspace);
427 const string mangle(oss.str());
432 const string rgrado_name(
string(
"radialout") + k::hyphen + mangle);
452 const string rgradi_name(
string(
"radialin") + k::hyphen + mangle);
456 rgradi.
stop(
"100%", klr, opacity);
476 using atype =
decltype(obj.
_M_area)::atype;
480 static std::mt19937_64 rg(std::random_device{}());
481 auto distr = std::uniform_real_distribution<>(0.0, 2 * 22/7);
482 auto disti = std::uniform_int_distribution<>(-3, 3);
484 for (
uint i = 0; i < nrays; ++i)
486 double theta = distr(rg);
487 double rvary = disti(rg);
489 atype xe = x + (r + rvary) * std::cos(theta);
490 atype ye = y + (r + rvary) * std::sin(theta);
506 const string id =
"")
508 using atype =
decltype(obj.
_M_area)::atype;
510 auto [xo, yo] = origin;
511 auto [xc, yc] = circump;
532 auto [ cx, cy ] = origin;
533 double x(cx + (r * std::cos(angler)));
534 double y(cy - (r * std::sin(angler)));
535 return std::make_tuple(x, y);
544 double angler = (k::pi / 180.0) * ad;
554 angled = 360 - angled;
580 std::ostringstream ossa;
581 for (
uint i = 0; i < lpoints.size(); ++i)
583 auto [x, y ] = lpoints[i];
588 ossa <<
"M" << k::space;
590 ossa <<
"L" << k::space;
603 const string name =
"",
const bool selfclosingtagp =
true)
628 const double r = 4,
const double angle = 120,
629 const bool selfclosingtagp =
true)
636 vrange pointz = { p1, p2, p3, p1 };
639 string argname = std::to_string(r) + k::hyphen + std::to_string(angle);
640 const string id =
"triangle-" + argname;
651 const double r = 4,
const double angle = 120)
663 const double r = 4,
const uint pointsn = 8)
666 const double angle(360.0/8);
671 for (
uint i = 0; i < pointsn; ++i)
678 pointz.push_back(pointz.front());
681 const string id =
"octogon-" + std::to_string(r);
702 const int sweepflag = 1)
706 std::ostringstream oss;
707 oss <<
"M" << k::space <<
to_string(start) << k::space;
708 oss <<
"A" << k::space;
709 oss << std::to_string(r) << k::space << std::to_string(r) << k::space;
710 oss << 0 << k::space << arcflag << k::space << sweepflag << k::space;
721 const int arcflag = 0,
const int sweepflag = 0)
730 std::ostringstream oss;
731 oss <<
"M" << k::space <<
to_string(origin) << k::space;
732 oss <<
"L" << k::space <<
to_string(start) << k::space;
733 oss <<
"A" << k::space;
734 oss << std::to_string(r) << k::space << std::to_string(r) << k::space;
735 oss << 0 << k::space << arcflag << k::space << sweepflag << k::space;
737 oss <<
"L" << k::space <<
to_string(origin) << k::space;
747 const int arcflag = 0,
const int sweepflag = 0)
758 const int len,
const int width)
762 const auto [ xo, yo ] = origin;
765 const double whalf(width / 2);
766 const int lenw = len - whalf;
767 const auto x = xo - whalf;
768 const auto y = yo - whalf;
770 std::ostringstream oss;
771 oss <<
"M" << k::space << x << k::comma << y << k::space;
774 oss <<
"H" << k::space << x - lenw << k::space;
775 oss <<
"V" << k::space << y + width << k::space;
776 oss <<
"H" << k::space << x << k::space;
779 oss <<
"V" << k::space << y + lenw + width << k::space;
780 oss <<
"H" << k::space << x + width << k::space;
781 oss <<
"V" << k::space << y + width << k::space;
784 oss <<
"H" << k::space << x + lenw + width << k::space;
785 oss <<
"V" << k::space << y << k::space;
786 oss <<
"H" << k::space << x + width << k::space;
789 oss <<
"V" << k::space << y - lenw << k::space;
790 oss <<
"H" << k::space << x << k::space;
791 oss <<
"V" << k::space << y << k::space;
793 const string pathdata = oss.str();
795 string id(
"center-mark-");
796 string attr(std::to_string(width) +
"-" + std::to_string(len));
807 const double radius,
const double tiltd = 0.0)
821 std::ostringstream oss;
832 const style& styl,
const int radius,
833 const double tiltd = 0.0)
846 const auto [ awidth, aheight ] = a;
862 svg_element obj(
"color_qis_" + std::to_string(klrs.size()) +
"_palette",
866 auto x = rwidth, y = rheight;
868 for (
const auto& klr : klrs)
871 const style s = { klr, 1.0, klr, 0.0, 2 };
877 x + xoffset, y - rheight / 2 + rspace, 90);
879 if (xoffset + rwidth + rspace < awidth - rwidth - rspace)
880 xoffset += rwidth + rspace;
884 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
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.
void point_to_rect_centered(svg_element &obj, const point_2t origin, style s, double width=4, double height=4, const string filterstr="")
Center a rectangle at this point.
line_element make_line(const point_2t origin, const point_2t end, style s, const string dasharray="")
Line primitive.
void styled_text_link(svg_element &obj, const string text, const point_2t origin, const typography typo, const string uri)
XXX Text at.
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 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).
void styled_text_r(svg_element &obj, const string text, const point_2t origin, const typography typo, const double deg)
Text at.
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.
const string to_string(const unit e)
void styled_text(svg_element &obj, const string text, const point_2t origin, const typography typo)
Text at.
void sized_text_r(svg_element &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.
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="")
path_element make_path_triangle(const point_2t origin, const style styl, const double r=4, const double angle=120, const bool selfclosingtagp=true)
Center a triangle at this point.
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.
void point_to_rect(svg_element &obj, const point_2t origin, style s, double width=4, double height=4, const string filterstr="")
Rectangle at this point.
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.
path_element make_path(const string &pathda, const style &styl, const string name="", const bool selfclosingtagp=true)
Draw path given serialized path data. Assumes pinstripe, ie top and bottom line layers....
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
rect_element make_rect(const point_2t origin, const style s, const area<> a, const string filterstr="")
Create rect_element at origin.
void sized_text(svg_element &obj, svg::typography typo, const int sz, const string text, const int tx, const int ty)
Text at size.
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 ....
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...
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.