Updates will be applied today, at 5:15 pm EDT (UTC-0500). This should not cause an interruption.

Commit c1b404a8 authored by Peter Franz's avatar Peter Franz

Customize vtkAxis

Make the following methods in vtkAxis virtual so users can customize vtkAxis:

GenerateSimpleLabel(), GenerateSprintfLabel(), GenerateLabelFormat(), GenerateLogSpacedLinearTicks()

This was originally proposed by a post on

http://vtk.1045678.n5.nabble.com/Request-Make-certain-methods-related-to-tick-labels-in-vtkAxis-virtual-td5744594.html

with the purpose of allowing the user to use customized axis labels, e.g. for displaying dates or times.

Apart from making the above methods virtual it is also required that the user can set the customized axis in a chart.
Hence further modifications were necessary in vtkChart, vtkChartXY and vtkChartXYZ to replace the axis created in the chart
by the customized axis.

Further a change was made to vtkAxis to allow the axis title to be switched off.
parent 0566ad88
......@@ -58,6 +58,7 @@ vtkAxis::vtkAxis()
this->LabelProperties->SetFontSize(12);
this->LabelProperties->SetFontFamilyToArial();
this->LabelProperties->SetJustificationToCentered();
this->TitleVisible = true;
this->TitleProperties = vtkTextProperty::New();
this->TitleProperties->SetColor(0.0, 0.0, 0.0);
this->TitleProperties->SetFontSize(12);
......@@ -325,7 +326,7 @@ bool vtkAxis::Paint(vtkContext2D *painter)
}
// Draw the axis title if there is one
if (!this->Title.empty())
if (!this->Title.empty() && this->TitleVisible)
{
int x = 0;
int y = 0;
......
......@@ -401,6 +401,14 @@ public:
vtkGetMacro(AxisVisible, bool);
//@}
//@{
/**
* Get/set whether the axis title should be visible.
*/
vtkSetMacro(TitleVisible, bool);
vtkGetMacro(TitleVisible, bool);
//@}
//@{
/**
* Get/set the numerical precision to use, default is 2. This is ignored
......@@ -581,7 +589,7 @@ public:
* Generate a single label using the current settings when TickLabelAlgorithm
* is TICK_SIMPLE.
*/
vtkStdString GenerateSimpleLabel(double val);
virtual vtkStdString GenerateSimpleLabel(double val);
protected:
vtkAxis();
......@@ -607,12 +615,12 @@ protected:
*/
void GenerateTickLabels();
void GenerateLabelFormat(int notation, double n);
virtual void GenerateLabelFormat(int notation, double n);
/**
* Generate label using a printf-style format string.
*/
vtkStdString GenerateSprintfLabel(double value, const std::string & format);
virtual vtkStdString GenerateSprintfLabel(double value, const std::string & format);
/**
* Calculate the next "nicest" numbers above and below the current minimum.
......@@ -645,7 +653,7 @@ protected:
* If more than 20 tick marks would result, the stride for the varying digit
* is increased.
*/
void GenerateLogSpacedLinearTicks(int order, double min, double max);
virtual void GenerateLogSpacedLinearTicks(int order, double min, double max);
/**
* Generate tick marks for logarithmic scale for specific order of magnitude.
......@@ -691,6 +699,7 @@ protected:
float LabelOffset; // Offset of label from the tick mark
bool TicksVisible; // Should the tick marks be visible.
bool AxisVisible; // Should the axis line be visible.
bool TitleVisible; // Should the title be visible.
int Precision; // Numerical precision to use, defaults to 2.
int Notation; // The notation to use (standard, scientific, mixed)
std::string LabelFormat; // The printf-style format string used for labels.
......
......@@ -145,6 +145,11 @@ vtkAxis* vtkChart::GetAxis(int)
return nullptr;
}
//-----------------------------------------------------------------------------
void vtkChart::SetAxis(int, vtkAxis*)
{
}
//-----------------------------------------------------------------------------
vtkIdType vtkChart::GetNumberOfAxes()
{
......
......@@ -138,6 +138,12 @@ public:
*/
virtual vtkAxis* GetAxis(int axisIndex);
/**
* Set the axis specified by axisIndex. 0 is x, 1 is y. This should probably
* be improved either using a string or enum to select the axis.
*/
virtual void SetAxis(int axisIndex, vtkAxis*);
/**
* Get the number of axes in the current chart.
*/
......
......@@ -1396,6 +1396,43 @@ vtkAxis* vtkChartXY::GetAxis(int axisIndex)
}
}
//-----------------------------------------------------------------------------
void vtkChartXY::SetAxis(int axisIndex, vtkAxis * axis)
{
if ((axisIndex < 4) && (axisIndex >= 0))
{
vtkAxis * old_axis = this->ChartPrivate->axes[axisIndex];
this->ChartPrivate->axes[axisIndex] = axis;
this->ChartPrivate->axes[axisIndex]->SetVisible(old_axis->GetVisible());
// remove the old axis
this->RemoveItem(old_axis);
this->AttachAxisRangeListener(this->ChartPrivate->axes[axisIndex]);
this->AddItem(this->ChartPrivate->axes[axisIndex]);
this->ChartPrivate->axes[axisIndex]->SetPosition(axisIndex);
vtkPlotGrid* grid1 = static_cast<vtkPlotGrid *>(this->ChartPrivate->Clip->GetItem(0));
vtkPlotGrid* grid2 = static_cast<vtkPlotGrid *>(this->ChartPrivate->Clip->GetItem(1));
switch (axisIndex)
{
case vtkAxis::BOTTOM:
grid1->SetXAxis(this->ChartPrivate->axes[vtkAxis::BOTTOM]);
break;
case vtkAxis::LEFT:
grid1->SetYAxis(this->ChartPrivate->axes[vtkAxis::LEFT]);
break;
case vtkAxis::TOP:
grid2->SetXAxis(this->ChartPrivate->axes[vtkAxis::TOP]);
break;
case vtkAxis::RIGHT:
grid2->SetYAxis(this->ChartPrivate->axes[vtkAxis::RIGHT]);
break;
}
}
}
//-----------------------------------------------------------------------------
vtkIdType vtkChartXY::GetNumberOfAxes()
{
......
......@@ -147,6 +147,13 @@ public:
*/
vtkAxis* GetAxis(int axisIndex) override;
/**
* Set the axis specified by axisIndex. This is specified with the vtkAxis
* position enum, valid values are vtkAxis::LEFT, vtkAxis::BOTTOM,
* vtkAxis::RIGHT and vtkAxis::TOP.
*/
virtual void SetAxis(int axisIndex, vtkAxis*);
/**
* Set whether the chart should draw a legend.
*/
......
......@@ -116,6 +116,13 @@ vtkAxis * vtkChartXYZ::GetAxis(int axis)
return this->Axes[axis];
}
//-----------------------------------------------------------------------------
void vtkChartXYZ::SetAxis(int axisIndex, vtkAxis* axis)
{
assert(axisIndex >= 0 && axisIndex < 3);
this->Axes[axisIndex] = axis;
}
//-----------------------------------------------------------------------------
void vtkChartXYZ::SetAxisColor(const vtkColor4ub& color)
{
......
......@@ -78,6 +78,13 @@ public:
*/
vtkAxis * GetAxis(int axis);
/**
* Set the x (0), y (1) or z (2) axis.
*/
virtual void SetAxis(int axisIndex, vtkAxis* axis);
//@{
/**
* Set the color for the axes.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment