Wt examples  4.0.2
Public Member Functions | List of all members
TimeSeriesExample Class Reference

A widget that demonstrates a times series chart. More...

#include <ChartsExample.h>

Inheritance diagram for TimeSeriesExample:
Inheritance graph
[legend]

Public Member Functions

 TimeSeriesExample ()
 Creates the time series scatter plot example. More...
 
- Public Member Functions inherited from Wt::WContainerWidget
 WContainerWidget ()
 
 ~WContainerWidget ()
 
void setLayout (std::unique_ptr< WLayout > layout)
 
WLayoutlayout () const
 
virtual void addWidget (std::unique_ptr< WWidget > widget)
 
Widget * addWidget (std::unique_ptr< Widget > widget)
 
Widget * addNew (Args &&...args)
 
virtual void insertBefore (std::unique_ptr< WWidget > widget, WWidget *before)
 
Widget * insertBefore (std::unique_ptr< Widget > widget, WWidget *before)
 
virtual void insertWidget (int index, std::unique_ptr< WWidget > widget)
 
Widget * insertWidget (int index, std::unique_ptr< Widget > widget)
 
Widget * insertNew (int index, Args &&...args)
 
virtual std::unique_ptr< WWidgetremoveWidget (WWidget *widget) override
 
virtual void clear ()
 
virtual int indexOf (WWidget *widget) const
 
virtual WWidgetwidget (int index) const
 
virtual int count () const
 
void setContentAlignment (WFlags< AlignmentFlag > contentAlignment)
 
void setPadding (const WLength &padding, WFlags< Side > sides=AllSides)
 
WLength padding (Side side) const
 
WFlags< AlignmentFlagcontentAlignment () const
 
void setOverflow (Overflow overflow, WFlags< Orientation > orientation=(Orientation::Horizontal|Orientation::Vertical))
 
void setList (bool list, bool ordered=false)
 
bool isList () const
 
bool isUnorderedList () const
 
bool isOrderedList () const
 
EventSignal< WScrollEvent > & scrolled ()
 
int scrollTop () const
 
int scrollLeft () const
 
- Public Member Functions inherited from Wt::WInteractWidget
 WInteractWidget ()
 
EventSignal< WKeyEvent > & keyWentDown ()
 
EventSignal< WKeyEvent > & keyPressed ()
 
EventSignal< WKeyEvent > & keyWentUp ()
 
EventSignalenterPressed ()
 
EventSignalescapePressed ()
 
EventSignal< WMouseEvent > & clicked ()
 
EventSignal< WMouseEvent > & doubleClicked ()
 
EventSignal< WMouseEvent > & mouseWentDown ()
 
EventSignal< WMouseEvent > & mouseWentUp ()
 
EventSignal< WMouseEvent > & mouseWentOut ()
 
EventSignal< WMouseEvent > & mouseWentOver ()
 
EventSignal< WMouseEvent > & mouseMoved ()
 
EventSignal< WMouseEvent > & mouseDragged ()
 
EventSignal< WMouseEvent > & mouseWheel ()
 
EventSignal< WTouchEvent > & touchStarted ()
 
EventSignal< WTouchEvent > & touchEnded ()
 
EventSignal< WTouchEvent > & touchMoved ()
 
EventSignal< WGestureEvent > & gestureStarted ()
 
EventSignal< WGestureEvent > & gestureChanged ()
 
EventSignal< WGestureEvent > & gestureEnded ()
 
void setDraggable (const std::string &mimeType, WWidget *dragWidget=nullptr, bool isDragWidgetOnly=false, WObject *sourceWidget=nullptr)
 
void unsetDraggable ()
 
void setMouseOverDelay (int delay)
 
int mouseOverDelay () const
 
virtual void setPopup (bool popup) override
 
virtual void load () override
 
virtual bool isEnabled () const override
 
- Public Member Functions inherited from Wt::WWebWidget
 WWebWidget ()
 
virtual std::vector< WWidget * > children () const override
 
SignalchildrenChanged ()
 
virtual void setPositionScheme (PositionScheme scheme) override
 
virtual PositionScheme positionScheme () const override
 
virtual void setOffsets (const WLength &offset, WFlags< Side > sides=AllSides) override
 
virtual WLength offset (Side s) const override
 
virtual void resize (const WLength &width, const WLength &height) override
 
virtual WLength width () const override
 
virtual WLength height () const override
 
virtual void setMinimumSize (const WLength &width, const WLength &height) override
 
virtual WLength minimumWidth () const override
 
virtual WLength minimumHeight () const override
 
virtual void setMaximumSize (const WLength &width, const WLength &height) override
 
virtual WLength maximumWidth () const override
 
virtual WLength maximumHeight () const override
 
virtual void setLineHeight (const WLength &height) override
 
virtual WLength lineHeight () const override
 
virtual void setFloatSide (Side s) override
 
virtual Side floatSide () const override
 
virtual void setClearSides (WFlags< Side > sides) override
 
virtual WFlags< SideclearSides () const override
 
virtual void setMargin (const WLength &margin, WFlags< Side > sides=AllSides) override
 
virtual WLength margin (Side side) const override
 
virtual void setHiddenKeepsGeometry (bool enabled) override
 
virtual bool hiddenKeepsGeometry () const override
 
virtual void setHidden (bool hidden, const WAnimation &animation=WAnimation()) override
 
virtual bool isHidden () const override
 
virtual bool isVisible () const override
 
virtual void setDisabled (bool disabled) override
 
virtual bool isDisabled () const override
 
virtual bool isPopup () const override
 
virtual void setInline (bool isInline) override
 
virtual bool isInline () const override
 
virtual void setDecorationStyle (const WCssDecorationStyle &style) override
 
virtual WCssDecorationStyledecorationStyle () override
 
virtual void setStyleClass (const WString &styleClass) override
 
virtual WString styleClass () const override
 
virtual void addStyleClass (const WString &styleClass, bool force=false) override
 
virtual void removeStyleClass (const WString &styleClass, bool force=false) override
 
virtual bool hasStyleClass (const WString &styleClass) const override
 
virtual void setVerticalAlignment (AlignmentFlag alignment, const WLength &length=WLength()) override
 
virtual AlignmentFlag verticalAlignment () const override
 
virtual WLength verticalAlignmentLength () const override
 
virtual void setToolTip (const WString &text, TextFormat textFormat=TextFormat::Plain) override
 
virtual void setDeferredToolTip (bool enable, TextFormat textFormat=TextFormat::Plain) override
 
virtual WString toolTip () const override
 
virtual void refresh () override
 
virtual void setAttributeValue (const std::string &name, const WString &value) override
 
virtual WString attributeValue (const std::string &name) const override
 
virtual void setJavaScriptMember (const std::string &name, const std::string &value) override
 
virtual std::string javaScriptMember (const std::string &name) const override
 
virtual void callJavaScriptMember (const std::string &name, const std::string &args) override
 
virtual bool loaded () const override
 
virtual void setId (const std::string &id) override
 
virtual WWidgetfind (const std::string &name) override
 
virtual WWidgetfindById (const std::string &id) override
 
virtual void setSelectable (bool selectable) override
 
virtual void doJavaScript (const std::string &javascript) override
 
virtual const std::string id () const override
 
void setLoadLaterWhenInvisible (bool)
 
std::string htmlTagName () const
 
void setHtmlTagName (const std::string &tag)
 
virtual void setCanReceiveFocus (bool enabled) override
 
virtual bool canReceiveFocus () const override
 
virtual bool setFirstFocus () override
 
virtual void setFocus (bool focus) override
 
virtual bool hasFocus () const override
 
virtual void setTabIndex (int index) override
 
virtual int tabIndex () const override
 
EventSignalblurred ()
 
EventSignalfocussed ()
 
virtual bool scrollVisibilityEnabled () const finaloverride
 
virtual void setScrollVisibilityEnabled (bool enabled) finaloverride
 
virtual int scrollVisibilityMargin () const finaloverride
 
virtual void setScrollVisibilityMargin (int margin) finaloverride
 
virtual Signal< bool > & scrollVisibilityChanged () finaloverride
 
virtual bool isScrollVisible () const finaloverride
 
virtual void setThemeStyleEnabled (bool enabled) finaloverride
 
virtual bool isThemeStyleEnabled () const finaloverride
 
virtual void setObjectName (const std::string &name) override
 
- Public Member Functions inherited from Wt::WWidget
virtual ~WWidget ()
 
WWidgetparent () const
 
std::unique_ptr< WWidgetremoveFromParent ()
 
void setWidth (const WLength &width)
 
void setHeight (const WLength &height)
 
virtual void positionAt (const WWidget *widget, Orientation orientation=Orientation::Vertical)
 
virtual void toggleStyleClass (const WString &styleClass, bool add, bool force=false)
 
std::string jsRef () const
 
void setFocus ()
 
virtual void acceptDrops (const std::string &mimeType, const WString &hoverStyleClass=WString())
 
virtual void stopAcceptDrops (const std::string &mimeType)
 
virtual void htmlText (std::ostream &out)
 
bool isRendered () const
 
void hide ()
 
void animateHide (const WAnimation &animation)
 
void show ()
 
void animateShow (const WAnimation &animation)
 
void enable ()
 
void disable ()
 
bool layoutSizeAware () const
 
- Public Member Functions inherited from Wt::WObject
void addChild (std::unique_ptr< WObject > child)
 
Child * addChild (std::unique_ptr< Child > child)
 
std::unique_ptr< WObjectremoveChild (WObject *child)
 
virtual std::string objectName () const
 
void resetLearnedSlots ()
 
void resetLearnedSlot (void(T::*method)())
 
WStatelessSlot * implementStateless (void(T::*method)())
 
WStatelessSlot * implementStateless (void(T::*method)(), void(T::*undoMethod)())
 
void isNotStateless ()
 
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
 
- Public Member Functions inherited from Wt::Core::observable
 observable () noexcept
 
virtual ~observable ()
 

Additional Inherited Members

- Public Types inherited from Wt::WObject
typedef void(WObject::* Method) ()
 
- Static Public Member Functions inherited from Wt::WWebWidget
static std::string jsStringLiteral (const std::string &v, char delimiter= '\'')
 
- Static Public Member Functions inherited from Wt::WWidget
static WString tr (const char *key)
 
- Protected Member Functions inherited from Wt::WInteractWidget
virtual void propagateSetEnabled (bool enabled) override
 
- Protected Member Functions inherited from Wt::WWebWidget
virtual void enableAjax () override
 
virtual WStatelessSlot * getStateless (Method method) override
 
virtual void render (WFlags< RenderFlag > flags) override
 
- Protected Member Functions inherited from Wt::WWidget
void setLayoutSizeAware (bool sizeAware)
 
virtual void layoutSizeChanged (int width, int height)
 
 WWidget ()
 
virtual void dropEvent (WDropEvent dropEvent)
 
virtual int boxPadding (Orientation orientation) const
 
virtual int boxBorder (Orientation orientation) const
 
void scheduleRender (WFlags< RepaintFlag > flags=None)
 

Detailed Description

A widget that demonstrates a times series chart.

Definition at line 29 of file ChartsExample.h.

Constructor & Destructor Documentation

TimeSeriesExample::TimeSeriesExample ( )

Creates the time series scatter plot example.

Definition at line 198 of file ChartsExample.C.

198  :
200 {
201  this->addWidget(cpp14::make_unique<WText>(WString::tr("scatter plot")));
202 
203  std::shared_ptr<WAbstractItemModel> model
204  = readCsvFile(WApplication::appRoot() + "timeseries.csv", this);
205 
206  if (!model)
207  return;
208 
209  /*
210  * Parses the first column as dates, to be able to use a date scale
211  */
212  for (int i = 0; i < model->rowCount(); ++i) {
213  WString s = asString(model->data(i, 0));
214  WDate d = WDate::fromString(s, "dd/MM/yy");
215  model->setData(i, 0, d);
216  }
217 
218  // Show a view that allows editing of the model.
219  auto *w = this->addWidget(cpp14::make_unique<WContainerWidget>());
220  auto *table = w->addWidget(cpp14::make_unique<WTableView>());
221 
222  table->setMargin(10, Side::Top | Side::Bottom);
223  table->setMargin(WLength::Auto, Side::Left | Side::Right);
224 
225  table->setModel(model);
226  table->setSortingEnabled(false); // Does not make much sense for time series
227  table->setColumnResizeEnabled(true);
228  table->setSelectionMode(SelectionMode::None);
229  table->setAlternatingRowColors(true);
230  table->setColumnAlignment(0, AlignmentFlag::Center);
231  table->setHeaderAlignment(0, AlignmentFlag::Center);
232  table->setRowHeight(22);
233 
234  // Editing does not really work without Ajax, it would require an
235  // additional button somewhere to confirm the edited value.
236  if (WApplication::instance()->environment().ajax()) {
237  table->resize(800, 20 + 5*22);
238  table->setEditTriggers(EditTrigger::SingleClicked);
239  } else {
240  table->resize(800, 20 + 5*22 + 25);
241  table->setEditTriggers(EditTrigger::None);
242  }
243 
244  std::shared_ptr<WItemDelegate> delegate
245  = std::make_shared<WItemDelegate>();
246  delegate->setTextFormat("%.1f");
247  table->setItemDelegate(delegate);
248 
249  std::shared_ptr<WItemDelegate> delegateColumn
250  = std::make_shared<WItemDelegate>();
251  table->setItemDelegateForColumn(0, delegateColumn);
252 
253  table->setColumnWidth(0, 80);
254  for (int i = 1; i < model->columnCount(); ++i)
255  table->setColumnWidth(i, 90);
256 
257  /*
258  * Create the scatter plot.
259  */
260  WCartesianChart *chart = this->addWidget(cpp14::make_unique<WCartesianChart>());
261  //chart->setPreferredMethod(WPaintedWidget::PngImage);
262  //chart->setBackground(gray);
263  chart->setModel(model); // set the model
264  chart->setXSeriesColumn(0); // set the column that holds the X data
265  chart->setLegendEnabled(true); // enable the legend
266  chart->setZoomEnabled(true);
267  chart->setPanEnabled(true);
268 
269  chart->setType(ChartType::Scatter); // set type to ScatterPlot
270  chart->axis(Axis::X).setScale(AxisScale::Date); // set scale of X axis to DateScale
271 
272  // Automatically layout chart (space for axes, legend, ...)
273  chart->setAutoLayoutEnabled();
274 
275  chart->setBackground(WColor(200,200,200));
276  /*
277  * Add first two columns as line series
278  */
279  for (int i = 1; i < 3; ++i) {
280  std::unique_ptr<WDataSeries> s
281  = cpp14::make_unique<WDataSeries>(i, SeriesType::Line);
282  s->setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
283  chart->addSeries(std::move(s));
284  }
285 
286  chart->resize(800, 400); // WPaintedWidget must be given explicit size
287 
288  chart->setMargin(10, Side::Top | Side::Bottom); // add margin vertically
289  chart->setMargin(WLength::Auto, Side::Left | Side::Right); // center horizontally
290 
291  this->addWidget(cpp14::make_unique<ChartConfig>(chart));
292 }
void setPanEnabled(bool pan=true)
void addSeries(std::unique_ptr< WDataSeries > series)
WAxis & axis(Axis axis)
void setType(ChartType type)
virtual void setMargin(const WLength &margin, WFlags< Side > sides=AllSides) override
void setZoomEnabled(bool zoom=true)
void setBackground(const WBrush &background)
virtual void resize(const WLength &width, const WLength &height) override
void setScale(AxisScale scale)
void setXSeriesColumn(int modelColumn)
WString asString(const cpp17::any &v, const WString &formatString=WString())
void setModel(const std::shared_ptr< WAbstractItemModel > &model)
void setAutoLayoutEnabled(bool enabled=true)
void setLegendEnabled(bool enabled)
virtual void addWidget(std::unique_ptr< WWidget > widget)

The documentation for this class was generated from the following files:

Generated on Fri Nov 24 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.11