izzi
SVG SUBSET C++ API
Loading...
Searching...
No Matches
a60-svg-radial-direction-arc-glyph.h
Go to the documentation of this file.
1// radial arc -*- mode: C++ -*-
2
3// alpha60
4// bittorrent x scrape x data + analytics
5
6// Copyright (c) 2020-2021, Benjamin De Kosnik <b.dekosnik@gmail.com>
7
8// This file is part of the alpha60 library. This library is free
9// software; you can redistribute it and/or modify it under the terms
10// of the GNU General Public License as published by the Free Software
11// Foundation; either version 3, or (at your option) any later
12// version.
13
14// This library is distributed in the hope that it will be useful, but
15// WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// General Public License for more details.
18
19#ifndef MiL_SVG_RADIAL_DIRECTION_ARC_GLYPH_H
20#define MiL_SVG_RADIAL_DIRECTION_ARC_GLYPH_H 1
21
22
23namespace svg {
24
25
26/// Arc + arrow glyph that traces path of start to finish trajectory.
27void
29 const double rr, svg::style s, const double spacer = 10)
30{
31 // Adjust style so the stroke color matches the fill color.
33
34 const double r = rr - spacer;
35 const auto [ mindeg, maxdeg ] = get_radial_range();
36 auto anglemin = zero_angle_north_cw(mindeg);
37 auto anglemax = zero_angle_north_cw(maxdeg);
38
39 // Define arc.
40 const bool largearcp = abs(anglemax - anglemin) > 180;
41 const bool cwp = true;
42 point_2t p0 = get_circumference_point_d(anglemin, r, origin);
43 point_2t p4 = get_circumference_point_d(anglemax, r, origin);
44 string sarc = make_path_arc_circumference(p0, p4, r, largearcp, cwp);
45
46 // Style for stroke/line.
47 s._M_fill_opacity = 0;
49
50 // Draw arc path.
51 path_element parc;
52 path_element::data da = { sarc, 0 };
53 parc.start_element();
54 parc.add_data(da);
55 parc.add_style(s);
56 parc.finish_element();
57 obj.add_element(parc);
58
59 // Define marker/arrow/triangle base points.
60 double rspacer = std::max(5.0, spacer - 2);
61 point_2t p5 = get_circumference_point_d(anglemax, r + rspacer, origin);
62 point_2t p7 = get_circumference_point_d(anglemax, r - rspacer, origin);
63
64 // ... and the tip of the triangle.
65 point_2t p6 = get_circumference_point_d(anglemax - 90, rspacer, p4);
66
67
68 // Define closed triangle/arrow path.
69 std::ostringstream ossm;
70 ossm << "M" << k::space << to_string(p4) << k::space;
71 ossm << "L" << k::space;
72 ossm << to_string(p5) << k::space;
73 ossm << to_string(p6) << k::space;
74 ossm << to_string(p7) << k::space;
75 ossm << to_string(p4) << k::space;
76
77 // Style so that fill will be shown, and stroke hidden.
78 s._M_fill_opacity = 1;
80
81 // End marker path.
82 path_element pmarker;
83 path_element::data dm = { ossm.str(), 0 };
84 pmarker.start_element();
85 pmarker.add_data(dm);
86 pmarker.add_style(s);
87 pmarker.finish_element();
88 obj.add_element(pmarker);
89}
90
91
92/// Title on same arc.
93void
95 const int radius, const typography typo,
96 const string title, const uint pcnt = 30)
97{
98 // Make arc text path
99 const auto [ mindeg, maxdeg ] = get_radial_range();
100 auto mina = zero_angle_north_cw(mindeg);
101 auto maxa = zero_angle_north_cw(maxdeg);
102
103 point_2t pmin = get_circumference_point_d(mina, radius, origin);
104 point_2t pmax = get_circumference_point_d(maxa, radius, origin);
105
106 string titlearc = make_path_arc_circumference(pmax, pmin, radius);
107
108 string arc_name("arc-text");
109 path_element parc;
110 path_element::data da = { titlearc, 0 };
111 parc.start_element(arc_name);
112 parc.add_data(da);
113 parc.add_style(typo._M_style);
114 parc.finish_element();
115 obj.store_element(parc);
116
117 // Put it together.
118 text_element::data dt = { 0, 0, title, typo };
119 text_path_element tp(arc_name, std::to_string(pcnt) + "%");
120 tp.start_element();
121 tp.add_data(dt);
122 tp.finish_element();
123 obj.add_element(tp);
124}
125
126} // namespace svg
127
128#endif
void add_style(const style &sty)
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_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_element(const element_base &e)
void store_element(const element_base &e)
const string to_string(const unit e)
point_2t & get_radial_range()
double zero_angle_north_cw(double angled)
Zero degrees is top, going clockwise (cw).
void direction_arc_title_at(svg_element &obj, const point_2t origin, const int radius, const typography typo, const string title, const uint pcnt=30)
Title on same arc.
point_2t get_circumference_point_d(const double ad, const double r, const point_2t origin)
Angle in degrees.
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 direction_arc_at(svg_element &obj, const point_2t origin, const double rr, svg::style s, const double spacer=10)
Arc + arrow glyph that traces path of start to finish trajectory.
unsigned int uint
Definition a60-svg.h:57
std::tuple< space_type, space_type > point_2t
Point (x,y) in 2D space.
Definition a60-svg.h:65
Datum consolidating style preferences.
color_qi _M_fill_color
color_qi _M_stroke_color