From 0e2bc18a24f58d61749efff3e3b9b262fd092d09 Mon Sep 17 00:00:00 2001 From: Jon Mease Date: Sat, 16 Sep 2023 06:04:09 -0400 Subject: [PATCH] Restore support for domains of the form "domain": { "fields": [["sum_value_start"], ["sum_value_end"]] } --- vegafusion-core/src/spec/scale.rs | 35 ++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/vegafusion-core/src/spec/scale.rs b/vegafusion-core/src/spec/scale.rs index 1a43e3ef..4a9fada9 100644 --- a/vegafusion-core/src/spec/scale.rs +++ b/vegafusion-core/src/spec/scale.rs @@ -68,6 +68,7 @@ impl ScaleTypeSpec { pub enum ScaleDomainSpec { Array(Vec), FieldReference(ScaleFieldReferenceSpec), + FieldsVecStrings(ScaleVecStringsSpec), FieldsReference(ScaleFieldsReferenceSpec), FieldsReferences(ScaleFieldsReferencesSpec), FieldsSignals(ScaleSignalsSpec), @@ -86,6 +87,14 @@ pub struct ScaleFieldsReferencesSpec { pub extra: HashMap, } +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct ScaleVecStringsSpec { + pub fields: Vec>, + + #[serde(flatten)] + pub extra: HashMap, +} + #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(untagged)] pub enum ScaleDataReferenceOrSignalSpec { @@ -110,7 +119,9 @@ pub struct ScaleFieldReferenceSpec { #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct ScaleFieldsReferenceSpec { - pub data: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub data: Option, + pub fields: Vec, #[serde(skip_serializing_if = "Option::is_none")] @@ -122,15 +133,19 @@ pub struct ScaleFieldsReferenceSpec { impl ScaleFieldsReferenceSpec { pub fn to_field_references(&self) -> Vec { - self.fields - .iter() - .map(|f| ScaleFieldReferenceSpec { - data: self.data.clone(), - field: f.clone(), - sort: self.sort.clone(), - extra: Default::default(), - }) - .collect::>() + if let Some(data) = &self.data.clone() { + self.fields + .iter() + .map(|f| ScaleFieldReferenceSpec { + data: data.clone(), + field: f.clone(), + sort: self.sort.clone(), + extra: Default::default(), + }) + .collect::>() + } else { + Vec::new() + } } }