Skip to content

Commit

Permalink
bug fix - default html application not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis Giagkiozis committed Mar 26, 2020
1 parent 555c79c commit cd7df6b
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.4.1] - 2020-03-26
### Fixed
- Added error message to capture the scenario when there is no default browser (or no browser at all) on a machine. The message suggests a few alternatives.

## [0.4.0] - 2020-02-27
### Added
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -9,7 +9,7 @@ Add this to your `Cargo.toml`:

```toml
[dependencies]
plotly = "0.4.0"
plotly = "0.4.1"
```

For changes since the last version please consult the [change log](CHANGELOG.md).
Expand All @@ -25,7 +25,7 @@ Saving to png, jpeg, webp, svg, pdf and eps formats can be made available by ena

```toml
[dependencies]
plotly = { version = "0.4.0", features = ["orca"] }
plotly = { version = "0.4.1", features = ["orca"] }
```
This feature requires some manual configuration to function. For details and installation instructions
please see the [plotly_orca](plotly_orca).
Expand Down
2 changes: 1 addition & 1 deletion plotly/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "plotly"
version = "0.4.0"
version = "0.4.1"
description = "A plotting library powered by Plotly.js"
authors = ["Ioannis Giagkiozis <i.giagkiozis@gmail.com>"]
license = "MIT"
Expand Down
5 changes: 1 addition & 4 deletions plotly/README.md
Expand Up @@ -9,12 +9,9 @@ Add this to your `Cargo.toml`:

```toml
[dependencies]
plotly = "0.4.0"
plotly = "0.4.1"
```

This feature requires some manual configuration to function. For details and installation instructions
please see the `plotly_orca` [README](plotly_orca/README.md).

## Plotly in action
```rust
extern crate plotly;
Expand Down
184 changes: 179 additions & 5 deletions plotly/src/layout.rs
Expand Up @@ -934,6 +934,176 @@ impl Axis {
}
}

#[derive(Serialize, Debug)]
pub enum RowOrder {
#[serde(rename="top to bottom")]
TopToBottom,
#[serde(rename="bottom to top")]
BottomToTop,
}

#[derive(Serialize, Debug)]
pub enum GridPattern {
#[serde(rename="independent")]
Independent,
#[serde(rename="independent")]
Coupled,
}

#[derive(Serialize, Debug)]
pub enum GridXSide {
#[serde(rename="bottom")]
Bottom,
#[serde(rename="bottom plot")]
BottomPlot,
#[serde(rename="top plot")]
TopPlot,
#[serde(rename="top")]
Top,
}

#[derive(Serialize, Debug)]
pub enum GridYSide {
#[serde(rename="left")]
Left,
#[serde(rename="left plot")]
LeftPlot,
#[serde(rename="right plot")]
RightPlot,
#[serde(rename="right")]
Right,
}

#[derive(Serialize, Debug)]
pub struct GridDomain {
#[serde(skip_serializing_if = "Option::is_none")]
x: Option<Vec<f64>>,
#[serde(skip_serializing_if = "Option::is_none")]
y: Option<Vec<f64>>,
}

impl GridDomain {
pub fn new() -> GridDomain {
GridDomain {x: None, y: None}
}

pub fn x(mut self, x: Vec<f64>) -> GridDomain {
self.x = Some(x);
self
}

pub fn y(mut self, y: Vec<f64>) -> GridDomain {
self.y = Some(y);
self
}
}

#[derive(Serialize, Debug)]
pub struct LayoutGrid {
#[serde(skip_serializing_if = "Option::is_none")]
rows: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none", rename="roworder")]
row_order: Option<RowOrder>,
#[serde(skip_serializing_if = "Option::is_none")]
columns: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none", rename="subplots")]
sub_plots: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none", rename="xaxes")]
x_axes: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none", rename="yaxes")]
y_axes: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pattern: Option<GridPattern>,
#[serde(skip_serializing_if = "Option::is_none", rename="xgap")]
x_gap: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none", rename="ygap")]
y_gap: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
domain: Option<GridDomain>,
#[serde(skip_serializing_if = "Option::is_none", rename="xside")]
x_side: Option<GridXSide>,
#[serde(skip_serializing_if = "Option::is_none", rename="yside")]
y_side: Option<GridYSide>,
}

impl LayoutGrid {
pub fn new() -> LayoutGrid {
LayoutGrid {
rows: None,
row_order: None,
columns: None,
sub_plots: None,
x_axes: None,
y_axes: None,
pattern: None,
x_gap: None,
y_gap: None,
domain: None,
x_side: None,
y_side: None,
}
}

pub fn rows(mut self, rows: usize) -> LayoutGrid {
self.rows = Some(rows);
self
}

pub fn row_order(mut self, row_order: RowOrder) -> LayoutGrid {
self.row_order = Some(row_order);
self
}

pub fn columns(mut self, columns: usize) -> LayoutGrid {
self.columns = Some(columns);
self
}

pub fn sub_plots(mut self, sub_plots: Vec<String>) -> LayoutGrid {
self.sub_plots = Some(sub_plots);
self
}

pub fn x_axes(mut self, x_axes: Vec<String>) -> LayoutGrid {
self.x_axes = Some(x_axes);
self
}

pub fn y_axes(mut self, y_axes: Vec<String>) -> LayoutGrid {
self.y_axes = Some(y_axes);
self
}

pub fn pattern(mut self, pattern: GridPattern) -> LayoutGrid {
self.pattern = Some(pattern);
self
}

pub fn x_gap(mut self, x_gap: f64) -> LayoutGrid {
self.x_gap = Some(x_gap);
self
}

pub fn y_gap(mut self, y_gap: f64) -> LayoutGrid {
self.y_gap = Some(y_gap);
self
}

pub fn domain(mut self, domain: GridDomain) -> LayoutGrid {
self.domain = Some(domain);
self
}

pub fn x_side(mut self, x_side: GridXSide) -> LayoutGrid {
self.x_side = Some(x_side);
self
}
pub fn y_side(mut self, y_side: GridYSide) -> LayoutGrid {
self.y_side = Some(y_side);
self
}
}

#[derive(Serialize, Debug)]
pub struct Layout {
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -985,7 +1155,8 @@ pub struct Layout {
#[serde(skip_serializing_if = "Option::is_none")]
template: Option<String>,

// grid: Option<LayoutGrid>,
#[serde(skip_serializing_if = "Option::is_none")]
grid: Option<LayoutGrid>,
#[serde(skip_serializing_if = "Option::is_none")]
calendar: Option<Calendar>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -1036,10 +1207,7 @@ pub struct Layout {

#[serde(skip_serializing_if = "Option::is_none", rename = "sunburstcolorway")]
sunburst_colorway: Option<Vec<String>>,
#[serde(
skip_serializing_if = "Option::is_none",
rename = "extendsuburstcolors"
)]
#[serde(skip_serializing_if = "Option::is_none", rename = "extendsuburstcolors")]
extend_sunburst_colors: Option<bool>,
}

Expand Down Expand Up @@ -1067,6 +1235,7 @@ impl Layout {
hover_distance: None,
spike_distance: None,
hover_label: None,
grid: None,
calendar: None,
xaxis: None,
yaxis: None,
Expand Down Expand Up @@ -1201,6 +1370,11 @@ impl Layout {
self
}

pub fn grid(mut self, grid: LayoutGrid) -> Layout {
self.grid = Some(grid);
self
}

pub fn calendar(mut self, calendar: Calendar) -> Layout {
self.calendar = Some(calendar);
self
Expand Down
17 changes: 14 additions & 3 deletions plotly/src/plot.rs
Expand Up @@ -70,6 +70,17 @@ pub struct Plot {
layout: Option<Layout>,
}

const DEFAULT_HTML_APP_NOT_FOUND: &str = r#"Could not find default application for HTML files.
Consider using the `to_html` method to save the plot instead. If using the `orca` feature the following
additional formats are available accessed by following methods:
- to_png
- to_jpeg
- to_webp
- to_svg
- to_pdf
- to_eps
"#;

impl Plot {
/// Create a new `Plot`.
pub fn new() -> Plot {
Expand Down Expand Up @@ -314,12 +325,12 @@ impl Plot {
Command::new("xdg-open")
.args(&[temp_path])
.output()
.unwrap();
.expect(DEFAULT_HTML_APP_NOT_FOUND);
}

#[cfg(target_os = "macos")]
fn show_with_default_app(temp_path: &str) {
Command::new("open").args(&[temp_path]).output().unwrap();
Command::new("open").args(&[temp_path]).output().expect(DEFAULT_HTML_APP_NOT_FOUND);
}

#[cfg(target_os = "windows")]
Expand All @@ -328,7 +339,7 @@ impl Plot {
.arg("/C")
.arg(format!(r#"start {}"#, temp_path))
.output()
.unwrap();
.expect(DEFAULT_HTML_APP_NOT_FOUND);
}
}

Expand Down

0 comments on commit cd7df6b

Please sign in to comment.