-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement loading spinner for visualisations. (#6512)
Fixes #5088. Adds a ensoGL spinner for visualizations waiting on data. https://user-images.githubusercontent.com/1428930/236801655-67a0ffed-da5d-4e27-8797-cd8126cb86d9.mp4 # Important Notes This spinner will not show up for the duration where visualizations are processing data on the frontend. If this is a concern, visualization need to implement heir own loading spinner, or we need to provide a unified API for them to keep the spinner visible.
- Loading branch information
1 parent
4b7afbf
commit 9e71fea
Showing
8 changed files
with
145 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "ensogl-spinner" | ||
version = "0.1.0" | ||
authors = ["Enso Team <[email protected]>"] | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["rlib", "cdylib"] | ||
|
||
[dependencies] | ||
enso-frp = { path = "../../../frp" } | ||
enso-prelude = { path = "../../../prelude" } | ||
enso-shapely = { path = "../../../shapely" } | ||
enso-types = { path = "../../../types" } | ||
ensogl-core = { path = "../../core" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//! An animated spinner component that can be used to indicate that a process | ||
//! is running. | ||
use ensogl_core::display::shape::*; | ||
use ensogl_core::prelude::*; | ||
|
||
use ensogl_core::display::IntoGlsl; | ||
|
||
|
||
|
||
// =============== | ||
// === Spinner === | ||
// =============== | ||
|
||
const ANIMATION_SPEED: f32 = 0.001; | ||
const SHAPE_RADIUS: f32 = 1.0; | ||
const SHAPE_OFFSET: f32 = 2.0; | ||
const ANIMATION_OFFSET_MS: f32 = 100.0; | ||
|
||
/// Convert a time value to an alpha value for the spinner animation. The | ||
/// animation is a sine wave that oscillates between 0 and 1. | ||
fn time_to_alpha<F1: Into<Var<f32>>, F2: Into<Var<f32>>, F3: Into<Var<f32>>>( | ||
time: F1, | ||
offset: F2, | ||
scale: F3, | ||
) -> Var<f32> { | ||
let time = time.into(); | ||
let offset = offset.into(); | ||
let scale = scale.into(); | ||
Var::from(0.5) + ((time + offset) * scale).sin() / 2.0 | ||
} | ||
|
||
ensogl_core::shape! { | ||
alignment = center; | ||
(style: Style, scale: f32, rgba: Vector4<f32>) { | ||
let time = &Var::<f32>::from("input_time"); | ||
let radius = (&scale * SHAPE_RADIUS).px(); | ||
let offset = (&scale * (SHAPE_RADIUS * 2.0 + SHAPE_OFFSET)).px(); | ||
let dot1 = Circle(&radius).translate_x(-&offset); | ||
let dot2 = Circle(&radius); | ||
let dot3 = Circle(&radius).translate_x(offset); | ||
let dot3_anim_start = 0.0; | ||
let dot2_anim_start = dot3_anim_start + ANIMATION_OFFSET_MS; | ||
let dot1_anim_start = dot2_anim_start + ANIMATION_OFFSET_MS; | ||
let dot1_alpha = rgba.w() * time_to_alpha(time, dot1_anim_start, ANIMATION_SPEED); | ||
let dot2_alpha = rgba.w() * time_to_alpha(time, dot2_anim_start, ANIMATION_SPEED); | ||
let dot3_alpha = rgba.w() * time_to_alpha(time, dot3_anim_start, ANIMATION_SPEED); | ||
let rgb = rgba.xyz(); | ||
let color1 = format!("srgba({}.x,{}.y,{}.z,{})", rgb, rgb, rgb, dot1_alpha.glsl()); | ||
let color2 = format!("srgba({}.x,{}.y,{}.z,{})", rgb, rgb, rgb, dot2_alpha.glsl()); | ||
let color3 = format!("srgba({}.x,{}.y,{}.z,{})", rgb, rgb, rgb, dot3_alpha.glsl()); | ||
let dot1 = dot1.fill(color1); | ||
let dot2 = dot2.fill(color2); | ||
let dot3 = dot3.fill(color3); | ||
let shape = dot1 + dot2 + dot3; | ||
shape.into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters