16#ifndef izzi_SVG_LINE_GRAPHS_H
17#define izzi_SVG_LINE_GRAPHS_H 1
125 double duprangep(
false);
129 if (y != get<1>(
last))
131 if (duprangep ==
true)
133 simplevr.push_back(
last);
136 simplevr.push_back(
pt);
156 if (y != get<1>(
last))
157 simplest.push_back(
pt);
174 for (
const auto&
pt : points)
179 edited.push_back(
pt);
195 auto [ minx, maxx ] = xrange;
196 auto [ miny, maxy ] = yrange;
203 double gwidth = pwidth - (2 * gstate.
xmargin);
204 double gheight = pheight - (2 * gstate.
ymargin);
205 const double chartyo = pheight - gstate.
ymargin;
209 for (
uint i = 0; i < points.size(); i++)
212 auto [ vx, vy ] =
pt;
220 double y = chartyo - ylen;
222 cpoints.push_back(std::make_tuple(
x, y));
237 const string imgprefix,
238 const string imgpath =
"../filmstrip/",
239 const string imgext =
".webp")
245 std::ostringstream oss;
246 oss << std::setfill(
'0') << std::setw(5);
247 oss << static_cast<uint>(std::get<0>(p));
248 const string xms = oss.str();
250 const string isrc = imgpath + imgprefix + xms + imgext;
257 i.
add_data(di,
"anonymous",
"hidden",
"");
270 const style styl,
const double radius,
271 const string tipstr =
"",
const string imgid =
"")
301 auto [ cx, cy ] = cpoint;
311 mkr =
make_lauburu(cpoint, styl, radius / 3, 4.0, 6, tipstr);
317 string m(
"make_marker_instance:: ");
318 m +=
"marker_shape (";
321 m +=
"is invalid or missing, skipping...";
323 std::clog <<
m << std::endl;
326 pointstr = mkr.
str();
336 const string imgidbase =
"")
339 for (
uint i = 0; i < points.size(); i++)
341 auto [ vx, vy ] = points[i];
342 auto cpoint = cpoints[i];
345 string imgid(imgidbase);
348 std::ostringstream oss;
349 oss << std::setfill(
'0') << std::setw(5);
350 oss << static_cast<uint>(vx);
351 const string xms = oss.str();
352 string imgidn(imgid + xms);
357 string tipstr(gstate.
title);
358 tipstr += k::newline;
360 tipstr += std::to_string(
static_cast<uint>(vx));
362 tipstr += k::newline;
364 std::ostringstream oss;
365 oss.imbue(std::locale(
""));
366 oss << std::fixed << std::setprecision(0) << vy;
389 const double dr = radius * 2;
390 const double shrinkf(0.75);
392 if (rep > 0 && i + 1 < points.size())
395 auto [ cx1, cy1 ] = cpoint;
396 auto cpointnext = cpoints[i + 1];
397 auto [ cx2, cy2 ] = cpointnext;
400 double dx = cx2 - cx1;
401 double dy = cy2 - cy1;
407 double unit_x = dx / d;
408 double unit_y = dy / d;
411 double x3 = cx1 + dr * unit_x;
412 double y3 = cy1 + dr * unit_y;
437 const double xscale = 1,
const double yscale = 1,
444 double gwidth = pwidth - (2 * gstate.
xmargin);
445 double gheight = pheight - (2 * gstate.
ymargin);
446 const double chartyo = pheight - gstate.
ymargin;
447 const double chartxo = gstate.
xmargin;
448 const double chartxe = pwidth - gstate.
xmargin;
450 auto [ xmin, xmax ] = xrange;
451 auto [ ymin, ymax ] = yrange;
458 const double xrangec(maxx - xmin);
459 const double gxscale(gwidth / xrangec);
460 const double yrangec(maxy - ymin);
461 const double gyscale(gheight / yrangec);
464 const double ydelta = yrangec / gstate.
yticdigits;
471 double xtickn(xrangec * 2);
482 double xticmindelta = 0.1;
483 double xdelta = std::max(xrangec / xtickn, xticmindelta);
487 double xticmindelta = 1;
488 double xdelta = std::max(xrangec / xtickn, xticmindelta);
507 const double loffset = double(anntypo.
_M_size);
508 point_2t xlabelp = make_tuple(pwidth / 2, lyo + loffset);
521 const double loffset = double(anntypo.
_M_size) * 1.5;
524 point_2t xlabelp = make_tuple(pwidth / 2, lyo + loffset);
525 string xlabel = gstate.
xlabel;
526 std::transform(xlabel.begin(), xlabel.end(), xlabel.begin(),
527 [](
unsigned char c){ return std::toupper(c); });
531 point_2t ylabelp = make_tuple(lxo - loffset, pheight / 2);
532 string ylabel = gstate.
ylabel;
533 std::transform(ylabel.begin(), ylabel.end(), ylabel.begin(),
534 [](
unsigned char c){ return std::toupper(c); });
535 styled_text_r(lanno, ylabel, ylabelp, anntypo, -90, ylabelp);
564 for (
double y = ymin + ydelta; y < maxy + ydelta; y += ydelta)
567 const double yto = chartyo - (y * gyscale);
577 for (
double x = xmin + xdelta;
x < maxx - xdelta;
x += xdelta)
579 const double xto = chartxo + (
x * gxscale);
580 const string syui = std::to_string(
static_cast<uint>(y)) + gstate.
yticu;
600 for (
uint i = 0; i < points.size(); i++)
602 const double xto = std::get<0>(cpoints[i]);
603 const double x = std::get<0>(points[i]);
610 oss << fixed << setprecision(gstate.
xticdigits) <<
x;
612 oss << std::trunc(
x);
614 const string sxui = oss.str() + gstate.
xticu;
624 const double xgol = gstate.
xmargin - yticspacer;
625 const double xgor = gstate.
xmargin + gwidth + yticspacer;
626 const double starty = ymin != 0 ? ymin : ymin + ydelta;
627 for (
double y = starty; y < maxy + ydelta; y += ydelta)
629 const double yto = chartyo - (y * gyscale);
630 const string syui = std::to_string(
static_cast<uint>(y)) + gstate.
yticu;
658 const double marker_radius = 3.0)
665 const string gname = gstate.
title +
"_line_graph";
696 string m(
"make_line_graph:: ");
697 m +=
"chart_line_style_3 requires use of different overloaded function";
699 throw std::runtime_error(
m);
718 const string gname = gstate.
title +
"_line_graph";
746 const string imgprefix = metadata + k::hyphen + gstate.
title +
"_";
static const script_element tooltip_script(const scope context)
void start_element()
For groups of elements that have the same name.
static string finish_group()
static const string tooltip_attribute(const string &id)
static string start_group(const string 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 add_raw(const string &raw)
scope
Where is the script element placed? On/within the element itself, or at the document (global)?...
@ element
Scripts scoped to element.
void add_element(const element_base &e)
string make_transform_attribute(const string s)
Common transforms include rotate(180)
void start_element(const string &id)
Abstract base class for all SVG Elements.
line_element make_line(const point_2t origin, const point_2t end, style s, const string dasharray="")
Line primitive.
group_element make_line_graph_images(const vrange &points, const graph_rstate &gstate, const string imgprefix, const string imgpath="../filmstrip/", const string imgext=".webp")
Return set of images for image tooltips, one for each point.
circle_element make_circle_marker(const point_2t origin, const style s, const space_type r, const string title, const string xform="", const string imgid="")
Make circle element with title and tooltip information.
string make_marker_instance(const marker_shape form, const point_2t &cpoint, const style styl, const double radius, const string tipstr="", const string imgid="")
Make marker or composite markers for one marker location.
@ pt
Point where 1 pixel x 1/72 dpi x 96 PPI = .26 mm.
unsigned short ushort
Base integer type: positive and negative, signed integral value.
path_element make_path_center_mark(const point_2t &origin, const style styl, const int len, const int width, const string xform="", const string tipstr="")
Plus or x tilt mark as closed path that can be filled.
void styled_text(element_base &obj, const string text, const point_2t origin, const typography typo, const string xform="")
Text at.
double scale_value_on_range(const ssize_type value, const ssize_type min, const ssize_type max, const ssize_type nfloor, const ssize_type nceil)
Scale value from min to max on range (nfloor, nceil).
const string to_string(const unit e)
group_element make_sunburst(const point_2t origin, const style s, const space_type r=4, const uint nrays=10, const string tipstr="")
Rectangles of various sizes rotated from center point (x,y).
double space_type
Base floating point type.
vrange find_tooltip_points(const vrange &points, const vspace &onlypoints)
Tramsform change points to points where the x-axis (time) matches a value in onlypoints.
graph_mode
Polyline/line options.
@ chart_line_style_1
One Element, one path plus css dasharray and markers.
@ chart_line_style_3
Three Element, one path, one marker, image.
@ chart_line_style_2
Two Element, one path, one marker.
rect_element make_rect_marker(const point_2t origin, const style s, const space_type r, const string title, const string filterstr="", const string imgid="")
Create rectangle element with title and tooltip information.
group_element make_octahedron(const point_2t, const style &, const double radius, const string tipstr="")
Make octahedron shape (8) in 2D simulated 3D @ret group element of polygon_elements.
marker_shape
Marker shape.
@ octahedron
Octahedron (8) 3D.
@ icosahedron
Icosahedron.
path_element make_path_ripple(const point_2t origin, const style s, const double length, const double amplitude, const double decay, const int cycles=3, const string tipstr="")
Make waves.
path_element make_path_marker(const point_2t origin, const style s, const double r, const uint pointsn, const string title, const string xattr="")
Make a polygon marker for line graphs.
path_element make_path_blob(const point_2t origin, const style s, const double size, const int numCurves=5+std::rand() % 4, const string tipstr="")
Make blob shape.
std::vector< point_2t > vrange
point_2t max_vrange(vspace &xpoints, vspace &ypoints, const uint pown)
For each dimension of vrnage, find min/max and return (xmax, ymax) NB: Assumes zero is min.
path_element make_lauburu(const point_2t origin, const style s, const double size, double swirlFactor=0.5, int pointsPerSwirl=8, const string tipstr="")
Make lauburu.
svg_element make_line_graph_annotations(const vrange &points, const graph_rstate &gstate, const point_2t xrange, const point_2t yrange, const double xscale=1, const double yscale=1, const typography typo=k::apercu_typo)
Axis Labels Axis X/Y Ticmarks X line increments.
vrange transform_to_graph_points(const vrange &points, const graph_rstate &gstate, const point_2t xrange, const point_2t yrange)
Map data points to cartestian points on graph area.
string make_line_graph_markers(const vrange &points, const vrange &cpoints, const graph_rstate &gstate, const double radius, const string imgidbase="")
Return set of paths of marker shapes with text tooltips. NB: For graph_mode >= chart_line_style_2.
vrange find_change_points(const vrange &vr)
Simplify sorted vrange by removing interior duplicates.
@ alt
alternate use specified in situ
@ vector
svg path, circle, rectangle, etc.
@ echo
b & w outline version of vector
vrange find_visual_change_points(const vrange &points)
Tramsform change points to points where the y-axis (% visual complete) changes.
svg_element make_line_graph(const vrange &points, const graph_rstate &gstate, const point_2t xrange, const point_2t yrange, const double marker_radius=3.0)
Returns a svg_element with the rendered line graph (char). Assumptions: vgrange x axis is monotonical...
std::vector< space_type > vspace
Split range, so one dimension of (x,y) cartesian plane.
void styled_text_r(element_base &obj, const string text, const point_2t origin, const typography typo, const double deg)
Text at.
group_element make_icosahedron(const point_2t origin, const style &s, const double radius, const string tipstr="")
Make icosahedron shape (20) in 2D simulated 3D.
space_type distance_cartesian(const point_2t &p1, const point_2t &p2)
Find cartesian distance between two 2D points.
polyline_element make_polyline(const vrange &points, const style s, const stroke_style sstyle={ })
Polyline primitive.
std::tuple< space_type, space_type > point_2t
Point (x,y) in 2D space, space_type defaults to double.
Per-graph constants, metadata, configuration, text.
string title
Key data: title, area, mode.
static constexpr uint yticdigits
area< space_type > area_type
static constexpr uint xticdigits
chart_line_style_n to use
string tooltip_id
chart_line_style_3 tooltip size
static constexpr uint th1sz
area_type tooltip_area
marker stroke style, if any.
area_type graph_area
graph title
stroke_style sstyle
line style
graph_mode mode
graph area
static constexpr uint tticsz
static constexpr uint ymargin
static constexpr uint xmargin
1920 x 1080 Margins/Spaces
static constexpr uint ttitlesz
Type sizes.
static constexpr uint tpsz
style lstyle
Line/Outline/Markers/Tooltip styles.
string tooltip_images
chart_line_style_3 toolip id prefix
render_state_base(const select m=select::none)
bool is_visible(const select v) const
Additional path/line/polyline stroke styles. NB: https://yuanchuan.dev/fun-with-stroke-dasharray.
ushort marker_reps
Marker repetitions, if any. Default is zero, no repitition, single marker.
marker_shape marker_form
Marker shapes. For graph_mode 2, this means the marker_shape of the mark.
string marker_defs
Marker string pointing to definitions elements. For graph_mode 1, this means the SVG equivalent of CS...
Datum consolidating style preferences.
@ central
For rotated text.