VTK  9.3.20240418
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 
127 #ifndef vtkChart_h
128 #define vtkChart_h
129 
130 #include "vtkChartsCoreModule.h" // For export macro
131 #include "vtkContextItem.h"
132 #include "vtkContextScene.h" // For SelectionModifier
133 #include "vtkRect.h" // For vtkRectf
134 #include "vtkSmartPointer.h" // For SP ivars
135 #include "vtkStdString.h" // For vtkStdString ivars
136 
137 VTK_ABI_NAMESPACE_BEGIN
138 class vtkTransform2D;
139 class vtkContextScene;
140 class vtkPlot;
141 class vtkAxis;
142 class vtkBrush;
143 class vtkTextProperty;
144 class vtkChartLegend;
145 
146 class vtkInteractorStyle;
147 class vtkAnnotationLink;
148 
149 class VTKCHARTSCORE_EXPORT vtkChart : public vtkContextItem
150 {
151 public:
152  vtkTypeMacro(vtkChart, vtkContextItem);
153  void PrintSelf(ostream& os, vtkIndent indent) override;
154 
158  enum
159  {
166  AREA
167  };
168 
183  enum
184  {
185  PAN = 0,
189  SELECT_RECTANGLE = SELECT,
193  ACTION_TYPES_COUNT
194  };
195 
199  enum EventIds
200  {
201  UpdateRange = 1002
202  };
203 
207  bool Paint(vtkContext2D* painter) override = 0;
208 
212  virtual vtkPlot* AddPlot(int type);
213 
217  virtual vtkIdType AddPlot(vtkPlot* plot);
218 
223  virtual bool RemovePlot(vtkIdType index);
224 
230  virtual bool RemovePlotInstance(vtkPlot* plot);
231 
235  virtual void ClearPlots();
236 
241 
246 
251  virtual vtkAxis* GetAxis(int axisIndex);
252 
257  virtual void SetAxis(int axisIndex, vtkAxis*);
258 
263 
268  virtual void RecalculateBounds();
269 
277  enum
278  {
281  SELECTION_COLUMNS
282  };
283 
285 
293  virtual void SetSelectionMethod(int method);
294  virtual int GetSelectionMethod();
296 
301 
303 
306  vtkGetObjectMacro(AnnotationLink, vtkAnnotationLink);
308 
310 
313  vtkSetVector2Macro(Geometry, int);
314  vtkGetVector2Macro(Geometry, int);
316 
318 
321  vtkSetVector2Macro(Point1, int);
322  vtkGetVector2Macro(Point1, int);
324 
326 
329  vtkSetVector2Macro(Point2, int);
330  vtkGetVector2Macro(Point2, int);
332 
334 
337  virtual void SetShowLegend(bool visible);
338  virtual bool GetShowLegend();
340 
346 
348 
351  virtual void SetTitle(const vtkStdString& title);
354 
356 
359  vtkGetObjectMacro(TitleProperties, vtkTextProperty);
361 
363 
366  void SetBottomBorder(int border);
367  void SetTopBorder(int border);
368  void SetLeftBorder(int border);
369  void SetRightBorder(int border);
371 
375  void SetBorders(int left, int bottom, int right, int top);
376 
382  virtual void SetSize(const vtkRectf& rect);
383 
388 
392  enum
393  {
394  FILL_SCENE, // Attempt to fill the entire scene.
395  FILL_RECT, // Attempt to supply the supplied vtkRectf in Size.
396  AXES_TO_RECT // Put the corners of the axes on the vtkRectf in Size.
397  };
398 
400 
405  vtkSetMacro(LayoutStrategy, int);
406  vtkGetMacro(LayoutStrategy, int);
408 
410 
414  virtual void SetAutoSize(bool isAutoSized)
415  {
416  this->LayoutStrategy = isAutoSized ? vtkChart::FILL_SCENE : vtkChart::FILL_RECT;
417  }
418  virtual bool GetAutoSize() { return this->LayoutStrategy == vtkChart::FILL_SCENE ? true : false; }
420 
422 
430  vtkSetMacro(RenderEmpty, bool);
431  vtkGetMacro(RenderEmpty, bool);
433 
444  virtual void SetActionToButton(int action, int button);
445 
450  virtual int GetActionToButton(int action);
451 
457  virtual void SetClickActionToButton(int action, int button);
458 
464  virtual int GetClickActionToButton(int action);
465 
467 
473 
475 
479  vtkSetClampMacro(
481  vtkGetMacro(SelectionMode, int);
483 
484 protected:
486  ~vtkChart() override;
487 
495 
500 
505 
506  void AxisRangeForwarderCallback(vtkObject*, unsigned long, void*);
507 
512 
516  int Geometry[2];
517 
521  int Point1[2];
522 
526  int Point2[2];
527 
531  int Borders[4];
532 
537 
542 
547 
549  // The layout strategy to employ when fitting the chart into the space.
552 
557 
558  // The mode when the chart is doing selection.
560 
561  // How plot selections are handled, SELECTION_ROWS (default) or
562  // SELECTION_PLOTS - based on the plot that created the selection.
564 
566 
570  {
571  public:
573  enum
574  {
575  MaxAction = 6
576  };
577  short& Pan() { return Data[0]; }
578  short& Zoom() { return Data[1]; }
579  short& ZoomAxis() { return Data[2]; }
580  short& Select() { return Data[3]; }
581  short& SelectPolygon() { return Data[4]; }
582  short& ClickAndDrag() { return Data[5]; }
583  short& operator[](int index) { return Data[index]; }
584  short Data[MaxAction];
585  };
587  {
588  public:
590  short& Notify() { return Data[0]; }
591  short& Select() { return Data[1]; }
592  short& operator[](int index) { return Data[index]; }
593  short Data[2];
594  };
596 
599 
600 private:
601  vtkChart(const vtkChart&) = delete;
602  void operator=(const vtkChart&) = delete;
603 };
604 
605 VTK_ABI_NAMESPACE_END
606 #endif // vtkChart_h
takes care of drawing 2D axes
Definition: vtkAxis.h:170
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:89
draw the chart legend
Hold mouse action mappings.
Definition: vtkChart.h:570
short & SelectPolygon()
Definition: vtkChart.h:581
short & ClickAndDrag()
Definition: vtkChart.h:582
short & operator[](int index)
Definition: vtkChart.h:583
short & operator[](int index)
Definition: vtkChart.h:592
Factory class for drawing 2D charts.
Definition: vtkChart.h:150
MouseClickActions ActionsClick
Definition: vtkChart.h:598
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:414
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:550
virtual void SetTitle(const vtkStdString &title)
Get/set the title text of the chart.
vtkStdString Title
The title of the chart.
Definition: vtkChart.h:541
vtkTextProperty * TitleProperties
The text properties associated with the chart.
Definition: vtkChart.h:546
@ SELECT_POLYGON
Definition: vtkChart.h:190
@ CLICK_AND_DRAG
Definition: vtkChart.h:191
@ ZOOM_AXIS
Definition: vtkChart.h:187
@ SELECT
Definition: vtkChart.h:188
@ NOTIFY
Definition: vtkChart.h:192
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:418
int SelectionMethod
Definition: vtkChart.h:563
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:597
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:511
vtkRectf GetSize()
Get the current size of the chart.
@ FUNCTIONALBAG
Definition: vtkChart.h:165
@ STACKED
Definition: vtkChart.h:163
@ POINTS
Definition: vtkChart.h:161
void SetBottomBorder(int border)
Set/get the borders of the chart (space in pixels around the chart).
@ SELECTION_PLOTS
Definition: vtkChart.h:280
@ SELECTION_ROWS
Definition: vtkChart.h:279
virtual int GetClickActionToButton(int action)
Get the mouse button associated with the supplied click action.
vtkRectf Size
Definition: vtkChart.h:548
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:556
virtual void SetClickActionToButton(int action, int button)
Assign action types to single mouse clicks.
@ FILL_SCENE
Definition: vtkChart.h:394
@ FILL_RECT
Definition: vtkChart.h:395
EventIds
Enum of event type that are triggered by the charts.
Definition: vtkChart.h:200
virtual bool RemovePlotInstance(vtkPlot *plot)
Remove the given plot.
int SelectionMode
Definition: vtkChart.h:559
void SetTopBorder(int border)
Set/get the borders of the chart (space in pixels around the chart).
bool RenderEmpty
Definition: vtkChart.h:551
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:536
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:69
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:108
provide event-driven interface to the rendering window (defines trackball mode)
abstract base class for most VTK objects
Definition: vtkObject.h:162
Abstract class for 2D plots.
Definition: vtkPlot.h:153
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:78
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