Draws the current animation frame. If [time] is `null`, draws the last frame (i.e. no animation).
(&self, ctx: &C, time: Option<i64>)
| 300 | /// |
| 301 | /// If [time] is `null`, draws the last frame (i.e. no animation). |
| 302 | fn draw_frame(&self, ctx: &C, time: Option<i64>) { |
| 303 | // clear surface |
| 304 | self.base.draw_frame(ctx, time); |
| 305 | |
| 306 | self.draw_axes_and_grid(ctx); |
| 307 | |
| 308 | let mut percent = self.base.calculate_percent(time); |
| 309 | |
| 310 | if percent >= 1.0 { |
| 311 | percent = 1.0; |
| 312 | |
| 313 | // Update the visibility states of all channel before the last frame. |
| 314 | let mut channels = self.base.channels.borrow_mut(); |
| 315 | for channel in channels.iter_mut() { |
| 316 | if channel.state == Visibility::Showing { |
| 317 | channel.state = Visibility::Shown; |
| 318 | } else if channel.state == Visibility::Hiding { |
| 319 | channel.state = Visibility::Hidden; |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | let props = self.base.props.borrow(); |
| 325 | |
| 326 | let ease = match props.easing { |
| 327 | Some(val) => val, |
| 328 | None => get_easing(Easing::Linear), |
| 329 | }; |
| 330 | self.draw_channels(ctx, ease(percent)); |
| 331 | // ctx.drawImageScaled(ctx.canvas, 0, 0, width, height); |
| 332 | // ctx.drawImageScaled(ctx.canvas, 0, 0, width, height); |
| 333 | self.base.draw_title(ctx); |
| 334 | |
| 335 | if percent < 1.0 { |
| 336 | // animation_frame_id = window.requestAnimationFrame(draw_frame); |
| 337 | } else if time.is_some() { |
| 338 | self.base.animation_end(); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | fn draw_channels(&self, ctx: &C, percent: f64) -> bool { |
| 343 | ctx.set_line_width(2.); |
no test coverage detected