Project

General

Profile

Bug #4510 » 0001-Chart-with-tooltip-layout-and-initial-zoom.patch

Bruce Toll, 10/14/2015 09:49 PM

View differences:

examples/charts/ChartsExample.C
#include <Wt/WBorderLayout>
#include <Wt/WFitLayout>
#include <Wt/WVBoxLayout>
#include <Wt/WStandardItem>
#include <Wt/WTableView>
......
};
/*
* Handler to update tooltips on model changes
*/
void updateToolTip(WStandardItemModel *model, WStandardItem *item)
{
WString old_tip = item->toolTip();
WString new_tip = asString(model->headerData(item->column())) + ": "
+ asString(item->data(DisplayRole), "%.f");
if (old_tip != new_tip) {
item->setToolTip(new_tip);
}
}
/*
* Reads a CSV file as an (editable) standard item model.
*/
WAbstractItemModel *readCsvFile(const std::string &fname,
......
for (int col = 0; col < model->columnCount(); ++col) {
model->item(row, col)->setFlags(ItemIsSelectable | ItemIsEditable);
/*
Example of tool tips (disabled here because they are not updated
when editing data)
*/
/*
WString toolTip = asString(model->headerData(col)) + ": "
+ asString(model->item(row, col)->data(DisplayRole), "%.f");
model->item(row, col)->setToolTip(toolTip);
*/
}
model->itemChanged().connect(boost::bind(updateToolTip, model, _1));
return model;
} else {
WString error(WString::tr("error-missing-data"));
......
model->setData(i, 0, x);
model->setData(i, 1, sin(x));
WString toolTip = asString(model->item(i, 1)->data(DisplayRole), "%.2f");
model->item(i, 1)->setToolTip(toolTip);
}
/*
* Create the scatter plot.
*/
WCartesianChart *chart = new WCartesianChart(this);
WContainerWidget *holder = new WContainerWidget(this);
holder->setLayout(new WVBoxLayout());
WCartesianChart *chart = new WCartesianChart();
holder->layout()->addWidget(chart);
chart->setModel(model); // set the model
chart->setXSeriesColumn(0); // set the column that holds the X data
chart->setLegendEnabled(true); // enable the legend
......
chart->setPanEnabled(true);
chart->setCrosshairEnabled(true);
chart->axis(XAxis).setZoom(2.0);
chart->axis(YAxis).setZoom(2.0);
chart->setBackground(WColor(200,200,200));
chart->setType(ScatterPlot); // set type to ScatterPlot
......
chart->setAutoLayoutEnabled();
// Add the curves
WDataSeries s(1, CurveSeries);
WDataSeries s(1, PointSeries);
s.setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
chart->addSeries(s);
chart->resize(800, 300); // WPaintedWidget must be given explicit size
holder->resize(800, 300);
chart->setMargin(10, Top | Bottom); // add margin vertically
chart->setMargin(WLength::Auto, Left | Right); // center horizontally
holder->setMargin(10, Top | Bottom); // add margin vertically
holder->setMargin(WLength::Auto, Left | Right); // center horizontally
ChartConfig *config = new ChartConfig(chart, this);
config->setValueFill(ZeroValueFill);
(1-1/2)