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 
18 #ifndef vtkChart_h
19 #define vtkChart_h
20 
21 #include "vtkChartsCoreModule.h" // For export macro
22 #include "vtkContextItem.h"
23 #include "vtkContextScene.h" // For SelectionModifier
24 #include "vtkRect.h" // For vtkRectf
25 #include "vtkSmartPointer.h" // For SP ivars
26 #include "vtkStdString.h" // For vtkStdString ivars
27 
28 VTK_ABI_NAMESPACE_BEGIN
29 class vtkTransform2D;
30 class vtkContextScene;
31 class vtkPlot;
32 class vtkAxis;
33 class vtkBrush;
34 class vtkTextProperty;
35 class vtkChartLegend;
36 
37 class vtkInteractorStyle;
38 class vtkAnnotationLink;
39 
40 class VTKCHARTSCORE_EXPORT vtkChart : public vtkContextItem
41 {
42 public:
43  vtkTypeMacro(vtkChart, vtkContextItem);
44  void PrintSelf(ostream& os, vtkIndent indent) override;
45 
49  enum
50  {
53  BAR,
55  BAG,
57  AREA
58  };
59 
74  enum
75  {
76  PAN = 0,
80  SELECT_RECTANGLE = SELECT,
84  ACTION_TYPES_COUNT
85  };
86 
90  enum EventIds
91  {
92  UpdateRange = 1002
93  };
94 
98  bool Paint(vtkContext2D* painter) override = 0;
99 
103  virtual vtkPlot* AddPlot(int type);
104 
108  virtual vtkIdType AddPlot(vtkPlot* plot);
109 
114  virtual bool RemovePlot(vtkIdType index);
115 
121  virtual bool RemovePlotInstance(vtkPlot* plot);
122 
126  virtual void ClearPlots();
127 
132 
137 
142  virtual vtkAxis* GetAxis(int axisIndex);
143 
148  virtual void SetAxis(int axisIndex, vtkAxis*);
149 
154 
159  virtual void RecalculateBounds();
160 
168  enum
169  {
172  SELECTION_COLUMNS
173  };
174 
176 
184  virtual void SetSelectionMethod(int method);
185  virtual int GetSelectionMethod();
187 
192 
194 
197  vtkGetObjectMacro(AnnotationLink, vtkAnnotationLink);
199 
201 
204  vtkSetVector2Macro(Geometry, int);
205  vtkGetVector2Macro(Geometry, int);
207 
209 
212  vtkSetVector2Macro(Point1, int);
213  vtkGetVector2Macro(Point1, int);
215 
217 
220  vtkSetVector2Macro(Point2, int);
221  vtkGetVector2Macro(Point2, int);
223 
225 
228  virtual void SetShowLegend(bool visible);
229  virtual bool GetShowLegend();
231 
237 
239 
242  virtual void SetTitle(const vtkStdString& title);
245 
247 
250  vtkGetObjectMacro(TitleProperties, vtkTextProperty);
252 
254 
257  void SetBottomBorder(int border);
258  void SetTopBorder(int border);
259  void SetLeftBorder(int border);
260  void SetRightBorder(int border);
262 
266  void SetBorders(int left, int bottom, int right, int top);
267 
273  virtual void SetSize(const vtkRectf& rect);
274 
279 
283  enum
284  {
285  FILL_SCENE, // Attempt to fill the entire scene.
286  FILL_RECT, // Attempt to supply the supplied vtkRectf in Size.
287  AXES_TO_RECT // Put the corners of the axes on the vtkRectf in Size.
288  };
289 
291 
296  vtkSetMacro(LayoutStrategy, int);
297  vtkGetMacro(LayoutStrategy, int);
299 
301 
305  virtual void SetAutoSize(bool isAutoSized)
306  {
307  this->LayoutStrategy = isAutoSized ? vtkChart::FILL_SCENE : vtkChart::FILL_RECT;
308  }
309  virtual bool GetAutoSize() { return this->LayoutStrategy == vtkChart::FILL_SCENE ? true : false; }
311 
313 
321  vtkSetMacro(RenderEmpty, bool);
322  vtkGetMacro(RenderEmpty, bool);
324 
335  virtual void SetActionToButton(int action, int button);
336 
341  virtual int GetActionToButton(int action);
342 
348  virtual void SetClickActionToButton(int action, int button);
349 
355  virtual int GetClickActionToButton(int action);
356 
358 
364 
366 
370  vtkSetClampMacro(
372  vtkGetMacro(SelectionMode, int);
374 
375 protected:
377  ~vtkChart() override;
378 
386 
391 
396 
397  void AxisRangeForwarderCallback(vtkObject*, unsigned long, void*);
398 
403 
407  int Geometry[2];
408 
412  int Point1[2];
413 
417  int Point2[2];
418 
422  int Borders[4];
423 
428 
433 
438 
440  // The layout strategy to employ when fitting the chart into the space.
443 
448 
449  // The mode when the chart is doing selection.
451 
452  // How plot selections are handled, SELECTION_ROWS (default) or
453  // SELECTION_PLOTS - based on the plot that created the selection.
455 
457 
461  {
462  public:
464  enum
465  {
466  MaxAction = 6
467  };
468  short& Pan() { return Data[0]; }
469  short& Zoom() { return Data[1]; }
470  short& ZoomAxis() { return Data[2]; }
471  short& Select() { return Data[3]; }
472  short& SelectPolygon() { return Data[4]; }
473  short& ClickAndDrag() { return Data[5]; }
474  short& operator[](int index) { return Data[index]; }
475  short Data[MaxAction];
476  };
478  {
479  public:
481  short& Notify() { return Data[0]; }
482  short& Select() { return Data[1]; }
483  short& operator[](int index) { return Data[index]; }
484  short Data[2];
485  };
487 
490 
491 private:
492  vtkChart(const vtkChart&) = delete;
493  void operator=(const vtkChart&) = delete;
494 };
495 
496 VTK_ABI_NAMESPACE_END
497 #endif // vtkChart_h
takes care of drawing 2D axes
Definition: vtkAxis.h:61
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:30
draw the chart legend
Hold mouse action mappings.
Definition: vtkChart.h:461
short & SelectPolygon()
Definition: vtkChart.h:472
short & ClickAndDrag()
Definition: vtkChart.h:473
short & operator[](int index)
Definition: vtkChart.h:474
short & operator[](int index)
Definition: vtkChart.h:483
Factory class for drawing 2D charts.
Definition: vtkChart.h:41
MouseClickActions ActionsClick
Definition: vtkChart.h:489
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:305
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:441
virtual void SetTitle(const vtkStdString &title)
Get/set the title text of the chart.
vtkStdString Title
The title of the chart.
Definition: vtkChart.h:432
vtkTextProperty * TitleProperties
The text properties associated with the chart.
Definition: vtkChart.h:437
@ SELECT_POLYGON
Definition: vtkChart.h:81
@ CLICK_AND_DRAG
Definition: vtkChart.h:82
@ ZOOM_AXIS
Definition: vtkChart.h:78
@ SELECT
Definition: vtkChart.h:79
@ ZOOM
Definition: vtkChart.h:77
@ NOTIFY
Definition: vtkChart.h:83
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:309
int SelectionMethod
Definition: vtkChart.h:454
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:488
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:402
vtkRectf GetSize()
Get the current size of the chart.
@ FUNCTIONALBAG
Definition: vtkChart.h:56
@ LINE
Definition: vtkChart.h:51
@ STACKED
Definition: vtkChart.h:54
@ POINTS
Definition: vtkChart.h:52
void SetBottomBorder(int border)
Set/get the borders of the chart (space in pixels around the chart).
@ SELECTION_PLOTS
Definition: vtkChart.h:171
@ SELECTION_ROWS
Definition: vtkChart.h:170
virtual int GetClickActionToButton(int action)
Get the mouse button associated with the supplied click action.
vtkRectf Size
Definition: vtkChart.h:439
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:447
virtual void SetClickActionToButton(int action, int button)
Assign action types to single mouse clicks.
@ FILL_SCENE
Definition: vtkChart.h:285
@ FILL_RECT
Definition: vtkChart.h:286
EventIds
Enum of event type that are triggered by the charts.
Definition: vtkChart.h:91
virtual bool RemovePlotInstance(vtkPlot *plot)
Remove the given plot.
int SelectionMode
Definition: vtkChart.h:450
void SetTopBorder(int border)
Set/get the borders of the chart (space in pixels around the chart).
bool RenderEmpty
Definition: vtkChart.h:442
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:427
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:50
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:29
provide event-driven interface to the rendering window (defines trackball mode)
abstract base class for most VTK objects
Definition: vtkObject.h:52
Abstract class for 2D plots.
Definition: vtkPlot.h:44
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:29
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