VTK  9.4.20241121
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#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
137
138VTK_ABI_NAMESPACE_BEGIN
139class vtkTransform2D;
140class vtkContextScene;
141class vtkPlot;
142class vtkAxis;
143class vtkBrush;
144class vtkTextProperty;
145class vtkChartLegend;
146
149
150class VTKCHARTSCORE_EXPORT VTK_MARSHALAUTO vtkChart : public vtkContextItem
151{
152public:
153 vtkTypeMacro(vtkChart, vtkContextItem);
154 void PrintSelf(ostream& os, vtkIndent indent) override;
155
159 enum
160 {
167 AREA
168 };
169
184 enum
185 {
186 PAN = 0,
190 SELECT_RECTANGLE = SELECT,
194 ACTION_TYPES_COUNT
195 };
196
201 {
202 UpdateRange = 1002
203 };
204
208 bool Paint(vtkContext2D* painter) override = 0;
209
213 virtual vtkPlot* AddPlot(int type);
214
218 virtual vtkIdType AddPlot(vtkPlot* plot);
219
224 virtual bool RemovePlot(vtkIdType index);
225
231 virtual bool RemovePlotInstance(vtkPlot* plot);
232 bool RemovePlot(vtkPlot* plot) { return this->RemovePlotInstance(plot); }
233
237 virtual void ClearPlots();
238 void RemoveAllPlots() { this->ClearPlots(); }
239
243 virtual vtkPlot* GetPlot(vtkIdType index);
244
249
254 virtual vtkAxis* GetAxis(int axisIndex);
255
260 virtual void SetAxis(int axisIndex, vtkAxis*);
261
266
271 virtual void RecalculateBounds();
272
280 enum
281 {
284 SELECTION_COLUMNS
285 };
286
288
296 virtual void SetSelectionMethod(int method);
297 virtual int GetSelectionMethod();
299
304
306
309 vtkGetObjectMacro(AnnotationLink, vtkAnnotationLink);
311
313
316 vtkSetVector2Macro(Geometry, int);
317 vtkGetVector2Macro(Geometry, int);
319
321
324 vtkSetVector2Macro(Point1, int);
325 vtkGetVector2Macro(Point1, int);
327
329
332 vtkSetVector2Macro(Point2, int);
333 vtkGetVector2Macro(Point2, int);
335
337
340 virtual void SetShowLegend(bool visible);
341 virtual bool GetShowLegend();
343
349
351
354 virtual void SetTitle(const vtkStdString& title);
357
359
362 vtkGetObjectMacro(TitleProperties, vtkTextProperty);
364
366
369 void SetBottomBorder(int border);
370 void SetTopBorder(int border);
371 void SetLeftBorder(int border);
372 void SetRightBorder(int border);
374
378 void SetBorders(int left, int bottom, int right, int top);
379
385 virtual void SetSize(const vtkRectf& rect);
386
391
395 enum
396 {
397 FILL_SCENE, // Attempt to fill the entire scene.
398 FILL_RECT, // Attempt to supply the supplied vtkRectf in Size.
399 AXES_TO_RECT // Put the corners of the axes on the vtkRectf in Size.
400 };
401
403
408 vtkSetMacro(LayoutStrategy, int);
409 vtkGetMacro(LayoutStrategy, int);
411
413
417 virtual void SetAutoSize(bool isAutoSized)
418 {
419 this->LayoutStrategy = isAutoSized ? vtkChart::FILL_SCENE : vtkChart::FILL_RECT;
420 }
421 virtual bool GetAutoSize() { return this->LayoutStrategy == vtkChart::FILL_SCENE ? true : false; }
423
425
433 vtkSetMacro(RenderEmpty, bool);
434 vtkGetMacro(RenderEmpty, bool);
436
447 virtual void SetActionToButton(int action, int button);
448
453 virtual int GetActionToButton(int action);
454
460 virtual void SetClickActionToButton(int action, int button);
461
467 virtual int GetClickActionToButton(int action);
468
470
476
478
482 vtkSetClampMacro(
484 vtkGetMacro(SelectionMode, int);
486
487protected:
489 ~vtkChart() override;
490
498
503
508
509 void AxisRangeForwarderCallback(vtkObject*, unsigned long, void*);
510
515
519 int Geometry[2];
520
524 int Point1[2];
525
529 int Point2[2];
530
534 int Borders[4];
535
540
545
550
552 // The layout strategy to employ when fitting the chart into the space.
555
560
561 // The mode when the chart is doing selection.
563
564 // How plot selections are handled, SELECTION_ROWS (default) or
565 // SELECTION_PLOTS - based on the plot that created the selection.
567
569
573 {
574 public:
576 enum
577 {
578 MaxAction = 6
579 };
580 short& Pan() { return Data[0]; }
581 short& Zoom() { return Data[1]; }
582 short& ZoomAxis() { return Data[2]; }
583 short& Select() { return Data[3]; }
584 short& SelectPolygon() { return Data[4]; }
585 short& ClickAndDrag() { return Data[5]; }
586 short& operator[](int index) { return Data[index]; }
587 short Data[MaxAction];
588 };
590 {
591 public:
593 short& Notify() { return Data[0]; }
594 short& Select() { return Data[1]; }
595 short& operator[](int index) { return Data[index]; }
596 short Data[2];
597 };
599
602
603private:
604 vtkChart(const vtkChart&) = delete;
605 void operator=(const vtkChart&) = delete;
606};
607
608VTK_ABI_NAMESPACE_END
609#endif // vtkChart_h
takes care of drawing 2D axes
Definition vtkAxis.h:171
provides a brush that fills shapes drawn by vtkContext2D.
Definition vtkBrush.h:90
draw the chart legend
Hold mouse action mappings.
Definition vtkChart.h:573
short & operator[](int index)
Definition vtkChart.h:586
short & SelectPolygon()
Definition vtkChart.h:584
short & operator[](int index)
Definition vtkChart.h:595
Factory class for drawing 2D charts.
Definition vtkChart.h:151
virtual vtkPlot * AddPlot(int type)
Add a plot to the chart, defaults to using the name of the y column.
MouseClickActions ActionsClick
Definition vtkChart.h:601
void AxisRangeForwarderCallback(vtkObject *, unsigned long, void *)
bool RemovePlot(vtkPlot *plot)
Definition vtkChart.h:232
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:417
virtual bool GetShowLegend()
Set/get whether the chart should draw a legend.
virtual vtkStdString GetTitle()
Get/set the title text of the chart.
virtual void ClearPlots()
Remove all plots from the chart.
int LayoutStrategy
Definition vtkChart.h:553
virtual void SetTitle(const vtkStdString &title)
Get/set the title text of the chart.
virtual vtkChartLegend * GetLegend()
Get the legend for the chart, if available.
vtkStdString Title
The title of the chart.
Definition vtkChart.h:544
vtkTextProperty * TitleProperties
The text properties associated with the chart.
Definition vtkChart.h:549
@ SELECT_POLYGON
Definition vtkChart.h:191
@ CLICK_AND_DRAG
Definition vtkChart.h:192
@ ZOOM_AXIS
Definition vtkChart.h:188
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:421
int SelectionMethod
Definition vtkChart.h:566
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:600
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:514
vtkRectf GetSize()
Get the current size of the chart.
@ FUNCTIONALBAG
Definition vtkChart.h:166
void SetBottomBorder(int border)
Set/get the borders of the chart (space in pixels around the chart).
@ SELECTION_PLOTS
Definition vtkChart.h:283
@ SELECTION_ROWS
Definition vtkChart.h:282
virtual int GetClickActionToButton(int action)
Get the mouse button associated with the supplied click action.
vtkRectf Size
Definition vtkChart.h:551
virtual void SetSelectionMethod(int method)
Set the selection method, which controls how selections are handled by the chart.
vtkSmartPointer< vtkBrush > BackgroundBrush
Brush to use for drawing the background.
Definition vtkChart.h:559
virtual void SetClickActionToButton(int action, int button)
Assign action types to single mouse clicks.
@ FILL_SCENE
Definition vtkChart.h:397
@ FILL_RECT
Definition vtkChart.h:398
EventIds
Enum of event type that are triggered by the charts.
Definition vtkChart.h:201
virtual bool RemovePlotInstance(vtkPlot *plot)
Remove the given plot.
int SelectionMode
Definition vtkChart.h:562
void SetTopBorder(int border)
Set/get the borders of the chart (space in pixels around the chart).
bool RenderEmpty
Definition vtkChart.h:554
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 vtkAxis * GetAxis(int axisIndex)
Get the axis specified by axisIndex.
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.
void RemoveAllPlots()
Definition vtkChart.h:238
virtual vtkPlot * GetPlot(vtkIdType index)
Get the plot at the specified index, returns null if the index is invalid.
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 ...
vtkBrush * GetBackgroundBrush()
Set/Get the brush to use for the background color.
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:539
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.
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:154
Hold a reference to a vtkObjectBase instance.
Wrapper around std::string to keep symbols short.
represent text properties.
describes linear transformations via a 3x3 matrix
int vtkIdType
Definition vtkType.h:315
#define VTK_MARSHALAUTO