VTK  9.3.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 
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 
131  virtual vtkPlot* GetPlot(vtkIdType index);
132 
136  virtual vtkIdType GetNumberOfPlots();
137 
142  virtual vtkAxis* GetAxis(int axisIndex);
143 
148  virtual void SetAxis(int axisIndex, vtkAxis*);
149 
153  virtual vtkIdType GetNumberOfAxes();
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 
191  virtual void SetAnnotationLink(vtkAnnotationLink* link);
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 
236  virtual vtkChartLegend* GetLegend();
237 
239 
242  virtual void SetTitle(const vtkStdString& title);
243  virtual vtkStdString GetTitle();
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 
278  vtkRectf GetSize();
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 
361  void SetBackgroundBrush(vtkBrush* brush);
362  vtkBrush* GetBackgroundBrush();
364 
366 
370  vtkSetClampMacro(
372  vtkGetMacro(SelectionMode, int);
374 
375 protected:
376  vtkChart();
377  ~vtkChart() override;
378 
385  bool CalculatePlotTransform(vtkAxis* x, vtkAxis* y, vtkTransform2D* transform);
386 
390  bool CalculateUnscaledPlotTransform(vtkAxis* x, vtkAxis* y, vtkTransform2D* transform);
391 
395  void AttachAxisRangeListener(vtkAxis*);
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:
463  MouseActions();
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
int SelectionMethod
Definition: vtkChart.h:454
MouseClickActions ActionsClick
Definition: vtkChart.h:489
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:28
vtkStdString Title
The title of the chart.
Definition: vtkChart.h:432
vtkTextProperty * TitleProperties
The text properties associated with the chart.
Definition: vtkChart.h:437
short & SelectPolygon()
Definition: vtkChart.h:472
abstract base class for most VTK objects
Definition: vtkObject.h:51
bool RenderEmpty
Definition: vtkChart.h:442
vtkAnnotationLink * AnnotationLink
Our annotation link, used for sharing selections etc.
Definition: vtkChart.h:402
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.
int LayoutStrategy
Definition: vtkChart.h:441
int vtkIdType
Definition: vtkType.h:315
short & ClickAndDrag()
Definition: vtkChart.h:473
int SelectionMode
Definition: vtkChart.h:450
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:49
Factory class for drawing 2D charts.
Definition: vtkChart.h:40
provides a brush that fills shapes drawn by vtkContext2D.
Definition: vtkBrush.h:29
takes care of drawing 2D axes
Definition: vtkAxis.h:60
Provides a 2D scene for vtkContextItem objects.
a simple class to control print indentation
Definition: vtkIndent.h:28
vtkRectf Size
Definition: vtkChart.h:439
virtual void SetAutoSize(bool isAutoSized)
Set/get whether the chart should automatically resize to fill the current render window.
Definition: vtkChart.h:305
bool ShowLegend
Display the legend?
Definition: vtkChart.h:427
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:309
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:90
short & operator[](int index)
Definition: vtkChart.h:474
draw the chart legend
provide event-driven interface to the rendering window (defines trackball mode)
Hold mouse action mappings.
Definition: vtkChart.h:460
void UpdateRange(A &min0, A &max0, const A &value, typename std::enable_if<!std::is_floating_point< A >::value >::type *=nullptr)
vtkSmartPointer< vtkBrush > BackgroundBrush
Brush to use for drawing the background.
Definition: vtkChart.h:447
short & operator[](int index)
Definition: vtkChart.h:483
MouseActions Actions
Definition: vtkChart.h:488