Chart Enhancements
While working with the VTK Charts API for the pyvista project (Charts PR), I noticed a couple of inconsistencies and bugs that I would like to address in this PR. I included some code fragments to reproduce the problems I encountered (using pyvista for code brevity) and 'before' and 'after' visualizations.
Fixes:
-
Chart backgrounds take borders correctly into account (resolves #18238 (closed)). -
Fix ChartXY.SetAxis leaving references to old axis.
Example
import pyvista
chart = pyvista.Chart2D()
plot = chart.line([0, 1, 2], [2, 1, 3])
old_axis = chart.x_axis
new_axis = pyvista.charts.Axis("Custom x")
chart.SetAxis(new_axis.BOTTOM, new_axis) # Below prints are False before these changes, True afterwards.
print(plot.GetXAxis().__this__ == new_axis.__this__) # Plots still referenced old axis instead of the new.
print(not old_axis.HasObserver(chart.UpdateRange)) # Old axis still had an active AxisRangeListener.
-
ChartPie properly apply Brush while painting.
Example
-
ChartPie legend is correctly replaced when any of the labels change.
Example
-
Fix ChartXY graphical glitch and vtkMath::Jacobi warning when using an axis with log scale.
Example
Enhancements:
-
ChartPie and ChartBox can have a custom size and location now (previously always filled the entire scene).
Example
-
ChartPie.SetPlot can be used now to set a custom PlotPie instance (like ChartBox.SetPlot).
Example
import pyvista
chart = pyvista.ChartPie([1,2,3])
plot = pyvista.charts.PiePlot([1,1,1]) # We can specify a custom vtkPiePlot instance now, which was previously impossible.
chart.SetPlot(plot)
chart.show()
-
Axis.SetPen and Axis.SetGridPen methods.
Example
import pyvista
chart = pyvista.Chart2D()
chart.line([0, 1, 2], [2, 1, 3])
pen = pyvista.charts.Pen('r')
grid_pen = pyvista.charts.Pen('b')
chart.x_axis.SetPen(pen) # We can specify a custom Pen instance now, which was previously impossible.
chart.y_axis.SetGridPen(grid_pen)
chart.show()
-
Increased ClipBox of ChartXY to properly display lines/points near the edge of the chart's patch.
Edited by dcbr