Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add multi-value support to table fields
Signed-off-by: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com>
  • Loading branch information
andrei-ng committed Sep 10, 2025
commit 136aaec83412ef90c8a870fb184223729c37135a
26 changes: 23 additions & 3 deletions examples/basic_charts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use plotly::{
TicksDirection, TraceOrder,
},
sankey::{Line as SankeyLine, Link, Node},
traces::table::{Cells, Header},
traces::table::{
Align as TableAlign, Cells, Fill as TableFill, Font as TableFont, Header, Line as TableLine,
},
Bar, Pie, Plot, Sankey, Scatter, ScatterPolar, Table,
};
use plotly_utils::write_example_to_html;
Expand Down Expand Up @@ -878,8 +880,26 @@ fn custom_node_sankey_diagram(show: bool, file_name: &str) {
// ANCHOR: table_chart
fn table_chart(show: bool, file_name: &str) {
let trace = Table::new(
Header::new(vec![String::from("col1"), String::from("col2")]),
Cells::new(vec![vec![1, 2], vec![2, 3]]),
Header::new(vec![String::from("col1"), String::from("col2")])
.font(TableFont::new().color_array(vec![NamedColor::Black, NamedColor::Blue]))
.align_array(vec![TableAlign::Left, TableAlign::Right]),
Cells::new(vec![vec![1, 2], vec![2, 3]])
.align_matrix(vec![
vec![TableAlign::Left, TableAlign::Right],
vec![TableAlign::Right, TableAlign::Left],
])
.fill(TableFill::new().color_matrix(vec![
vec![NamedColor::LightBlue, NamedColor::LightCoral],
vec![NamedColor::LightGreen, NamedColor::LightYellow],
]))
.line(
TableLine::new()
.color_matrix(vec![
vec![NamedColor::Black, NamedColor::Blue],
vec![NamedColor::Green, NamedColor::Yellow],
])
.width_matrix(vec![vec![2.5, 3.3], vec![4.5, 5.3]]),
),
);
let mut plot = Plot::new();
plot.add_trace(trace);
Expand Down
1 change: 1 addition & 0 deletions plotly/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ where
{
Scalar(T),
Vector(Vec<T>),
Matrix(Vec<Vec<T>>),
}

#[derive(Serialize, Clone, Debug, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion plotly/src/layout/polar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ pub enum ThetaUnit {
#[cfg(test)]
mod tests {
use super::*;
use crate::{common::Mode, Layout, Plot, ScatterPolar};
use crate::Layout;

// The focus of the test is serialization, so we test all options for
// [`LayoutPolar`], even though some of those options would normally be mutually
Expand Down
33 changes: 20 additions & 13 deletions plotly/src/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,9 @@ mod tests {
#[cfg(any(feature = "kaleido", feature = "plotly_static"))]
use {base64::engine::general_purpose, base64::Engine};

#[cfg(feature = "plotly_static")]
use crate::export::sync::ExporterSyncExt;

use super::*;
use crate::Scatter;

Expand Down Expand Up @@ -1001,7 +1004,8 @@ mod tests {
.webdriver_port(get_unique_port())
.build()
.unwrap();
plot.write_image_with_exporter(&mut exporter, &dst, ImageFormat::PNG, 1024, 680, 1.0)
exporter
.write_image(&plot, &dst, ImageFormat::PNG, 1024, 680, 1.0)
.unwrap();
assert!(dst.exists());
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
Expand All @@ -1021,7 +1025,8 @@ mod tests {
.webdriver_port(get_unique_port())
.build()
.unwrap();
plot.write_image_with_exporter(&mut exporter, &dst, ImageFormat::JPEG, 1024, 680, 1.0)
exporter
.write_image(&plot, &dst, ImageFormat::JPEG, 1024, 680, 1.0)
.unwrap();
assert!(dst.exists());
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
Expand All @@ -1041,7 +1046,8 @@ mod tests {
.webdriver_port(get_unique_port())
.build()
.unwrap();
plot.write_image_with_exporter(&mut exporter, &dst, ImageFormat::SVG, 1024, 680, 1.0)
exporter
.write_image(&plot, &dst, ImageFormat::SVG, 1024, 680, 1.0)
.unwrap();
assert!(dst.exists());
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
Expand Down Expand Up @@ -1069,7 +1075,8 @@ mod tests {
.webdriver_port(get_unique_port())
.build()
.unwrap();
plot.write_image_with_exporter(&mut exporter, &dst, ImageFormat::PDF, 1024, 680, 1.0)
exporter
.write_image(&plot, &dst, ImageFormat::PDF, 1024, 680, 1.0)
.unwrap();
assert!(dst.exists());
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
Expand All @@ -1089,7 +1096,8 @@ mod tests {
.webdriver_port(get_unique_port())
.build()
.unwrap();
plot.write_image_with_exporter(&mut exporter, &dst, ImageFormat::WEBP, 1024, 680, 1.0)
exporter
.write_image(&plot, &dst, ImageFormat::WEBP, 1024, 680, 1.0)
.unwrap();
assert!(dst.exists());
let metadata = std::fs::metadata(&dst).expect("Could not retrieve file metadata");
Expand All @@ -1109,8 +1117,8 @@ mod tests {
.build()
.unwrap();

let image_base64 = plot
.to_base64_with_exporter(&mut exporter, ImageFormat::PNG, 200, 150, 1.0)
let image_base64 = exporter
.to_base64(&plot, ImageFormat::PNG, 200, 150, 1.0)
.unwrap();

assert!(!image_base64.is_empty());
Expand All @@ -1134,9 +1142,7 @@ mod tests {
.webdriver_port(get_unique_port())
.build()
.unwrap();
let image_svg = plot
.to_svg_with_exporter(&mut exporter, 200, 150, 1.0)
.unwrap();
let image_svg = exporter.to_svg(&plot, 200, 150, 1.0).unwrap();

assert!(!image_svg.is_empty());

Expand Down Expand Up @@ -1172,12 +1178,13 @@ mod tests {
.build()
.unwrap();

assert!(!plot
.to_base64_with_exporter(&mut exporter, ImageFormat::PNG, 1024, 680, 1.0)
assert!(!exporter
.to_base64(&plot, ImageFormat::PNG, 1024, 680, 1.0)
.unwrap()
.is_empty());

plot.write_image_with_exporter(&mut exporter, &dst, ImageFormat::PNG, 800, 600, 1.0)
exporter
.write_image(&plot, &dst, ImageFormat::PNG, 800, 600, 1.0)
.unwrap();
assert!(dst.exists());

Expand Down
Loading