@kitware/vtk.js 34.13.2 → 34.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ const Orientation = {
2
+ HORIZONTAL: 'horizontal',
3
+ VERTICAL: 'vertical',
4
+ AUTO: 'auto'
5
+ };
6
+ var Constants = {
7
+ Orientation
8
+ };
9
+
10
+ export { Orientation, Constants as default };
@@ -19,13 +19,16 @@ export interface IStyle {
19
19
  fontColor?: string;
20
20
  fontStyle?: string;
21
21
  fontFamily?: string;
22
- fontSize?: string;
22
+ fontSize?: number | string;
23
23
  }
24
24
 
25
+ export type Orientation = 'horizontal' | 'vertical' | 'auto' | null;
26
+
25
27
  /**
26
28
  *
27
29
  */
28
- export interface IScalarBarActorInitialValues extends IActorInitialValues {
30
+ export interface IScalarBarActorInitialValues
31
+ extends Omit<IActorInitialValues, 'orientation'> {
29
32
  automated?: boolean;
30
33
  autoLayout?: (publicAPI: object, model: object) => void;
31
34
  axisLabel?: string;
@@ -42,9 +45,11 @@ export interface IScalarBarActorInitialValues extends IActorInitialValues {
42
45
  drawBelowRangeSwatch?: boolean;
43
46
  drawAboveRangeSwatch?: boolean;
44
47
  drawNanAnnotation?: boolean;
48
+ orientation?: Orientation;
45
49
  }
46
50
 
47
- export interface vtkScalarBarActor extends vtkActor {
51
+ export interface vtkScalarBarActor
52
+ extends Omit<vtkActor, 'getOrientation' | 'setOrientation'> {
48
53
  /**
49
54
  *
50
55
  * @param {Boolean} doUpdate
@@ -222,6 +227,27 @@ export interface vtkScalarBarActor extends vtkActor {
222
227
  */
223
228
  setAxisTextStyle(axisTextStyle: IStyle): boolean;
224
229
 
230
+ /**
231
+ * Get the current bar orientation setting
232
+ */
233
+ getOrientation(): Orientation;
234
+
235
+ /**
236
+ * Forces the scalar bar to use horizontal orientation regardless of aspect ratio
237
+ */
238
+ setOrientationToHorizontal(): boolean;
239
+
240
+ /**
241
+ * Forces the scalar bar to use vertical orientation regardless of aspect ratio
242
+ */
243
+ setOrientationToVertical(): boolean;
244
+
245
+ /**
246
+ * Set the orientation of the scalar bar
247
+ * @param orientation 'horizontal' to force horizontal, 'vertical' to force vertical, or null/undefined for auto
248
+ */
249
+ setOrientation(orientation: Orientation): boolean;
250
+
225
251
  /**
226
252
  *
227
253
  * @param {Number} axisTitlePixelOffset
@@ -7,10 +7,14 @@ import vtkScalarsToColors from '../../Common/Core/ScalarsToColors.js';
7
7
  import vtkMapper from './Mapper.js';
8
8
  import vtkPolyData from '../../Common/DataModel/PolyData.js';
9
9
  import vtkTexture from './Texture.js';
10
+ import Constants from './ScalarBarActor/Constants.js';
10
11
 
11
12
  const {
12
13
  VectorMode
13
14
  } = vtkScalarsToColors;
15
+ const {
16
+ Orientation
17
+ } = Constants;
14
18
 
15
19
  // ----------------------------------------------------------------------------
16
20
  // vtkScalarBarActor
@@ -28,11 +32,12 @@ const {
28
32
  //
29
33
  // ----------------------------------------------------------------------------
30
34
 
31
- function applyTextStyle(ctx, style) {
35
+ function applyTextStyle(ctx, style, defaultFontSize) {
32
36
  ctx.strokeStyle = style.strokeColor;
33
37
  ctx.lineWidth = style.strokeSize;
34
38
  ctx.fillStyle = style.fontColor;
35
- ctx.font = `${style.fontStyle} ${style.fontSize}px ${style.fontFamily}`;
39
+ const fontSize = style.fontSize ?? defaultFontSize;
40
+ ctx.font = `${style.fontStyle} ${fontSize}px ${style.fontFamily}`;
36
41
  }
37
42
 
38
43
  // ----------------------------------------------------------------------------
@@ -68,12 +73,16 @@ function defaultAutoLayout(publicAPI, model) {
68
73
  Object.assign(axisTextStyle, model.axisTextStyle);
69
74
  Object.assign(tickTextStyle, model.tickTextStyle);
70
75
 
71
- // compute a reasonable font size first
72
- axisTextStyle.fontSize = Math.max(24 * minAdjust, 12);
73
- if (helper.getLastAspectRatio() > 1.0) {
74
- tickTextStyle.fontSize = Math.max(20 * minAdjust, 10);
75
- } else {
76
- tickTextStyle.fontSize = Math.max(16 * minAdjust, 10);
76
+ // compute a reasonable font size first, but only if user hasn't explicitly set it
77
+ if (axisTextStyle.fontSize === undefined) {
78
+ axisTextStyle.fontSize = Math.max(24 * minAdjust, 12);
79
+ }
80
+ if (tickTextStyle.fontSize === undefined) {
81
+ if (helper.getLastAspectRatio() > 1.0) {
82
+ tickTextStyle.fontSize = Math.max(20 * minAdjust, 10);
83
+ } else {
84
+ tickTextStyle.fontSize = Math.max(16 * minAdjust, 10);
85
+ }
77
86
  }
78
87
 
79
88
  // rebuild the text atlas
@@ -84,8 +93,19 @@ function defaultAutoLayout(publicAPI, model) {
84
93
  helper.setTopTitle(false);
85
94
  const boxSize = helper.getBoxSizeByReference();
86
95
 
96
+ // Determine orientation: user-forced, or auto based on aspect ratio
97
+ let isVertical = false;
98
+ if (model.orientation === Orientation.VERTICAL) {
99
+ isVertical = true;
100
+ } else if (model.orientation === Orientation.HORIZONTAL) {
101
+ isVertical = false;
102
+ } else {
103
+ // auto: use aspect ratio (original behavior)
104
+ isVertical = helper.getLastAspectRatio() > 1.0;
105
+ }
106
+
87
107
  // if vertical
88
- if (helper.getLastAspectRatio() > 1.0) {
108
+ if (isVertical) {
89
109
  helper.setTickLabelPixelOffset(0.3 * tickTextStyle.fontSize);
90
110
 
91
111
  // if the title will fit within the width of the bar then that looks
@@ -243,7 +263,7 @@ function vtkScalarBarActorHelper(publicAPI, model) {
243
263
  const newTmAtlas = new Map();
244
264
  let maxWidth = 0;
245
265
  let totalHeight = 1; // start one pixel in so we have a border
246
- applyTextStyle(model.tmContext, model.axisTextStyle);
266
+ applyTextStyle(model.tmContext, model.axisTextStyle, 18);
247
267
  let metrics = model.tmContext.measureText(model.renderable.getAxisLabel());
248
268
  let entry = {
249
269
  height: metrics.actualBoundingBoxAscent + 2,
@@ -260,7 +280,7 @@ function vtkScalarBarActorHelper(publicAPI, model) {
260
280
  // and the ticks, NaN Below and Above
261
281
  results.tickWidth = 0;
262
282
  results.tickHeight = 0;
263
- applyTextStyle(model.tmContext, model.tickTextStyle);
283
+ applyTextStyle(model.tmContext, model.tickTextStyle, 14);
264
284
  const strings = [...publicAPI.getTickStrings(), 'NaN', 'Below', 'Above'];
265
285
  for (let t = 0; t < strings.length; t++) {
266
286
  if (!newTmAtlas.has(strings[t])) {
@@ -304,7 +324,8 @@ function vtkScalarBarActorHelper(publicAPI, model) {
304
324
 
305
325
  // draw the text onto the texture
306
326
  newTmAtlas.forEach((value, key) => {
307
- applyTextStyle(model.tmContext, value.textStyle);
327
+ const defaultSize = value.textStyle === model.axisTextStyle ? 18 : 14;
328
+ applyTextStyle(model.tmContext, value.textStyle, defaultSize);
308
329
  model.tmContext.fillText(key, 1, value.startingHeight + value.height - 1);
309
330
  });
310
331
  model.tmTexture.setCanvas(model.tmCanvas);
@@ -720,6 +741,8 @@ function vtkScalarBarActor(publicAPI, model) {
720
741
  };
721
742
  publicAPI.modified();
722
743
  };
744
+ publicAPI.setOrientationToHorizontal = () => publicAPI.setOrientation(Orientation.HORIZONTAL);
745
+ publicAPI.setOrientationToVertical = () => publicAPI.setOrientation(Orientation.VERTICAL);
723
746
  publicAPI.resetAutoLayoutToDefault = () => {
724
747
  publicAPI.setAutoLayout(defaultAutoLayout(publicAPI, model));
725
748
  };
@@ -746,20 +769,21 @@ function defaultValues(initialValues) {
746
769
  axisTextStyle: {
747
770
  fontColor: 'white',
748
771
  fontStyle: 'normal',
749
- fontSize: 18,
772
+ fontSize: undefined,
750
773
  fontFamily: 'serif'
751
774
  },
752
775
  tickLabelPixelOffset: 14.0,
753
776
  tickTextStyle: {
754
777
  fontColor: 'white',
755
778
  fontStyle: 'normal',
756
- fontSize: 14,
779
+ fontSize: undefined,
757
780
  fontFamily: 'serif'
758
781
  },
759
782
  generateTicks: null,
760
783
  drawNanAnnotation: true,
761
784
  drawBelowRangeSwatch: true,
762
785
  drawAboveRangeSwatch: true,
786
+ orientation: null,
763
787
  ...initialValues
764
788
  };
765
789
  }
@@ -776,7 +800,7 @@ function extend(publicAPI, model) {
776
800
  vtkActor.extend(publicAPI, model, initialValues);
777
801
  publicAPI.getProperty().setDiffuse(0.0);
778
802
  publicAPI.getProperty().setAmbient(1.0);
779
- macro.setGet(publicAPI, model, ['automated', 'autoLayout', 'axisTitlePixelOffset', 'axisLabel', 'scalarsToColors', 'tickLabelPixelOffset', 'generateTicks', 'drawNanAnnotation', 'drawBelowRangeSwatch', 'drawAboveRangeSwatch']);
803
+ macro.setGet(publicAPI, model, ['automated', 'autoLayout', 'axisTitlePixelOffset', 'axisLabel', 'scalarsToColors', 'tickLabelPixelOffset', 'generateTicks', 'drawNanAnnotation', 'drawBelowRangeSwatch', 'drawAboveRangeSwatch', 'orientation']);
780
804
  macro.get(publicAPI, model, ['axisTextStyle', 'tickTextStyle']);
781
805
  macro.getArray(publicAPI, model, ['barPosition', 'barSize', 'boxPosition', 'boxSize']);
782
806
  macro.setArray(publicAPI, model, ['barPosition', 'barSize', 'boxPosition', 'boxSize'], 2);
@@ -794,7 +818,8 @@ const newInstance = macro.newInstance(extend, 'vtkScalarBarActor');
794
818
  var vtkScalarBarActor$1 = {
795
819
  newInstance,
796
820
  extend,
797
- newScalarBarActorHelper
821
+ newScalarBarActorHelper,
822
+ ...Constants
798
823
  };
799
824
 
800
825
  export { vtkScalarBarActor$1 as default, extend, newInstance };
@@ -1214,7 +1214,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1214
1214
  width,
1215
1215
  height,
1216
1216
  dataArray: vtkDataArray.newInstance({
1217
- numComps,
1217
+ numberOfComponents: numComps,
1218
1218
  dataType,
1219
1219
  values: data,
1220
1220
  ranges
@@ -1411,7 +1411,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1411
1411
  height,
1412
1412
  depth,
1413
1413
  dataArray: vtkDataArray.newInstance({
1414
- numComps,
1414
+ numberOfComponents: numComps,
1415
1415
  dataType,
1416
1416
  values: data,
1417
1417
  ranges
@@ -126,6 +126,7 @@ function widgetBehavior(publicAPI, model) {
126
126
  translation[axisIndex] = translateState.startPos + delta;
127
127
  model.widgetState.getTransform().setTranslation(translation);
128
128
  }
129
+ return macro.EVENT_ABORT;
129
130
  };
130
131
  publicAPI.handleScaleEvent = (callData, axis, axisIndex) => {
131
132
  model.lineManipulator.setHandleOrigin(model.activeState.getOrigin());
@@ -140,6 +141,7 @@ function widgetBehavior(publicAPI, model) {
140
141
  scales[axisIndex] = scale;
141
142
  model.widgetState.getTransform().setScale(scales);
142
143
  }
144
+ return macro.EVENT_ABORT;
143
145
  };
144
146
  publicAPI.handleRotateEvent = callData => {
145
147
  model.rotationManipulator.setHandleOrigin(model.activeState.getOrigin());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "34.13.2",
3
+ "version": "34.15.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",