VTK  9.7.1
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 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
28 
29 VTK_ABI_NAMESPACE_BEGIN
30 class vtkTransform2D;
31 class vtkContextScene;
32 class vtkPlot;
33 class vtkAxis;
34 class vtkBrush;
35 class vtkTextProperty;
36 class vtkChartLegend;
37 
38 class vtkInteractorStyle;
39 class vtkAnnotationLink;
40 
41 class VTKCHARTSCORE_EXPORT VTK_MARSHALAUTO vtkChart : public vtkContextItem
42 {
43 public:
44  vtkTypeMacro(vtkChart, vtkContextItem);
45  void PrintSelf(ostream& os, vtkIndent indent) override;
46 
50  enum
51  {
54  BAR,
56  BAG,
58  AREA
59  };
60 
75  enum
76  {
77  PAN = 0,
78  ZOOM = 1,
79  ZOOM_AXIS = 2,
80  SELECT = 3,
81  SELECT_RECTANGLE = SELECT,
82  SELECT_POLYGON = 4,
83  CLICK_AND_DRAG = 5,
84  NOTIFY = 6,
85  ACTION_TYPES_COUNT = 7
86  };
87 
91  enum EventIds
92  {
93  UpdateRange = 1002
94  };
95 
99  bool Paint(vtkContext2D* painter) override = 0;
100 
104  virtual vtkPlot* AddPlot(int type);
105 
109  virtual vtkIdType AddPlot(vtkPlot* plot);
110 
115  virtual bool RemovePlot(vtkIdType index);
116 
122  virtual bool RemovePlotInstance(vtkPlot* plot);
123  bool RemovePlot(vtkPlot* plot) { return this->RemovePlotInstance(plot); }
124 
128  virtual void ClearPlots();
129  void RemoveAllPlots() { this->ClearPlots(); }
130 
134  virtual vtkPlot* GetPlot(vtkIdType index);
135 
139  virtual vtkIdType GetNumberOfPlots();
140 
145  virtual vtkAxis* GetAxis(int axisIndex);
146 
151  virtual void SetAxis(int axisIndex, vtkAxis*);
152 
156  virtual vtkIdType GetNumberOfAxes();
157 
162  virtual void RecalculateBounds();
163 
171  enum
172  {
175  SELECTION_COLUMNS
176  };
177 
179 
187  virtual void SetSelectionMethod(int method);
188  virtual int GetSelectionMethod();
190 
194  virtual void SetAnnotationLink(vtkAnnotationLink* link);
195 
197 
200  vtkGetObjectMacro(AnnotationLink, vtkAnnotationLink);
202 
204 
207  vtkSetVector2Macro(Geometry, int);
208  vtkGetVector2Macro(Geometry, int);
210 
212 
215  vtkSetVector2Macro(Point1, int);
216  vtkGetVector2Macro(Point1, int);
218 
220 
223  vtkSetVector2Macro(Point2, int);
224  vtkGetVector2Macro(Point2, int);
226 
228 
231  virtual void SetShowLegend(bool visible);
232  virtual bool GetShowLegend();
234 
239  virtual vtkChartLegend* GetLegend();
240 
242 
245  virtual void SetTitle(const vtkStdString& title);
246  virtual vtkStdString GetTitle();
248 
250 
253  vtkGetObjectMacro(TitleProperties, vtkTextProperty);
255 
257 
260  void SetBottomBorder(int border);
261  void SetTopBorder(int border);
262  void SetLeftBorder(int border);
263  void SetRightBorder(int border);
265 
269  void SetBorders(int left, int bottom, int right, int top);
270 
276  virtual void SetSize(const vtkRectf& rect);
277 
281  vtkRectf GetSize();
282 
286  enum
287  {
288  FILL_SCENE, // Attempt to fill the entire scene.
289  FILL_RECT, // Attempt to supply the supplied vtkRectf in Size.
290  AXES_TO_RECT // Put the corners of the axes on the vtkRectf in Size.
291  };
292 
294 
299  vtkSetMacro(LayoutStrategy, int);
300  vtkGetMacro(LayoutStrategy, int);
302 
304 
308  virtual void SetAutoSize(bool isAutoSized)
309  {
310  this->LayoutStrategy = isAutoSized ? vtkChart::FILL_SCENE : vtkChart::FILL_RECT;
311  }
312  virtual bool GetAutoSize() { return this->LayoutStrategy == vtkChart::FILL_SCENE ? true : false; }
314 
316 
324  vtkSetMacro(RenderEmpty, bool);
325  vtkGetMacro(RenderEmpty, bool);
327 
338  virtual void SetActionToButton(int action, int button);
339 
344  virtual int GetActionToButton(int action);
345 
351  virtual void SetClickActionToButton(int action, int button);
352 
358  virtual int GetClickActionToButton(int action);
359 
361 
364  void SetBackgroundBrush(vtkBrush* brush);
365  vtkBrush* GetBackgroundBrush();
367 
369 
373  vtkSetClampMacro(
375  vtkGetMacro(SelectionMode, int);
377 
379 
385  int GetSelectionModeFromMouseModifiers(const vtkContextMouseEvent& mouseEvent);
386  static int GetSelectionModeFromMouseModifiers(
387  const vtkContextMouseEvent& mouseEvent, int currentSelectionMode);
389 
390 protected:
391  vtkChart();
392  ~vtkChart() override;
393 
400  bool CalculatePlotTransform(vtkAxis* x, vtkAxis* y, vtkTransform2D* transform);
401 
405  bool CalculateUnscaledPlotTransform(vtkAxis* x, vtkAxis* y, vtkTransform2D* transform);
406 
410  void AttachAxisRangeListener(vtkAxis*);
411 
412  void AxisRangeForwarderCallback(vtkObject*, unsigned long, void*);
413 
418 
422  int Geometry[2];
423 
427  int Point1[2];
428 
432  int Point2[2];
433 
437  int Borders[4];
438 
443 
448 
453 
455  // The layout strategy to employ when fitting the chart into the space.
458 
463 
464  // The mode when the chart is doing selection.
466 
467  // How plot selections are handled, SELECTION_ROWS (default) or
468  // SELECTION_PLOTS - based on the plot that created the selection.
470 
472 
476  {
477  public:
478  MouseActions();
479  enum
480  {
481  MaxAction = 6
482  };
483  short& Pan() { return Data[0]; }
484  short& Zoom() { return Data[1]; }
485  short& ZoomAxis() { return Data[2]; }
486  short& Select() { return Data[3]; }
487  short& SelectPolygon() { return Data[4]; }
488  short& ClickAndDrag() { return Data[5]; }
489  short& operator[](int index) { return Data[index]; }
490  short Data[MaxAction];
491  };
493  {
494  public:
496  short& Notify() { return Data[0]; }
497  short& Select() { return Data[1]; }
498  short& operator[](int index) { return Data[index]; }
499  short Data[2];
500  };
502 
505 
506 private:
507  vtkChart(const vtkChart&) = delete;
508  void operator=(const vtkChart&) = delete;
509 };
510 
511 VTK_ABI_NAMESPACE_END
512 #endif // vtkChart_h
int SelectionMethod
Definition: vtkChart.h:469
MouseClickActions ActionsClick
Definition: vtkChart.h:504
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:27
vtkStdString Title
The title of the chart.
Definition: vtkChart.h:447
vtkTextProperty * TitleProperties
The text properties associated with the chart.
Definition: vtkChart.h:452
short & SelectPolygon()
Definition: vtkChart.h:487
abstract base class for most VTK objects
Definition: vtkObject.h:52
bool RenderEmpty
Definition: vtkChart.h:457
vtkAnnotationLink * AnnotationLink
Our annotation link, used for sharing selections etc.
Definition: vtkChart.h:417
base class for items that are part of a vtkContextScene.
virtual bool Paint(vtkContext2D *painter)
Paint event for the item, called whenever the item needs to be drawn.
bool RemovePlot(vtkPlot *plot)
Definition: vtkChart.h:123
int LayoutStrategy
Definition: vtkChart.h:456
int vtkIdType
Definition: vtkType.h:363
short & ClickAndDrag()
Definition: vtkChart.h:488
int SelectionMode
Definition: vtkChart.h:465
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:49
Factory class for drawing 2D charts.
Definition: vtkChart.h:41
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:30
takes care of drawing 2D axes
Definition: vtkAxis.h:61
Provides a 2D scene for vtkContextItem objects.
data structure to represent mouse events.
a simple class to control print indentation
Definition: vtkIndent.h:28
vtkRectf Size
Definition: vtkChart.h:454
virtual void SetAutoSize(bool isAutoSized)
Set/get whether the chart should automatically resize to fill the current render window.
Definition: vtkChart.h:308
bool ShowLegend
Display the legend?
Definition: vtkChart.h:442
void RemoveAllPlots()
Definition: vtkChart.h:129
void UpdateRange(A &min, A &max, const A &value)
Update an existing min - max range with a new prospective value.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual bool GetAutoSize()
Set/get whether the chart should automatically resize to fill the current render window.
Definition: vtkChart.h:312
describes linear transformations via a 3x3 matrix
Abstract class for 2D plots.
Definition: vtkPlot.h:43
represent text properties.
EventIds
Enum of event type that are triggered by the charts.
Definition: vtkChart.h:91
short & operator[](int index)
Definition: vtkChart.h:489
draw the chart legend
provide event-driven interface to the rendering window (defines trackball mode)
Hold mouse action mappings.
Definition: vtkChart.h:475
vtkSmartPointer< vtkBrush > BackgroundBrush
Brush to use for drawing the background.
Definition: vtkChart.h:462
#define VTK_MARSHALAUTO
short & operator[](int index)
Definition: vtkChart.h:498
MouseActions Actions
Definition: vtkChart.h:503