Created
February 1, 2020 14:39
-
-
Save DougBurke/d0ee4e37291c3066d709b57818b330c5 to your computer and use it in GitHub Desktop.
Suggested changes to eventlog2html for proposed hvega 0.5 changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
diff --git a/src/Eventlog/VegaTemplate.hs b/src/Eventlog/VegaTemplate.hs | |
index 773c916..eafafa6 100644 | |
--- a/src/Eventlog/VegaTemplate.hs | |
+++ b/src/Eventlog/VegaTemplate.hs | |
@@ -18,8 +18,9 @@ import Data.Text.Lazy (toStrict) | |
-- | Workaround for some limitations in the HVega library. | |
-- This function should be removed once the features are merged into HVega. | |
-injectJSON :: Text -> Value -> BuildLabelledSpecs | |
-injectJSON t val = \x -> x ++ [(t,val)] | |
+injectJSON :: Text -> Value -> BuildSelectSpecs | |
+injectJSON t val = \x -> toSelectSpec t val : x | |
+ | |
data AreaChartType | |
= Stacked | |
@@ -72,21 +73,21 @@ vegaResult conf = toVegaLite $ | |
AreaChart ct -> areaChartFull ct c' | |
] | |
-areaChartFull :: AreaChartType -> ChartConfig -> (VLProperty, VLSpec) | |
+areaChartFull :: AreaChartType -> ChartConfig -> PropertySpec | |
areaChartFull ct c = hConcat | |
[ | |
asSpec [vConcat [areaChart ct c, selectionChart c]] | |
, legendDiagram | |
] | |
-lineChartFull :: ChartConfig -> (VLProperty, VLSpec) | |
+lineChartFull :: ChartConfig -> PropertySpec | |
lineChartFull c = hConcat | |
[ | |
asSpec [vConcat [lineChart c, selectionChart c]] | |
, legendDiagram | |
] | |
-config :: [LabelledSpec] -> (VLProperty, VLSpec) | |
+config :: [ConfigureSpec] -> PropertySpec | |
config = | |
configure | |
. configuration (TextStyle [(MAlign AlignRight), (MdX (-5)), (MdY 5)]) | |
@@ -109,7 +110,7 @@ linesLayer c = asSpec | |
transformLineLayer [] | |
] | |
-encodingLineLayer :: ChartConfig -> [LabelledSpec] -> (VLProperty, VLSpec) | |
+encodingLineLayer :: ChartConfig -> [EncodingSpec] -> PropertySpec | |
encodingLineLayer c | |
= encoding | |
. color [MName "c", MmType Nominal, MScale [colourProperty c], MLegend []] | |
@@ -117,7 +118,7 @@ encodingLineLayer c | |
PScale [SDomain (DSelection "brush")]] | |
. position Y [PName "norm_y", PmType Quantitative, PAxis [AxTitle "Allocation", AxFormat ".1f"]] | |
-transformLineLayer :: [LabelledSpec] -> (VLProperty, VLSpec) | |
+transformLineLayer :: [TransformSpec] -> PropertySpec | |
transformLineLayer = | |
transform | |
. window [([WField "y", WAggregateOp Max], "max_y")] [WFrame Nothing Nothing, WGroupBy ["k"]] | |
@@ -128,18 +129,22 @@ transformLineLayer = | |
-- The Selection Chart | |
----------------------------------------------------------------------------------- | |
-encodingSelection :: ChartConfig -> [LabelledSpec] -> (VLProperty, VLSpec) | |
+encodingSelection :: ChartConfig -> [EncodingSpec] -> PropertySpec | |
encodingSelection c = | |
encoding | |
. order [OName "k", OmType Quantitative] | |
- . injectJSON "tooltip" Null | |
+ . tooltip [] -- new in hvega 0.5.0.0 (although tooltips are also | |
+ -- off by default in Vega-Lite 4) | |
. color [MName "c", MmType Nominal, MScale [colourProperty c], MLegend []] | |
. position X [PName "x", PmType Quantitative, PAxis [AxTitle "Time (s)"]] | |
. position Y [PName "y", PmType Quantitative, PAxis [{-AxTitle "Allocation", AxFormat "s"-}], PAggregate Sum, PStack StZero] | |
-brush :: (VLProperty, VLSpec) | |
-brush = (selection . injectJSON "brush" (object [ "type" .= String "interval" | |
+brush :: PropertySpec | |
+brush = (selection . | |
+ {- Is this valid Vega-Lite? -} | |
+ injectJSON "brush" (object [ "type" .= String "interval" | |
, "init" .= object [ "x" .= [Null, Null] ] ])) [] | |
+ | |
-- init field is not supported and necessary for dynamic loading | |
selectionChart :: ChartConfig -> VLSpec | |
@@ -178,8 +183,8 @@ bandsLayer ct c = asSpec | |
encodingBandsLayer :: AreaChartType | |
-> ChartConfig | |
- -> [LabelledSpec] | |
- -> (VLProperty, VLSpec) | |
+ -> [EncodingSpec] | |
+ -> PropertySpec | |
encodingBandsLayer ct c = | |
encoding | |
. order [OName "k", OmType Quantitative] | |
@@ -207,7 +212,7 @@ encodingBandsLayer ct c = | |
++ | |
[PScale [SDomain (DNumbers [0, extent])] | Just extent <- [fixedYAxisExtent c]] ) | |
-transformBandsLayer :: [LabelledSpec] -> (VLProperty, VLSpec) | |
+transformBandsLayer :: [TransformSpec] -> PropertySpec | |
transformBandsLayer = | |
transform | |
. filter (FSelection "legend") | |
@@ -224,7 +229,7 @@ tracesLayer = asSpec | |
encodingTracesLayer [] | |
] | |
-encodingTracesLayer :: [LabelledSpec] -> (VLProperty, VLSpec) | |
+encodingTracesLayer :: [EncodingSpec] -> PropertySpec | |
encodingTracesLayer = | |
encoding | |
. color [MString "grey"] | |
@@ -247,10 +252,10 @@ legendDiagram = asSpec | |
selectionRight [] | |
] | |
-encodingRight :: [LabelledSpec] -> (VLProperty, VLSpec) | |
+encodingRight :: [EncodingSpec] -> PropertySpec | |
encodingRight = | |
encoding | |
- . injectJSON "tooltip" Null | |
+ . tooltip [] | |
. color | |
[ | |
MSelectionCondition (SelectionName "legend") [MName "c", MmType Nominal, MLegend []] [MString "lightgray"] | |
@@ -265,7 +270,7 @@ encodingRight = | |
, AxMaxExtent 100] | |
, PSort [(ByFieldOp "k" Mean), Descending]] | |
-selectionRight :: [LabelledSpec] -> (VLProperty, VLSpec) | |
+selectionRight :: [SelectSpec] -> PropertySpec | |
selectionRight = | |
selection | |
. select "legend" Multi [On "click", Encodings [ChColor], ResolveSelections Global, Toggle "event.shiftKey"] | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment