Misplaced chart background
When creating a vtkChartXY in a context scene, the background seems to be misplaced. Instead of covering the whole chart, including axes and labels, only the plot is covered and the background seems to even extend beyond this plot area and overlap with other context items. I.e. it seems the background is translated to start from the origin, instead of the bottom-left most point of the chart.
I’m working on Windows 10, using python 3.7 and the pypi package of vtk, version 8.1.2. Python code to reproduce the above example:
import vtk
import math
renwin = vtk.vtkRenderWindow()
renwin.SetSize(640, 480)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renwin)
renderer = vtk.vtkRenderer()
renderer.SetBackground([1, 1, 1])
renwin.AddRenderer(renderer)
chart_scene = vtk.vtkContextScene()
chart_actor = vtk.vtkContextActor()
chart_actor.SetScene(chart_scene)
renderer.AddActor(chart_actor)
chart_scene.SetRenderer(renderer)
chart_left = vtk.vtkChartXY()
chart_scene.AddItem(chart_left)
chart_left.SetAutoSize(False)
chart_left.SetSize(vtk.vtkRectf(10, 10, 300, 300))
chart_left.GetBackgroundBrush().SetColorF(0, 1, 1, 0.4)
chart_right = vtk.vtkChartXY()
chart_scene.AddItem(chart_right)
chart_right.SetAutoSize(False)
chart_right.SetSize(vtk.vtkRectf(330, 10, 300, 300))
chart_right.GetBackgroundBrush().SetColorF(1, 0, 1, 0.4)
table = vtk.vtkTable()
arrX = vtk.vtkFloatArray()
arrX.SetName('X Axis')
arrC = vtk.vtkFloatArray()
arrC.SetName('Cosine')
arrS = vtk.vtkFloatArray()
arrS.SetName('Sine')
table.AddColumn(arrC)
table.AddColumn(arrS)
table.AddColumn(arrX)
numPoints = 40
inc = 7.5 / (numPoints - 1)
table.SetNumberOfRows(numPoints)
for i in range(numPoints):
table.SetValue(i, 0, i * inc)
table.SetValue(i, 1, math.cos(i * inc))
table.SetValue(i, 2, math.sin(i * inc))
points = chart_left.AddPlot(vtk.vtkChart.POINTS)
points.SetInputData(table, 0, 1)
points.SetColor(0, 0, 0, 255)
points.SetWidth(1.0)
points.SetMarkerStyle(vtk.vtkPlotPoints.CROSS)
points = chart_right.AddPlot(vtk.vtkChart.POINTS)
points.SetInputData(table, 0, 2)
points.SetColor(0, 0, 0, 255)
points.SetWidth(1.0)
points.SetMarkerStyle(vtk.vtkPlotPoints.PLUS)
renwin.SetMultiSamples(0)
renwin.Render()
print(f"Left point1: {chart_left.GetPoint1()}") # Equals chart_left.GetAxis(1).GetPoint1() instead of (10,10)?
print(f"Right point1: {chart_right.GetPoint1()}") # Equals chart_right.GetAxis(1).GetPoint1() instead of (330,10)?
iren.Initialize()
iren.Start()
I already asked on discourse to see what possible solutions there are. The suggestion there was to use multiple viewports and set the background color of the renderer instead of the chart. That works fine for small examples like the one above, but feels like unnecessary overhead when combining multiple charts and viewports. Any idea why this is happening and how this could be resolved (unless it's not classified as a bug)? I also tried out different layout strategies. Both 'FILL_SCENE' and 'FILL_RECT' seem to have overflowing backgrounds, whereas 'AXES_TO_RECT' has no such overflow (but only colors the plot area, without axes and labels).