16#ifndef izzi_SVG_GRAPHS_LINE_H
17#define izzi_SVG_GRAPHS_LINE_H 1
110 double duprangep(
false);
114 if (y != get<1>(
last))
116 if (duprangep ==
true)
118 simplevr.push_back(
last);
121 simplevr.push_back(
pt);
141 if (y != get<1>(
last))
142 simplest.push_back(
pt);
157 for (
const auto&
pt : points)
162 edited.push_back(
pt);
178 auto [ minx, maxx ] = xrange;
179 auto [ miny, maxy ] = yrange;
186 double gwidth = pwidth - (2 * gstate.
xmargin);
187 double gheight = pheight - (2 * gstate.
ymargin);
188 const double chartyo = pheight - gstate.
ymargin;
192 for (
uint i = 0; i < points.size(); i++)
195 auto [ vx, vy ] =
pt;
199 double x = gstate.
xmargin + xlen;
203 double y = chartyo - ylen;
205 cpoints.push_back(std::make_tuple(x, y));
220 const string imgprefix,
221 const string imgpath =
"../filmstrip/",
222 const string imgext =
".webp")
228 std::ostringstream oss;
229 oss << std::setfill(
'0') << std::setw(5);
230 oss << static_cast<uint>(std::get<0>(p));
231 const string xms = oss.str();
233 const string isrc = imgpath + imgprefix + xms + imgext;
240 i.
add_data(di,
"anonymous",
"hidden",
"");
254 const string imgidbase =
"")
257 for (
uint i = 0; i < points.size(); i++)
259 auto [ vx, vy ] = points[i];
260 auto [ cx, cy ] = cpoints[i];
262 std::ostringstream oss;
263 oss << std::setfill(
'0') << std::setw(5);
264 oss << static_cast<uint>(vx);
265 const string xms = oss.str();
266 const string imgid = imgidbase + xms;
269 string tipstr(gstate.
title);
270 tipstr += k::newline;
271 tipstr += std::to_string(
static_cast<uint>(vy));
275 tipstr += std::to_string(
static_cast<uint>(vx));
279 const bool roundp = linecap ==
"round" || linecap ==
"circle";
280 const bool squarep = linecap ==
"square";
281 const bool trianglep = linecap ==
"triangle";
300 if (!imgidbase.empty())
314 2 * radius, 2 * radius };
318 if (!imgidbase.empty())
330 if (!imgidbase.empty())
334 const double tradius = radius * 1.3;
343 if (!roundp && !squarep && !trianglep)
345 string m(
"make_line_graph_markers:: ");
346 m +=
"linecap value invalid or missing, currently set to: ";
349 throw std::runtime_error(
m);
369 const double xscale = 1,
const double yscale = 1,
377 double gwidth = pwidth - (2 * gstate.
xmargin);
378 double gheight = pheight - (2 * gstate.
ymargin);
379 const double chartyo = pheight - gstate.
ymargin;
380 const double chartxo = gstate.
xmargin;
381 const double chartxe = pwidth - gstate.
xmargin;
394 point_2t xlabelp = make_tuple(pwidth / 2, chartyo + (gstate.
ymargin / 2));
397 point_2t ylabelp = make_tuple(chartxo / 2, pheight / 2);
421 const double xrange(maxx - minx);
422 const double gxscale(gwidth / xrange);
423 const double yrange(maxy - miny);
424 const double gyscale(gheight / yrange);
430 double xtickn(xrange * 2);
437 double xdelta = std::max(xrange / xtickn, 0.1);
443 const double ydelta = yrange / gstate.
yticdigits;
451 for (
double x = minx; x < maxx; x += xdelta)
453 const double xto = chartxo + (x * gxscale);
455 oss << fixed << setprecision(gstate.
xticdigits) << x;
456 const string sxui = oss.str() + gstate.
xticu;
465 const double xgol = gstate.
xmargin - yticspacer;
466 const double xgor = gstate.
xmargin + gwidth + yticspacer;
467 const double starty = miny != 0 ? miny : miny + ydelta;
468 for (
double y = starty; y < maxy + ydelta; y += ydelta)
470 const double yto = chartyo - (y * gyscale);
471 const string syui = std::to_string(
static_cast<uint>(y)) + gstate.
yticu;
489 for (
double y = miny + ydelta; y < maxy + ydelta; y += ydelta)
492 const double yto = chartyo - (y * gyscale);
501 for (
double x = minx + xdelta; x < maxx - xdelta; x += xdelta)
503 const double xto = chartxo + (x * gxscale);
504 const string syui = std::to_string(
static_cast<uint>(y)) + gstate.
yticu;
539 const string gname = gstate.
title +
"_line_graph";
570 string m(
"requested mode requires use of different overloaded function");
571 throw std::runtime_error(
m);
590 const string gname = gstate.
title +
"_line_graph";
619 const string imgprefix = metadata + k::hyphen + gstate.
title +
"_";
void add_data(const data &d)
Either serialize immediately (as below), or create data structure that adds data to data_vec and then...
static const script_element tooltip_script(const scope context)
void add_style(const style &sty)
void add_data(const data &d, string trans="")
static constexpr const char * pair_finish_tag
static string finish_group()
void add_title(const string &t)
static const string tooltip_attribute(const string &id)
static string start_group(const string name="")
static constexpr const char * pair_finish_tag
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 add_raw(const string &raw)
scope
Where is the script element placed? On/within the element itself, or at the document (global)?...
void add_element(const element_base &e)
void start_element(const string &id)
static constexpr string finish_tag_hard
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.
@ 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.
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).
double space_type
Base floating point type.
@ alt
alternate use specified in situ
@ vector
svg path, circle, rectangle, etc.
@ echo
b & w outline version of vector
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. 1: use one line with css dasharray and markers mid, end points 2: use two line...
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 make_line_graph(const vrange &points, const graph_rstate &gstate, const point_2t xrange, const point_2t yrange)
Returns a svg_element with the rendered line graph (char). Assumptions: vgrange x axis is monotonical...
svg_element make_line_graph_annotations(const vrange &points, const graph_rstate &gstate, const double xscale=1, const double yscale=1, const typography typo=k::apercu_typo)
Axis Labels Axis X/Y Ticmarks X line increments.
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.
std::vector< double > vspace
Split range, so one dimension of (x,y) cartesian plane.
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.
vrange find_change_points(const vrange &vr)
Simplify sorted vrange by removing interior duplicates.
vrange find_visual_change_points(const vrange &points)
Tramsform change points to points where the y-axis (% visual complete) changes.
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.
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
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
string xlabel
Labels, tic units.
stroke_style sstyle
line style
graph_mode mode
graph area
static constexpr uint tticsz
static constexpr uint ymargin
static constexpr uint xmargin
chart_line_style_n to use
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.
Datum consolidating style preferences.
@ central
For rotated text.