TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_plot_types.h
Go to the documentation of this file.
1#pragma once
2
3// Plot: series of values drawn as lines, bars or a filled area over a range, with handles
4// dragged along it (a Levels control's black, gray and white points).
5
10
11#include <functional>
12#include <span>
13#include <string>
14#include <vector>
15
16namespace tachyon
17{
20
22 enum class PlotSeriesKind : uint8_t
23 {
27 };
28
30 enum class PlotScale : uint8_t
31 {
32 Linear,
33 Log
34 };
35
47
50 {
51 std::string name;
52 float x = 0.0f;
56 };
57
59 struct PlotEdit
60 {
61 std::vector<float> from, to;
62 bool empty() const { return from == to; }
63 };
64
68 struct PlotData
69 {
70 std::vector<PlotSeries> series;
71 float xMin = 0.0f, xMax = 1.0f;
73 float yMin = 0.0f, yMax = 1.0f;
74 bool fitY = true;
76 bool labels = true;
78 std::vector<PlotHandle> handles;
79
81 std::function<void(const PlotEdit&)> onEdit;
82 };
83
87 {
89 int shownSeries = -1;
90
95 float shownXMin = 0.0f, shownXMax = 1.0f;
96 bool shownSet = false;
97 int activeHandle = 0;
99 float hoverX = 0.0f;
100 bool hovered = false;
101 uint32_t edits = 0;
102 uint32_t editsSeen = 0;
104 };
105
108 {
109 };
110
114
117 std::vector<float> HistogramBins(std::span<const float> samples, int bins, float min = 0.0f, float max = 1.0f);
118
120 void ApplyPlotEdit(PlotData& data, const PlotEdit& edit, bool undo = false);
123 PlotEdit MovePlotHandleEdit(const PlotData& data, int handle, float x);
125 void CommitPlotEdit(PlotViewRef view, const PlotEdit& edit);
126
128 struct PlotRange { float min, max; };
135 float PlotScaleY(const PlotData& data, float value);
136
138}
CurveChannelColor
The color a channel is drawn in.
Definition gui_curve_types.h:93
@ Value
one value: the warning color, as a scalar channel in the design
Definition gui_curve_types.h:94
PlotSeriesKind
How a series is drawn.
Definition gui_plot_types.h:23
PlotRange PlotShownY(ConstPlotViewRef view)
The y range drawn: yMax from the values in view with fitY, then mapped by yScale.
std::vector< float > HistogramBins(std::span< const float > samples, int bins, float min=0.0f, float max=1.0f)
samples counted into bins equal bins over [min, max]; a sample at max goes in the last one,...
PlotScale
How the y axis maps values.
Definition gui_plot_types.h:31
void CommitPlotEdit(PlotViewRef view, const PlotEdit &edit)
Applies edit and hands it to view.data.onEdit; does nothing for an empty one.
PlotRange PlotShownX(ConstPlotViewRef view)
The part of the x range in view: all of it until the plot is zoomed, then the part zoomed to,...
void ApplyPlotEdit(PlotData &data, const PlotEdit &edit, bool undo=false)
Does (or with undo, undoes) edit on the handles.
BasicViewRef< const PlotData, const PlotViewState > ConstPlotViewRef
Definition gui_plot_types.h:113
PlotEdit MovePlotHandleEdit(const PlotData &data, int handle, float x)
Moves handle handle to x, kept between its neighbours and inside the x range; the edit,...
BasicViewRef< PlotData, PlotViewState > PlotViewRef
A plot and one view of it, as Plot and the helpers take them.
Definition gui_plot_types.h:112
float PlotScaleY(const PlotData &data, float value)
value along the drawn y axis, by the view's scale.
@ Bars
one bar per value, from zero
Definition gui_plot_types.h:25
@ Area
filled from zero up to the line
Definition gui_plot_types.h:26
@ Linear
Definition gui_plot_types.h:32
@ Line
Definition gui_render_primitives.h:213
Definition gui_logging.h:24
What a control shows and one view of it, as the control takes them.
Definition gui_view_ref.h:20
One press that may become a drag, with what every control does around it: the focus and the capture o...
Definition gui_gesture.h:60
Definition gui_base_types.h:406
A plot: what it shows and how.
Definition gui_plot_types.h:69
float yMin
The y range; with fitY, it runs from yMin out to the values shown (below it too).
Definition gui_plot_types.h:73
std::vector< PlotHandle > handles
Kept in order, each between its neighbours and inside the x range.
Definition gui_plot_types.h:78
std::vector< PlotSeries > series
Definition gui_plot_types.h:70
float xMax
Definition gui_plot_types.h:71
bool labels
the grid's numbers
Definition gui_plot_types.h:76
std::function< void(const PlotEdit &)> onEdit
A handle moved (already applied): put it in the undo history.
Definition gui_plot_types.h:81
float xMin
Definition gui_plot_types.h:71
float yMax
Definition gui_plot_types.h:73
bool fitY
Definition gui_plot_types.h:74
PlotScale yScale
Definition gui_plot_types.h:75
A change to the handles: where each was and is.
Definition gui_plot_types.h:60
std::vector< float > from
Definition gui_plot_types.h:61
bool empty() const
Definition gui_plot_types.h:62
std::vector< float > to
Definition gui_plot_types.h:61
A marker dragged along the x axis under the plot.
Definition gui_plot_types.h:50
color4f color
Its triangle's fill; alpha 0 uses the text color.
Definition gui_plot_types.h:55
std::string name
what it sets, for the app's own labels
Definition gui_plot_types.h:51
float x
Definition gui_plot_types.h:52
A span of one axis.
Definition gui_plot_types.h:128
float max
Definition gui_plot_types.h:128
float min
Definition gui_plot_types.h:128
One set of values, such as a histogram's red channel.
Definition gui_plot_types.h:38
std::string name
its chip's text when there are several
Definition gui_plot_types.h:39
CurveChannelColor color
Its color, as a curve channel's: the warning color, the axis colors, the text color.
Definition gui_plot_types.h:42
bool visible
Definition gui_plot_types.h:45
std::vector< float > values
Evenly spread over the x range: value i fills the i-th of values.size() equal slots.
Definition gui_plot_types.h:44
PlotSeriesKind kind
Definition gui_plot_types.h:40
How one Plot shows a PlotData: the series picked, the part in view, and what the user is doing in it.
Definition gui_plot_types.h:87
IntRect plotRect
the plot last frame, in screen pixels
Definition gui_plot_types.h:98
float hoverX
where the pointer is, along x
Definition gui_plot_types.h:99
int activeHandle
the one dragged last; the arrow keys move it
Definition gui_plot_types.h:97
bool hovered
a handle dragged; the handles as they were, for Escape and the edit
Definition gui_plot_types.h:100
float shownXMin
a handle dragged; the handles as they were, for Escape and the edit
Definition gui_plot_types.h:95
int shownSeries
The series shown on its own (its chip picked), or -1 for all of them overlaid.
Definition gui_plot_types.h:89
Gesture< float > panDrag
the view dragged (middle, or Alt + left); its left end as it was
Definition gui_plot_types.h:94
uint32_t editsSeen
a handle dragged; the handles as they were, for Escape and the edit
Definition gui_plot_types.h:102
Gesture< std::vector< float > > handleDrag
a handle dragged; the handles as they were, for Escape and the edit
Definition gui_plot_types.h:93
bool shownSet
false: all of the x range
Definition gui_plot_types.h:96
uint32_t edits
counts the edits committed through this view, for Plot's return
Definition gui_plot_types.h:101
float shownXMax
the part of the x range in view, once zoomed
Definition gui_plot_types.h:95
A plot shown in one place: what it shows and the one view of it together.
Definition gui_plot_types.h:108
Definition gui_base_types.h:394