-
Notifications
You must be signed in to change notification settings - Fork 1
/
charthelper.h
123 lines (91 loc) · 3.38 KB
/
charthelper.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
120
121
122
123
///////////////////////////////////////////////////////////////////////////////
// Project: wxECharts
// Home: https://github.com/PBfordev/wxecharts
// File Name: charthelper.h
// Purpose: Implementation of helper class using Apache ECharts
// Author: PB
// Created: 2024-08-22
// Copyright: (c) 2024 PB
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include <vector>
#include <wx/string.h>
class wxColour;
class wxImage;
class wxMemoryBuffer;
class wxWebView;
/*****************************************************************
ChartHelper
---------------
helper class for communication with Apache ECharts
To create the chart:
1. Add variable names.
2. Add series.
4. Call SetWebView().
5. Call ChartCreate().
6. Call ChartUpdateSeries().
After a variable name or series properties are modified, the
appropriate ChartUpdate<X>() method must be called to reflect
the changes in the chart itself.
******************************************************************/
class ChartHelper final
{
public:
enum ScriptResult
{
CreateChart,
UpdateSeries,
UpdateVariableNames,
GetColors,
SetColors,
GetSizingOptions,
SetSizingOptions,
GetPNG,
GetEChartsVersion,
};
enum SeriesType
{
Bar,
Line,
};
struct ValueSeries
{
wxString name;
SeriesType type{Bar};
std::vector<double> data;
};
ChartHelper();
void SetWebView(wxWebView* webView);
size_t GetVariableNamesCount() const;
bool GetVariableName(const size_t nameIdx, wxString& name) const;
std::vector<wxString> GetVariableNames() const;
bool AddVariableName(const wxString& name);
bool AddVariableNames(const std::vector<wxString>& names);
bool SetVariableName(const size_t nameIdx, const wxString& name);
size_t GetSeriesCount() const;
bool AddSeries(const ValueSeries& series);
bool GetSeriesName(const size_t seriesIdx, wxString& name) const;
std::vector<wxString> GetSeriesNames() const;
bool SetSeriesName(const size_t seriesIdx, const wxString& name);
bool GetSeriesType(const size_t seriesIdx, SeriesType& type) const;
bool SetSeriesType(const size_t seriesIdx, const SeriesType& type);
bool GetSeriesData(const size_t seriesIdx, std::vector<double>& data) const;
bool SetSeriesData(const size_t seriesIdx, const std::vector<double>& data);
void RunChartCreate();
void RunChartUpdateSeries();
void RunChartUpdateVariableNames();
void RunChartGetColors();
void RunChartSetColors(const std::vector<wxColour>& colors);
void RunChartGetSizingOptions();
void RunChartSetSizingOptions(const double widthToHeightRatio, const int minWidth, const int minHeight);
void RunChartGetPNG(const int imageWidth);
void RunChartGetEChartsVersion();
static bool JSONToColors(const wxString& JSONStr, std::vector<wxColour>& colors);
static bool JSONToSizingOptions(const wxString& JSONStr, double& widthToHeightRatio,
int& minWidth, int& minHeight);
private:
wxWebView* m_webView{nullptr};
std::vector<wxString> m_variableNames;
std::vector<ValueSeries> m_series;
};