[kde-edu]: KTouch Statistics Charts...
Jason Harris
kstars at 30doradus.org
Sat Apr 30 22:04:32 CEST 2005
Hi Andreas,
There is a plotting library in KDE-Edu, currently used by KStars and
Kalzium. Look in kdeedu/libkdeedu/kdeeduplot.
KStars uses the plot widget in several places, but our simplest use case
is probably the Jupiter Moons tool:
kdeedu/kstars/kstars/tools/jmoontool.[h|cpp]
(note that I'm actually using KStarsPlotWidget, an extension of
KPlotWidget. You may want to subclass your own version as well, if
KPlotWidget doesn't do everything you need).
Anyway, in the JMoonToll ctor, you can see how the widget gets
initialized:
pw = new KStarsPlotWidget( 0.0, 1.0, 0.0, 1.0, page );
pw->setShowGrid( false );
pw->setYAxisType0( KStarsPlotWidget::TIME );
pw->setLimits( -12.0, 12.0, -240.0, 240.0 );
pw->setXAxisLabel( i18n( "offset from Jupiter (arcmin)" ) );
pw->setYAxisLabel( i18n( "time since now (days)" ) );
This sets the limits of the X and Y axes, and adds labels to each axis.
(don't worry about setYAxisType0, that's a KStarsPlotWidget extension).
Once the plot widget is initialized, all you have to do is create
KPlotObjects and add them to the KPlotWidget. In
JMoonTool::initPlotObjects(), it looks like this:
KPlotObject *orbit[4];
KPlotObject *jpath;
.. .
orbit[0] = new KPlotObject( "io", colIo, KPlotObject::CURVE, 1,
KPlotObject::SOLID );
orbit[1] = new KPlotObject( "europa", colEu, KPlotObject::CURVE,
1,
KPlotObject::SOLID );
orbit[2] = new KPlotObject( "ganymede", colGn,
KPlotObject::CURVE, 1,
KPlotObject::SOLID );
orbit[3] = new KPlotObject( "callisto", colCa,
KPlotObject::CURVE, 1,
KPlotObject::SOLID );
jpath = new KPlotObject( "jupiter", colJp,
KPlotObject::CURVE, 1,
KPlotObject::SOLID );
Each KPlotObject is a group of points which are plotted together in the
widget. They can be disconnected POINTS, or a connected CURVE, or
text LABELs or POLYGONs. Once the PlotObjects are created, you have to
add points to them with KPlotObject::addPoint(); again, see the example
in JMoonTool::initPlotObjects().
So, once you have created a KPlotWidget and added some KPlotObjects,
you're done. The code takes care of drawing the objects on the widget,
and drawing the tickmarks and axes. The key usefullness of the classes
is that you don't have to worry about "pixel space" at all. You just
set the limits of the plot, and add the plot objects with their native
*data* coordinates.
Hope this makes sense; if you're having trouble, I'd be happy to write
up a small example application (which I should probably do anyway, and
put it in libkdeedu/kdeeduplot...)
regards,
Jason
On Saturday 30 April 2005 23:39, Andreas Nicolai wrote:
> Hi again,
>
> another question regarding the KTouch stats. Since it was frequently
> requested I'll add some more reasonable progress charts (for progress
> in a level/lecture/over several sessions ...). Up to now I used my
> handcrafted mini-chart, but I think that could be improved as well.
> Surely there's something out there for simple X-Y-charts. If I
> remember well, something like that is part of KDE-EDU, am I right?
>
> Has anyone a small example code or documentation for that so I could
> start using those chart-classes instead of my simple one?
>
> Thanks for any suggestions!
> Andreas
> _______________________________________________
> kde-edu mailing list
> kde-edu at mail.kde.org
> https://mail.kde.org/mailman/listinfo/kde-edu
--
KStars: Desktop Planetarium for KDE
http://edu.kde.org/kstars
More information about the kde-edu
mailing list