|
#include <Wt/WApplication>
|
|
#include <Wt/WBootstrapTheme>
|
|
#include <Wt/WCheckBox>
|
|
#include <Wt/WComboBox>
|
|
#include <Wt/WDialog>
|
|
#include <Wt/WLabel>
|
|
#include <Wt/WLineEdit>
|
|
#include <Wt/WPushButton>
|
|
#include <Wt/WStandardItem>
|
|
#include <Wt/WStandardItemModel>
|
|
#include <Wt/WStringListModel>
|
|
#include <Wt/WText>
|
|
#include <Wt/WVBoxLayout>
|
|
#include <Wt/Chart/WCartesianChart>
|
|
|
|
using namespace Wt;
|
|
|
|
class TestApplication : public WApplication
|
|
{
|
|
public:
|
|
TestApplication(const WEnvironment& env);
|
|
~TestApplication() { }
|
|
|
|
private:
|
|
WBootstrapTheme theme_;
|
|
WStandardItemModel *chartModel_;
|
|
int chartInstance_ = 0;
|
|
};
|
|
|
|
TestApplication::TestApplication(const WEnvironment& env) : WApplication(env)
|
|
{
|
|
setTitle("WCartesianChart Tooltips");
|
|
theme_.setVersion(WBootstrapTheme::Version3);
|
|
setTheme(&theme_);
|
|
styleSheet().addRule(".form-control", "margin-bottom: 10px;");
|
|
|
|
root()->setStyleClass("container-fluid");
|
|
root()->setMinimumSize(900, 0);
|
|
auto outerWell = new WContainerWidget(root());
|
|
outerWell->setStyleClass("col-xs-4 well well-sm");
|
|
auto form = new WContainerWidget(new WContainerWidget(outerWell));
|
|
|
|
auto chartPositionerHolder = new WContainerWidget(root());
|
|
chartPositionerHolder->setStyleClass("col-xs-8");
|
|
auto chartPositioner = new WContainerWidget(chartPositionerHolder);
|
|
chartPositioner->setPositionScheme(Relative);
|
|
|
|
auto top = new WContainerWidget(form);
|
|
top->setStyleClass("col-xs-12");
|
|
|
|
new WText("<h5>Press 'Create Chart' to add new chart based on options. "
|
|
"Test location of tooltips, with zoom enabled and disabled.</h5>", top);
|
|
|
|
auto zoomableCheckBox = new WCheckBox("Zoom", top);
|
|
zoomableCheckBox->setStyleClass("checkbox-inline");
|
|
|
|
auto crosshairCheckBox = new WCheckBox("Crosshair", top);
|
|
crosshairCheckBox->setStyleClass("checkbox-inline");
|
|
|
|
auto y2AxisCheckBox = new WCheckBox("Y2Axis", top);
|
|
y2AxisCheckBox->setStyleClass("checkbox-inline");
|
|
|
|
auto smallMarkerCheckBox = new WCheckBox("SmallMarker", top);
|
|
smallMarkerCheckBox->setStyleClass("checkbox-inline");
|
|
|
|
auto titleCheckBox = new WCheckBox("Title", top);
|
|
titleCheckBox->setStyleClass("checkbox-inline");
|
|
|
|
auto legendCheckBox = new WCheckBox("Legend", top);
|
|
legendCheckBox->setStyleClass("checkbox-inline");
|
|
|
|
auto openDialogButton = new WPushButton("Create Chart", top);
|
|
openDialogButton->setStyleClass("btn-primary btn-block");
|
|
openDialogButton->setMargin(20, Bottom);
|
|
|
|
chartModel_ = new WStandardItemModel(11, 3, this);
|
|
chartModel_->setHeaderData(1, Horizontal, "Series 1");
|
|
chartModel_->setHeaderData(2, Horizontal, "Series 2");
|
|
|
|
for (int col=0; col < 3; ++col) {
|
|
for (int row=0; row < 11; ++row) {
|
|
auto item = new WStandardItem(boost::lexical_cast<std::string>(row + col));
|
|
std::string coords = "(" + boost::lexical_cast<std::string>(row) + ", " +
|
|
boost::lexical_cast<std::string>(row + col) + ")";
|
|
item->setData(coords, ToolTipRole);
|
|
chartModel_->setItem(row, col, item);
|
|
}
|
|
}
|
|
|
|
openDialogButton->clicked().connect(std::bind([=] {
|
|
auto dialog = new WDialog(
|
|
zoomableCheckBox->checkState() ? "Zoomable" : "Not Zoomable");
|
|
dialog->setModal(false);
|
|
dialog->setResizable(true);
|
|
dialog->setClosable(true);
|
|
dialog->rejectWhenEscapePressed(true);
|
|
dialog->setSelectable(false);
|
|
dialog->setMinimumSize(400, 400);
|
|
dialog->contents()->setLayout(new WVBoxLayout());
|
|
|
|
Chart::WCartesianChart *chart = new Chart::WCartesianChart(Chart::ScatterPlot);
|
|
chart->setAutoLayoutEnabled();
|
|
chart->setZoomEnabled(zoomableCheckBox->isChecked());
|
|
chart->setPanEnabled(zoomableCheckBox->isChecked());
|
|
chart->setLegendEnabled(legendCheckBox->isChecked());
|
|
if (zoomableCheckBox->isChecked()) {
|
|
chart->setCrosshairEnabled(crosshairCheckBox->isChecked());
|
|
}
|
|
|
|
dynamic_cast<WVBoxLayout *>(dialog->contents()->layout())->addWidget(chart, 1);
|
|
++chartInstance_;
|
|
if (titleCheckBox->isChecked())
|
|
chart->setTitle("Test Chart " + boost::lexical_cast<std::string>(chartInstance_));
|
|
chart->setModel(chartModel_);
|
|
chart->setXSeriesColumn(0);
|
|
chart->addSeries(Chart::WDataSeries(1, Chart::PointSeries));
|
|
chart->addSeries(Chart::WDataSeries(2, Chart::PointSeries)); // for Y2Axis
|
|
|
|
for (auto ax: {Chart::YAxis, Chart::Y2Axis}) {
|
|
chart->axis(ax).setLabelFormat("%.1f");
|
|
chart->axis(ax).setTitleOrientation(Vertical);
|
|
}
|
|
if (y2AxisCheckBox->isChecked()) {
|
|
chart->series(2).bindToAxis(Chart::Y2Axis);
|
|
chart->axis(Chart::Y2Axis).setVisible(y2AxisCheckBox->isChecked());
|
|
chart->axis(Chart::Y2Axis).setTitle("y-axis2 label");
|
|
}
|
|
|
|
if (smallMarkerCheckBox->isChecked()) {
|
|
chart->series(1).setMarkerSize(5);
|
|
chart->series(2).setMarkerSize(5);
|
|
}
|
|
|
|
chart->axis(Chart::XAxis).setTitle("x-axis label");
|
|
chart->axis(Chart::XAxis).setLabelFormat("%.1f");
|
|
chart->axis(Chart::XAxis).setGridLinesEnabled(true);
|
|
chart->axis(Chart::XAxis).setGridLinesPen(WPen(WColor(224, 224, 224)));
|
|
|
|
chart->axis(Chart::YAxis).setTitle("y-axis label");
|
|
chart->axis(Chart::YAxis).setGridLinesEnabled(true);
|
|
chart->axis(Chart::YAxis).setGridLinesPen(WPen(WColor(224, 224, 224)));
|
|
|
|
|
|
dialog->contents()->setSelectable(false);
|
|
dialog->setCanReceiveFocus(true);
|
|
chartPositioner->resize(0, ((chartInstance_) % 7) * 40);
|
|
chartPositioner->setOffsets(((chartInstance_) % 7) * 40, Left);
|
|
dialog->positionAt(chartPositioner, Vertical);
|
|
dialog->show();
|
|
}));
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
return WRun(argc, argv, [](const WEnvironment& env) {return new TestApplication(env);});
|
|
}
|