VTK  9.5.20250902
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 "vtkDeprecation.h" // For VTK_DEPRECATED_9_5_0
157#include "vtkPen.h" // For vtkPen
158#include "vtkRect.h" // For bounding rect
159#include "vtkSmartPointer.h" // For vtkSmartPointer
160#include "vtkStdString.h" // For vtkStdString ivars
161#include "vtkVector.h" // For position variables
162#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
163
164VTK_ABI_NAMESPACE_BEGIN
165class vtkContext2D;
166class vtkFloatArray;
167class vtkDoubleArray;
168class vtkStringArray;
169class vtkTextProperty;
170
171class VTKCHARTSCORE_EXPORT VTK_MARSHALAUTO vtkAxis : public vtkContextItem
172{
173public:
174 vtkTypeMacro(vtkAxis, vtkContextItem);
175 void PrintSelf(ostream& os, vtkIndent indent) override;
176
182 {
183 LEFT = 0,
187 PARALLEL
188 };
189
190 enum
191 {
192 TICK_SIMPLE = 0,
193 TICK_WILKINSON_EXTENDED
194 };
195
199 static vtkAxis* New();
200
202
205 virtual void SetPosition(int position);
206 vtkGetMacro(Position, int);
208
210
213 void SetPoint1(const vtkVector2f& pos);
214 void SetPoint1(float x, float y);
216
218
221 vtkGetVector2Macro(Point1, float);
224
226
229 void SetPoint2(const vtkVector2f& pos);
230 void SetPoint2(float x, float y);
232
234
237 vtkGetVector2Macro(Point2, float);
240
245 virtual void SetNumberOfTicks(int numberOfTicks);
246
248
251 vtkGetMacro(NumberOfTicks, int);
253
255
258 vtkSetMacro(TickLength, float);
259 vtkGetMacro(TickLength, float);
261
263
267 vtkGetObjectMacro(LabelProperties, vtkTextProperty);
269
275 virtual void SetMinimum(double minimum);
276
278
283 vtkGetMacro(Minimum, double);
285
291 virtual void SetMaximum(double maximum);
292
294
299 vtkGetMacro(Maximum, double);
301
307 virtual void SetUnscaledMinimum(double minimum);
308
310
313 vtkGetMacro(UnscaledMinimum, double);
315
319 virtual void SetUnscaledMaximum(double maximum);
320
322
325 vtkGetMacro(UnscaledMaximum, double);
327
329
338 virtual void SetRange(double minimum, double maximum);
339 virtual void SetRange(double range[2]);
340 virtual void SetUnscaledRange(double minimum, double maximum);
341 virtual void SetUnscaledRange(double range[2]);
343
345
352 virtual void GetRange(double* range);
353 virtual void GetUnscaledRange(double* range);
355
359 virtual void SetMinimumLimit(double lowest);
360
362
365 vtkGetMacro(MinimumLimit, double);
367
371 virtual void SetMaximumLimit(double highest);
372
374
377 vtkGetMacro(MaximumLimit, double);
379
383 virtual void SetUnscaledMinimumLimit(double lowest);
384
386
389 vtkGetMacro(UnscaledMinimumLimit, double);
391
395 virtual void SetUnscaledMaximumLimit(double highest);
396
398
401 vtkGetMacro(UnscaledMaximumLimit, double);
403
405
408 vtkGetVector2Macro(Margins, int);
410
412
415 vtkSetVector2Macro(Margins, int);
417
419
422 virtual void SetTitle(const vtkStdString& title);
425
427
430 vtkGetObjectMacro(TitleProperties, vtkTextProperty);
432
434
446 vtkGetMacro(LogScaleActive, bool);
448
450
456 vtkGetMacro(LogScale, bool);
457 virtual void SetLogScale(bool logScale);
458 vtkBooleanMacro(LogScale, bool);
460
462
465 vtkSetMacro(GridVisible, bool);
466 vtkGetMacro(GridVisible, bool);
468
470
473 vtkSetMacro(LabelsVisible, bool);
474 vtkGetMacro(LabelsVisible, bool);
476
478
481 vtkSetMacro(RangeLabelsVisible, bool);
482 vtkGetMacro(RangeLabelsVisible, bool);
484
486
489 vtkSetMacro(LabelOffset, float);
490 vtkGetMacro(LabelOffset, float);
492
494
497 vtkSetMacro(TicksVisible, bool);
498 vtkGetMacro(TicksVisible, bool);
500
502
505 vtkSetMacro(AxisVisible, bool);
506 vtkGetMacro(AxisVisible, bool);
508
510
513 vtkSetMacro(TitleVisible, bool);
514 vtkGetMacro(TitleVisible, bool);
516
518
522 virtual void SetPrecision(int precision);
523 vtkGetMacro(Precision, int);
525
530 {
531 STANDARD_NOTATION = 0,
534 PRINTF_NOTATION VTK_DEPRECATED_IN_9_6_0("Use format notation"),
535 STD_FORMAT_NOTATION
536 };
537
539
543 virtual void SetLabelFormat(const std::string& format);
544 vtkGetMacro(LabelFormat, std::string);
546
548
553 vtkSetMacro(RangeLabelFormat, std::string);
554 vtkGetMacro(RangeLabelFormat, std::string);
556
558
563 virtual void SetNotation(int notation);
564 vtkGetMacro(Notation, int);
566
570 enum
571 {
572 AUTO = 0, // Automatically scale the axis to view all data that is visible.
573 FIXED, // Use a fixed axis range and make no attempt to rescale.
574 CUSTOM // Deprecated, use the tick label settings instead.
575 };
576
578
581 vtkSetMacro(Behavior, int);
582 vtkGetMacro(Behavior, int);
584
586
589 vtkSetSmartPointerMacro(Pen, vtkPen);
590 vtkGetObjectMacro(Pen, vtkPen);
592
594
597 vtkSetSmartPointerMacro(GridPen, vtkPen);
598 vtkGetObjectMacro(GridPen, vtkPen);
600
602
609 vtkSetMacro(TickLabelAlgorithm, int);
610 vtkGetMacro(TickLabelAlgorithm, int);
612
614
618 vtkSetMacro(ScalingFactor, double);
619 vtkGetMacro(ScalingFactor, double);
620 vtkSetMacro(Shift, double);
621 vtkGetMacro(Shift, double);
623
628 void Update() override;
629
633 bool Paint(vtkContext2D* painter) override;
634
641 virtual void AutoScale();
642
648
654
660
665
673 virtual bool SetCustomTickPositions(vtkDoubleArray* positions, vtkStringArray* labels = nullptr);
674
682
688 static double NiceNumber(double number, bool roundUp);
689
694 static double NiceMinMax(double& min, double& max, float pixelRange, float tickPixelSpacing);
695
701
705 bool Hit(const vtkContextMouseEvent& mouse) override;
706
707protected:
709 ~vtkAxis() override;
710
719 void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
720
724 virtual void GenerateTickLabels(double min, double max);
725
729 virtual void GenerateTickLabels();
730
731 virtual void GenerateLabelFormat(int notation, double n);
732
736 virtual vtkStdString GenerateStdFormatLabel(double value, const std::string& format);
737
741 VTK_DEPRECATED_IN_9_6_0("Use GenerateStdFormatLabel(double, const std::string&) instead.")
742 virtual vtkStdString GenerateSprintfLabel(double value, const std::string& format);
743
748 double CalculateNiceMinMax(double& min, double& max);
749
759 double LogScaleTickMark(double number, bool roundUp, bool& niceValue, int& order);
760
772 virtual void GenerateLogSpacedLinearTicks(int order, double min, double max);
773
784 void GenerateLogScaleTickMarks(
785 int order, double min = 1.0, double max = 9.0, bool detailLabels = true);
786
790 void CalculateTitlePosition(vtkVector2f& out);
791
792 int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
793 float* Point1; // The position of point 1 (usually the origin)
794 float* Point2; // The position of point 2 (usually the terminus)
795 vtkVector2f Position1, Position2;
796 double TickInterval; // Interval between tick marks in plot space
797 int NumberOfTicks; // The number of tick marks to draw
798 float TickLength; // The length of the tick marks
799 vtkTextProperty* LabelProperties; // Text properties for the labels.
800 double Minimum; // Minimum value of the axis
801 double Maximum; // Maximum values of the axis
802 double MinimumLimit; // Lowest possible value for Minimum
803 double MaximumLimit; // Highest possible value for Maximum
804 double UnscaledMinimum; // UnscaledMinimum value of the axis
805 double UnscaledMaximum; // UnscaledMaximum values of the axis
806 double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
807 double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
808 double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
809 double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
810 int Margins[2]; // Horizontal/vertical margins for the axis
811 vtkStdString Title; // The text label drawn on the axis
812 vtkTextProperty* TitleProperties; // Text properties for the axis title
813 bool LogScale; // *Should* the axis use a log scale?
814 bool LogScaleActive; // *Is* the axis using a log scale?
815 bool GridVisible; // Whether the grid for the axis should be drawn
816 bool LabelsVisible; // Should the axis labels be visible
817 bool RangeLabelsVisible; // Should range labels be visible?
818 float LabelOffset; // Offset of label from the tick mark
819 bool TicksVisible; // Should the tick marks be visible.
820 bool AxisVisible; // Should the axis line be visible.
821 bool TitleVisible; // Should the title be visible.
822 int Precision; // Numerical precision to use, defaults to 2.
823 int Notation; // The notation to use (standard, scientific, mixed)
824 std::string LabelFormat; // The std::format/printf style format string used for labels.
825 std::string RangeLabelFormat; // The std::format/printf style format string used for range labels.
826 int Behavior; // The behaviour of the axis (auto, fixed, custom).
827 float MaxLabel[2]; // The widest/tallest axis label.
828 bool TitleAppended; // Track if the title is updated when the label formats
829 // are changed in the Extended Axis Labeling algorithm
830
832
837 double ScalingFactor;
838 double Shift;
840
844 bool CustomTickLabels;
845
850
855
860
864 vtkSmartPointer<vtkFloatArray> TickScenePositions;
865
870
875 bool UsingNiceMinMax;
876
880 bool TickMarksDirty;
881
885 bool Resized;
886
890 int TickLabelAlgorithm;
891
895 vtkTimeStamp BuildTime;
896
897private:
898 vtkAxis(const vtkAxis&) = delete;
899 void operator=(const vtkAxis&) = delete;
900
904 bool InRange(double value);
905};
906
907VTK_ABI_NAMESPACE_END
908#endif // vtkAxis_h
takes care of drawing 2D axes
Definition vtkAxis.h:172
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.
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.
void SetPoint1(float x, float y)
Set point 1 of the axis (in pixels), this is usually the origin.
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.
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...
void Update() override
Update the geometry of the axis.
vtkRectf GetBoundingRect(vtkContext2D *painter)
Request the space the axes require to be drawn.
virtual vtkDoubleArray * GetTickPositions()
An array with the positions of the tick marks along the axis line.
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.
bool Hit(const vtkContextMouseEvent &mouse) override
Return true if the supplied x, y coordinate is inside the item.
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.
static double NiceMinMax(double &min, double &max, float pixelRange, float tickPixelSpacing)
Static function to calculate "nice" minimum, maximum, and tick spacing values.
virtual void SetUnscaledRange(double range[2])
Set the logical range of the axis, in plot coordinates.
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:530
@ FIXED_NOTATION
Definition vtkAxis.h:533
@ SCIENTIFIC_NOTATION
Definition vtkAxis.h:532
virtual void SetPosition(int position)
Get/set the position of the axis (LEFT, BOTTOM, RIGHT, TOP, PARALLEL).
virtual void GetRange(double *range)
Get the logical range of the axis, in plot coordinates.
vtkVector2f GetPosition1()
Get point 1 of the axis (in pixels), this is usually the origin.
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.
virtual void SetMinimumLimit(double lowest)
Set the logical lowest possible value for Minimum, in plot coordinates.
virtual void RecalculateTickSpacing()
Recalculate the spacing of the tick marks - typically useful to do after scaling the axis.
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.
~vtkAxis() override
@ FIXED
Definition vtkAxis.h:573
Location
Enumeration of the axis locations in a conventional XY chart.
Definition vtkAxis.h:182
@ BOTTOM
Definition vtkAxis.h:184
@ RIGHT
Definition vtkAxis.h:185
virtual vtkStdString GenerateSimpleLabel(double val)
Generate a single label using the current settings when TickLabelAlgorithm is TICK_SIMPLE.
virtual void GenerateTickLabels(double min, double max)
Calculate and assign nice labels/logical label positions.
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.
virtual void GetUnscaledRange(double *range)
Get the logical range of the axis, in plot coordinates.
virtual void SetRange(double minimum, double maximum)
Set the logical range of the axis, in plot coordinates.
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.
virtual void SetUnscaledRange(double minimum, double maximum)
Set the logical range of the axis, in plot coordinates.
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.
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_DEPRECATED_IN_9_6_0(reason)
#define VTK_MARSHALAUTO
#define max(a, b)