Project

General

Profile

Bug #4828 ยป test_20160326a_axis_minimum_loop.C

Bruce Toll, 03/26/2016 01:20 PM

 
#include <Wt/WApplication>
#include <Wt/WStandardItemModel>
#include <Wt/WText>
#include <Wt/WPushButton>
#include <Wt/Chart/WCartesianChart>
#include <Wt/Chart/WStandardPalette>

using namespace Wt;

class TestApplication : public WApplication
{
public:
TestApplication(const WEnvironment& env);
~TestApplication() { }

private:
Chart::WCartesianChart *chart_ = nullptr;
WStandardItemModel *chartModel_ = nullptr;
WPushButton *button_ = nullptr;
};

TestApplication::TestApplication(const WEnvironment& env) : WApplication(env)
{
setTitle("WCartesianChart Axis Location Update Test");

new WText("<h5>Press button to set XAxis minimum to 0.0 (with LogScale). NOTE: Set a reasonable virtual memory limit!</h5>", root());
button_ = new WPushButton("Set XAxis minimum to 0.0", root());

chartModel_ = new WStandardItemModel(3, 2, this);

chartModel_->setData(chartModel_->index(0, 0), 1.0);
chartModel_->setData(chartModel_->index(0, 1), 0.0);
chartModel_->setData(chartModel_->index(1, 0), 20.0);
chartModel_->setData(chartModel_->index(1, 1), 0.2);
chartModel_->setData(chartModel_->index(2, 0), 40.0);
chartModel_->setData(chartModel_->index(2, 1), 2.0);

chart_ = new Chart::WCartesianChart(Chart::ScatterPlot, root());
chart_->resize(600, 400);
chart_->setAutoLayoutEnabled();
chart_->setZoomEnabled(true);
chart_->setModel(chartModel_);
chart_->setXSeriesColumn(0);
chart_->addSeries(Chart::WDataSeries(1, Chart::LineSeries));
chart_->axis(Chart::XAxis).setScale(Chart::LogScale);

button_->clicked().connect(std::bind([this] {
/*
* It doesn't make sense to set LogScale axis minimum to 0.0, but it might happen by accident...
*/
chart_->axis(Chart::XAxis).setMinimum(0.0);
button_->setEnabled(false);
}));
}

int main(int argc, char **argv)
{
return WRun(argc, argv, [](const WEnvironment& env) {return new TestApplication(env);});
}
    (1-1/1)