Skip to content

Commit

Permalink
Remove markbar enitrely, rely on Altair automatic bin detection https…
Browse files Browse the repository at this point in the history
  • Loading branch information
micahtyong committed Feb 22, 2021
1 parent b322f1d commit 9cb9418
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions lux/vislib/altair/Histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,7 @@ def initialize_chart(self):
if isinstance(msr_attr.attribute, str):
msr_attr.attribute = msr_attr.attribute.replace(".", "")

colval = self.vis.data[msr_attr.attribute]
x_range = abs(max(colval) - min(colval))
plot_range = abs(x_max - x_min)
markbar = x_range / plot_range * 10

self.data = AltairChart.sanitize_dataframe(self.data)
end_attr_abv = str(msr_attr.attribute) + "_end"
self.data[end_attr_abv] = self.data[str(msr_attr.attribute)].apply(lambda x: x + markbar)

axis_title = f"{msr_attr_abv} (binned)"
if msr_attr.attribute == " ":
Expand All @@ -69,11 +62,10 @@ def initialize_chart(self):
x=alt.X(
str(msr_attr.attribute),
title=axis_title,
bin=alt.Bin(binned=True, step=markbar),
bin=alt.Bin(),
type=msr_attr.data_type,
axis=alt.Axis(title=axis_title),
),
x2=end_attr_abv,
y=alt.Y("Number of Records", type="quantitative"),
)
)
Expand All @@ -86,7 +78,7 @@ def initialize_chart(self):
y=alt.Y(
str(msr_attr.attribute),
title=axis_title,
bin=alt.Bin(binned=True, step=markbar),
bin=alt.Bin(),
axis=alt.Axis(title=axis_title),
),
)
Expand All @@ -100,14 +92,14 @@ def initialize_chart(self):
self.code += f"visData = pd.DataFrame({str(self.data.to_dict())})\n"
if measure.channel == "x":
self.code += f"""
chart = alt.Chart(visData).mark_bar(size={markbar}).encode(
chart = alt.Chart(visData).mark_bar().encode(
alt.X('{msr_attr.attribute}', title='{axis_title}',bin=alt.Bin(binned=True), type='{msr_attr.data_type}', axis=alt.Axis(labelOverlap=True, title='{axis_title}'), scale=alt.Scale(domain=({x_min}, {x_max}))),
alt.Y("Number of Records", type="quantitative")
)
"""
elif measure.channel == "y":
self.code += f"""
chart = alt.Chart(visData).mark_bar(size={markbar}).encode(
chart = alt.Chart(visData).mark_bar().encode(
alt.Y('{msr_attr.attribute}', title='{axis_title}',bin=alt.Bin(binned=True), type='{msr_attr.data_type}', axis=alt.Axis(labelOverlap=True, title='{axis_title}'), scale=alt.Scale(domain=({x_min}, {x_max}))),
alt.X("Number of Records", type="quantitative")
)
Expand Down

0 comments on commit 9cb9418

Please sign in to comment.