Skip to content

Commit

Permalink
supporting setPlotConfig for View and ViewCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
dorisjlee committed Jun 16, 2020
1 parent 93362fd commit aa9e382
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lux/luxDataFrame/LuxDataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def setExecutorType(self, exe):
self.executorType = exe
def setPlotConfig(self,configFunc:typing.Callable):
"""
Modify plot aesthetic settings to the Altair chart object
Modify plot aesthetic settings to all Views in the dataframe display
Currently only supported for Altair visualizations
Parameters
Expand Down
14 changes: 13 additions & 1 deletion lux/view/View.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class View:
'''

def __init__(self, specLst, mark="", title=""):
# self.specLst = Parser.parse(specLst) #TODO: make sure this is not duplicated for programmatically generated views
self.specLst = specLst
self.title = title
self.mark = mark
Expand Down Expand Up @@ -50,6 +49,19 @@ def __repr__(self):
return f"<View ({str_channels[:-2]} -- [{filter_spec.attribute}{filter_spec.filterOp}{filter_spec.value}]) mark: {self.mark}, score: {self.score} >"
else:
return f"<View ({str_channels[:-2]}) mark: {self.mark}, score: {self.score} >"
def setPlotConfig(self,configFunc:Callable):
"""
Modify plot aesthetic settings to the View
Currently only supported for Altair visualizations
Parameters
----------
configFunc : typing.Callable
A function that takes in an AltairChart (https://altair-viz.github.io/user_guide/generated/toplevel/altair.Chart.html) as input and returns an AltairChart as output
"""
self.plotConfig = configFunc
def clearPlotConfig(self):
self.plotConfig = None
def _repr_html_(self):
from IPython.display import display
checkImportLuxWidget()
Expand Down
16 changes: 15 additions & 1 deletion lux/view/ViewCollection.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations
from lux.vizLib.altair.AltairRenderer import AltairRenderer
from lux.utils.utils import checkImportLuxWidget
from typing import List, Union
from typing import List, Union, Callable
from lux.view.View import View
from lux.context.Spec import Spec
class ViewCollection():
Expand Down Expand Up @@ -118,7 +118,21 @@ def getField(dObj):

def set(self,fieldName,fieldVal):
return NotImplemented
def setPlotConfig(self,configFunc:Callable):
"""
Modify plot aesthetic settings to the View Collection
Currently only supported for Altair visualizations
Parameters
----------
configFunc : typing.Callable
A function that takes in an AltairChart (https://altair-viz.github.io/user_guide/generated/toplevel/altair.Chart.html) as input and returns an AltairChart as output
"""
for view in self.collection:
view.plotConfig = configFunc
def clearPlotConfig(self):
for view in self.collection:
view.plotConfig = None
def sort(self, removeInvalid=True, descending = True):
# remove the items that have invalid (-1) score
if (removeInvalid): self.collection = list(filter(lambda x: x.score!=-1,self.collection))
Expand Down

0 comments on commit aa9e382

Please sign in to comment.