Skip to content

Commit

Permalink
vega: Extract _fill_properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
daavoo committed Mar 8, 2022
1 parent 6b316ef commit 00d2ee6
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/dvc_render/vega.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ def __init__(self, datapoints: Dict, name: str, **properties):
self.properties.get("template_dir", None),
)

def _fill_properties(self, content: str) -> str:
self.properties.setdefault("title", "")
self.properties.setdefault("x_label", self.properties.get("x"))
self.properties.setdefault("y_label", self.properties.get("y"))

names = ["title", "x", "y", "x_label", "y_label"]
for name in names:
value = self.properties.get(name)
if value is not None:
content = self.template.fill_anchor(content, name, value)
return content

def partial_html(self) -> str:
content = deepcopy(self.template.content)
if self.template.anchor_str("data") not in self.template.content:
Expand All @@ -55,15 +67,7 @@ def partial_html(self) -> str:
self.datapoints, self.properties.get("y")
)

content = self._fill_properties(content)
content = self.template.fill_anchor(content, "data", self.datapoints)

self.properties.setdefault("title", "")
self.properties.setdefault("x_label", self.properties.get("x"))
self.properties.setdefault("y_label", self.properties.get("y"))

names = ["title", "x", "y", "x_label", "y_label"]
for name in names:
value = self.properties.get(name)
if value is not None:
content = self.template.fill_anchor(content, name, value)
return content

0 comments on commit 00d2ee6

Please sign in to comment.