| 96 | } |
| 97 | |
| 98 | pub fn plot_clusters(&self, assets: &[String]) -> Result<HrpDendrogram, HrpError> { |
| 99 | if self.clusters.is_empty() || self.ordered_indices.is_empty() { |
| 100 | return Err(HrpError::MissingClusters); |
| 101 | } |
| 102 | let mut icoord = Vec::with_capacity(self.clusters.len()); |
| 103 | let mut dcoord = Vec::with_capacity(self.clusters.len()); |
| 104 | let mut color_list = Vec::with_capacity(self.clusters.len()); |
| 105 | for (i, _) in self.clusters.iter().enumerate() { |
| 106 | let x0 = (i * 10) as f64; |
| 107 | icoord.push([x0, x0 + 2.5, x0 + 7.5, x0 + 10.0]); |
| 108 | dcoord.push([0.0, 1.0, 1.0, 0.0]); |
| 109 | color_list.push("C0".to_string()); |
| 110 | } |
| 111 | let leaves = self.ordered_indices.clone(); |
| 112 | let ivl = leaves.iter().map(|i| assets[*i].clone()).collect(); |
| 113 | Ok(HrpDendrogram { icoord, dcoord, ivl, leaves, color_list }) |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | fn freq_step(resample_by: Option<&str>) -> usize { |