Skip to content

Commit

Permalink
Restore support for domains of the form
Browse files Browse the repository at this point in the history
"domain": {
  "fields": [["sum_value_start"], ["sum_value_end"]]
}
  • Loading branch information
jonmmease committed Sep 16, 2023
1 parent f2e3d6c commit 0e2bc18
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions vegafusion-core/src/spec/scale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl ScaleTypeSpec {
pub enum ScaleDomainSpec {
Array(Vec<ScaleArrayElementSpec>),
FieldReference(ScaleFieldReferenceSpec),
FieldsVecStrings(ScaleVecStringsSpec),
FieldsReference(ScaleFieldsReferenceSpec),
FieldsReferences(ScaleFieldsReferencesSpec),
FieldsSignals(ScaleSignalsSpec),
Expand All @@ -86,6 +87,14 @@ pub struct ScaleFieldsReferencesSpec {
pub extra: HashMap<String, Value>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ScaleVecStringsSpec {
pub fields: Vec<Vec<String>>,

#[serde(flatten)]
pub extra: HashMap<String, Value>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ScaleDataReferenceOrSignalSpec {
Expand All @@ -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<String>,

pub fields: Vec<String>,

#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -122,15 +133,19 @@ pub struct ScaleFieldsReferenceSpec {

impl ScaleFieldsReferenceSpec {
pub fn to_field_references(&self) -> Vec<ScaleFieldReferenceSpec> {
self.fields
.iter()
.map(|f| ScaleFieldReferenceSpec {
data: self.data.clone(),
field: f.clone(),
sort: self.sort.clone(),
extra: Default::default(),
})
.collect::<Vec<_>>()
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::<Vec<_>>()
} else {
Vec::new()
}
}
}

Expand Down

0 comments on commit 0e2bc18

Please sign in to comment.