Skip to content

Commit a877aee

Browse files
authored
Merge pull request #250 from Nick-Pearson/fix-book-graphs
Fix book chart rendering for basic charts
2 parents 8580c87 + c36133b commit a877aee

File tree

8 files changed

+299
-877
lines changed

8 files changed

+299
-877
lines changed

.github/workflows/book.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Book
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- '[0-9]+.[0-9]+.[0-9]+'
8+
9+
env:
10+
RUST_BACKTRACE: full
11+
12+
jobs:
13+
build:
14+
name: Build and deploy book
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- run: cargo install mdbook
19+
- name: Build examples
20+
run: cd ${{ github.workspace }}/examples/basic_charts && cargo run
21+
- run: mdbook build docs/book
22+
- name: Checkout gh-pages branch
23+
run: |
24+
git fetch origin gh-pages:gh-pages
25+
git checkout gh-pages
26+
- name: Overwrite book content
27+
run: |
28+
rm -rf content
29+
cp -r gh-pages/content .
30+
- name: Deploy to GitHub Pages
31+
run: |
32+
git config --global user.name 'github-actions[bot]'
33+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
34+
35+
git add content
36+
git commit --allow-empty -m 'Deploy to GitHub Pages'
37+
git push origin gh-pages

docs/book/book.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ src = "src"
99
[build]
1010
build-dir = "../../gh-pages/content"
1111
create-missing = false
12+
extra-watch-dirs = ["../../examples"]
1213

1314
[output.html]
1415
default-theme = "Ayu"

docs/book/src/recipes/basic_charts/bar_charts.md

Lines changed: 13 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
The following imports have been used to produce the plots below:
44

5-
```rust
6-
use itertools_num::linspace;
5+
```rust,no_run
6+
use ndarray::Array;
77
use plotly::common::{
88
ColorScale, ColorScalePalette, DashType, Fill, Font, Line, LineShape, Marker, Mode, Title,
99
};
@@ -16,99 +16,22 @@ The `to_inline_html` method is used to produce the html plot displayed in this p
1616

1717

1818
## Basic Bar Chart
19-
```rust
20-
fn basic_bar_chart(show: bool) {
21-
let animals = vec!["giraffes", "orangutans", "monkeys"];
22-
let t = Bar::new(animals, vec![20, 14, 23]);
23-
let mut plot = Plot::new();
24-
plot.add_trace(t);
25-
if show {
26-
plot.show();
27-
}
28-
println!("{}", plot.to_inline_html(Some("basic_bar_chart")));
29-
}
30-
19+
```rust,no_run
20+
{{#include ../../../../../examples/basic_charts/src/main.rs:basic_bar_chart}}
3121
```
32-
<div id="basic_bar_chart" class="plotly-graph-div" style="height:100%; width:100%;"></div>
33-
<script type="text/javascript">
34-
window.PLOTLYENV=window.PLOTLYENV || {};
35-
if (document.getElementById("basic_bar_chart")) {
36-
var d3 = Plotly.d3;
37-
var image_element= d3.select('#image-export');
38-
var trace_0 = {"x":["giraffes","orangutans","monkeys"],"y":[20,14,23],"type":"bar"};
39-
var data = [trace_0];
40-
var layout = {};
41-
Plotly.newPlot('basic_bar_chart', data, layout, {"responsive": true});
42-
};
43-
</script>
44-
45-
## Grouped Bar Chart
46-
```rust
47-
fn grouped_bar_chart(show: bool) {
48-
let animals1 = vec!["giraffes", "orangutans", "monkeys"];
49-
let trace1 = Bar::new(animals1, vec![20, 14, 23]).name("SF Zoo");
5022

51-
let animals2 = vec!["giraffes", "orangutans", "monkeys"];
52-
let trace2 = Bar::new(animals2, vec![12, 18, 29]).name("LA Zoo");
23+
{{#include ../../../../../examples/basic_charts/out/basic_bar_chart.html}}
5324

54-
let layout = Layout::new().bar_mode(BarMode::Group);
55-
56-
let mut plot = Plot::new();
57-
plot.add_trace(trace1);
58-
plot.add_trace(trace2);
59-
plot.set_layout(layout);
60-
if show {
61-
plot.show();
62-
}
63-
println!("{}", plot.to_inline_html(Some("grouped_bar_chart")));
64-
}
25+
## Grouped Bar Chart
26+
```rust,no_run
27+
{{#include ../../../../../examples/basic_charts/src/main.rs:grouped_bar_chart}}
6528
```
66-
<div id="grouped_bar_chart" class="plotly-graph-div" style="height:100%; width:100%;"></div>
67-
<script type="text/javascript">
68-
window.PLOTLYENV=window.PLOTLYENV || {};
69-
if (document.getElementById("grouped_bar_chart")) {
70-
var d3 = Plotly.d3;
71-
var image_element= d3.select('#image-export');
72-
var trace_0 = {"x":["giraffes","orangutans","monkeys"],"y":[20,14,23],"type":"bar","name":"SF Zoo"};
73-
var trace_1 = {"x":["giraffes","orangutans","monkeys"],"y":[12,18,29],"type":"bar","name":"LA Zoo"};
74-
var data = [trace_0,trace_1];
75-
var layout = {"barmode":"group"};
76-
Plotly.newPlot('grouped_bar_chart', data, layout, {"responsive": true});
77-
};
78-
</script>
7929

30+
{{#include ../../../../../examples/basic_charts/out/grouped_bar_chart.html}}
8031

8132
## Stacked Bar Chart
82-
```rust
83-
fn stacked_bar_chart(show: bool) {
84-
let animals1 = vec!["giraffes", "orangutans", "monkeys"];
85-
let trace1 = Bar::new(animals1, vec![20, 14, 23]).name("SF Zoo");
86-
87-
let animals2 = vec!["giraffes", "orangutans", "monkeys"];
88-
let trace2 = Bar::new(animals2, vec![12, 18, 29]).name("LA Zoo");
89-
90-
let layout = Layout::new().bar_mode(BarMode::Stack);
91-
92-
let mut plot = Plot::new();
93-
plot.add_trace(trace1);
94-
plot.add_trace(trace2);
95-
plot.set_layout(layout);
96-
if show {
97-
plot.show();
98-
}
99-
println!("{}", plot.to_inline_html(Some("stacked_bar_chart")));
100-
}
33+
```rust,no_run
34+
{{#include ../../../../../examples/basic_charts/src/main.rs:stacked_bar_chart}}
10135
```
102-
<div id="stacked_bar_chart" class="plotly-graph-div" style="height:100%; width:100%;"></div>
103-
<script type="text/javascript">
104-
window.PLOTLYENV=window.PLOTLYENV || {};
105-
if (document.getElementById("stacked_bar_chart")) {
106-
var d3 = Plotly.d3;
107-
var image_element= d3.select('#image-export');
108-
var trace_0 = {"x":["giraffes","orangutans","monkeys"],"y":[20,14,23],"type":"bar","name":"SF Zoo"};
109-
var trace_1 = {"x":["giraffes","orangutans","monkeys"],"y":[12,18,29],"type":"bar","name":"LA Zoo"};
110-
var data = [trace_0,trace_1];
111-
var layout = {"barmode":"stack"};
112-
Plotly.newPlot('stacked_bar_chart', data, layout, {"responsive": true});
113-
};
114-
</script>
36+
37+
{{#include ../../../../../examples/basic_charts/out/stacked_bar_chart.html}}

0 commit comments

Comments
 (0)