1 // This may look like C code, but it's really -*- C++ -*- 2 /* 3 * Copyright (C) 2015 Emweb bv, Herent, Belgium. 4 * 5 * See the LICENSE file for terms of use. 6 */ 7 #ifndef CHART_WAXIS_SLIDER_WIDGET_H_ 8 #define CHART_WAXIS_SLIDER_WIDGET_H_ 9 10 #include <Wt/WBrush.h> 11 #include <Wt/WJavaScriptHandle.h> 12 #include <Wt/WPaintedWidget.h> 13 #include <Wt/WPen.h> 14 #include <Wt/WRectF.h> 15 16 namespace Wt { 17 18 class WRectF; 19 20 namespace Chart { 21 22 class WDataSeries; 23 24 /*! \class WAxisSliderWidget Wt/Chart/WAxisSliderWidget.h Wt/Chart/WAxisSliderWidget.h 25 * \brief A widget for selecting an X axis range to display on an associated WCartesianChart. 26 * 27 * \note This widget currently only works with the HtmlCanvas rendering method. 28 * 29 * \ingroup charts 30 */ 31 class WT_API WAxisSliderWidget : public WPaintedWidget { 32 public: 33 /*! \brief Creates an axis slider widget. 34 * 35 * Creates an axis slider widget that is not associated with a chart. 36 * Before it is used, a chart should be assigned with setChart(), 37 * and a series column chosen with setSeriesColumn(). 38 */ 39 WAxisSliderWidget(); 40 41 /*! \brief Creates an axis slider widget. 42 * 43 * Creates an axis slider widget associated with the given data series 44 * of the given chart. 45 */ 46 WAxisSliderWidget(WDataSeries *series); 47 48 /*! \brief Destructor 49 */ 50 virtual ~WAxisSliderWidget(); 51 52 void setSeries(WDataSeries *series); 53 54 /*! \brief Set the pen to draw the data series with. 55 */ 56 void setSeriesPen(const WPen& pen); 57 58 /*! \brief Returns the pen to draw the data series with. 59 */ seriesPen()60 const WPen& seriesPen() const { return seriesPen_; } 61 62 /*! \brief Set the pen to draw the selected part of the data series with. 63 * 64 * If not set, this defaults to seriesPen(). 65 */ 66 void setSelectedSeriesPen(const WPen& pen); 67 68 /*! \brief Returns the pen to draw the selected part of the data series with. 69 */ selectedSeriesPen()70 WPen selectedSeriesPen() const { return *selectedSeriesPen_; } 71 72 /*! \brief Set the brush to draw the handles left and right of the selected area with. 73 */ 74 void setHandleBrush(const WBrush& brush); 75 76 /*! \brief Returns the brush to draw the handles left and right of the selected area with. 77 */ handleBrush()78 const WBrush& handleBrush() const { return handleBrush_; } 79 80 /*! \brief Set the background brush. 81 */ 82 void setBackground(const WBrush& background); 83 84 /*! \brief Returns the background brush. 85 */ background()86 const WBrush& background() const { return background_; } 87 88 /*! \brief Set the brush for the selected area. 89 */ 90 void setSelectedAreaBrush(const WBrush& brush); 91 92 /*! \brief Returns the brush for the selected area. 93 */ selectedAreaBrush()94 const WBrush& selectedAreaBrush() const { return selectedAreaBrush_; } 95 96 /*! \brief Sets an internal margin for the selection area. 97 * 98 * This configures the area (in pixels) around the selection area that 99 * is available for the axes and labels, and the handles. 100 * 101 * Alternatively, you can configure the chart layout to be computed automatically using setAutoLayoutEnabled(). 102 * 103 * \sa setAutoLayoutEnabled() 104 */ 105 void setSelectionAreaPadding(int padding, WFlags<Side> sides = AllSides); 106 107 /*! \brief Returns the internal margin for the selection area. 108 * 109 * This is either the padding set through setSelectionAreaPadding() or computed using setAutoLayoutEnabled(). 110 * 111 * \sa setPlotAreaPadding() 112 */ 113 int selectionAreaPadding(Side side) const; 114 115 /*! \brief Configures the axis slider layout to be automatic. 116 * 117 * This configures the selection area so that the space around it is suited for the text that is rendered. 118 */ 119 void setAutoLayoutEnabled(bool enabled = true); 120 121 /*! \brief Returns whether chart layout is computed automatically. 122 * 123 * \sa setAutoLayoutEnabled() 124 */ isAutoLayoutEnabled()125 bool isAutoLayoutEnabled() const { return autoPadding_; } 126 127 /*! \brief Set whether to draw the X axis tick labels on the slider widget. 128 * 129 * AxisProperty::Labels are enabled by default. 130 */ 131 void setLabelsEnabled(bool enabled = true); 132 133 /*! \brief Returns whether the X axis tick labels are drawn. 134 * 135 * \sa setLabelsEnabled() 136 */ isLabelsEnabled()137 bool isLabelsEnabled() const { return labelsEnabled_; } 138 139 /*! \brief Set whether the Y axis of the associated chart should be updated to fit the series. 140 * 141 * Y axis zoom is enabled by default. 142 */ 143 void setYAxisZoomEnabled(bool enabled = true); 144 145 /*! \brief Returns whether the Y axis of the associated chart should be updated to fit the series. 146 * 147 * \sa setYAxisZoomEnabled() 148 */ isYAxisZoomEnabled()149 bool isYAxisZoomEnabled() const { return yAxisZoomEnabled_; } 150 series()151 WDataSeries *series() { return series_; } series()152 const WDataSeries *series() const { return series_; } 153 154 protected: 155 virtual void render(WFlags<RenderFlag> flags) override; 156 virtual void paintEvent(WPaintDevice *paintDevice) override; 157 158 private: 159 void init(); 160 std::string sObjJsRef() const; 161 WRectF hv(const WRectF& rect) const; 162 WTransform hv(const WTransform& t) const; 163 164 WCartesianChart *chart(); 165 const WCartesianChart *chart() const; 166 167 WDataSeries *series_; 168 WPen seriesPen_; 169 WPen *selectedSeriesPen_; 170 WBrush handleBrush_; 171 WBrush background_; 172 WBrush selectedAreaBrush_; 173 bool autoPadding_; 174 bool labelsEnabled_; 175 bool yAxisZoomEnabled_; 176 int padding_[4]; 177 178 WJavaScriptHandle<WTransform> transform_; 179 }; 180 181 } 182 } 183 184 #endif // CHART_WAXIS_SLIDER_WIDGET_H_ 185