|
//
|
|
// Created by mark on 6/6/25.
|
|
//
|
|
#pragma once
|
|
|
|
#ifndef CHARTJSOPTIONS_H
|
|
#define CHARTJSOPTIONS_H
|
|
|
|
#include <string>
|
|
#include <variant>
|
|
#include <ReportsAndCharts/WChartJSLibrary.h>
|
|
#include <Wt/Json/Object.h>
|
|
|
|
|
|
// --- Nested Structs for Organization ---
|
|
class WChartJSOptions {
|
|
public:
|
|
struct LegendOptions {
|
|
bool display = true;
|
|
std::string position = "bottom";
|
|
bool reverse = false;
|
|
Wt::Json::Object toJsonObject() const;
|
|
};
|
|
|
|
struct TitleOptions {
|
|
bool display = false;
|
|
std::string text;
|
|
std::string position = "top";
|
|
int fontSize = 12;
|
|
Wt::Json::Object toJsonObject() const;
|
|
};
|
|
|
|
struct TooltipOptions {
|
|
bool enabled = true;
|
|
std::string mode = "index";
|
|
bool intersect = false;
|
|
bool reverse = false;
|
|
Wt::Json::Object freeFormOptions;
|
|
Wt::Json::Object toJsonObject() const;
|
|
};
|
|
|
|
struct ZoomAndPanOptions {
|
|
bool enabled = true;
|
|
bool wheelEnabled = true;
|
|
bool pinchEnabled = true;
|
|
bool panEnabled = true;
|
|
std::string mode = "xy";
|
|
std::string modifierKey = "alt";
|
|
Wt::Json::Object toJsonObject() const;
|
|
};
|
|
|
|
struct PluginOptions {
|
|
LegendOptions legend;
|
|
TitleOptions title;
|
|
TooltipOptions tooltip;
|
|
ZoomAndPanOptions zoomAndPan;
|
|
Wt::Json::Object toJsonObject() const;
|
|
};
|
|
|
|
struct TickOptions {
|
|
bool display = true;
|
|
std::string color;
|
|
bool autoSkip = true;
|
|
// Add other tick properties as needed (font, padding, etc.)
|
|
Wt::Json::Object freeFormOptions;
|
|
Wt::Json::Object toJsonObject() const;
|
|
};
|
|
|
|
struct ScaleTitleOptions {
|
|
bool display = false;
|
|
std::string text;
|
|
Wt::Json::Object toJsonObject() const;
|
|
};
|
|
|
|
struct GridOptions {
|
|
bool display = true;
|
|
std::string color = "rgba(245, 245, 247, 0.8)";
|
|
// Add other grid properties as needed
|
|
Wt::Json::Object freeFormOptions;
|
|
Wt::Json::Object toJsonObject() const;
|
|
};
|
|
|
|
struct AxisOptions {
|
|
bool display = true;
|
|
std::string axis = "x";
|
|
std::string type = "category"; // linear, logarithmic, category, time, radiallinear
|
|
bool stacked = false;
|
|
TickOptions ticks;
|
|
ScaleTitleOptions title;
|
|
GridOptions grid;
|
|
Wt::Json::Object freeFormOptions;
|
|
// Add other axis properties as needed
|
|
Wt::Json::Object toJsonObject() const;
|
|
};
|
|
|
|
struct ScalesOptions {
|
|
AxisOptions axisOptions;
|
|
Wt::Json::Object toJsonObject() const;
|
|
};
|
|
|
|
struct LayoutOptions {
|
|
// e.g., padding: 10 or padding: { left: 10, top: 5 }
|
|
std::variant<int, Wt::Json::Object> padding;
|
|
Wt::Json::Object toJsonObject() const;
|
|
};
|
|
|
|
struct InteractionOptions {
|
|
std::string mode = "nearest";
|
|
bool intersect = true;
|
|
std::string axis = "x";
|
|
Wt::Json::Object toJsonObject() const;
|
|
};
|
|
|
|
|
|
// --- Main Options Class ---
|
|
|
|
|
|
WChartJSOptions(ChartJSType type);
|
|
// --- General Chart Options ---
|
|
void setResponsive(bool isResponsive);
|
|
void setMaintainAspectRatio(bool maintain);
|
|
void setAspectRatio(double ratio);
|
|
void setDevicePixelRatio(int ratio);
|
|
void setLocale(const std::string& locale);
|
|
void setIndexAxis(const std::string& axis);
|
|
|
|
// --- Nested Options Setters ---
|
|
void setPlugins(const PluginOptions& plugins);
|
|
void setXScales(const ScalesOptions& scales);
|
|
void setYScales(const ScalesOptions& scales);
|
|
void setRScales(const ScalesOptions& scales);
|
|
void setLayout(const LayoutOptions& layout);
|
|
void setInteraction(const InteractionOptions& interaction);
|
|
|
|
// Method to get the final JSON object
|
|
const Wt::Json::Object& getOptions() const;
|
|
|
|
private:
|
|
// General properties
|
|
ChartJSType chartType_;
|
|
bool responsive_ = true;
|
|
bool maintainAspectRatio_ = false;
|
|
double aspectRatio_ = 2.0;
|
|
int devicePixelRatio_;
|
|
std::string locale_;
|
|
|
|
// Nested properties
|
|
PluginOptions plugins_;
|
|
ScalesOptions scales_;
|
|
LayoutOptions layout_;
|
|
InteractionOptions interaction_;
|
|
|
|
// The master JSON object that holds all options
|
|
Wt::Json::Object options_;
|
|
};
|
|
|
|
#endif //CHARTJSOPTIONS_H
|