MCPcopy Create free account
hub / github.com/alceal/plotlars / ensure_color

Method ensure_color

crates/plotlars-plotly/src/subplot_grid/shared.rs:203–265  ·  view source on GitHub ↗
(&mut self, global_index: usize)

Source from the content-addressed store, hash-verified

201 }
202
203 pub(super) fn ensure_color(&mut self, global_index: usize) {
204 let trace_type = self.data.get("type").and_then(|v| v.as_str()).unwrap_or("");
205
206 let default_color = DEFAULT_COLORWAY[global_index % DEFAULT_COLORWAY.len()];
207 let color_str = format!(
208 "rgb({},{},{})",
209 default_color.0, default_color.1, default_color.2
210 );
211
212 match trace_type {
213 "scatter" | "scattergl" | "scatter3d" | "scatterpolar" | "scattergeo"
214 | "scattermapbox" => {
215 let mode = self.data.get("mode").and_then(|v| v.as_str()).unwrap_or("");
216
217 let has_marker_color = self
218 .data
219 .get("marker")
220 .and_then(|m| m.get("color"))
221 .is_some();
222
223 let has_line_color = self.data.get("line").and_then(|l| l.get("color")).is_some();
224
225 if mode.contains("markers") && !has_marker_color {
226 if self.data.get("marker").is_none() {
227 self.data["marker"] = Value::Object(Map::new());
228 }
229 if let Some(obj) = self.data.get_mut("marker").and_then(|m| m.as_object_mut()) {
230 obj.insert("color".to_string(), json!(color_str));
231 }
232 } else if mode.contains("lines") && !has_line_color {
233 if self.data.get("line").is_none() {
234 self.data["line"] = Value::Object(Map::new());
235 }
236 if let Some(obj) = self.data.get_mut("line").and_then(|l| l.as_object_mut()) {
237 obj.insert("color".to_string(), json!(color_str));
238 }
239 } else if !has_marker_color && !has_line_color {
240 if self.data.get("marker").is_none() {
241 self.data["marker"] = Value::Object(Map::new());
242 }
243 if let Some(obj) = self.data.get_mut("marker").and_then(|m| m.as_object_mut()) {
244 obj.insert("color".to_string(), json!(color_str));
245 }
246 }
247 }
248 "bar" | "box" | "histogram" | "barpolar" => {
249 let has_color = self
250 .data
251 .get("marker")
252 .and_then(|m| m.get("color"))
253 .is_some();
254 if !has_color {
255 if self.data.get("marker").is_none() {
256 self.data["marker"] = Value::Object(Map::new());
257 }
258 if let Some(obj) = self.data.get_mut("marker").and_then(|m| m.as_object_mut()) {
259 obj.insert("color".to_string(), json!(color_str));
260 }

Callers 5

build_regularFunction · 0.80
build_irregularFunction · 0.80
test_ensure_color_cyclesFunction · 0.80

Calls

no outgoing calls