├── Cargo.toml ├── .gitignore ├── src └── lib.rs └── README.md /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "plotapi" 3 | version = "0.1.1" 4 | edition = "2021" 5 | authors = ["Dr. Shahin Rostami "] 6 | description = "Engaging visualisations, made easy." 7 | homepage = "https://plotapi.com" 8 | repository = "http://github.com/shahinrostami/plotapi_rs" 9 | license = "MIT" 10 | keywords = ["plot", "chart", "visualization"] 11 | 12 | [dependencies] 13 | ureq = {version = "1.5.5", features = ["json"]} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | debug/ 4 | target/ 5 | 6 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 7 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 8 | Cargo.lock 9 | 10 | # These are backup files generated by rustfmt 11 | **/*.rs.bk 12 | 13 | # MSVC Windows builds of rustc generate these, which store debugging information 14 | *.pdb -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | use std::io::prelude::*; 3 | 4 | pub use ureq::json as params; 5 | pub use ureq::SerdeValue as Params; 6 | 7 | pub struct Visualisation { 8 | pub api_key: &'static str, 9 | pub endpoint: &'static str, 10 | pub params: Params, 11 | } 12 | 13 | impl Visualisation { 14 | fn endpoint_url(&self) -> String { 15 | ["https://plotapi.com/", &self.endpoint, "/"].concat() 16 | } 17 | 18 | pub fn show(&self) { 19 | let html = self.render(); 20 | println!("EVCXR_BEGIN_CONTENT text/html\n{}\nEVCXR_END_CONTENT", html); 21 | } 22 | 23 | pub fn to_html(&self) { 24 | let html = self.render(); 25 | let file_name = "out.html"; 26 | 27 | let mut file = fs::File::create(file_name).unwrap(); 28 | file.write_all(html.as_bytes()) 29 | .expect("writing to output file failed"); 30 | } 31 | 32 | fn render(&self) -> String { 33 | ureq::post(&self.endpoint_url()) 34 | .auth("api_key", &self.api_key.to_string()) 35 | .send_json(self.params.clone()) 36 | .into_string() 37 | .unwrap() 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |

3 |
4 | Plotapi 5 |

6 | 7 |

Engaging visualisations, made easy.

8 | 9 |

10 | 11 | 12 | 13 | 14 | 15 | 16 |

17 | 18 |

19 | Key Features • 20 | Get Access • 21 | Installation • 22 | Usage • 23 | License 24 |

25 | 26 | ![screenshot](https://plotapi.com/wp-content/uploads/2021/08/1500x500.jpeg) 27 | 28 | ## Key Features 29 | 30 | * **Plotapi Chord** - Illustrate inter-relationships between data. 31 | * **Plotapi Sankey** - Illustrate the flow from one set of values to another. 32 | * **Plotapi Terminus** - Illustrate distributing something out amongst recipients. 33 | * **Plotapi Bar Fight** - A beautiful take on the classic Bar Chart Race. 34 | * **Plotapi Pie Fight** - A beautiful take on the classic Pie Chart Race. 35 | * **Plotapi Heat Map** - Beautiful and interactive heat maps. 36 | * **Plotapi Line Fight** - A beautiful take on the classic Line Chart Race. 37 | * **Plotapi Pareto Front** - Illustrate non-dominated (Pareto) fronts over time. 38 | * **Upcoming Visualisations** - Access to new visualisations as they are introduced. 39 | * **Supports Most Programming Languages** - Get started with any language able to make HTTP requests. 40 | * **First-Class Python Support** - Get started with pip install plotapi 41 | * **Jupyter Lab/Notebook + Google Colab Support** - Super-charge your notebooks with inline visualisations. 42 | * **Beautiful Themes & Fonts** - Select from pre-made beautiful themes, or add your own. 43 | * **Share or Embed Interactive HTML** - Download and embed your interactive visualisations. 44 | * **Render to PDF, SVG, or PNG** - Generate high-quality output ready for print. 45 | * **Record Animation to Video** - Create social media-ready animated visualisations. 46 | 47 | ## Get Access 48 | 49 | Visit [the website](https://plotapi.com/#pricing) to get access to Plotapi. 50 | 51 | ## Installation 52 | 53 | Get up and running with Rust with the `plotapi` crate. 54 | 55 | ## Usage 56 | 57 | ### Example - Chord Pro 58 | 59 | https://user-images.githubusercontent.com/15690380/126084021-b008b256-2a31-4106-84af-42777ea480d9.mp4 60 | 61 | #### Created with Plotapi 62 | 63 | ```rust 64 | use plotapi::params; 65 | use plotapi::Visualisation; 66 | 67 | fn main() { 68 | let names: Vec = vec!["A", "B", "C", "1", "2", "3"] 69 | .into_iter() 70 | .map(String::from) 71 | .collect(); 72 | 73 | let matrix: Vec> = vec![ 74 | vec![0.0, 0.0, 0.0, 1.0, 4.0, 1.0], 75 | vec![0.0, 0.0, 0.0, 1.0, 3.0, 2.0], 76 | vec![0.0, 0.0, 0.0, 1.0, 2.0, 2.0], 77 | vec![1.0, 1.0, 1.0, 0.0, 0.0, 0.0], 78 | vec![4.0, 3.0, 2.0, 0.0, 0.0, 0.0], 79 | vec![1.0, 2.0, 2.0, 0.0, 0.0, 0.0], 80 | ]; 81 | 82 | let colors: Vec = vec![ 83 | "#7400B8", "#5E60CE", "#5684D6", "#56CFE1", "#64DFDF", "#80FFDB", 84 | ] 85 | .into_iter() 86 | .map(String::from) 87 | .collect(); 88 | 89 | let param = params!({ 90 | "matrix": matrix, 91 | "names": names, 92 | "colors": colors 93 | 94 | }); 95 | 96 | Visualisation { 97 | api_key: "17ec2f26-076c-4110-a23a-9a02efe2d52a", 98 | params: param, 99 | endpoint: "chord", 100 | } 101 | .to_html(); 102 | } 103 | 104 | ``` 105 | 106 | ### Example - Sankey Pro 107 | 108 | https://user-images.githubusercontent.com/15690380/126084745-712fd744-b626-429d-85f3-30b11979fe30.mp4 109 | 110 | 111 | 112 | ## License 113 | 114 | MIT 115 | 116 | --- 117 | 118 | ## Prefer not to code? Check out the App at [PlotAPI.com](https://plotapi.com). Python version available. 119 | 120 | PlotPanel 121 | 122 | 123 | > [plotapi.com](https://plotapi.com)  ·  124 | > GitHub [@shahinrostami](https://github.com/shahinrostami)  ·  125 | > Twitter [@shahinrostami](https://twitter.com/shahinrostami)  ·  126 | > A [Polyra](https://polyra.com) innovation 127 | --------------------------------------------------------------------------------