scenepic 1.1.0
3D Visualization Made Easy
graph.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#ifndef _SCENEPIC_GRAPH_H_
5#define _SCENEPIC_GRAPH_H_
6
7#include "color.h"
8#include "json_value.h"
9#include "matrix.h"
10
11#include <memory>
12#include <string>
13#include <vector>
14
15namespace scenepic
16{
18 class Graph
19 {
20 public:
22 struct Margin
23 {
26
30 Margin(double size);
31
38 Margin(double top, double right, double bottom, double left);
39
41 std::string to_string() const;
42
47
49 double top;
50
52 double right;
53
55 double bottom;
56
58 double left;
59 };
60
63 {
70 std::int64_t frame,
72 float line_width = 1.0f);
73
75 std::string to_string() const;
76
81
83 std::int64_t frame;
88 };
89
91 const std::string& canvas_id() const;
92
101 const std::string& name,
102 const std::vector<float>& values,
103 const scenepic::Color& line_color = scenepic::Colors::Black,
104 float line_width = 1.0f,
105 const std::vector<VerticalRule>& vertical_rules = {});
106
108 std::string to_string() const;
109
114
116 const Color& background_color() const;
117
120
122 const Margin& margin() const;
123
126
130 const std::string& name_align() const;
131
135 Graph& name_align(const std::string& name_align);
136
140 const std::string& value_align() const;
141
145 Graph& value_align(const std::string& value_align);
146
148 const std::string& font_family() const;
149
151 Graph& font_family(const std::string& font_family);
152
154 float name_size() const;
155
158
160 float value_size() const;
161
164
169 const std::string& media_id() const;
170
172 Graph& media_id(const std::string& media_id);
173
174 private:
175 class Sparkline
176 {
177 public:
178 Sparkline(
179 const std::string& name,
180 const ValueBuffer& values,
181 const Color& color,
182 float line_width,
183 const std::vector<VerticalRule>& vertical_rules);
184
185 std::string to_string() const;
186 JsonValue to_json() const;
187
188 private:
189 std::string m_name;
190 ValueBuffer m_values;
191 Color m_color;
192 float m_line_width;
193 std::vector<VerticalRule> m_vertical_rules;
194 };
195
196 friend class Scene;
197
201 Graph(const std::string& canvas_id);
202
203 std::string m_canvas_id;
204 std::string m_media_id;
205 std::vector<Sparkline> m_sparklines;
206 Color m_background_color;
207 Margin m_margin;
208 std::string m_font_family;
209 std::string m_name_align;
210 std::string m_value_align;
211 float m_name_size;
212 float m_value_size;
213 };
214} // namespace scenepic
215
216#endif
Class for representing color values.
Definition: color.h:19
A 2D viewport that animates one or more sparklines.
Definition: graph.h:19
const std::string & value_align() const
How to align the sparkline value (one of 'left', 'right', 'top', 'bottom', or 'none')
std::string to_string() const
Return a JSON string representing the object.
const std::string & font_family() const
The font family used for the graph labels.
float value_size() const
The size of the graph labels in pixels.
const std::string & media_id() const
The unique ID of the media file associated with this canvas.
Graph & name_align(const std::string &name_align)
How to align the sparkline label (one of 'left', 'right', 'top', 'bottom', or 'none')
void add_sparkline(const std::string &name, const std::vector< float > &values, const scenepic::Color &line_color=scenepic::Colors::Black, float line_width=1.0f, const std::vector< VerticalRule > &vertical_rules={})
Adds a sparkline to the graph.
Graph & background_color(const Color &color)
Set the background color of the frame.
const Color & background_color() const
The background color of the frame.
const std::string & name_align() const
How to align the sparkline label (one of 'left', 'right', 'top', 'bottom', or 'none')
float name_size() const
The size of the graph labels in pixels.
Graph & name_size(float name_size)
Set the size of the graph labels in pixels.
const std::string & canvas_id() const
A unique identifier for the canvas.
Graph & media_id(const std::string &media_id)
The unique ID of the media file associated with this canvas.
Graph & value_size(float value_size)
Set the size of the graph labels in pixels.
const Margin & margin() const
The outside margin of the graph.
Graph & value_align(const std::string &value_align)
How to align the sparkline value (one of 'left', 'right', 'top', 'bottom', or 'none')
Graph & font_family(const std::string &font_family)
Set the font family used for the graph labels.
Graph & margin(const Margin &margin)
Set the outside margin of the graph.
JsonValue to_json() const
Convert this object into ScenePic json.
Representation of a JSON value according to the specification at https://www.json....
Definition: json_value.h:30
Top level container representing an entire ScenePic.
Definition: scene.h:58
const Color Black
Definition: color.h:95
Definition: audio_track.h:14
Represents the margin along the edges of a graph.
Definition: graph.h:23
std::string to_string() const
Returns a string representation of the margin.
double right
The right margin in pixels.
Definition: graph.h:52
double top
The top margin in pixels.
Definition: graph.h:49
Margin(double size)
Constructor.
JsonValue to_json() const
Convert this object into ScenePic json.
Margin(double top, double right, double bottom, double left)
Constructor.
double left
The left margin in pixels.
Definition: graph.h:58
double bottom
The bottom margin in pixels.
Definition: graph.h:55
Margin()
Default constructor.
Represents a vertical line in a sparkline graph.
Definition: graph.h:63
Color color
The color of the line.
Definition: graph.h:85
std::string to_string() const
Returns a string representation of the margin.
JsonValue to_json() const
Convert this object into ScenePic json.
float line_width
The width of the line in pixels.
Definition: graph.h:87
VerticalRule(std::int64_t frame, const Color &color=scenepic::Colors::Black, float line_width=1.0f)
Constructor.
std::int64_t frame
The frame at which to add the line.
Definition: graph.h:83