Skip to content

Commit d82f091

Browse files
committed
description edit - fixed hover - simplified again finding nearest on axis
1 parent bc8334b commit d82f091

File tree

3 files changed

+39
-45
lines changed

3 files changed

+39
-45
lines changed

src/traces/isosurface/convert.js

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@ function IsosurfaceTrace(scene, mesh, uid) {
3131

3232
var proto = IsosurfaceTrace.prototype;
3333

34-
function findNearestOnAxis(w, arr, nPoints, nDim, step) {
35-
var id = nDim;
36-
for(var q = nPoints - 1; q > 0 && id > 0; q -= step) {
37-
id--;
38-
var min = Math.min(arr[q], arr[q - step]);
39-
var max = Math.max(arr[q], arr[q - step]);
34+
function findNearestOnAxis(w, arr) {
35+
for(var q = arr.length - 1; q > 0; q--) {
36+
var min = Math.min(arr[q], arr[q - 1]);
37+
var max = Math.max(arr[q], arr[q - 1]);
4038
if(max > min && min < w && w <= max) {
4139
return {
42-
id: id,
40+
id: q,
4341
distRatio: (max - w) / (max - min)
4442
};
4543
}
@@ -59,14 +57,12 @@ proto.handlePick = function(selection) {
5957
var y = this.data.y[rawId];
6058
var z = this.data.z[rawId];
6159

62-
var width = this.data.width;
63-
var height = this.data.height;
64-
var depth = this.data.depth;
65-
var nPoints = width * height * depth;
60+
var height = this.data._Ys.length;
61+
var depth = this.data._Zs.length;
6662

67-
var i = findNearestOnAxis(x, this.data.x, nPoints, width, 1 + depth * height).id;
68-
var j = findNearestOnAxis(y, this.data.y, nPoints, height, 1 + depth).id;
69-
var k = findNearestOnAxis(z, this.data.z, nPoints, depth, 1).id;
63+
var i = findNearestOnAxis(x, this.data._Xs).id;
64+
var j = findNearestOnAxis(y, this.data._Ys).id;
65+
var k = findNearestOnAxis(z, this.data._Zs).id;
7066

7167
var selectIndex = selection.index = k + depth * j + depth * height * i;
7268

@@ -888,16 +884,11 @@ function generateIsosurfaceMesh(data) {
888884

889885
for(var q = 0; q < slice.locations.length; q++) {
890886

891-
var location = slice.locations[q];
892-
893-
var near;
894-
if(e === 'x') {
895-
near = findNearestOnAxis(location, data.x, width * height * depth, width, 1 + depth * height);
896-
} else if(e === 'y') {
897-
near = findNearestOnAxis(location, data.y, width * height * depth, height, 1 + depth);
898-
} else {
899-
near = findNearestOnAxis(location, data.z, width * height * depth, depth, 1);
900-
}
887+
var near = findNearestOnAxis(
888+
slice.locations[q],
889+
(e === 'x') ? Xs :
890+
(e === 'y') ? Ys : Zs
891+
);
901892

902893
if(near.distRatio === 0) {
903894
exactIndices.push(near.id);
@@ -967,6 +958,10 @@ function generateIsosurfaceMesh(data) {
967958
data.y = allYs;
968959
data.z = allZs;
969960
data.intensity = allVs;
961+
962+
data._Xs = Xs;
963+
data._Ys = Ys;
964+
data._Zs = Zs;
970965
}
971966

972967
drawAll();

src/traces/isosurface/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ Isosurface.basePlotModule = require('../../plots/gl3d');
2626
Isosurface.categories = ['gl3d'];
2727
Isosurface.meta = {
2828
description: [
29-
'Draws isosurfaces, with or without caps, slices and braces with coordinates given by',
30-
'three 1-dimensional arrays in `x`, `y`, `z` defining axes',
31-
'and another 1-dimensional array titled `value`.',
32-
'The `value` array (data cube) should have a size equal to',
33-
'the multiplication of lengths of `x`, `y`, and `z`.'
29+
'Draws isosurfaces between iso-min and iso-max values with coordinates given by',
30+
'four 1-dimensional arrays containing the `value`, `x`, `y` and `z` of every vertex',
31+
'of a uniform or non-uniform 3-D grid. Horizontal or vertical slices, caps as well as',
32+
'spaceframe between iso-min and iso-max values could also be drawn using this trace.'
3433
].join(' ')
3534
};
3635

test/jasmine/tests/isosurface_test.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -335,17 +335,17 @@ describe('Test isosurface', function() {
335335
}
336336

337337
function _hover2() {
338-
mouseEvent('mouseover', 150, 150);
338+
mouseEvent('mouseover', 100, 100);
339339
return delay(20)();
340340
}
341341

342342
function _hover3() {
343-
mouseEvent('mouseover', 300, 200);
343+
mouseEvent('mouseover', 300, 150);
344344
return delay(20)();
345345
}
346346

347347
function _hover4() {
348-
mouseEvent('mouseover', 200, 300);
348+
mouseEvent('mouseover', 150, 300);
349349
return delay(20)();
350350
}
351351

@@ -356,9 +356,9 @@ describe('Test isosurface', function() {
356356
assertHoverLabelContent({
357357
nums: [
358358
'x: 0.4',
359-
'y: 0.01',
359+
'y: 100μ',
360360
'z: −8',
361-
'value: −0.31'
361+
'value: −1.31'
362362
].join('\n')
363363
});
364364
})
@@ -367,10 +367,10 @@ describe('Test isosurface', function() {
367367
.then(function() {
368368
assertHoverLabelContent({
369369
nums: [
370-
'x: 0.4',
371-
'y: 0.01',
372-
'z: −8',
373-
'value: −0.31'
370+
'x: 0.3',
371+
'y: 0.001',
372+
'z: −16',
373+
'value: −0.27'
374374
].join('\n')
375375
});
376376
})
@@ -380,9 +380,9 @@ describe('Test isosurface', function() {
380380
assertHoverLabelContent({
381381
nums: [
382382
'x: 0.2',
383-
'y: 0.01',
384-
'z: −8',
385-
'value: −0.17'
383+
'y: 100μ',
384+
'z: −16',
385+
'value: −1.12'
386386
].join('\n')
387387
});
388388
})
@@ -391,10 +391,10 @@ describe('Test isosurface', function() {
391391
.then(function() {
392392
assertHoverLabelContent({
393393
nums: [
394-
'x: 0.3',
395-
'y: 0.01',
396-
'z: −2',
397-
'value: −1.14'
394+
'x: 0.4',
395+
'y: 100μ',
396+
'z: −4',
397+
'value: −1.3'
398398
].join('\n')
399399
});
400400
})

0 commit comments

Comments
 (0)