/usr/lib/Wt/test/chart/WChartTest.C is in witty-examples 3.1.10-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | /*
* Copyright (C) 2009 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <fstream>
#include <Wt/Chart/WCartesianChart>
#include <Wt/Chart/WDataSeries>
#include <Wt/WStandardItemModel>
#include <Wt/WSvgImage>
#include <Wt/WPainter>
#include <Wt/WDate>
#include <Wt/WDateTime>
#include <Wt/WTime>
using namespace Wt;
using namespace Wt::Chart;
namespace {
void plotTimeSeriesChart(WStandardItemModel* model,
std::string fileName,
AxisScale xScale)
{
WCartesianChart chart;
chart.setModel(model);
chart.setXSeriesColumn(0);
chart.setLegendEnabled(true);
chart.setType(ScatterPlot);
chart.axis(XAxis).setScale(xScale);
chart.setPlotAreaPadding(100, Left);
chart.setPlotAreaPadding(50, Top | Bottom);
for (int i = 1; i < model->columnCount(); ++i) {
WDataSeries s(i, LineSeries);
chart.addSeries(s);
}
chart.setMargin(10, Top | Bottom);
chart.setMargin(WLength::Auto, Left | Right);
/*
chart.resize(400, 300);
chart.initLayout();
std::cerr << chart.axis(YAxis).minimum()
<< "-" << chart.axis(YAxis).maximum() << std::endl;
*/
{
WSvgImage image(400, 300);
WPainter painter(&image);
chart.paint(painter);
painter.end();
std::ofstream f(fileName.c_str(), std::ios::out | std::ios::binary);
image.write(f);
f.close();
}
}
} // end anonymous namespace
BOOST_AUTO_TEST_CASE( chart_test_WDateTimeChartMinutes )
{
WStandardItemModel model;
WDate d(2009, 10, 1);
WDateTime start(d, WTime(1, 0, 0));
WDateTime end(d, WTime(2, 0, 0));
WDateTime dt = start;
int row = 0;
model.insertColumns(0, 2);
while (dt < end) {
model.insertRow(model.rowCount());
model.setData(row, 0, boost::any(dt));
model.setData(row, 1, boost::any(row * 10));
dt = dt.addSecs(60);
row++;
}
plotTimeSeriesChart(&model, "minutes.svg", DateTimeScale);
}
BOOST_AUTO_TEST_CASE( chart_test_WDateTimeChartHours )
{
WStandardItemModel model;
WDate d(2009, 10, 1);
WDateTime start(d, WTime(0, 0, 0));
WDateTime end(d, WTime(23, 30, 0));
WDateTime dt = start;
int row = 0;
model.insertColumns(0, 2);
while (dt < end) {
model.insertRow(model.rowCount());
model.setData(row, 0, boost::any(dt));
model.setData(row, 1, boost::any(row * 10));
dt = dt.addSecs(60 * 60);
row++;
}
plotTimeSeriesChart(&model, "hours.svg", DateTimeScale);
}
BOOST_AUTO_TEST_CASE( chart_test_WDateTimeChartDays )
{
WStandardItemModel model;
WDate start(2009, 10, 1);
WDate end(2009, 11, 1);
WDate d = start;
int row = 0;
model.insertColumns(0, 2);
while (d < end) {
model.insertRow(model.rowCount());
model.setData(row, 0, boost::any(d));
model.setData(row, 1, boost::any(row * 10));
d = d.addDays(1);
row++;
}
plotTimeSeriesChart(&model, "days.svg", DateScale);
}
BOOST_AUTO_TEST_CASE( chart_test_WDateTimeChartWeeks )
{
WStandardItemModel model;
WDate start(2009, 10, 1);
WDate end(2009, 11, 1);
WDate d = start;
int row = 0;
model.insertColumns(0, 2);
while (d < end) {
model.insertRow(model.rowCount());
model.setData(row, 0, boost::any(d));
model.setData(row, 1, boost::any(row * 10));
d = d.addDays(7);
row++;
}
plotTimeSeriesChart(&model, "weeks.svg", DateScale);
}
BOOST_AUTO_TEST_CASE( chart_test_WDateTimeChartMonths )
{
WStandardItemModel model;
WDate start(2008, 4, 1);
WDate end(2008, 8, 1);
WDate d = start;
int row = 0;
model.insertColumns(0, 2);
while (d < end) {
model.insertRow(model.rowCount());
model.setData(row, 0, boost::any(d));
model.setData(row, 1, boost::any(row * 10));
d = d.addMonths(1);
row++;
}
plotTimeSeriesChart(&model, "months.svg", DateScale);
}
|