VTK  9.3.0
vtkChart.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 
27 #ifndef vtkChart_h
28 #define vtkChart_h
29 
30 #include "vtkChartsCoreModule.h" // For export macro
31 #include "vtkContextItem.h"
32 #include "vtkContextScene.h" // For SelectionModifier
33 #include "vtkRect.h" // For vtkRectf
34 #include "vtkSmartPointer.h" // For SP ivars
35 #include "vtkStdString.h" // For vtkStdString ivars
36 
37 VTK_ABI_NAMESPACE_BEGIN
38 class vtkTransform2D;
39 class vtkContextScene;
40 class vtkPlot;
41 class vtkAxis;
42 class vtkBrush;
43 class vtkTextProperty;
44 class vtkChartLegend;
45 
46 class vtkInteractorStyle;
47 class vtkAnnotationLink;
48 
49 class VTKCHARTSCORE_EXPORT vtkChart : public vtkContextItem
50 {
51 public:
52  vtkTypeMacro(vtkChart, vtkContextItem);
53  void PrintSelf(ostream& os, vtkIndent indent) override;
54 
58  enum
59  {
62  BAR,
64  BAG,
66  AREA
67  };
68 
83  enum
84  {
85  PAN = 0,
89  SELECT_RECTANGLE = SELECT,
93  ACTION_TYPES_COUNT
94  };
95 
99  enum EventIds
100  {
101  UpdateRange = 1002
102  };
103 
107  bool Paint(vtkContext2D* painter) override = 0;
108 
112  virtual vtkPlot* AddPlot(int type);
113 
117  virtual vtkIdType AddPlot(vtkPlot* plot);
118 
123  virtual bool RemovePlot(vtkIdType index);
124 
130  virtual bool RemovePlotInstance(vtkPlot* plot);
131 
135  virtual void ClearPlots();
136 
141 
146 
151  virtual vtkAxis* GetAxis(int axisIndex);
152 
157  virtual void SetAxis(int axisIndex, vtkAxis*);
158 
163 
168  virtual void RecalculateBounds();
169 
177  enum
178  {
181  SELECTION_COLUMNS
182  };
183 
185 
193  virtual void SetSelectionMethod(int method);
194  virtual int GetSelectionMethod();
196 
201 
203 
206  vtkGetObjectMacro(AnnotationLink, vtkAnnotationLink);
208 
210 
213  vtkSetVector2Macro(Geometry, int);
214  vtkGetVector2Macro(Geometry, int);
216 
218 
221  vtkSetVector2Macro(Point1, int);
222  vtkGetVector2Macro(Point1, int);
224 
226 
229  vtkSetVector2Macro(Point2, int);
230  vtkGetVector2Macro(Point2, int);
232 
234 
237  virtual void SetShowLegend(bool visible);
238  virtual bool GetShowLegend();
240 
246 
248 
251  virtual void SetTitle(const vtkStdString& title);
254 
256 
259  vtkGetObjectMacro(TitleProperties, vtkTextProperty);
261 
263 
266  void SetBottomBorder(int border);
267  void SetTopBorder(int border);
268  void SetLeftBorder(int border);
269  void SetRightBorder(int border);
271 
275  void SetBorders(int left, int bottom, int right, int top);
276 
282  virtual void SetSize(const vtkRectf& rect);
283 
288 
292  enum
293  {
294  FILL_SCENE, // Attempt to fill the entire scene.
295  FILL_RECT, // Attempt to supply the supplied vtkRectf in Size.
296  AXES_TO_RECT // Put the corners of the axes on the vtkRectf in Size.
297  };
298 
300 
305  vtkSetMacro(LayoutStrategy, int);
306  vtkGetMacro(LayoutStrategy, int);
308 
310 
314  virtual void SetAutoSize(bool isAutoSized)
315  {
316  this->LayoutStrategy = isAutoSized ? vtkChart::FILL_SCENE : vtkChart::FILL_RECT;
317  }
318  virtual bool GetAutoSize() { return this->LayoutStrategy == vtkChart::FILL_SCENE ? true : false; }
320 
322 
330  vtkSetMacro(RenderEmpty, bool);
331  vtkGetMacro(RenderEmpty, bool);
333 
344  virtual void SetActionToButton(int action, int button);
345 
350  virtual int GetActionToButton(int action);
351 
357  virtual void SetClickActionToButton(int action, int button);
358 
364  virtual int GetClickActionToButton(int action);
365 
367 
373 
375 
379  vtkSetClampMacro(
381  vtkGetMacro(SelectionMode, int);
383 
384 protected:
386  ~vtkChart() override;
387 
395 
400 
405 
406  void AxisRangeForwarderCallback(vtkObject*, unsigned long, void*);
407 
412 
416  int Geometry[2];
417 
421  int Point1[2];
422 
426  int Point2[2];
427 
431  int Borders[4];
432 
437 
442 
447 
449  // The layout strategy to employ when fitting the chart into the space.
452 
457 
458  // The mode when the chart is doing selection.
460 
461  // How plot selections are handled, SELECTION_ROWS (default) or
462  // SELECTION_PLOTS - based on the plot that created the selection.
464 
466 
470  {
471  public:
473  enum
474  {
475  MaxAction = 6
476  };
477  short& Pan() { return Data[0]; }
478  short& Zoom() { return Data[1]; }
479  short& ZoomAxis() { return Data[2]; }
480  short& Select() { return Data[3]; }
481  short& SelectPolygon() { return Data[4]; }
482  short& ClickAndDrag() { return Data[5]; }
483  short& operator[](int index) { return Data[index]; }
484  short Data[MaxAction];
485  };
487  {
488  public:
490  short& Notify() { return Data[0]; }
491  short& Select() { return Data[1]; }
492  short& operator[](int index) { return Data[index]; }
493  short Data[2];
494  };
496 
499 
500 private:
501  vtkChart(const vtkChart&) = delete;
502  void operator=(const vtkChart&) = delete;
503 };
504 
505 VTK_ABI_NAMESPACE_END
506 #endif // vtkChart_h
takes care of drawing 2D axes
Definition: vtkAxis.h:70
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:39
draw the chart legend
Hold mouse action mappings.
Definition: vtkChart.h:470
short & SelectPolygon()
Definition: vtkChart.h:481
short & ClickAndDrag()
Definition: vtkChart.h:482
short & operator[](int index)
Definition: vtkChart.h:483
short & operator[](int index)
Definition: vtkChart.h:492
Factory class for drawing 2D charts.
Definition: vtkChart.h:50
MouseClickActions ActionsClick
Definition: vtkChart.h:498
void AxisRangeForwarderCallback(vtkObject *, unsigned long, void *)
virtual void SetSize(const vtkRectf &rect)
Set the size of the chart.
virtual void SetAutoSize(bool isAutoSized)
Set/get whether the chart should automatically resize to fill the current render window.
Definition: vtkChart.h:314
virtual bool GetShowLegend()
Set/get whether the chart should draw a legend.
virtual vtkStdString GetTitle()
Get/set the title text of the chart.
virtual vtkPlot * AddPlot(int type)
Add a plot to the chart, defaults to using the name of the y column.
virtual void ClearPlots()
Remove all plots from the chart.
int LayoutStrategy
Definition: vtkChart.h:450
virtual void SetTitle(const vtkStdString &title)
Get/set the title text of the chart.
vtkStdString Title
The title of the chart.
Definition: vtkChart.h:441
vtkTextProperty * TitleProperties
The text properties associated with the chart.
Definition: vtkChart.h:446
@ SELECT_POLYGON
Definition: vtkChart.h:90
@ CLICK_AND_DRAG
Definition: vtkChart.h:91
@ ZOOM_AXIS
Definition: vtkChart.h:87
@ SELECT
Definition: vtkChart.h:88
@ ZOOM
Definition: vtkChart.h:86
@ NOTIFY
Definition: vtkChart.h:92
bool CalculateUnscaledPlotTransform(vtkAxis *x, vtkAxis *y, vtkTransform2D *transform)
Calculate the unshifted, and unscaled plot transform for the x and y axis.
virtual bool GetAutoSize()
Set/get whether the chart should automatically resize to fill the current render window.
Definition: vtkChart.h:318
int SelectionMethod
Definition: vtkChart.h:463
virtual void SetAnnotationLink(vtkAnnotationLink *link)
Set the vtkAnnotationLink for the chart.
virtual int GetActionToButton(int action)
Get the mouse button associated with the supplied action.
MouseActions Actions
Definition: vtkChart.h:497
void SetRightBorder(int border)
Set/get the borders of the chart (space in pixels around the chart).
vtkAnnotationLink * AnnotationLink
Our annotation link, used for sharing selections etc.
Definition: vtkChart.h:411
vtkRectf GetSize()
Get the current size of the chart.
@ FUNCTIONALBAG
Definition: vtkChart.h:65
@ LINE
Definition: vtkChart.h:60
@ STACKED
Definition: vtkChart.h:63
@ POINTS
Definition: vtkChart.h:61
void SetBottomBorder(int border)
Set/get the borders of the chart (space in pixels around the chart).
@ SELECTION_PLOTS
Definition: vtkChart.h:180
@ SELECTION_ROWS
Definition: vtkChart.h:179
virtual int GetClickActionToButton(int action)
Get the mouse button associated with the supplied click action.
vtkRectf Size
Definition: vtkChart.h:448
virtual void SetSelectionMethod(int method)
Set the selection method, which controls how selections are handled by the chart.
virtual vtkAxis * GetAxis(int axisIndex)
Get the axis specified by axisIndex.
vtkSmartPointer< vtkBrush > BackgroundBrush
Brush to use for drawing the background.
Definition: vtkChart.h:456
virtual void SetClickActionToButton(int action, int button)
Assign action types to single mouse clicks.
@ FILL_SCENE
Definition: vtkChart.h:294
@ FILL_RECT
Definition: vtkChart.h:295
EventIds
Enum of event type that are triggered by the charts.
Definition: vtkChart.h:100
virtual bool RemovePlotInstance(vtkPlot *plot)
Remove the given plot.
int SelectionMode
Definition: vtkChart.h:459
void SetTopBorder(int border)
Set/get the borders of the chart (space in pixels around the chart).
bool RenderEmpty
Definition: vtkChart.h:451
void SetBackgroundBrush(vtkBrush *brush)
Set/Get the brush to use for the background color.
bool Paint(vtkContext2D *painter) override=0
Paint event for the chart, called whenever the chart needs to be drawn.
virtual void SetShowLegend(bool visible)
Set/get whether the chart should draw a legend.
virtual vtkIdType GetNumberOfPlots()
Get the number of plots the chart contains.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void RecalculateBounds()
Request that the chart recalculates the range of its axes.
virtual void SetAxis(int axisIndex, vtkAxis *)
Set the axis specified by axisIndex.
virtual bool RemovePlot(vtkIdType index)
Remove the plot at the specified index, returns true if successful, false if the index was invalid.
virtual vtkChartLegend * GetLegend()
Get the legend for the chart, if available.
virtual vtkIdType GetNumberOfAxes()
Get the number of axes in the current chart.
virtual void SetActionToButton(int action, int button)
Assign action types to mouse buttons.
void AttachAxisRangeListener(vtkAxis *)
Attach axis range listener so we can forward those events at the chart level.
virtual vtkIdType AddPlot(vtkPlot *plot)
Add a plot to the chart.
vtkBrush * GetBackgroundBrush()
Set/Get the brush to use for the background color.
virtual int GetSelectionMethod()
Set the selection method, which controls how selections are handled by the chart.
bool CalculatePlotTransform(vtkAxis *x, vtkAxis *y, vtkTransform2D *transform)
Given the x and y vtkAxis, and a transform, calculate the transform that the points in a chart would ...
virtual vtkPlot * GetPlot(vtkIdType index)
Get the plot at the specified index, returns null if the index is invalid.
void SetLeftBorder(int border)
Set/get the borders of the chart (space in pixels around the chart).
~vtkChart() override
bool ShowLegend
Display the legend?
Definition: vtkChart.h:436
void SetBorders(int left, int bottom, int right, int top)
Set/get the borders of the chart (space in pixels around the chart).
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:59
base class for items that are part of a vtkContextScene.
Provides a 2D scene for vtkContextItem objects.
a simple class to control print indentation
Definition: vtkIndent.h:38
provide event-driven interface to the rendering window (defines trackball mode)
abstract base class for most VTK objects
Definition: vtkObject.h:61
Abstract class for 2D plots.
Definition: vtkPlot.h:53
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:38
represent text properties.
describes linear transformations via a 3x3 matrix
void UpdateRange(A &min0, A &max0, const A &value, typename std::enable_if<!std::is_floating_point< A >::value >::type *=nullptr)
@ top
Definition: vtkX3D.h:502
@ type
Definition: vtkX3D.h:516
@ bottom
Definition: vtkX3D.h:290
@ index
Definition: vtkX3D.h:246
@ title
Definition: vtkX3D.h:500
int vtkIdType
Definition: vtkType.h:315