From ad7435ee94addcfa2687218958e4e8303b45042c Mon Sep 17 00:00:00 2001 From: Julien Finet Date: Fri, 5 Apr 2024 08:55:42 +0200 Subject: [PATCH] fix(cubeaxesactor): resize texture when number of ticks changes --- Examples/Geometry/CubeAxes/index.js | 18 ++++----- Sources/Rendering/Core/CubeAxesActor/index.js | 37 ++++++++++--------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/Examples/Geometry/CubeAxes/index.js b/Examples/Geometry/CubeAxes/index.js index 6ad048b87ba..65a1bcfe268 100644 --- a/Examples/Geometry/CubeAxes/index.js +++ b/Examples/Geometry/CubeAxes/index.js @@ -44,17 +44,15 @@ const cubeAxes = vtkCubeAxesActor.newInstance(); cubeAxes.setCamera(renderer.getActiveCamera()); cubeAxes.setDataBounds(actor.getBounds()); // Replace ticks from axis 0 -function myGenerateTicks(defaultGenerateTicks) { - return (dataBounds) => { - const res = defaultGenerateTicks(dataBounds); - const scale = d3scale.scaleLinear().domain([dataBounds[0], dataBounds[1]]); - res.ticks[0] = d3array.range(dataBounds[0], dataBounds[1], 0.1); - const format = scale.tickFormat(res.ticks[0].length); - res.tickStrings[0] = res.ticks[0].map(format); - return res; - }; +function myGenerateTicks(dataBounds) { + const res = vtkCubeAxesActor.defaultGenerateTicks(dataBounds); + const scale = d3scale.scaleLinear().domain([dataBounds[0], dataBounds[1]]); + res.ticks[0] = d3array.range(dataBounds[0], dataBounds[1], 0.1); + const format = scale.tickFormat(res.ticks[0].length); + res.tickStrings[0] = res.ticks[0].map(format); + return res; } -cubeAxes.setGenerateTicks(myGenerateTicks(cubeAxes.getGenerateTicks())); +cubeAxes.setGenerateTicks(myGenerateTicks); renderer.addActor(cubeAxes); renderer.resetCamera(); diff --git a/Sources/Rendering/Core/CubeAxesActor/index.js b/Sources/Rendering/Core/CubeAxesActor/index.js index 4d638597fc3..11f0c526d69 100644 --- a/Sources/Rendering/Core/CubeAxesActor/index.js +++ b/Sources/Rendering/Core/CubeAxesActor/index.js @@ -81,20 +81,18 @@ function applyTextStyle(ctx, style) { ctx.font = `${style.fontStyle} ${style.fontSize}px ${style.fontFamily}`; } -function defaultGenerateTicks(publicApi, model) { - return (dataBounds) => { - const ticks = []; - const tickStrings = []; - for (let i = 0; i < 3; i++) { - const scale = d3 - .scaleLinear() - .domain([dataBounds[i * 2], dataBounds[i * 2 + 1]]); - ticks[i] = scale.ticks(5); - const format = scale.tickFormat(5); - tickStrings[i] = ticks[i].map(format); - } - return { ticks, tickStrings }; - }; +function defaultGenerateTicks(dataBounds) { + const ticks = []; + const tickStrings = []; + for (let i = 0; i < 3; i++) { + const scale = d3 + .scaleLinear() + .domain([dataBounds[i * 2], dataBounds[i * 2 + 1]]); + ticks[i] = scale.ticks(5); + const format = scale.tickFormat(5); + tickStrings[i] = ticks[i].map(format); + } + return { ticks, tickStrings }; } // many properties of this actor depend on the API specific view The main @@ -824,7 +822,7 @@ function defaultValues(publicAPI, model, initialValues) { axisLabels: null, axisTitlePixelOffset: 35.0, tickLabelPixelOffset: 12.0, - generateTicks: defaultGenerateTicks(publicAPI, model), + generateTicks: defaultGenerateTicks, ...initialValues, axisTextStyle: { fontColor: 'white', @@ -865,7 +863,7 @@ export function extend(publicAPI, model, initialValues = {}) { model._tmAtlas = new Map(); // for texture atlas - model.tmTexture = vtkTexture.newInstance(); + model.tmTexture = vtkTexture.newInstance({ resizable: true }); model.tmTexture.setInterpolate(false); publicAPI.getProperty().setDiffuse(0.0); @@ -913,4 +911,9 @@ export const newInstance = macro.newInstance(extend, 'vtkCubeAxesActor'); // ---------------------------------------------------------------------------- -export default { newInstance, extend, newCubeAxesActorHelper }; +export default { + newInstance, + extend, + newCubeAxesActorHelper, + defaultGenerateTicks, +};