/usr/include/Wt/Chart/WPieChart is in libwt-dev 3.3.6+dfsg-1.1.
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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | // This may look like C code, but it's really -*- C++ -*-
/*
* Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#ifndef CHART_WPIE_CHART_H_
#define CHART_WPIE_CHART_H_
#include <Wt/Chart/WAbstractChart>
#include <Wt/WRectF>
namespace Wt {
class WPainter;
namespace Chart {
class WChartPalette;
/*! \brief Enumeration that specifies options for the labels.
*
* \sa WPieChart::setDisplayLabels(WFlags<LabelOption>)
*
* \ingroup charts
*/
enum LabelOption {
NoLabels = 0x00, //!< Do not display labels (default).
Inside = 0x01, //!< Display labels inside each segment.
Outside = 0x02, //!< Display labels outside each segment.
TextLabel = 0x10, //!< Display the label text
TextPercentage = 0x20 //!< Display the value (as percentage)
};
W_DECLARE_OPERATORS_FOR_FLAGS(LabelOption);
/*! \class WPieChart Wt/Chart/WPieChart Wt/Chart/WPieChart
* \brief A pie chart.
*
* A pie chart renders a single data series as segments of a circle, so that
* the area of each segment is proportional to the value in the data series.
*
* To use a pie chart, you need to set a model using setModel(), and use
* setLabelsColumn() and setDataColumn() to specify the model column that
* contains the category labels and data.
*
* The pie chart may be customized visually by enabling a 3D effect
* (setPerspectiveEnabled()), or by specifying the angle of the first
* segment. One or more segments may be exploded, which seperates the
* segment from the rest of the pie chart, using setExplode().
*
* The segments may be labeled in various ways using
* setDisplayLabels().
*
* <h3>CSS</h3>
*
* Styling through CSS is not applicable.
*
* \image html ChartWPieChart-1.png "Example of a pie chart"
*
* \sa WCartesianChart
*
* \ingroup charts modelview
*/
class WT_API WPieChart : public WAbstractChart
{
public:
/*! \brief Creates a new pie chart.
*/
WPieChart(WContainerWidget *parent = 0);
/*! \brief Sets the model column that holds the labels.
*
* The labels are used only when setDisplayLabels() is called with
* the \link Chart::TextLabel TextLabel\endlink option.
*
* The default value is -1 (not defined).
*
* \sa setModel(WAbstractItemModel *), setDisplayLabels(), setDataColumn(int)
*/
void setLabelsColumn(int column);
/*! \brief Returns the model column used for the labels.
*
* \sa setLabelsColumn(int)
*/
int labelsColumn() const { return labelsColumn_; }
/*! \brief Sets the model column that holds the data.
*
* \if cpp
* The data column should contain data that can be converted to
* a number, but should not necessarily be of a number type, see
* also asNumber(const boost::any&).
* \elseif java
* The data column should contain data that can be converted to
* a number, but should not necessarily be of a number type, see
* also {javadoclink StringUtils#asNumber(Object)}.
* \endif
*
* The default value is -1 (not defined).
*
* \sa setModel(WAbstractItemModel *), setLabelsColumn(int)
*/
void setDataColumn(int modelColumn);
/*! \brief Returns the model column used for the data.
*
* \sa setDataColumn(int)
*/
int dataColumn() const { return dataColumn_; }
/*! \brief Customizes the brush used for a pie segment.
*
* By default, the brush is taken from the palette(). You can use
* this method to override the palette's brush for a particular
* <i>modelRow</i>.
*
* \sa setPalette(WChartPalette *)
*/
void setBrush(int modelRow, const WBrush& brush);
/*! \brief Returns the brush used for a pie segment.
*
* \sa setBrush(int, const WBrush&)
*/
WBrush brush(int modelRow) const;
/*! \brief Sets the explosion factor for a pie segment.
*
* Separates the segment corresponding to model row <i>modelRow</i>
* from the rest of the pie. The <i>factor</i> is a positive number
* that represents the distance from the center as a fraction of the
* pie radius. Thus, 0 corresponds to no separation, and 0.1 to a
* 10% separation, and 1 to a separation where the segment tip is on
* the outer perimeter of the pie.
*
* The default value is 0.
*/
void setExplode(int modelRow, double factor);
/*! \brief Returns the explosion factor for a segment.
*
* \sa setExplode(int, double)
*/
double explode(int modelRow) const;
/*! \brief Enables a 3D perspective effect on the pie.
*
* A 3D perspective effect is added, which may be customized by
* specifying the simulated <i>height</i> of the pie. The height is
* defined as a fraction of the pie radius.
*
* The default value is false.
*/
void setPerspectiveEnabled(bool enabled, double height = 1.0);
/*! \brief Returns whether a 3D effect is enabled.
*
* \sa setPerspectiveEnabled(bool, double)
*/
bool isPerspectiveEnabled() const { return height_ > 0.0; }
/*! \brief Enables a shadow effect.
*
* A soft shadow effect is added.
*
* The default value is false.
*/
void setShadowEnabled(bool enabled);
/*! \brief Returns whether a shadow effect is enabled.
*
* \sa setShadowEnabled()
*/
bool isShadowEnabled() const { return shadow_; }
/*! \brief Sets the angle of the first segment.
*
* The default value is 45 degrees.
*/
void setStartAngle(double degrees);
/*! \brief Returns the angle of the first segment.
*
* \sa setStartAngle(double)
*/
double startAngle() const { return startAngle_; }
/*! \brief Sets the percentage value to avoid rendering of label texts.
*
* The default value is 0 percent.
*/
void setAvoidLabelRendering(double percent);
/*! \brief Returns the percentage to avoid label rendering.
*
* \sa setAvoidLabelRendering(double)
*/
double avoidLabelRendering() const { return avoidLabelRendering_; }
/*! \brief Configures if and how labels should be displayed
*
* The <i>options</i> must be the logical OR of a placement option
* (\link Chart::Inside Inside\endlink or \link
* Chart::Outside Outside\endlink) and \link
* Chart::TextLabel TextLabel\endlink and/or \link
* Chart::TextPercentage TextPercentage\endlink. If both
* TextLabel and TextPercentage are specified, then these are
* combined as "<label>: <percentage>".
*
* The default value is \link Chart::NoLabels NoLabels\endlink.
*/
void setDisplayLabels(WFlags<LabelOption> options);
/*! \brief Returns options set for displaying labels.
*
* \sa WPieChart::setDisplayLabels()
*/
WFlags<LabelOption> displayLabels() const { return labelOptions_; }
/*! \brief Sets the label format.
*
* Sets a format string which is used to format label (percentage)
* values.
*
* The format string must be a format string that is accepted by
* snprintf() and which formats one double. If the format string is
* an empty string, then WLocale::toString() is used.
*
* The default value is "%.3g%%".
*
* \sa labelFormat()
*/
void setLabelFormat(const WString& format);
/*! \brief Returns the label format string.
*
* \sa setLabelFormat()
*/
WString labelFormat() const;
/*! \brief Creates a widget which renders the a legend item.
*
* Depending on the passed LabelOption flags, the legend item widget,
* will contain a text (with or without the percentage) and/or a span with
* the segment's color.
*/
WWidget* createLegendItemWidget(int index, WFlags<LabelOption> options);
/*! \brief Adds a data point area (used for displaying e.g. tooltips).
*
* You may want to specialize this is if you wish to modify (or delete)
* the area.
*
* \note Currently, an area is only created if the ToolTipRole data at the
* data point is not empty.
*/
virtual void addDataPointArea(int row, int column, WAbstractArea *area)
const;
/**
* @brief createLabelWidget possition textWidget where the text would be
* rendered.
* Assuming that textWidget is added to a container with same dimensions as
* the WPieChart.
* This should be used in combinaltion with drawLabel().
*
* @return The new WContainerWidget that contains textWidget and can be placed
* on an other layer that has the same dimensions as the WPieChart.
* \sa drawLabel()
*
* Usage example, PieChart with label links.
* \code
* class PChart : public Wt::Chart::WPieChart {
* private:
* Wt::WContainerWidget *widgetsLayer_;
* public:
* PChart(Wt::WContainerWidget *widgetsLayer) :
* Wt::Chart::WPieChart(widgetsLayer),
* widgetsLayer_(widgetsLayer)
* {
* widgetsLayer_->resize(800, 300);
* resize(800, 300);
* widgetsLayer_->setPositionScheme(Wt::Relative);
* }
* virtual void drawLabel(Wt::WPainter* painter, const Wt::WRectF& rect,
* Wt::WFlags<Wt::AlignmentFlag> alignmentFlags,
* const Wt::WString& text, int row) const
* {
* if (model()->link(row, dataColumn()) == 0){
* Wt::Chart::WPieChart::drawLabel(painter, rect, alignmentFlags,
* text, row);
* } else {
* Wt::WAnchor *a = new Wt::WAnchor(*model()->link(row, dataColumn()),
* text);
* widgetsLayer_->addWidget(createLabelWidget(a, painter, rect,
* alignmentFlags));
* }
* }
* };
* \endcode
*/
virtual WContainerWidget *createLabelWidget(WWidget *textWidget,
WPainter* painter, const WRectF& rect,
Wt::WFlags<AlignmentFlag> alignmentFlags) const;
virtual void paint(WPainter& painter, const WRectF& rectangle = WRectF())
const;
protected:
void paintEvent(Wt::WPaintDevice *paintDevice);
/**
* @brief drawLabel draw a label on the chart. Will be called by paint.
*
* You may want to specialize this if you wish to replace the label by
* a widget.
* \sa createLabelWidget() if you wish to replace the label by a Widget.
*
*/
virtual void drawLabel(WPainter* painter, const WRectF& rect,
WFlags<AlignmentFlag> alignmentFlags,
const WString& text, int row) const;
private:
int labelsColumn_;
int dataColumn_;
double height_;
double startAngle_;
double avoidLabelRendering_;
WFlags<LabelOption> labelOptions_;
bool shadow_;
WString labelFormat_;
struct PieData {
bool customBrush;
WBrush brush;
double explode;
PieData();
};
std::vector<PieData> pie_;
protected:
virtual void modelChanged();
virtual void modelReset();
private:
void drawPie(WPainter& painter, double cx, double cy, double r, double h,
double total) const;
void drawSlices(WPainter& painter, double cx, double cy, double r,
double total, bool ignoreBrush) const;
void drawSide(WPainter& painter, double pcx, double pcy, double r,
double angle, double h) const;
void drawOuter(WPainter& painter, double pcx, double pcy, double r,
double a1, double a2, double h) const;
void setShadow(WPainter& painter) const;
int prevIndex(int i) const;
int nextIndex(int i) const;
static WBrush darken(const WBrush& brush);
WString labelText(int index, double v, double total,
WFlags<LabelOption> options) const;
};
}
}
#endif // CHART_WPIE_CHART_H_
|