-
Notifications
You must be signed in to change notification settings - Fork 2
/
Plots.h
119 lines (100 loc) · 3.76 KB
/
Plots.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//
// Created by ryanz on 9/17/2022.
//
#ifndef PHYSICSFORMULA_PLOTS_H
#define PHYSICSFORMULA_PLOTS_H
#include "pbPlots.hpp"
#include "supportLib.hpp"
class Plots {
public:
static void drawScatterPlot(int width, int height, vector<double> *x,
vector<double> *y, const string& filename);
static void drawScatterPlot(int width,
int height,
vector<double> *x,
vector<double> *y,
const string& filename,
vector<wchar_t> *title,
vector<wchar_t> *xLabel,
vector<wchar_t> *yLabel,
const string& lineType = "Solid",
int lineThickness = 2,
bool display = false);
static void FreeAllocations();
}; //end class Plots
void Plots::drawScatterPlot(int width, int height, vector<double> *x,
vector<double> *y, const string& filename) {
RGBABitmapImageReference *imageRef = CreateRGBABitmapImageReference();
vector<wchar_t> *value = nullptr;
StringReference *stringRef = CreateStringReference(value);
DrawScatterPlot(imageRef, width, height, x, y, stringRef);
vector<double> *pngData = ConvertToPNG(imageRef->image);
WriteToFile(pngData, filename);
DeleteImage(imageRef->image);
}
void Plots::drawScatterPlot(int width,
int height,
vector<double> *x,
vector<double> *y,
const string& filename,
vector<wchar_t> *title,
vector<wchar_t> *xLabel,
vector<wchar_t> *yLabel,
const string& lineType,
const int lineThickness,
bool display
)
{
bool success;
auto errorMessage = CreateStringReferenceLengthValue(0, L' ');
RGBABitmapImageReference *imageRef = CreateRGBABitmapImageReference();
auto series = GetDefaultScatterPlotSeriesSettings();
series->xs = x;
series->ys = y;
series->linearInterpolation = true;
if(lineType == "Solid")
series->lineType = toVector(L"Solid");
else if(lineType == "Dashed")
series->lineType = toVector(L"Dashed");
else if(lineType == "Dotted")
series->lineType = toVector(L"Dotted");
else if(lineType == "DashDot")
series->lineType = toVector(L"DashDot");
else if(lineType == "DashDotDot")
series->lineType = toVector(L"DashDotDot");
else
series->lineType = toVector(L"Solid");
series->lineThickness = lineThickness;
auto settings = GetDefaultScatterPlotSettings();
settings->width = width;
settings->height = height;
settings->autoBoundaries = true;
settings->autoPadding = true;
settings->title = (vector<wchar_t> *) title;
settings->xLabel = (vector<wchar_t> *) xLabel;
settings->yLabel = (vector<wchar_t> *) yLabel;
settings->scatterPlotSeries->push_back(series);
success = DrawScatterPlotFromSettings(imageRef, settings, errorMessage);
if (success)
{
vector<double> *pngData = ConvertToPNG(imageRef->image);
WriteToFile(pngData, filename);
DeleteImage(imageRef->image);
if(display)
{
system(filename.c_str());
}
}
else
{
cerr << "Error: ";
for (wchar_t c : *errorMessage->string)
wcerr << c;
cerr << endl;
}
// free all allocated memory
FreeAllocations();
}
void Plots::FreeAllocations() {
}
#endif //PHYSICSFORMULA_PLOTS_H