(&self, ctx: &C, percent: f64, highlight: bool)
| 92 | C: CanvasContext<Pattern>, |
| 93 | { |
| 94 | fn draw(&self, ctx: &C, percent: f64, highlight: bool) { |
| 95 | let mut a1 = lerp(self.old_start_angle, self.start_angle, percent); |
| 96 | let mut a2 = lerp(self.old_end_angle, self.end_angle, percent); |
| 97 | if a1 > a2 { |
| 98 | std::mem::swap(&mut a1, &mut a2); |
| 99 | } |
| 100 | let center = &self.center; |
| 101 | if highlight { |
| 102 | let highlight_outer_radius = HIGHLIGHT_OUTER_RADIUS_FACTOR * self.outer_radius; |
| 103 | ctx.set_fill_color(self.highlight_color); |
| 104 | ctx.begin_path(); |
| 105 | ctx.arc(center.x, center.y, highlight_outer_radius, a1, a2, false); |
| 106 | ctx.arc(center.x, center.y, self.inner_radius, a2, a1, true); |
| 107 | ctx.fill(); |
| 108 | } |
| 109 | |
| 110 | ctx.set_fill_color(self.color); |
| 111 | ctx.begin_path(); |
| 112 | ctx.arc(center.x, center.y, self.outer_radius, a1, a2, false); |
| 113 | ctx.arc(center.x, center.y, self.inner_radius, a2, a1, true); |
| 114 | ctx.fill(); |
| 115 | ctx.stroke(); |
| 116 | |
| 117 | if !self.formatted_value.is_empty() && a2 - a1 > PI / 36.0 { |
| 118 | // let labels = self.chart.options.channel.labels; |
| 119 | // if labels.enabled { |
| 120 | let r = 0.25 * self.inner_radius + 0.65 * self.outer_radius; |
| 121 | let a = 0.5 * (a1 + a2); |
| 122 | let p = utils::polar2cartesian(center, r, a); |
| 123 | ctx.set_fill_color(color::WHITE); // labels.style.color |
| 124 | let w = ctx.measure_text(self.formatted_value.as_str()).width; |
| 125 | // TODO: should have a global state in ctx i think |
| 126 | ctx.fill_text(self.formatted_value.as_str(), p.x - w / 2., p.y + 4.); |
| 127 | // } |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | #[derive(Default, Clone)] |
no test coverage detected