Skip to content

Commit 0ec402b

Browse files
authored
Port: Fix dynamic range for ScatterGL (#23)
1 parent d895111 commit 0ec402b

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

src/ScatterGLView.ts

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,8 @@ export class ScatterGLView extends Mark {
654654
animate = true,
655655
after_animation: Function = () => {}
656656
) {
657-
if (animate) {
657+
const animation_duration = this.parent.model.get('animation_duration');
658+
if (animate && animation_duration > 0) {
658659
// `value_previous.array` must have at least the same length as `value.array` in order for animation to work
659660
if (
660661
value.array.length < new_parameters.array.length &&
@@ -722,11 +723,30 @@ export class ScatterGLView extends Mark {
722723
this.material.uniforms['animation_time_' + name]['value'] = 0;
723724
const set = (value) => {
724725
this.material.uniforms['animation_time_' + name]['value'] = value;
726+
727+
if (value == 1) {
728+
const updater =
729+
{
730+
x: this.updateX,
731+
y: this.updateY,
732+
size: this.updateSize,
733+
opacity: this.updateOpacity,
734+
}[name] || null;
735+
if (updater !== null) {
736+
// we update once without animation, otherwise we might
737+
// have dynamic range issues https://github.com/bqplot/bqplot/issues/1661
738+
// when the previous values are in a completely different d3-domain
739+
// the issue resides in vec3 center = mix(vec3(x_previous, y_previous, 0), vec3(x, y, 0), animation_time);
740+
// in scatter-vertex.glsl where x/y_previous is of a different magnitude, which somehow affects
741+
// the precision in center, causing aliasing (on some hardware)
742+
updater.apply(this, [true, false]);
743+
}
744+
}
725745
};
726746
this.transition(set, after_animation, this);
727747
}
728748

729-
updateX(rerender = true) {
749+
updateX(rerender = true, animate: boolean = true) {
730750
const x_array = to_float_array(this.model.get('x'));
731751

732752
const new_markers_number = Math.min(x_array.length, this.y.array.length);
@@ -740,15 +760,16 @@ export class ScatterGLView extends Mark {
740760
'x',
741761
this.x,
742762
this.x_previous,
743-
new AttributeParameters(x_array, 1, 1)
763+
new AttributeParameters(x_array, 1, 1),
764+
animate
744765
);
745766

746767
if (rerender) {
747768
this.parent.extras.webGLRequestRender();
748769
}
749770
}
750771

751-
updateY(rerender = true) {
772+
updateY(rerender = true, animate: boolean = true) {
752773
const y_array = to_float_array(this.model.get('y'));
753774

754775
const new_markers_number = Math.min(this.x.array.length, y_array.length);
@@ -762,7 +783,8 @@ export class ScatterGLView extends Mark {
762783
'y',
763784
this.y,
764785
this.y_previous,
765-
new AttributeParameters(y_array, 1, 1)
786+
new AttributeParameters(y_array, 1, 1),
787+
animate
766788
);
767789

768790
if (rerender) {
@@ -803,41 +825,44 @@ export class ScatterGLView extends Mark {
803825
}
804826
}
805827

806-
updateOpacity(rerender = true) {
828+
updateOpacity(rerender = true, animate: boolean = true) {
807829
const opacity_parameters = this.getOpacityAttributeParameters();
808830
[this.opacity, this.opacity_previous] = this.updateAttributes(
809831
'opacity',
810832
this.opacity,
811833
this.opacity_previous,
812-
opacity_parameters
834+
opacity_parameters,
835+
animate
813836
);
814837

815838
if (rerender) {
816839
this.parent.extras.webGLRequestRender();
817840
}
818841
}
819842

820-
updateSize(rerender = true) {
843+
updateSize(rerender = true, animate: boolean = true) {
821844
const size_parameters = this.getSizeAttributeParameters();
822845
[this.size, this.size_previous] = this.updateAttributes(
823846
'size',
824847
this.size,
825848
this.size_previous,
826-
size_parameters
849+
size_parameters,
850+
animate
827851
);
828852

829853
if (rerender) {
830854
this.parent.extras.webGLRequestRender();
831855
}
832856
}
833857

834-
updateRotation(rerender = true) {
858+
updateRotation(rerender = true, animate: boolean = true) {
835859
const rotation_parameters = this.getRotationAttributeParameters();
836860
[this.rotation, this.rotation_previous] = this.updateAttributes(
837861
'rotation',
838862
this.rotation,
839863
this.rotation_previous,
840-
rotation_parameters
864+
rotation_parameters,
865+
animate
841866
);
842867

843868
if (rerender) {

0 commit comments

Comments
 (0)