16#ifndef MiL_SVG_RENDER_BASICS_H
17#define MiL_SVG_RENDER_BASICS_H 1
29 const double pi(22/7);
30 double a1 = radius * radius * pi;
31 double ap = a1 * weight;
32 double rpa = std::sqrt(ap/pi);
40 double rpr = radius * weight;
48 const string xtransf =
"")
50 auto [ x, y ] = origin;
65 const double deg,
const point_2t rorigin,
66 const k::rrotation rr = k::rrotation::none)
68 auto [ rx, ry ] = rorigin;
71 if (rr == k::rrotation::cw)
76 if (rr == k::rrotation::ccw)
102 auto [ x, y ] = origin;
118 auto [ x, y ] = origin;
134 auto [ x, y ] = origin;
135 auto [ rx, ry ] = rorigin;
151 auto [ x, y ] = origin;
163 while ((pos = uriconv.find(
'&', pos)) != std::string::npos)
165 uriconv.replace(pos, 1,
"&");
169 string astart =
"<a href=";
174 astart += k::newline;
179 string afinish =
"</a>";
180 afinish += k::newline;
188 const string text,
const int tx,
const int ty)
203 const string text,
const int tx,
const int ty,
const double deg)
220 auto [ x, y ] = origin;
222 string textcut(
text);
223 while (textcut.size() > maxlen)
226 auto sppos = textcut.find_last_of(k::space, maxlen);
227 if (sppos == string::npos)
235 string namesubs = textcut.substr(0, sppos);
237 textcut = textcut.substr(sppos);
249 const uint lettingsz = 0)
251 const auto [ x, y ] = origin;
252 const double line_max = std::ceil(
double(
text.size()) / maxlen);
253 const uint lines(line_max);
256 string textcut(
text);
259 while (linen < lines)
263 auto xp = x - ((sz + lettingsz) * (lines - linen - 1));
266 if (textcut.size() < maxlen)
267 epos = textcut.size();
271 auto sppos = textcut.find_last_of(k::space, maxlen);
272 if (sppos == string::npos)
282 string namesubs = textcut.substr(0, epos);
284 textcut = textcut.substr(epos);
286 xmin = std::min(xmin,
uint(xp));
295 const string dasharray =
"")
297 auto [ xo, yo ] = origin;
298 auto [ xe, ye ] = end;
313 const string dasharray =
"")
325 polyline_element pl(points);
337 const string filterstr =
"")
339 auto [ width, height ] = a;
340 auto [ x, y ] = origin;
349 if (!filterstr.empty())
359 const string filterstr =
"")
361 auto [ width, height ] = a;
362 auto [ x, y ] = origin;
375 double width = 4,
double height = 4,
376 const string filterstr =
"")
386 double width = 4,
double height = 4,
387 const string filterstr =
"")
397 const space_type r = 4,
const string xform =
"")
400 auto [ x, y ] = origin;
413 const space_type r = 4,
const string xform =
"")
426 const space_type radius,
const double blurspace,
429 const double opacity = 1)
431 using atype =
decltype(obj.
_M_area)::atype;
433 auto [ xd, yd ] = origin;
438 const double oring = radius + blurspace;
441 const double iring = radius - blurspace;
444 std::ostringstream oss;
445 oss <<
"x" << std::to_string(x) << k::hyphen
446 <<
"y" << std::to_string(y) << k::hyphen
447 <<
"r" << std::to_string(radius) << k::hyphen
448 <<
"blurspace" << std::to_string(blurspace);
449 const string mangle(oss.str());
454 const string rgrado_name(
string(
"radialout") + k::hyphen + mangle);
474 const string rgradi_name(
string(
"radialin") + k::hyphen + mangle);
478 rgradi.
stop(
"100%", klr, opacity);
498 using atype =
decltype(obj.
_M_area)::atype;
502 static std::mt19937_64 rg(std::random_device{}());
503 auto distr = std::uniform_real_distribution<>(0.0, 2 * 22/7);
504 auto disti = std::uniform_int_distribution<>(-3, 3);
506 for (
uint i = 0; i < nrays; ++i)
508 double theta = distr(rg);
509 double rvary = disti(rg);
511 atype xe = x + (r + rvary) * std::cos(theta);
512 atype ye = y + (r + rvary) * std::sin(theta);
528 const string id =
"")
530 using atype =
decltype(obj.
_M_area)::atype;
532 auto [xo, yo] = origin;
533 auto [xc, yc] = circump;
554 auto [ cx, cy ] = origin;
555 double x(cx + (r * std::cos(angler)));
556 double y(cy - (r * std::sin(angler)));
557 return std::make_tuple(x, y);
566 double angler = (k::pi / 180.0) * ad;
576 angled = 360 - angled;
602 std::ostringstream ossa;
603 for (
uint i = 0; i < lpoints.size(); ++i)
605 auto [x, y ] = lpoints[i];
610 ossa <<
"M" << k::space;
612 ossa <<
"L" << k::space;
625 const bool selfclosingtagp =
true,
const string xattr =
"")
652 const double r = 4,
const double angle = 120,
653 const bool selfclosingtagp =
true,
const string xattr =
"")
660 vrange pointz = { p1, p2, p3, p1 };
674 const double r = 4,
const uint pointsn = 8,
675 const bool selfclosingtagp =
true,
const string xattr =
"")
678 const double angle(360.0/pointsn);
683 for (
uint i = 0; i < pointsn; ++i)
690 pointz.push_back(pointz.front());
693 const string id =
"polygon-n" + std::to_string(pointsn) +
"-r" + std::to_string(r);
704 const int sweepflag = 1)
708 std::ostringstream oss;
709 oss <<
"M" << k::space <<
to_string(start) << k::space;
710 oss <<
"A" << k::space;
711 oss << std::to_string(r) << k::space << std::to_string(r) << k::space;
712 oss << 0 << k::space << arcflag << k::space << sweepflag << k::space;
723 const int arcflag = 0,
const int sweepflag = 0)
732 std::ostringstream oss;
733 oss <<
"M" << k::space <<
to_string(origin) << k::space;
734 oss <<
"L" << k::space <<
to_string(start) << k::space;
735 oss <<
"A" << k::space;
736 oss << std::to_string(r) << k::space << std::to_string(r) << k::space;
737 oss << 0 << k::space << arcflag << k::space << sweepflag << k::space;
739 oss <<
"L" << k::space <<
to_string(origin) << k::space;
749 const int arcflag = 0,
const int sweepflag = 0)
760 const int len,
const int width)
764 const auto [ xo, yo ] = origin;
767 const double whalf(width / 2);
768 const int lenw = len - whalf;
769 const auto x = xo - whalf;
770 const auto y = yo - whalf;
772 std::ostringstream oss;
773 oss <<
"M" << k::space << x << k::comma << y << k::space;
776 oss <<
"H" << k::space << x - lenw << k::space;
777 oss <<
"V" << k::space << y + width << k::space;
778 oss <<
"H" << k::space << x << k::space;
781 oss <<
"V" << k::space << y + lenw + width << k::space;
782 oss <<
"H" << k::space << x + width << k::space;
783 oss <<
"V" << k::space << y + width << k::space;
786 oss <<
"H" << k::space << x + lenw + width << k::space;
787 oss <<
"V" << k::space << y << k::space;
788 oss <<
"H" << k::space << x + width << k::space;
791 oss <<
"V" << k::space << y - lenw << k::space;
792 oss <<
"H" << k::space << x << k::space;
793 oss <<
"V" << k::space << y << k::space;
795 const string pathdata = oss.str();
797 string id(
"center-mark-");
798 string attr(std::to_string(width) +
"-" + std::to_string(len));
809 const double radius,
const double tiltd = 0.0)
823 std::ostringstream oss;
834 const style& styl,
const int radius,
835 const double tiltd = 0.0)
853 const uint hexn,
const bool cfillp,
854 const style styl,
const string xform =
"")
856 using std::to_string;
859 string gbase =
"hexagon-honeycomb-";
864 for (
const auto& phex : hexpoints)
887 const uint hexn,
const bool cfillp,
const string s,
888 const typography typo,
const string xform =
"")
890 using std::to_string;
893 string gbase =
"text-honeycomb-";
899 auto [ x, y ] = origin;
906 for (
uint i = 0; !s.empty() && i < hexpoints.size(); i++)
908 const auto& p = hexpoints[i];
909 const double d = hexangles[i];
930 const auto [ awidth, aheight ] = a;
946 svg_element obj(
"color_qis_" + std::to_string(klrs.size()) +
"_palette",
950 auto x = rwidth, y = rheight;
952 for (
const auto& klr : klrs)
955 const style s = { klr, 1.0, klr, 0.0, 2 };
961 x + xoffset, y - rheight / 2 + rspace, 90);
963 if (xoffset + rwidth + rspace < awidth - rwidth - rspace)
964 xoffset += rwidth + rspace;
968 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 start_element()
For groups of elements that have the same name.
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.
group_element make_text_honeycomb(const point_2t origin, const double r, const uint hexn, const bool cfillp, const string s, const typography typo, const string xform="")
Center rings of text in a hexagon pattern at this point.
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_polygon(const point_2t origin, const style styl, const double r=4, const uint pointsn=8, const bool selfclosingtagp=true, const string xattr="")
Center an octogon at this point. radius 4 is pixels to draw out from center point....
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).
text_element style_text_r(const string text, const point_2t origin, const typography typo, const double deg, const point_2t rorigin, const k::rrotation rr=k::rrotation::none)
Text element at.
vrange radiate_hexagon_honeycomb(const point_2t origin, const double r, const uint n, const bool centerfilledp)
Compute set of points for a radial fill of hexograms centered at p.
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="")
group_element make_hexagon_honeycomb(const point_2t origin, const double r, const uint hexn, const bool cfillp, const style styl, const string xform="")
Center rings of hexagons 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.
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.
text_element style_text(const string text, const point_2t origin, const typography typo, const string xtransf="")
Text element at.
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, space_type defaults to double.
vspace get_honeycomb_angles(const point_2t origin, const vrange &hexagons, const bool degreesp=true)
Compute set of angles, given points for a radial fill of hexograms centered at p.
Additional path/line/polyline stroke styles.
Datum consolidating style preferences.
@ central
For rotated text.
@ right
Right part of text block.
@ left
Left-most part of text block.
@ end
End the text block at point.
@ start
Start the text block at point.