yuankunzhang / charming Goto Github PK
View Code? Open in Web Editor NEWA visualization library for Rust
License: Apache License 2.0
A visualization library for Rust
License: Apache License 2.0
quick q, how do I set the theme?
The JavaScript V8 engine was too difficult to download during initial compilation, are there any other solutions?
Or other ways for communication?
Compiling charm v0.1.0 (/home/xxx/rust/charm)
error[E0432]: unresolved import charming::ImageRenderer
--> src/main.rs:5:12
|
5 | Chart, ImageRenderer,
| ^^^^^^^^^^^^^ no ImageRenderer
in the root
For more information about this error, try rustc --explain E0432
.
error: could not compile charm
(bin "charm") due to previous error
// here is the code
use charming::{
component::Legend,
element::ItemStyle,
series::{Pie, PieRoseType},
Chart, ImageRenderer,
};
fn main() {
let chart = Chart::new().legend(Legend::new().top("bottom")).series(
Pie::new()
.name("Nightingale Chart")
.rose_type(PieRoseType::Radius)
.radius(vec!["50", "250"])
.center(vec!["50%", "50%"])
.item_style(ItemStyle::new().border_radius(8))
.data(vec![
(40.0, "rose 1"),
(38.0, "rose 2"),
(32.0, "rose 3"),
(30.0, "rose 4"),
(28.0, "rose 5"),
(26.0, "rose 6"),
(22.0, "rose 7"),
(18.0, "rose 8"),
]),
);
let mut renderer = ImageRenderer::new(1000, 800);
renderer.save(&chart, "/tmp/nightingale.svg");
}
I have converted some polars dataframes into the underlying Vec types to pass into the charming df! macro and managed to build a working pipeline for making charts.
Running into an issue with a chart that starts from YTD for daily bars, and it compiles and saves the data into an html file.
When it comes to opening the file in the web browser it only renders a few bars and then nothing more. Even though the date axis and raw html data is fully available in the file.
In JavaScript, if an image is too large, we can use mouse movements to pan and zoom the image. However, this is not possible in charming.
I would love to have this heatmap: https://echarts.apache.org/examples/en/editor.html?c=heatmap-cartesian
It would be nice to be able to use custom themes defined in a JSON or .toml file by deserialzing these into a custom theme struct.
A possible way to achieve this is by creating a CustomTheme
struct with fields corresponding to the settings, while using preexisting structs from the crate. As those struct already has most of (if not all) of the needed fields, e.g the Line
struct has line_style
which is needed. The problem however is that the Line
struct also has fields which are not required, nor wanted (?), for a theme struct - i.e the type_
(?) and the data
field.
Is this something that is in the works? If wanted I could try to implement this, however, then there would be need for some guidance what needs to be done.
A small example of what I'm getting at..
use serde::{Serialize, Deserialize};
use charming::element::Color;
use charming::series::Line;
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct CustomTheme {
#[serde(skip_serializing_if = "Option::is_none")]
color: Option<Vec<Color>>,
#[serde(skip_serializing_if = "Option::is_none")]
line: Option<Line>,
// and then more...
}
let theme: &str = r#"
{
"color": ["\#ff0000", "\#00ff00", "\#0000ff"],
"line": {
"lineStyle" : {
"width": 3
},
"symbolSize": 8
}
}
"#;
let my_custom_theme: CustomTheme = serde_json::from_str(theme).unwrap();
// Then set theme....
The crate has "MIT/Apache-2.0" license but its missing on the repository itself
doc is here:
https://echarts.apache.org/en/option.html#series-line.label
can not add label for Line:
charming/examples/leptos-demo/src/main.rs
Line 20 in dbf7e05
I may be missing something, but I did not find a way to build a ChartResize structure since all of its fields are private.
Something as simple as
--- a/charming/src/renderer/wasm_renderer.rs
+++ b/charming/src/renderer/wasm_renderer.rs
@@ -76,6 +76,17 @@ pub struct ChartResize {
animation: Option<Animation>,
}
+impl ChartResize {
+ pub fn new(width: u32, height: u32, silent: bool, animation: Option<Animation>) -> Self {
+ ChartResize {
+ width,
+ height,
+ silent,
+ animation,
+ }
+ }
+}
+
#[derive(Serialize)]
pub struct Animation {
would solve the issue.
Hey, I've tried implementing a dynamic approach to initializing the x axis with a polars series of "Datetime" objects and my code compiles but panics when unwrapping the result of the chart creation. I screenshotted the ErrString, "expected Date got str"
I will fork and try to fix this issue, hopefully you may have some insight too.
There is already support for default decals, but the method to set them individually is missing from element::item_style::ItemStyle
.
Reproducer:
use std::iter;
use charming::{component::Axis, element::AxisType, series::Scatter, Chart, ImageRenderer};
fn main() {
let c = Chart::new()
.x_axis(Axis::new().type_(AxisType::Value))
.y_axis(Axis::new().type_(AxisType::Value))
.series(
Scatter::new().data(
(0..=100)
.flat_map(|x| iter::zip(iter::repeat(x), 0..=100))
.map(|(x, y)| vec![x, y])
.collect(),
),
);
let mut renderer: ImageRenderer = ImageRenderer::new(1200, 1200);
renderer.save(&c, format!("/tmp/chc.svg")).unwrap();
}
Expected result (a screenshot from html page made by HtmlRenderer
):
I want to suggest deriving Clone
and PartialEq
for charts and containing structs. Serialize
and Deserialize
for example could also be feature gated, if necessary. What do you think?
Will there be support for decal patterns?
PS: Thank you for the library, it's great to work with. I wanted to use it for plots in publications, but could not find any option for decal patterns. It makes little difference on screen, but the bars are much easier to distinguish in B&W print when using patterns, so I wonder if they will be added later.
I'm unable to use the renderer (and I can't find it anywhere else)
charming = { version = "0.1.2", feature = "wasm" }
But same for 0.2.1
error[E0432]: unresolved import `charming::WasmRenderer`
--> src/main.rs:3:5
|
3 | use charming::WasmRenderer;
| ^^^^^^^^^^------------
| | |
| | help: a similar name exists in the module: `HtmlRenderer`
| no `WasmRenderer` in the root
Is there any leptos example?
Hi,
Thanks for your great work! I am looking for rust visualization library for a long time. I have tried plotters (https://github.com/plotters-rs/plotters) and plotly (https://github.com/igiagkiozis/plotly), both of them are disappointing cannot meet my demand. Charming is the best one of all the rust visualization library I have ever seen and worth trying!
Do you have a roadmap of charming and will you maintain this project ? Though I am not a developer, I can test charming for you. And can I convert charming chart to json now using something like Chart.to_json() ? if so, I can send the json to web front end and render it. Besides, can I use charming in vscode jupyter and render them ?
if I recall correctly, I remember at one point seeing an example for how to load data for candlesticks, but the example is now gone. Adding this back would be great since there's only the svg examples. I have a Polars Dataframe as my source.
I am embedding charming graphs inside leptos components. To handle canvas resizes correctly, I need to keep track of the Echart object in the reactive effect by inserting it in a leptos Read/WriteSignal. This requires Echart to be Clone, unless I am missing a a simpler solution.
Something like this would solve the issue:
--- a/charming/src/renderer/wasm_renderer.rs
+++ b/charming/src/renderer/wasm_renderer.rs
@@ -144,6 +155,8 @@ impl Animation {
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_name = echarts)]
+ #[derive(Clone)]
pub type Echarts;
#[wasm_bindgen(js_namespace = echarts, js_name = init)]
Are there any drawbacks with this change?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.