Jason Harris [Sun, 29 Oct 2006 03:25:34 +0000 (03:25 +0000)]
Implementing non-colliding text labels in kdeeduplot, based on kmplot
code.
It works, but it could probably be faster. You don't need to know
anything about it to use the feature, it all happens behind the scenes.
Just add some items with labels and enjoy the magic.
However, in the interest of inspiring optimization, here's a brief
description of how it works:
KPlotWidget now has a private array of floats: PlotMask[100][100].
This is a rough division of the content of the plot into a 100x100
grid. Where the plot is empty, the array is zero, where it has content,
it is >0. When items are added to the plot (points, lines, bars, or
labels), the corresponding positions in PlotMask are incremented by an
amount that can vary for different kinds of items (for example, right
now Bars don't increment as much as points or lines).
The function KPlotWidget::placeLabel() is responsible for positioning
item labels. It attempts to place the label close to the point to
which it belongs, while minimizing the label's overlap with masked
regions of the plot. Ideally, it won't overlap with masked regions at
all. This is done in a rather brute-force way: it tests label
positions in a 40x40 grid around the position of the point, and
determines the "cost" for placing the label at each position. Higher
cost is incurred for (a) overlapping with a masked region, (b) being
further from the point position, and (c) extending beyond the bounds
of the plot. The position that has the lowest "cost" is then adopted,
and the label is drawn at that position.
You can get an idea of the CPU impact of this cost-analysis using
the test suite I added to kdeeduplot. Display the "Points, lines
and bars" plot, and then resize the window. Note the smoothness of
the redraws. Now display "Points, lines and bars with labels" and
resize the window. The redraws take much longer in this case.
Jason Harris [Sat, 28 Oct 2006 00:04:44 +0000 (00:04 +0000)]
Internal changes to libkdeeduplot in preparation for implementing
non-colliding labels. Basically, I was looking at the code and
saw several things that needed to be improved.
+ Added a "BARS" type for KPlotObject, and removed the "POLYGON"
type. "CURVES" type is now called "LINES".
+ A single KPlotObject can now be any combination of POINTS,
LINES, and BARS. These enum items have bitmask values (1,2,4),
so you should be able to OR them together in the ctor, but I
haven't gotten that to work yet. Instead you can set it to one
type in the ctor, and use the
setShowPoints(bool)/setShowLines(bool)/setShowBars(bool)
convenience functions.
+ There are many more point shapes available now: CIRCLE, LETTER,
TRIANGLE, SQUARE, PENTAGON, HEXAGON, ASTERISK, and STAR
+ Plot objects no longer have a Name property. It's unnecessary with
the new labeling scheme.
+ There is no longer a LABEL object type. Instead, you can
define a label for any data point by adding a string argument to
addPoint(), like so:
+ There is no longer an enum for specifying line styles.
Instead, you can now define QPens and QBrushes for drawing
points, lines and bars. This is much more flexible.
+ renamed mapToPoint() to toScreen()
+ I added a "tests" subdirectory which demonstrates the library.
Please have a look.
TODO: It looks like drawing an axis using secondary data limits
is not working. The "Lines" demo in the tests directory should
show the angle in degrees along the top axis (the angle is shown
in radians on the bottom axis).
As I said, I haven't gotten the KPlotObject ctor to accept multiple PlotType values. i.e., this works:
I checked to see that the kdeedu module compiles with these changes
(other than kstars changes, I only had to make a few modifications to
kalzium/src/elementdataviewer.cpp and ktouch/src/ktouchstatistics.cpp;
check it out, I think you'll like the new API)
Jason Harris [Wed, 25 Oct 2006 01:17:21 +0000 (01:17 +0000)]
Convert plotting data to floating-point variants (QPoint-->QPointF,
QPolygon-->QPolygonF, etc). Moved mapToPoint() definition from
kplotwidget.h to kplotwidget.cpp.
Laurent Montel [Mon, 23 Oct 2006 08:12:44 +0000 (08:12 +0000)]
Apply Alex patch (now we can use enable-final argument
some module compiles with enable-final now)
As discussed with Alex it's not necessary to have program name
into automoc macro
Carsten Niehaus [Tue, 17 Oct 2006 16:14:32 +0000 (16:14 +0000)]
I needed to introduce this new ctor because I am using a KPlotWidget in a .ui file in Kalzium (see Revision 596474). The uic always uses Foo(QWidget*) and you cannot change this. Therefor I need a KPlotWidget(QWidget*)-ctor. Another solution would be to change the order of the arguements so that the QWidget = 0 would be at the first position. I would of course prefere that solution as it would remove this stupid second ctor.
Laurent Montel [Fri, 13 Oct 2006 07:58:31 +0000 (07:58 +0000)]
Necessary to change KDE4_AUTOMOC macro to support
enable-final argument
(there was not a dependancy between <name>_final.cpp file and
moc generated files => moc files were never created)
Not necessary to rebuild all kdelibs just cp kdelibs/cmake/modules/KDE4Macros.cmake <path_kde4>/share/apps/cmake/modules
I ported and tested all kde module (without enable-final argument, it compiles fines (test and program))
Don't try to use enable-final argument for the moment it doesn't compile (but dependancy works)
Jason Harris [Fri, 15 Sep 2006 21:45:57 +0000 (21:45 +0000)]
Fixed crash condition in ExtDate::fromString(QString, QDateFormat).
When using the TextFormat QDateFormat, the code creates a QStringList
from the space-separated fields of the input string, but it then assumed
that the stringlist contains at least three members, which caused a
crash when this was not the case. Now, it will return an invalid
ExtDate if the stringlist contains fewer than three members.
Jason Harris [Wed, 6 Sep 2006 14:17:11 +0000 (14:17 +0000)]
Cleanup KPlotWidget
KPlotWidget:
- added setAntialias(bool), set to true for smoother (but slower)
plots
- removed explicit double-buffering (Qt4 does this automatically)
- added top and right axes (by default, they show the same tickmarks
as bottom and left)
- added optional secondary data limits for showing alternate
set of tickmarks on top and right axes.
- removed setShowTickMarks() / setShowTickLabels()...each axis now
handles its own visibility logic.
KPlotAxis:
- each axis now calculates its own tickmark positions (rather
than KPlotWidget)
- rather than setting the number of tickmarks and distance between
them, the tickmark positions are now stored in a QList<double>
- simplified visibility logic:
+ isVisible() : draw axis and tickmarks ?
+ showTickLabels() : obvious
+ the axis label is drawn if it is not empty
- added new ticklabel format 't', which indicates that the ticklabel
values are decimal hours, and should be rendered with a clock-time
format ("hh:mm"). Other special format flags are possible.
I didn't have to modify kalzium or ktouch, so the API hasn't
changed too much. Most of the changes are "under the hood".
I also didn't look at kmathtool, since they have their own copy
of KPlotWidget in the playground. I'll let them decide if and when
to use this version.
Jason Harris [Thu, 8 Jun 2006 14:34:19 +0000 (14:34 +0000)]
Closing bug #127011 (need to distinguish long/short form of the month of
"May" with an i18nc() comment)
The specific case of May had already been fixed in trunk; this commit
adds uniform i18nc() comments to all short-form month and day names, for
consistency.
Carsten Niehaus [Fri, 2 Jun 2006 13:39:20 +0000 (13:39 +0000)]
* adding demo-xml for r/s phrases. emc2[]: please hand me the real data
* adding the reading code in the parser
* adding a demo in the datadialog so taht emc2[] sees how to do it
-cleanup the toplevel CMakeLists.txt a bit
-remove include_directories( CMAKE_CURRENT_SOURCE_DIR CMAKE_CURRENT_BINARY_DIR)
in the subdirs, since this is done now automatically by cmake (the CMAKE_INCLUDE_CURRENT_DIR option
-include_directories(KDE4_INCLUDES) in the toplevel CMakeLists.txt, so it
doesn't have to be done in every subdir