Steppable 0.0.1
A CAS project written from scratch in C++
Loading...
Searching...
No Matches
conPlotTypes.hpp
1/**************************************************************************************************
2 * Copyright (c) 2023-2025 NWSOFT *
3 * *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy *
5 * of this software and associated documentation files (the "Software"), to deal *
6 * in the Software without restriction, including without limitation the rights *
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
8 * copies of the Software, and to permit persons to whom the Software is *
9 * furnished to do so, subject to the following conditions: *
10 * *
11 * The above copyright notice and this permission notice shall be included in all *
12 * copies or substantial portions of the Software. *
13 * *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
20 * SOFTWARE. *
21 **************************************************************************************************/
22
23#pragma once
24
25#include "colors.hpp"
26#include "steppable/number.hpp"
27#include "steppable/parameter.hpp"
28
29#include <string>
30#include <string_view>
31#include <utility>
32
33namespace steppable::graphing
34{
35 using namespace steppable::__internals::utils;
36 using namespace steppable::__internals::symbols;
37 using namespace steppable::__internals::parameter;
38
39 using GraphFn = std::function<Number(Number)>;
40
45 namespace GraphDot
46 {
47 constexpr std::string_view ROUND_DOT = "\u25CF";
48 constexpr std::string_view BLOCK = "\u2588";
49 constexpr std::string_view LIGHT_BLOCK_1 = "\u2591";
50 constexpr std::string_view LIGHT_BLOCK_2 = "\u2592";
51 constexpr std::string_view LIGHT_BLOCK_3 = "\u2593";
52 } // namespace GraphDot
53
55 {
56 std::string title = "Graph";
57 std::string xAxisTitle = "X Axis Title";
58 std::string yAxisTitle = "Y Axis Title";
59
60 long long width = 30;
61 long long height = 20;
62
63 long long xTickSpacing = 10;
64 long long yTickSpacing = 5;
65
66 Number xMin = -1;
68 };
69
80
81 using NumberPair = std::pair<Number, Number>;
82
88 {
94 template<typename... Params>
95 GraphOptions(Params... params)
96 {
97 auto map = processParams(params...);
98
99 PARAM_GET_FALLBACK(map, Number, xMin, -1);
100 PARAM_GET_FALLBACK(map, Number, xMax, 1);
101 PARAM_GET_FALLBACK(map, long long, width, 30LL);
102 PARAM_GET_FALLBACK(map, long long, height, 20LL);
103 PARAM_GET_FALLBACK(map, long long, xTickSpacing, 10LL);
104 PARAM_GET_FALLBACK(map, long long, yTickSpacing, 5LL);
105 PARAM_GET_FALLBACK(map, std::string, title, "Graph");
106 PARAM_GET_FALLBACK(map, std::string, xAxisTitle, "X Axis Title");
107 PARAM_GET_FALLBACK(map, std::string, yAxisTitle, "Y Axis Title");
108
109 this->xMin = xMin;
110 this->xMax = xMax;
111 this->width = width;
112 this->height = height;
115 this->title = title;
116 this->xAxisTitle = xAxisTitle;
117 this->yAxisTitle = yAxisTitle;
118 }
119 };
120
122 {
123 long long yTickSpacing = 5;
124 long long xTickSpacing = 2;
127
133 template<typename... Params>
134 BarGraphOptions(Params... params)
135 {
136 auto map = processParams(params...);
137
138 PARAM_GET_FALLBACK(map, long long, width, 30LL);
139 PARAM_GET_FALLBACK(map, long long, height, 20LL);
140 PARAM_GET_FALLBACK(map, long long, yTickSpacing, 5LL);
141 PARAM_GET_FALLBACK(map, long long, barWidth, 2LL);
142 PARAM_GET_FALLBACK(map, std::string, title, "Bar Graph");
143 PARAM_GET_FALLBACK(map, std::string, xAxisTitle, "X Axis Title");
144 PARAM_GET_FALLBACK(map, std::string, yAxisTitle, "Y Axis Title");
145
146 this->width = width;
147 this->height = height;
148 this->yTickSpacing = yTickSpacing;
149 this->title = title;
150 this->xAxisTitle = xAxisTitle;
151 this->yAxisTitle = yAxisTitle;
152 this->xTickSpacing = barWidth;
153 }
154 };
155
157 {
158 std::string_view lineDot = GraphDot::BLOCK;
160 std::string title = "Line";
161 };
162
163 template<typename T>
164 concept LineOptionsDerivation = std::derived_from<T, LineOptionsBase>;
165
171 {
172 long long samplesSpacing = 2;
176
182 template<typename... Params>
183 LineOptions(Params... params)
184 {
185 auto map = processParams(params...);
186 PARAM_GET_FALLBACK(map, std::string_view, lineDot, GraphDot::BLOCK);
187 PARAM_GET_FALLBACK(map, ColorFunc, lineColor, (ColorFunc)colors::green);
188 PARAM_GET_FALLBACK(map, std::string, title, "Line"s);
189 PARAM_GET_FALLBACK(map, long long, samplesSpacing, 2LL);
190
191 PARAM_GET_FALLBACK(map, NumberPair, shadeValues, {});
192 PARAM_GET_FALLBACK(map, ShadeOptions, shadeOptions, ShadeOptions::NO_SHADE);
193 PARAM_GET_FALLBACK(map, std::string_view, shadeBlock, GraphDot::LIGHT_BLOCK_1);
194
195 this->lineDot = lineDot;
196 this->lineColor = lineColor;
197 this->title = title;
198 this->samplesSpacing = samplesSpacing;
199
200 this->shadeValues = shadeValues;
201 this->shadeOptions = shadeOptions;
202 this->shadeDot = shadeBlock;
203 }
204 };
205
207 {
208 std::string title = "Bar";
209
210 template<typename... Params>
211 BarOptions(Params... params)
212 {
213 auto map = processParams(params...);
214 PARAM_GET_FALLBACK(map, std::string_view, block, GraphDot::BLOCK);
215 PARAM_GET_FALLBACK(map, ColorFunc, color, colors::keepOriginal);
216 PARAM_GET_FALLBACK(map, long long, barWidth, 2);
217 PARAM_GET_FALLBACK(map, std::string, title, "Bar"s);
218
219 this->lineDot = block;
220 this->lineColor = color;
221 this->title = title;
222 }
223 };
224} // namespace steppable::graphing
Represents a number with arbitrary precision. It basically stores the value as a string.
Definition number.hpp:53
Definition conPlotTypes.hpp:164
ParameterMap processParams(Params... params)
Process parameters passed into a function.
Definition parameter.hpp:175
std::ostream & keepOriginal(std::ostream &stream)
Does nothing.
Definition colors.cpp:94
std::ostream & green(std::ostream &stream)
Set the text color to green.
Definition colors.cpp:114
std::function< std::ostream &(std::ostream &)> ColorFunc
Definition colors.hpp:65
Contains string values of dots to be graphed on the screen.
constexpr std::string_view ROUND_DOT
Round dot.
Definition conPlotTypes.hpp:47
constexpr std::string_view LIGHT_BLOCK_3
More densly-filled block.
Definition conPlotTypes.hpp:51
constexpr std::string_view LIGHT_BLOCK_1
Lightly-filled block.
Definition conPlotTypes.hpp:49
constexpr std::string_view BLOCK
Solid-filled block.
Definition conPlotTypes.hpp:48
constexpr std::string_view LIGHT_BLOCK_2
Medium-lightly-filled block.
Definition conPlotTypes.hpp:50
Graphing utilities for showing graphs in the console.
Definition conPlot.cpp:35
std::function< Number(Number)> GraphFn
Definition conPlotTypes.hpp:39
std::pair< Number, Number > NumberPair
Definition conPlotTypes.hpp:81
ShadeOptions
Definition conPlotTypes.hpp:71
@ SHADE_ABOVE_SECOND
Definition conPlotTypes.hpp:77
@ SHADE_BELOW_FIRST
Definition conPlotTypes.hpp:78
@ NO_SHADE
Definition conPlotTypes.hpp:72
@ SHADE_BETWEEN_BOTH
Definition conPlotTypes.hpp:75
@ SHADE_ABOVE_FIRST
Definition conPlotTypes.hpp:73
@ SHADE_OUTSIDE_BOTH
Definition conPlotTypes.hpp:76
@ SHADE_BELOW_SECOND
Definition conPlotTypes.hpp:74
Number xMin
Definition conPlotTypes.hpp:125
BarGraphOptions(Params... params)
Initializes a new GraphOptions instance.
Definition conPlotTypes.hpp:134
Number xMax
Definition conPlotTypes.hpp:126
long long yTickSpacing
Spacing between each y axis tick.
Definition conPlotTypes.hpp:123
long long xTickSpacing
Width of a single bar.
Definition conPlotTypes.hpp:124
BarOptions(Params... params)
Definition conPlotTypes.hpp:211
std::string title
Definition conPlotTypes.hpp:208
Definition conPlotTypes.hpp:55
Number xMax
Maximum x value.
Definition conPlotTypes.hpp:67
long long xTickSpacing
Spacing between each x axis tick.
Definition conPlotTypes.hpp:63
std::string xAxisTitle
Title of the x axis.
Definition conPlotTypes.hpp:57
std::string title
Title of the graph.
Definition conPlotTypes.hpp:56
std::string yAxisTitle
Title of the y axis.
Definition conPlotTypes.hpp:58
long long width
Width of the graph.
Definition conPlotTypes.hpp:60
long long yTickSpacing
Spacing between each y axis tick.
Definition conPlotTypes.hpp:64
long long height
Height of the graph.
Definition conPlotTypes.hpp:61
Number xMin
Minimum x value.
Definition conPlotTypes.hpp:66
GraphOptions(Params... params)
Initializes a new GraphOptions instance.
Definition conPlotTypes.hpp:95
Definition conPlotTypes.hpp:157
ColorFunc lineColor
Color of the dot to output.
Definition conPlotTypes.hpp:159
std::string_view lineDot
Dot type to be drawn on screen.
Definition conPlotTypes.hpp:158
std::string title
Name of the line to be shown in the legend.
Definition conPlotTypes.hpp:160
LineOptions(Params... params)
Initializes a new LineOptions instance.
Definition conPlotTypes.hpp:183
NumberPair shadeValues
Definition conPlotTypes.hpp:173
std::string_view shadeDot
Definition conPlotTypes.hpp:175
ShadeOptions shadeOptions
Definition conPlotTypes.hpp:174
long long samplesSpacing
Frequency to take a sample, units: grids.
Definition conPlotTypes.hpp:172
Untitled