Skip to content

Commit

Permalink
FIX-lux-org#298: Abbrev long filter values and add to vis test (lux-o…
Browse files Browse the repository at this point in the history
…rg#466)

* FIX-lux-org#298: Abbrev long filter values and add to vis test

Signed-off-by: Labanya Mukhopadhyay <[email protected]>

* Update tests/test_vis.py

Co-authored-by: Doris Lee <[email protected]>
  • Loading branch information
labanyamukhopadhyay and dorisjlee authored Mar 20, 2022
1 parent 3ca053d commit 6387fe9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lux/vislib/altair/AltairChart.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def encode_color(self):
def add_title(self):
chart_title = self.vis.title
if chart_title:
if len(chart_title) > 25:
chart_title = chart_title[:15] + "..." + chart_title[-10:]
self.chart = self.chart.encode().properties(title=chart_title)
if self.code != "":
self.code += f"chart = chart.encode().properties(title = '{chart_title}')"
Expand Down
2 changes: 2 additions & 0 deletions lux/vislib/matplotlib/MatplotlibChart.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def encode_color(self):
def add_title(self):
chart_title = self.vis.title
if chart_title:
if len(chart_title) > 25:
chart_title = chart_title[:15] + "..." + chart_title[-10:]
self.ax.set_title(chart_title)
self.code += f"ax.set_title('{chart_title}')\n"

Expand Down
21 changes: 21 additions & 0 deletions tests/test_vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,3 +582,24 @@ def test_intent_override_all_column():
assert (
"y = alt.Y('Record', type= 'quantitative', title='Number of Records'" in current_vis_code
), "All column not overriden by intent"


def test_abbrev_title():
long_content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
dataset = [
{"long_attr": long_content, "normal": 3, "normal2": 1},
{"long_attr": long_content, "normal": 3, "normal2": 1},
{"long_attr": long_content, "normal": 2, "normal2": 1},
{"long_attr": long_content, "normal": 4, "normal2": 1},
]
df = pd.DataFrame(dataset)
lux.config.plotting_backend = "matplotlib"
vis = Vis(["normal2", "normal", f"long_attr={long_content}"], df)
vis_code = vis.to_matplotlib()
print(vis_code)
assert "long_attr = Lor...t laborum.'" in vis_code

vis_code = vis.to_altair()
print(vis_code)
assert "long_attr = Lor...t laborum.'" in vis_code
lux.config.plotting_backend = "altair"

0 comments on commit 6387fe9

Please sign in to comment.