Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 14 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ jobs:
components: clippy
targets: wasm32-unknown-unknown
# lint plotly_static for all features
- run: cargo clippy -p plotly_static --features geckodriver,webdriver_download -- -D warnings -A deprecated
- run: cargo clippy -p plotly_static --features chromedriver,webdriver_download -- -D warnings -A deprecated
- run: |
export WEBDRIVER_PATH="${{ steps.setup-chrome.outputs.chromedriver-path }}"
export BROWSER_PATH="${{ steps.setup-chrome.outputs.chrome-path }}"
cargo clippy -p plotly_static --features geckodriver,webdriver_download -- -D warnings -A deprecated
cargo clippy -p plotly_static --features chromedriver,webdriver_download -- -D warnings -A deprecated
# lint the main library workspace for non-wasm target
- run: cargo clippy --features all -- -D warnings -A deprecated
# lint the non-wasm examples
Expand Down Expand Up @@ -132,7 +135,10 @@ jobs:
# Run tests on Ubuntu with Chrome
- name: Run tests (${{ matrix.os }} - Chrome)
if: matrix.os == 'ubuntu-latest' && matrix.browser == 'chrome'
run: cargo test --workspace --features ${{ matrix.features }} --exclude plotly_kaleido
run: |
export WEBDRIVER_PATH="${{ steps.setup-chrome.outputs.chromedriver-path }}"
export BROWSER_PATH="${{ steps.setup-chrome.outputs.chrome-path }}"
cargo test --workspace --features ${{ matrix.features }} --exclude plotly_kaleido

# Install xvfb for Firefox WebGL support
- name: Install xvfb
Expand All @@ -146,6 +152,7 @@ jobs:
if: matrix.os == 'ubuntu-latest' && matrix.browser == 'firefox'
run: |
# Set environment variables for Firefox WebDriver
export WEBDRIVER_PATH="/usr/local/share/gecko_driver"
export BROWSER_PATH="${{ steps.setup-firefox.outputs.firefox-path }}"
export RUST_LOG="debug"
export RUST_BACKTRACE="1"
Expand All @@ -159,7 +166,10 @@ jobs:
# Run tests on macOS with Chrome
- name: Run tests (${{ matrix.os }} - Chrome)
if: matrix.os == 'macos-latest' && matrix.browser == 'chrome'
run: cargo test --workspace --features ${{ matrix.features }} --exclude plotly_kaleido
run: |
export WEBDRIVER_PATH="${{ steps.setup-chrome.outputs.chromedriver-path }}"
export BROWSER_PATH="${{ steps.setup-chrome.outputs.chrome-path }}"
cargo test --workspace --features ${{ matrix.features }} --exclude plotly_kaleido

# Run tests on Windows with Chrome WebDriver
- name: Run tests (${{ matrix.os }} - Chrome)
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

https://github.com/plotly/plotly.rs/pull/350

## [Unreleased]

### Fixed

- [#5583](https://github.com/plotly/plotly.rs/issues/5583) Use string axis ids for trace `x_axis` and `y_axis` setters

## [0.14.1] - 2026-02-15

### Fixed
Expand Down
14 changes: 14 additions & 0 deletions plotly/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,12 @@ pub enum Reference {
Paper,
}

/// Axis id for a 2D cartesian x axis.
pub type XAxisId = String;

/// Axis id for a 2D cartesian y axis.
pub type YAxisId = String;

#[derive(Serialize, Clone, Debug)]
pub struct Pad {
t: usize,
Expand Down Expand Up @@ -1799,6 +1805,14 @@ mod tests {
assert_eq!(to_value(Reference::Paper).unwrap(), json!("paper"));
}

#[test]
fn serialize_axis_id() {
assert_eq!(to_value(XAxisId::from("x")).unwrap(), json!("x"));
assert_eq!(to_value(XAxisId::from("x3")).unwrap(), json!("x3"));
assert_eq!(to_value(YAxisId::from("y")).unwrap(), json!("y"));
assert_eq!(to_value(YAxisId::from("y8")).unwrap(), json!("y8"));
}

#[test]
#[rustfmt::skip]
fn serialize_legend_group_title() {
Expand Down
8 changes: 4 additions & 4 deletions plotly/src/traces/contour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ where
Box::new(self)
}

pub fn x_axis(mut self, axis: &str) -> Box<Self> {
self.x_axis = Some(axis.to_string());
pub fn x_axis(mut self, axis: impl Into<String>) -> Box<Self> {
self.x_axis = Some(axis.into());
Box::new(self)
}

Expand All @@ -418,8 +418,8 @@ where
Box::new(self)
}

pub fn y_axis(mut self, axis: &str) -> Box<Self> {
self.y_axis = Some(axis.to_string());
pub fn y_axis(mut self, axis: impl Into<String>) -> Box<Self> {
self.y_axis = Some(axis.into());
Box::new(self)
}

Expand Down
17 changes: 17 additions & 0 deletions plotly/src/traces/scatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,4 +528,21 @@ mod tests {

assert_eq!(to_value(trace).unwrap(), expected);
}

#[test]
fn serialize_scatter_axis_ids() {
let trace = Scatter::new(vec![0, 1], vec![2, 3])
.x_axis("x2")
.y_axis("y3");

let expected = json!({
"type": "scatter",
"x": [0, 1],
"y": [2, 3],
"xaxis": "x2",
"yaxis": "y3"
});

assert_eq!(to_value(trace).unwrap(), expected);
}
}
28 changes: 22 additions & 6 deletions plotly_derive/src/field_setter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,28 @@ impl FieldReceiver {
crate::color::ColorArray(value).into()
)],
),
FieldType::OptionString => (
quote![impl AsRef<str>],
quote![value.as_ref().to_owned()],
quote![],
),
FieldType::OptionOther(inner_ty) => (quote![#inner_ty], quote![value], quote![]),
FieldType::OptionString => {
if matches!(kind, Kind::Trace)
&& matches!(field_ident.to_string().as_str(), "x_axis" | "y_axis")
{
(quote![impl Into<String>], quote![value.into()], quote![])
} else {
(
quote![impl AsRef<str>],
quote![value.as_ref().to_owned()],
quote![],
)
}
}
FieldType::OptionOther(inner_ty) => {
if matches!(kind, Kind::Trace)
&& matches!(field_ident.to_string().as_str(), "x_axis" | "y_axis")
{
(quote![impl Into<#inner_ty>], quote![value.into()], quote![])
} else {
(quote![#inner_ty], quote![value], quote![])
}
}
FieldType::OptionVecString => (
quote![Vec<impl AsRef<str>>],
quote![value.into_iter().map(|v| v.as_ref().to_owned()).collect()],
Expand Down
20 changes: 10 additions & 10 deletions plotly_static/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,19 @@ fn setup_driver(config: &WebdriverDownloadConfig) -> Result<()> {
match config.driver_name {
CHROMEDRIVER_NAME => {
let driver_info = ChromedriverInfo::new(webdriver_bin.clone(), browser_path);
runtime
.block_on(async { download_with_retry(&driver_info, false, true, 1).await })
.with_context(|| {
format!("Failed to download and install {}", config.driver_name)
})?;
let dl_res = runtime
.block_on(async { download_with_retry(&driver_info, false, true, 1).await });
if let Err(e) = dl_res {
return Err(anyhow!("Failed to download and install chromedriver").context(e));
}
}
GECKODRIVER_NAME => {
let driver_info = GeckodriverInfo::new(webdriver_bin.clone(), browser_path);
runtime
.block_on(async { download_with_retry(&driver_info, false, true, 1).await })
.with_context(|| {
format!("Failed to download and install {}", config.driver_name)
})?;
let dl_res = runtime
.block_on(async { download_with_retry(&driver_info, false, true, 1).await });
if let Err(e) = dl_res {
return Err(anyhow!("Failed to download and install geckodriver").context(e));
}
}
_ => return Err(anyhow!("Unsupported driver type: {}", config.driver_name)),
}
Expand Down
Loading