VTK  9.7.20260805
vtkAxis.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
41
42#ifndef vtkAxis_h
43#define vtkAxis_h
44
45#include "vtkChartsCoreModule.h" // For export macro
46#include "vtkContextItem.h"
47#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_8_0
48#include "vtkPen.h" // For vtkPen
49#include "vtkRect.h" // For bounding rect
50#include "vtkSmartPointer.h" // For vtkSmartPointer
51#include "vtkStdString.h" // For vtkStdString ivars
52#include "vtkVector.h" // For position variables
53#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
54
55VTK_ABI_NAMESPACE_BEGIN
56class vtkContext2D;
57class vtkFloatArray;
58class vtkDoubleArray;
59class vtkStringArray;
60class vtkTextProperty;
61
62class VTKCHARTSCORE_EXPORT VTK_MARSHALAUTO vtkAxis : public vtkContextItem
63{
64public:
65 vtkTypeMacro(vtkAxis, vtkContextItem);
66 void PrintSelf(ostream& os, vtkIndent indent) override;
67
80
81 enum
82 {
85 };
86
90 static vtkAxis* New();
91
93
96 virtual void SetPosition(int position);
97 vtkGetMacro(Position, int);
99
101
104 void SetPoint1(const vtkVector2f& pos);
105 void SetPoint1(float x, float y);
107
109
112 vtkGetVector2Macro(Point1, float);
115
117
120 void SetPoint2(const vtkVector2f& pos);
121 void SetPoint2(float x, float y);
123
125
128 vtkGetVector2Macro(Point2, float);
131
136 virtual void SetNumberOfTicks(int numberOfTicks);
137
139
142 vtkGetMacro(NumberOfTicks, int);
144
146
149 vtkSetMacro(TickLength, float);
150 vtkGetMacro(TickLength, float);
152
154
158 vtkGetObjectMacro(LabelProperties, vtkTextProperty);
160
166 virtual void SetMinimum(double minimum);
167
169
174 vtkGetMacro(Minimum, double);
176
182 virtual void SetMaximum(double maximum);
183
185
190 vtkGetMacro(Maximum, double);
192
198 virtual void SetUnscaledMinimum(double minimum);
199
201
204 vtkGetMacro(UnscaledMinimum, double);
206
210 virtual void SetUnscaledMaximum(double maximum);
211
213
216 vtkGetMacro(UnscaledMaximum, double);
218
220
229 virtual void SetRange(double minimum, double maximum);
230 virtual void SetRange(double range[2]);
231 virtual void SetUnscaledRange(double minimum, double maximum);
232 virtual void SetUnscaledRange(double range[2]);
234
236
243 virtual void GetRange(double* range);
244 virtual void GetUnscaledRange(double* range);
246
250 virtual void SetMinimumLimit(double lowest);
251
253
256 vtkGetMacro(MinimumLimit, double);
258
262 virtual void SetMaximumLimit(double highest);
263
265
268 vtkGetMacro(MaximumLimit, double);
270
274 virtual void SetUnscaledMinimumLimit(double lowest);
275
277
280 vtkGetMacro(UnscaledMinimumLimit, double);
282
286 virtual void SetUnscaledMaximumLimit(double highest);
287
289
292 vtkGetMacro(UnscaledMaximumLimit, double);
294
296
299 vtkGetVector2Macro(Margins, int);
301
303
306 vtkSetVector2Macro(Margins, int);
308
310
313 virtual void SetTitle(const vtkStdString& title);
316
318
321 vtkGetObjectMacro(TitleProperties, vtkTextProperty);
323
325
337 vtkGetMacro(LogScaleActive, bool);
339
341
347 vtkGetMacro(LogScale, bool);
348 virtual void SetLogScale(bool logScale);
349 vtkBooleanMacro(LogScale, bool);
351
353
356 vtkSetMacro(GridVisible, bool);
357 vtkGetMacro(GridVisible, bool);
359
361
364 vtkSetMacro(LabelsVisible, bool);
365 vtkGetMacro(LabelsVisible, bool);
367
369
372 vtkSetMacro(RangeLabelsVisible, bool);
373 vtkGetMacro(RangeLabelsVisible, bool);
375
377
380 virtual void SetVerticalLabels(bool verticalLabels);
381 vtkGetMacro(VerticalLabels, bool);
383
385
388 vtkSetMacro(LabelOffset, float);
389 vtkGetMacro(LabelOffset, float);
391
393
396 vtkSetMacro(OverlappingLabels, bool);
397 vtkGetMacro(OverlappingLabels, bool);
399
401
404 vtkSetMacro(TicksVisible, bool);
405 vtkGetMacro(TicksVisible, bool);
407
409
412 vtkSetMacro(AxisVisible, bool);
413 vtkGetMacro(AxisVisible, bool);
415
417
420 vtkSetMacro(TitleVisible, bool);
421 vtkGetMacro(TitleVisible, bool);
423
425
429 virtual void SetPrecision(int precision);
430 vtkGetMacro(Precision, int);
432
444
446
450 virtual void SetLabelFormat(const std::string& format);
451 vtkGetMacro(LabelFormat, std::string);
453
455
460 vtkSetMacro(RangeLabelFormat, std::string);
461 vtkGetMacro(RangeLabelFormat, std::string);
463
465
470 virtual void SetNotation(int notation);
471 vtkGetMacro(Notation, int);
473
477 enum
478 {
479 AUTO = 0, // Automatically scale the axis to view all data that is visible.
480 FIXED, // Use a fixed axis range and make no attempt to rescale.
481 CUSTOM VTK_DEPRECATED_IN_9_8_0("Use tick label settings instead")
482 };
483
485
488 vtkSetMacro(Behavior, int);
489 vtkGetMacro(Behavior, int);
491
493
496 vtkSetSmartPointerMacro(Pen, vtkPen);
497 vtkGetObjectMacro(Pen, vtkPen);
499
501
504 vtkSetSmartPointerMacro(GridPen, vtkPen);
505 vtkGetObjectMacro(GridPen, vtkPen);
507
509
516 vtkSetMacro(TickLabelAlgorithm, int);
517 vtkGetMacro(TickLabelAlgorithm, int);
519
521
525 vtkSetMacro(ScalingFactor, double);
526 vtkGetMacro(ScalingFactor, double);
527 vtkSetMacro(Shift, double);
528 vtkGetMacro(Shift, double);
530
535 void Update() override;
536
540 bool Paint(vtkContext2D* painter) override;
541
548 virtual void AutoScale();
549
555
561
567
572
580 virtual bool SetCustomTickPositions(vtkDoubleArray* positions, vtkStringArray* labels = nullptr);
581
589
595 static double NiceNumber(double number, bool roundUp);
596
601 static double NiceMinMax(double& min, double& max, float pixelRange, float tickPixelSpacing);
602
608
612 bool Hit(const vtkContextMouseEvent& mouse) override;
613
614protected:
616 ~vtkAxis() override;
617
626 void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
627
631 virtual void GenerateTickLabels(double min, double max);
632
636 virtual void GenerateTickLabels();
637
638 virtual void GenerateLabelFormat(int notation, double n);
639
643 virtual vtkStdString GenerateStdFormatLabel(double value, const std::string& format);
644
648 virtual vtkStdString GenerateSprintfLabel(double value, const std::string& format);
649
654 double CalculateNiceMinMax(double& min, double& max);
655
665 double LogScaleTickMark(double number, bool roundUp, bool& niceValue, int& order);
666
678 virtual void GenerateLogSpacedLinearTicks(int order, double min, double max);
679
691 int order, double min = 1.0, double max = 9.0, bool detailLabels = true);
692
697
698 int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
699 float* Point1; // The position of point 1 (usually the origin)
700 float* Point2; // The position of point 2 (usually the terminus)
702 double TickInterval; // Interval between tick marks in plot space
703 int NumberOfTicks; // The number of tick marks to draw
704 float TickLength; // The length of the tick marks
705 vtkTextProperty* LabelProperties; // Text properties for the labels.
706 double Minimum; // Minimum value of the axis
707 double Maximum; // Maximum values of the axis
708 double MinimumLimit; // Lowest possible value for Minimum
709 double MaximumLimit; // Highest possible value for Maximum
710 double UnscaledMinimum; // UnscaledMinimum value of the axis
711 double UnscaledMaximum; // UnscaledMaximum values of the axis
712 double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
713 double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
714 double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
715 double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
716 int Margins[2]; // Horizontal/vertical margins for the axis
717 vtkStdString Title; // The text label drawn on the axis
718 vtkTextProperty* TitleProperties; // Text properties for the axis title
719 bool LogScale; // *Should* the axis use a log scale?
720 bool LogScaleActive; // *Is* the axis using a log scale?
721 bool GridVisible; // Whether the grid for the axis should be drawn
722 bool LabelsVisible; // Should the axis labels be visible
723 bool RangeLabelsVisible; // Should range labels be visible?
724 bool VerticalLabels; // Draw labels vertically
725 float LabelOffset; // Offset of label from the tick mark
726 bool OverlappingLabels; // Allow labels to overlap
727 bool TicksVisible; // Should the tick marks be visible.
728 bool AxisVisible; // Should the axis line be visible.
729 bool TitleVisible; // Should the title be visible.
730 int Precision; // Numerical precision to use, defaults to 2.
731 int Notation; // The notation to use (standard, scientific, mixed)
732 std::string LabelFormat; // The std::format/printf style format string used for labels.
733 std::string RangeLabelFormat; // The std::format/printf style format string used for range labels.
734 int Behavior; // The behaviour of the axis (auto, fixed, custom).
735 float MaxLabel[2]; // The widest/tallest axis label.
736 bool TitleAppended; // Track if the title is updated when the label formats
737 // are changed in the Extended Axis Labeling algorithm
738
740
746 double Shift;
748
753
758
763
768
773
778
784
789
794
799
804
805private:
806 vtkAxis(const vtkAxis&) = delete;
807 void operator=(const vtkAxis&) = delete;
808
812 bool InRange(double value);
813
817 void UpdateOrientation();
818};
819
820VTK_ABI_NAMESPACE_END
821#endif // vtkAxis_h
virtual void SetUnscaledMaximumLimit(double highest)
Set the logical highest possible value for Maximum, in plot coordinates.
bool Paint(vtkContext2D *painter) override
Paint event for the axis, called whenever the axis needs to be drawn.
virtual vtkStdString GenerateStdFormatLabel(double value, const std::string &format)
Generate label using a std::format style format string.
virtual void SetMinimum(double minimum)
Set the logical minimum value of the axis, in plot coordinates.
vtkVector2f Position1
Definition vtkAxis.h:701
void GenerateLogScaleTickMarks(int order, double min=1.0, double max=9.0, bool detailLabels=true)
Generate tick marks for logarithmic scale for specific order of magnitude.
virtual void SetUnscaledMinimumLimit(double lowest)
Set the logical lowest possible value for Minimum, in plot coordinates.
virtual void GenerateTickLabels()
Generate tick labels from the supplied double array of tick positions.
bool TitleVisible
Definition vtkAxis.h:729
void SetPoint1(float x, float y)
Set point 1 of the axis (in pixels), this is usually the origin.
double UnscaledMaximumLimit
Definition vtkAxis.h:713
bool TitleAppended
Definition vtkAxis.h:736
int Behavior
Definition vtkAxis.h:734
static double NiceNumber(double number, bool roundUp)
Return a "nice number", often defined as 1, 2 or 5.
void SetPoint2(const vtkVector2f &pos)
Set point 2 of the axis (in pixels), this is usually the terminus.
vtkVector2f GetPosition2()
Get point 2 of the axis (in pixels), this is usually the terminus.
std::string RangeLabelFormat
Definition vtkAxis.h:733
static vtkAxis * New()
Creates a 2D Chart object.
virtual void SetNotation(int notation)
Get/set the numerical notation, standard, scientific, fixed, or a std::format/printf style format str...
int Precision
Definition vtkAxis.h:730
void Update() override
Update the geometry of the axis.
int Margins[2]
Definition vtkAxis.h:716
vtkRectf GetBoundingRect(vtkContext2D *painter)
Request the space the axes require to be drawn.
double NonLogUnscaledMinLimit
Definition vtkAxis.h:714
virtual vtkDoubleArray * GetTickPositions()
An array with the positions of the tick marks along the axis line.
vtkVector2f Position2
Definition vtkAxis.h:701
int Position
Definition vtkAxis.h:698
bool UsingNiceMinMax
Hint as to whether a nice min/max was set, otherwise labels may not be present at the top/bottom of t...
Definition vtkAxis.h:783
virtual void SetNumberOfTicks(int numberOfTicks)
Set the number of tick marks for this axis.
virtual vtkStringArray * GetTickLabels()
A string array containing the tick labels for the axis.
virtual void GenerateLogSpacedLinearTicks(int order, double min, double max)
Generate logarithmically-spaced tick marks with linear-style labels.
bool Hit(const vtkContextMouseEvent &mouse) override
Return true if the supplied x, y coordinate is inside the item.
float MaxLabel[2]
Definition vtkAxis.h:735
double CalculateNiceMinMax(double &min, double &max)
Calculate the next "nicest" numbers above and below the current minimum.
int TickLabelAlgorithm
The algorithm being used to tick label placement.
Definition vtkAxis.h:798
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void SetTitle(const vtkStdString &title)
Get/set the title text of the axis.
bool GridVisible
Definition vtkAxis.h:721
double Shift
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition vtkAxis.h:746
double UnscaledMinimumLimit
Definition vtkAxis.h:712
vtkTextProperty * LabelProperties
Definition vtkAxis.h:705
static double NiceMinMax(double &min, double &max, float pixelRange, float tickPixelSpacing)
Static function to calculate "nice" minimum, maximum, and tick spacing values.
float * Point2
Definition vtkAxis.h:700
@ TICK_SIMPLE
Definition vtkAxis.h:83
@ TICK_WILKINSON_EXTENDED
Definition vtkAxis.h:84
virtual void SetUnscaledRange(double range[2])
Set the logical range of the axis, in plot coordinates.
int NumberOfTicks
Definition vtkAxis.h:703
vtkStdString Title
Definition vtkAxis.h:717
void SetPoint1(const vtkVector2f &pos)
Set point 1 of the axis (in pixels), this is usually the origin.
Notations
Enumeration of the axis notations available.
Definition vtkAxis.h:437
@ FIXED_NOTATION
Definition vtkAxis.h:440
@ STD_FORMAT_NOTATION
Definition vtkAxis.h:442
@ PRINTF_NOTATION
Definition vtkAxis.h:441
@ SCIENTIFIC_NOTATION
Definition vtkAxis.h:439
@ STANDARD_NOTATION
Definition vtkAxis.h:438
bool Resized
Flag to indicate that the axis has been resized.
Definition vtkAxis.h:793
double MinimumLimit
Definition vtkAxis.h:708
virtual void SetPosition(int position)
Get/set the position of the axis (LEFT, BOTTOM, RIGHT, TOP, PARALLEL).
double UnscaledMinimum
Definition vtkAxis.h:710
float TickLength
Definition vtkAxis.h:704
virtual void GetRange(double *range)
Get the logical range of the axis, in plot coordinates.
bool RangeLabelsVisible
Definition vtkAxis.h:723
vtkVector2f GetPosition1()
Get point 1 of the axis (in pixels), this is usually the origin.
double TickInterval
Definition vtkAxis.h:702
virtual void SetLabelFormat(const std::string &format)
Get/Set the std::format/printf style format style string used when TickLabelAlgorithm is TICK_SIMPLE ...
virtual void SetMaximumLimit(double highest)
Set the logical highest possible value for Maximum, in plot coordinates.
void SetPoint2(float x, float y)
Set point 2 of the axis (in pixels), this is usually the terminus.
virtual void SetPrecision(int precision)
Get/set the numerical precision to use, default is 2.
vtkSmartPointer< vtkFloatArray > TickScenePositions
Position of tick marks in screen coordinates.
Definition vtkAxis.h:772
virtual void SetMinimumLimit(double lowest)
Set the logical lowest possible value for Minimum, in plot coordinates.
virtual vtkStdString GenerateSprintfLabel(double value, const std::string &format)
Generate label using a printf-style format string.
virtual void RecalculateTickSpacing()
Recalculate the spacing of the tick marks - typically useful to do after scaling the axis.
vtkSmartPointer< vtkPen > Pen
This object stores the vtkPen that controls how the axis is drawn.
Definition vtkAxis.h:757
virtual void SetUnscaledMinimum(double minimum)
Set the logical, unscaled minimum value of the axis, in plot coordinates.
bool VerticalLabels
Definition vtkAxis.h:724
virtual void SetRange(double range[2])
Set the logical range of the axis, in plot coordinates.
bool LabelsVisible
Definition vtkAxis.h:722
void CalculateTitlePosition(vtkVector2f &out)
Calculate the position where the title of the axis would be drawn.
~vtkAxis() override
bool TicksVisible
Definition vtkAxis.h:727
Location
Enumeration of the axis locations in a conventional XY chart.
Definition vtkAxis.h:73
@ TOP
Definition vtkAxis.h:77
@ BOTTOM
Definition vtkAxis.h:75
@ PARALLEL
Definition vtkAxis.h:78
@ RIGHT
Definition vtkAxis.h:76
@ LEFT
Definition vtkAxis.h:74
double Maximum
Definition vtkAxis.h:707
virtual vtkStdString GenerateSimpleLabel(double val)
Generate a single label using the current settings when TickLabelAlgorithm is TICK_SIMPLE.
double Minimum
Definition vtkAxis.h:706
virtual void GenerateTickLabels(double min, double max)
Calculate and assign nice labels/logical label positions.
virtual void SetVerticalLabels(bool verticalLabels)
Get/set whether the labels are drawn vertically, default is false.
int Notation
Definition vtkAxis.h:731
virtual bool SetCustomTickPositions(vtkDoubleArray *positions, vtkStringArray *labels=nullptr)
Set the tick positions, and optionally custom tick labels.
virtual void GenerateLabelFormat(int notation, double n)
virtual void AutoScale()
Use this function to autoscale the axes after setting the minimum and maximum values.
virtual vtkFloatArray * GetTickScenePositions()
An array with the positions of the tick marks along the axis line.
virtual void SetUnscaledMaximum(double maximum)
Set the logical maximum value of the axis, in plot coordinates.
double ScalingFactor
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition vtkAxis.h:745
vtkSmartPointer< vtkPen > GridPen
This object stores the vtkPen that controls how the grid lines are drawn.
Definition vtkAxis.h:762
double NonLogUnscaledMaxLimit
Definition vtkAxis.h:715
float * Point1
Definition vtkAxis.h:699
double MaximumLimit
Definition vtkAxis.h:709
virtual void GetUnscaledRange(double *range)
Get the logical range of the axis, in plot coordinates.
vtkTextProperty * TitleProperties
Definition vtkAxis.h:718
virtual void SetRange(double minimum, double maximum)
Set the logical range of the axis, in plot coordinates.
bool CustomTickLabels
Are we using custom tick labels, or should the axis generate them?
Definition vtkAxis.h:752
void UpdateLogScaleActive(bool updateMinMaxFromUnscaled)
Update whether log scaling will be used for layout and rendering.
virtual vtkStdString GetTitle()
Get/set the title text of the axis.
std::string LabelFormat
Definition vtkAxis.h:732
double LogScaleTickMark(double number, bool roundUp, bool &niceValue, int &order)
Return a tick mark for a logarithmic axis.
bool TickMarksDirty
Mark the tick labels as dirty when the min/max value is changed.
Definition vtkAxis.h:788
float LabelOffset
Definition vtkAxis.h:725
bool AxisVisible
Definition vtkAxis.h:728
vtkSmartPointer< vtkStringArray > TickLabels
The labels for the tick marks.
Definition vtkAxis.h:777
virtual void SetUnscaledRange(double minimum, double maximum)
Set the logical range of the axis, in plot coordinates.
double UnscaledMaximum
Definition vtkAxis.h:711
bool LogScale
Definition vtkAxis.h:719
virtual void SetMaximum(double maximum)
Set the logical maximum value of the axis, in plot coordinates.
virtual void SetLogScale(bool logScale)
Get/set whether the axis should attempt to use a log scale.
@ FIXED
Definition vtkAxis.h:480
@ CUSTOM
Definition vtkAxis.h:481
bool LogScaleActive
Definition vtkAxis.h:720
vtkTimeStamp BuildTime
The point cache is marked dirty until it has been initialized.
Definition vtkAxis.h:803
vtkSmartPointer< vtkDoubleArray > TickPositions
Position of tick marks in screen coordinates.
Definition vtkAxis.h:767
bool OverlappingLabels
Definition vtkAxis.h:726
Class for drawing 2D primitives to a graphical context.
vtkContextItem()=default
data structure to represent mouse events.
dynamic, self-adjusting array of double
dynamic, self-adjusting array of float
a simple class to control print indentation
Definition vtkIndent.h:29
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition vtkPen.h:30
Hold a reference to a vtkObjectBase instance.
Wrapper around std::string to keep symbols short.
a vtkAbstractArray subclass for strings
represent text properties.
record modification and/or execution time
#define VTK_DEPRECATED_IN_9_8_0(reason)
#define VTK_MARSHALAUTO
#define max(a, b)