Skip to content

Commit

Permalink
Added macros "df_transposed" to transpose vectors (mixed data type) i…
Browse files Browse the repository at this point in the history
…nto Echarts dataframe format.
  • Loading branch information
humphreylee authored Jul 31, 2024
1 parent 288301e commit 86c41a1
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions charming/src/datatype/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,43 @@ macro_rules! df {
]
};
}

#[macro_export]
macro_rules! df_transposed {
($([$($x:expr),*]),* $(,)?) => {

// Determine the length of the vectors (assuming they are all the same length)
let len = $crate::vec_len!($($col),*);

// Create a vector to store the resulting rows
let mut rows = Vec::with_capacity(len);

// Iterate over the length of the vectors
for i in 0..len {
vec![
$(
$crate::datatype::DataPoint::from($crate::datatype::CompositeValue::from(vec![
$(
$crate::datatype::CompositeValue::from($x[i].clone())
),*
]))
),*
]
}
};
($($x:expr),* $(,)?) => {
vec![
$(
$crate::datatype::DataPoint::from($x)
),*
]
};
}

#[macro_export]
macro_rules! vec_len {
($first:expr $(, $rest:expr)*) => {
$first.len()
};
}

0 comments on commit 86c41a1

Please sign in to comment.