For weeks now I have been seeing this problem with my WCartesianChart
plots, where, if I manually set the axes spans to be less than the full
span of the data in the chart's data model, I get this odd clipping
behavior for the plotted series. Specifically, the series lines clip
not at the axis edges (that is to say not inside the plot region), but
at the edges of the whole WCartesianChart widget (that is to say, out
beyond the axes labels, title and legend). However, even though the
series
lines do not clip properly, I've recently discovered that data markers
(turned on with series.setMarker()) DO clip within the boundaries of the
plot region! (This is true when viewed under Firefox or IE).
I thought maybe this was an important clue, so, for the last few days,
I've been going through the WChart2DRender code and associated code
modules, hoping I could find some glaring problem. Well, the charting
code is complex and uncommented, so I didn't make much headway.
However, while building another simple test case this morning, I did
come across something that I think may be another important clue. And
that is this...
First some background. In my real application (not my test case), I am
plotting pressure and temperature sensor histories. All available
sensors are listed on the Wt-generated web application with checkboxes
so the user can choose which sensors' data to plot. Once the user has
selected the sensors he's interested in, he clicks a "Refresh" push
button, and the chart is redrawn to display just the data for those
sensors that are checked. Okay, so in my application, the number of
series stored in the data model can vary each time the user clicks
"Refresh", and I handle that by first clearing the existing model using
model->clear();
and then rebuilding the model from scratch adding only those rows and
columns that I need to display the data for the sensors currently
checked. Because I clear the model each time in my real application, I
was also initially clearing the model in my little test case application
(appears below). When I do this, the clipping problem occurs (lines
don't crop properly, data markers do). However, it occurred to me that
for my test case, I didn't really need to clear the model because I was
only going to build a single model, one time, to demonstrate the problem
and then not again. So, I removed the call to model->clear(). To my
surprise, that version clipped both the lines AND the markers completely
correctly! Evidently, clearing the model is causing the clipping path
to get set incorrectly for the chart. I briefly looked at the code for
WStandardItemModel::clear(). It seems to ultimately result in the
emission of a modelReset signal that I suppose is acted upon by the
WCartesianChart. I suspect the problem is in there, but I didn't find
the code that dealt with the signal, and probably wouldn't have
understood it well even if I had.
At any rate, I've attached a copy of my little test case so you guys
could more easily see what I'm talking about. If you run the following
code unaltered, you'll see the clipping problem. If you comment out the
model->clear() line, the clipping problem goes way. I have good
screenshots as well, but I've not attached them because the mailing list
software seems to get a little whiny when I do that :-)
Any ideas?
I'm running on an Ubuntu 9.10 system, using g++ version 4.4.1, boost
1.38 libraries (from Ubuntu package install) and the latest public git
version of Wt. I've used Firefox 3.5.5 on Ubuntu and Windows and IE7 on
Windows to display the result.
Best Regards,
Charlie Hubbard
//======================================================================
=====
#include <Wt/Chart/WCartesianChart>
#include <Wt/WApplication>
#include <Wt/WStandardItemModel>
using namespace Wt;
using namespace Wt::Chart;
#include <math.h>
class PlotTest : public WApplication
{
public:
PlotTest(const WEnvironment &env);
~PlotTest();
private:
WCartesianChart *chart;
WStandardItemModel *model;
};
PlotTest::PlotTest(const WEnvironment &env) : WApplication(env)
{
int i;
double x, y1, y2;
double radians;
setTitle("plotTest");
chart = new WCartesianChart(ScatterPlot, root());
model = new WStandardItemModel(1, 1);
chart->setTitle("plotTest WITH model->clear()");
chart->setModel(model);
chart->setXSeriesColumn(0);
chart->setLegendEnabled(true);
chart->axis(XAxis).setScale(LinearScale);
chart->axis(XAxis).setGridLinesEnabled(true);
chart->axis(YAxis).setGridLinesEnabled(true);
chart->axis(XAxis).setTitle("Degrees (x)");
chart->axis(YAxis).setTitle("sin(x)");
chart->setPlotAreaPadding(70, Left | Top | Bottom);
chart->setPlotAreaPadding(140, Right);
chart->resize(950, 600);
// !!! Commenting out the following line causes the clipping problem
to go away !!!
model->clear();
model->insertColumns(0, 1); // A column to hold the X data
chart->setXSeriesColumn(0);
model->insertColumns(1, 2); // Columns to hold the two Y data series
model->insertRows(0, 720); // Enough rows for two cycles of sine()
model->setHeaderData(1, boost::any(WString("sin(x)")));
model->setHeaderData(2, boost::any(WString("sin(2x)")));
for (i=0; i<720; i++) {
radians = ((2.0 * 3.14159) / 360.0) * (double)i;
x = (double)i;
y1 = 100.0 * sin(radians); // first series
y2 = 100.0 * sin(radians * 2.0); // second series (sine wave at
twice the frequency)
model->setData(i, 0, x);
model->setData(i, 1, y1);
model->setData(i, 2, y2);
}
chart->axis(XAxis).setRange(200.0, 500.0);
chart->axis(YAxis).setRange(-70.0, 70.0);
chart->addSeries(WDataSeries(1, LineSeries));
chart->series(1).setMarker(SquareMarker);
chart->addSeries(WDataSeries(2, LineSeries));
chart->series(2).setMarker(CircleMarker);
}
PlotTest::~PlotTest()
{
}
WApplication* createApplication(const WEnvironment &env)
{
WApplication *retval;
retval = new PlotTest(env);
return retval;
}
int main(int argc, char** argv)
{
int retval;
retval = WRun(argc, argv, &createApplication);
return retval;
}
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest