VTK  9.4.20241016
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
151#ifndef vtkAxis_h
152#define vtkAxis_h
153
154#include "vtkChartsCoreModule.h" // For export macro
155#include "vtkContextItem.h"
156#include "vtkPen.h" // For vtkPen
157#include "vtkRect.h" // For bounding rect
158#include "vtkSmartPointer.h" // For vtkSmartPointer
159#include "vtkStdString.h" // For vtkStdString ivars
160#include "vtkVector.h" // For position variables
161#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
162
163VTK_ABI_NAMESPACE_BEGIN
164class vtkContext2D;
165class vtkFloatArray;
166class vtkDoubleArray;
167class vtkStringArray;
168class vtkTextProperty;
169
170class VTKCHARTSCORE_EXPORT VTK_MARSHALAUTO vtkAxis : public vtkContextItem
171{
172public:
173 vtkTypeMacro(vtkAxis, vtkContextItem);
174 void PrintSelf(ostream& os, vtkIndent indent) override;
175
181 {
182 LEFT = 0,
186 PARALLEL
187 };
188
189 enum
190 {
191 TICK_SIMPLE = 0,
192 TICK_WILKINSON_EXTENDED
193 };
194
198 static vtkAxis* New();
199
201
204 virtual void SetPosition(int position);
205 vtkGetMacro(Position, int);
207
209
212 void SetPoint1(const vtkVector2f& pos);
213 void SetPoint1(float x, float y);
215
217
220 vtkGetVector2Macro(Point1, float);
223
225
228 void SetPoint2(const vtkVector2f& pos);
229 void SetPoint2(float x, float y);
231
233
236 vtkGetVector2Macro(Point2, float);
239
244 virtual void SetNumberOfTicks(int numberOfTicks);
245
247
250 vtkGetMacro(NumberOfTicks, int);
252
254
257 vtkSetMacro(TickLength, float);
258 vtkGetMacro(TickLength, float);
260
262
266 vtkGetObjectMacro(LabelProperties, vtkTextProperty);
268
274 virtual void SetMinimum(double minimum);
275
277
282 vtkGetMacro(Minimum, double);
284
290 virtual void SetMaximum(double maximum);
291
293
298 vtkGetMacro(Maximum, double);
300
306 virtual void SetUnscaledMinimum(double minimum);
307
309
312 vtkGetMacro(UnscaledMinimum, double);
314
318 virtual void SetUnscaledMaximum(double maximum);
319
321
324 vtkGetMacro(UnscaledMaximum, double);
326
328
337 virtual void SetRange(double minimum, double maximum);
338 virtual void SetRange(double range[2]);
339 virtual void SetUnscaledRange(double minimum, double maximum);
340 virtual void SetUnscaledRange(double range[2]);
342
344
351 virtual void GetRange(double* range);
352 virtual void GetUnscaledRange(double* range);
354
358 virtual void SetMinimumLimit(double lowest);
359
361
364 vtkGetMacro(MinimumLimit, double);
366
370 virtual void SetMaximumLimit(double highest);
371
373
376 vtkGetMacro(MaximumLimit, double);
378
382 virtual void SetUnscaledMinimumLimit(double lowest);
383
385
388 vtkGetMacro(UnscaledMinimumLimit, double);
390
394 virtual void SetUnscaledMaximumLimit(double highest);
395
397
400 vtkGetMacro(UnscaledMaximumLimit, double);
402
404
407 vtkGetVector2Macro(Margins, int);
409
411
414 vtkSetVector2Macro(Margins, int);
416
418
421 virtual void SetTitle(const vtkStdString& title);
424
426
429 vtkGetObjectMacro(TitleProperties, vtkTextProperty);
431
433
445 vtkGetMacro(LogScaleActive, bool);
447
449
455 vtkGetMacro(LogScale, bool);
456 virtual void SetLogScale(bool logScale);
457 vtkBooleanMacro(LogScale, bool);
459
461
464 vtkSetMacro(GridVisible, bool);
465 vtkGetMacro(GridVisible, bool);
467
469
472 vtkSetMacro(LabelsVisible, bool);
473 vtkGetMacro(LabelsVisible, bool);
475
477
480 vtkSetMacro(RangeLabelsVisible, bool);
481 vtkGetMacro(RangeLabelsVisible, bool);
483
485
488 vtkSetMacro(LabelOffset, float);
489 vtkGetMacro(LabelOffset, float);
491
493
496 vtkSetMacro(TicksVisible, bool);
497 vtkGetMacro(TicksVisible, bool);
499
501
504 vtkSetMacro(AxisVisible, bool);
505 vtkGetMacro(AxisVisible, bool);
507
509
512 vtkSetMacro(TitleVisible, bool);
513 vtkGetMacro(TitleVisible, bool);
515
517
521 virtual void SetPrecision(int precision);
522 vtkGetMacro(Precision, int);
524
528 enum
529 {
530 STANDARD_NOTATION = 0,
533 PRINTF_NOTATION
534 };
535
537
541 virtual void SetLabelFormat(const std::string& fmt);
542 vtkGetMacro(LabelFormat, std::string);
544
546
551 vtkSetMacro(RangeLabelFormat, std::string);
552 vtkGetMacro(RangeLabelFormat, std::string);
554
556
561 virtual void SetNotation(int notation);
562 vtkGetMacro(Notation, int);
564
568 enum
569 {
570 AUTO = 0, // Automatically scale the axis to view all data that is visible.
571 FIXED, // Use a fixed axis range and make no attempt to rescale.
572 CUSTOM // Deprecated, use the tick label settings instead.
573 };
574
576
579 vtkSetMacro(Behavior, int);
580 vtkGetMacro(Behavior, int);
582
584
588 vtkGetObjectMacro(Pen, vtkPen);
590
592
596 vtkGetObjectMacro(GridPen, vtkPen);
598
600
607 vtkSetMacro(TickLabelAlgorithm, int);
608 vtkGetMacro(TickLabelAlgorithm, int);
610
612
616 vtkSetMacro(ScalingFactor, double);
617 vtkGetMacro(ScalingFactor, double);
618 vtkSetMacro(Shift, double);
619 vtkGetMacro(Shift, double);
621
626 void Update() override;
627
631 bool Paint(vtkContext2D* painter) override;
632
639 virtual void AutoScale();
640
646
652
658
663
671 virtual bool SetCustomTickPositions(vtkDoubleArray* positions, vtkStringArray* labels = nullptr);
672
680
686 static double NiceNumber(double number, bool roundUp);
687
692 static double NiceMinMax(double& min, double& max, float pixelRange, float tickPixelSpacing);
693
699
703 bool Hit(const vtkContextMouseEvent& mouse) override;
704
705protected:
707 ~vtkAxis() override;
708
717 void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
718
722 virtual void GenerateTickLabels(double min, double max);
723
727 virtual void GenerateTickLabels();
728
729 virtual void GenerateLabelFormat(int notation, double n);
730
734 virtual vtkStdString GenerateSprintfLabel(double value, const std::string& format);
735
740 double CalculateNiceMinMax(double& min, double& max);
741
751 double LogScaleTickMark(double number, bool roundUp, bool& niceValue, int& order);
752
764 virtual void GenerateLogSpacedLinearTicks(int order, double min, double max);
765
777 int order, double min = 1.0, double max = 9.0, bool detailLabels = true);
778
783
784 int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
785 float* Point1; // The position of point 1 (usually the origin)
786 float* Point2; // The position of point 2 (usually the terminus)
788 double TickInterval; // Interval between tick marks in plot space
789 int NumberOfTicks; // The number of tick marks to draw
790 float TickLength; // The length of the tick marks
791 vtkTextProperty* LabelProperties; // Text properties for the labels.
792 double Minimum; // Minimum value of the axis
793 double Maximum; // Maximum values of the axis
794 double MinimumLimit; // Lowest possible value for Minimum
795 double MaximumLimit; // Highest possible value for Maximum
796 double UnscaledMinimum; // UnscaledMinimum value of the axis
797 double UnscaledMaximum; // UnscaledMaximum values of the axis
798 double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
799 double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
800 double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
801 double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
802 int Margins[2]; // Horizontal/vertical margins for the axis
803 vtkStdString Title; // The text label drawn on the axis
804 vtkTextProperty* TitleProperties; // Text properties for the axis title
805 bool LogScale; // *Should* the axis use a log scale?
806 bool LogScaleActive; // *Is* the axis using a log scale?
807 bool GridVisible; // Whether the grid for the axis should be drawn
808 bool LabelsVisible; // Should the axis labels be visible
809 bool RangeLabelsVisible; // Should range labels be visible?
810 float LabelOffset; // Offset of label from the tick mark
811 bool TicksVisible; // Should the tick marks be visible.
812 bool AxisVisible; // Should the axis line be visible.
813 bool TitleVisible; // Should the title be visible.
814 int Precision; // Numerical precision to use, defaults to 2.
815 int Notation; // The notation to use (standard, scientific, mixed)
816 std::string LabelFormat; // The printf-style format string used for labels.
817 std::string RangeLabelFormat; // The printf-style format string used for range labels.
818 int Behavior; // The behaviour of the axis (auto, fixed, custom).
819 float MaxLabel[2]; // The widest/tallest axis label.
820 bool TitleAppended; // Track if the title is updated when the label formats
821 // are changed in the Extended Axis Labeling algorithm
822
824
830 double Shift;
832
837
842
847
852
857
862
868
873
878
883
888
889private:
890 vtkAxis(const vtkAxis&) = delete;
891 void operator=(const vtkAxis&) = delete;
892
896 bool InRange(double value);
897};
898
899VTK_ABI_NAMESPACE_END
900#endif // vtkAxis_h
takes care of drawing 2D axes
Definition vtkAxis.h:171
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 void SetMinimum(double minimum)
Set the logical minimum value of the axis, in plot coordinates.
vtkVector2f Position1
Definition vtkAxis.h:787
vtkSetSmartPointerMacro(GridPen, vtkPen)
Set/get the vtkPen object that controls the way this axis is drawn.
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:813
void SetPoint1(float x, float y)
Set point 1 of the axis (in pixels), this is usually the origin.
double UnscaledMaximumLimit
Definition vtkAxis.h:799
bool TitleAppended
Definition vtkAxis.h:820
int Behavior
Definition vtkAxis.h:818
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:817
static vtkAxis * New()
Creates a 2D Chart object.
virtual void SetNotation(int notation)
Get/set the numerical notation, standard, scientific, fixed, or a printf-style format string.
int Precision
Definition vtkAxis.h:814
void Update() override
Update the geometry of the axis.
vtkRectf GetBoundingRect(vtkContext2D *painter)
Request the space the axes require to be drawn.
double NonLogUnscaledMinLimit
Definition vtkAxis.h:800
virtual vtkDoubleArray * GetTickPositions()
An array with the positions of the tick marks along the axis line.
int Position
Definition vtkAxis.h:784
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:867
virtual void SetNumberOfTicks(int numberOfTicks)
Set the number of tick marks for this axis.
virtual void SetLabelFormat(const std::string &fmt)
Get/Set the printf-style format string used when TickLabelAlgorithm is TICK_SIMPLE and Notation is PR...
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.
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:882
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:807
double Shift
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition vtkAxis.h:830
double UnscaledMinimumLimit
Definition vtkAxis.h:798
vtkTextProperty * LabelProperties
Definition vtkAxis.h:791
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:786
virtual void SetUnscaledRange(double range[2])
Set the logical range of the axis, in plot coordinates.
int NumberOfTicks
Definition vtkAxis.h:789
vtkStdString Title
Definition vtkAxis.h:803
void SetPoint1(const vtkVector2f &pos)
Set point 1 of the axis (in pixels), this is usually the origin.
@ FIXED
Definition vtkAxis.h:571
bool Resized
Flag to indicate that the axis has been resized.
Definition vtkAxis.h:877
double MinimumLimit
Definition vtkAxis.h:794
virtual void SetPosition(int position)
Get/set the position of the axis (LEFT, BOTTOM, RIGHT, TOP, PARALLEL).
double UnscaledMinimum
Definition vtkAxis.h:796
float TickLength
Definition vtkAxis.h:790
virtual void GetRange(double *range)
Get the logical range of the axis, in plot coordinates.
bool RangeLabelsVisible
Definition vtkAxis.h:809
vtkSetSmartPointerMacro(Pen, vtkPen)
Set/get the vtkPen object that controls the way this axis is drawn.
vtkVector2f GetPosition1()
Get point 1 of the axis (in pixels), this is usually the origin.
double TickInterval
Definition vtkAxis.h:788
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:856
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:841
virtual void SetUnscaledMinimum(double minimum)
Set the logical, unscaled minimum value of the axis, in plot coordinates.
virtual void SetRange(double range[2])
Set the logical range of the axis, in plot coordinates.
bool LabelsVisible
Definition vtkAxis.h:808
void CalculateTitlePosition(vtkVector2f &out)
Calculate the position where the title of the axis would be drawn.
~vtkAxis() override
bool TicksVisible
Definition vtkAxis.h:811
@ FIXED_NOTATION
Definition vtkAxis.h:532
@ SCIENTIFIC_NOTATION
Definition vtkAxis.h:531
Location
Enumeration of the axis locations in a conventional XY chart.
Definition vtkAxis.h:181
@ BOTTOM
Definition vtkAxis.h:183
@ RIGHT
Definition vtkAxis.h:184
double Maximum
Definition vtkAxis.h:793
virtual vtkStdString GenerateSimpleLabel(double val)
Generate a single label using the current settings when TickLabelAlgorithm is TICK_SIMPLE.
double Minimum
Definition vtkAxis.h:792
virtual void GenerateTickLabels(double min, double max)
Calculate and assign nice labels/logical label positions.
int Notation
Definition vtkAxis.h:815
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:829
vtkSmartPointer< vtkPen > GridPen
This object stores the vtkPen that controls how the grid lines are drawn.
Definition vtkAxis.h:846
double NonLogUnscaledMaxLimit
Definition vtkAxis.h:801
float * Point1
Definition vtkAxis.h:785
double MaximumLimit
Definition vtkAxis.h:795
virtual void GetUnscaledRange(double *range)
Get the logical range of the axis, in plot coordinates.
vtkTextProperty * TitleProperties
Definition vtkAxis.h:804
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:836
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:816
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:872
float LabelOffset
Definition vtkAxis.h:810
bool AxisVisible
Definition vtkAxis.h:812
vtkSmartPointer< vtkStringArray > TickLabels
The labels for the tick marks.
Definition vtkAxis.h:861
virtual void SetUnscaledRange(double minimum, double maximum)
Set the logical range of the axis, in plot coordinates.
double UnscaledMaximum
Definition vtkAxis.h:797
bool LogScale
Definition vtkAxis.h:805
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.
bool LogScaleActive
Definition vtkAxis.h:806
vtkTimeStamp BuildTime
The point cache is marked dirty until it has been initialized.
Definition vtkAxis.h:887
vtkSmartPointer< vtkDoubleArray > TickPositions
Position of tick marks in screen coordinates.
Definition vtkAxis.h:851
Class for drawing 2D primitives to a graphical context.
base class for items that are part of a vtkContextScene.
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:108
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition vtkPen.h:79
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_MARSHALAUTO
#define max(a, b)