yuankunzhang / charming

A visualization library for Rust
Apache License 2.0
1.85k stars 74 forks source link

Add dz! macro to construct (multiple dimensions) ECharts DataFrame from any number of data vectors/ columns #100

Closed humphreylee closed 4 weeks ago

humphreylee commented 1 month ago

The main objective of macro dz! is to transpose mixed data type vectors, aka columns or dimensions into ECharts dataframe format.

LukaOber commented 1 month ago

Can you provide some examples of how to use this macro?

Some small unit test to check the correct functionality would also be great.

I am not super familiar with macros that's why I am hesitant to merge this. Especially because it was generated by a LLM.

humphreylee commented 1 month ago

The dz! macro was developed to address the challenges of constructing ECharts dataframes with dynamic and mixed data types. While reviewing examples, I found examples in the repository typically hardcode all data directly into the chart code. Although the dataframe format is preferred by ECharts, Rust’s type system does not permit mixed data types within a single vector. An example file bubble_scater2.rs has been added to demonstrate the usage of the dz! macro with an existing example.

humphreylee commented 1 month ago

I believed the existing df! macro could accomplish my goals, but I couldn’t get it to work as intended. I might have overlooked some nuances. Therefore, I developed the dz! macro.

humphreylee commented 1 month ago

Added a simple dz_test.rs unit test file.

yuankunzhang commented 1 month ago

Overall this looks good to me, is there any particular meaning of the macro name dz!?

humphreylee commented 1 month ago

Overall this looks good to me, is there any particular meaning of the macro name dz!?

The naming of dz! is based on three primary considerations:

  1. The dz! macro constructs a dataframe by interleaving vectors in a zig-zag pattern, iterating row by row across multiple columns/vectors;
  2. The syntax let df = df() is frequently encountered in data manipulation libraries such as Rust Polars, R, and Pandas. Personally, I find df notation can be ambiguous and potentially overused; &
  3. df! is already in use. But dz! is cool.
LukaOber commented 4 weeks ago

Thank you very much for the implementation and especially for providing the tests and examples. I am also a big fan of noting down that some of the code was generated using LLM.