timeplot 1.0.16 → 1.0.17
raw patch · 3 files changed
+27/−11 lines, 3 files
Files
- Graphics/Rendering/Chart/Event.hs +9/−0
- Tools/TimePlot/Render.hs +17/−10
- timeplot.cabal +1/−1
Graphics/Rendering/Chart/Event.hs view
@@ -3,6 +3,9 @@ PlotEvent(..), Event(..), + eventStart,+ eventEnd,+ defaultPlotEvent, plot_event_title, plot_event_data,@@ -25,6 +28,12 @@ -- True = "known explicitly", False = "implicit" (e.g. imposed by axis bounds) | PulseEvent t e -- ^ A zero-length event deriving (Show)++eventStart (LongEvent (t0,_) (t1,_) _) = t0+eventStart (PulseEvent t _) = t++eventEnd (LongEvent (t0,_) (t1,_) _) = t1+eventEnd (PulseEvent t _) = t -- | A chart that depict events. -- There are two kinds of events: long and impulse events. A long event
Tools/TimePlot/Render.hs view
@@ -23,20 +23,31 @@ (map f' grid) dataToPlot :: AxisData LocalTime -> (LocalTime,LocalTime) -> PlotData -> AnyLayout1 LocalTime -dataToPlot commonTimeAxis tr p@PlotBarsData{} = withAnyOrdinate $ layoutWithTitle commonTimeAxis tr [plotBars plot] (plotName p) (length (barsTitles p) > 1) +dataToPlot commonTimeAxis tr = dataToPlot' commonTimeAxis . constrainTime tr + +constrainTime :: (LocalTime,LocalTime) -> PlotData -> PlotData +constrainTime tr@(t0,t1) p@PlotBarsData{} = p {barsValues = filter (inRange tr . fst) (barsValues p)} +constrainTime tr@(t0,t1) p@PlotEventData{} = p {eventData = filter (any (inRange tr) . eventTimes) (eventData p)} +constrainTime tr@(t0,t1) p@PlotLinesData{} = p {linesData = map (filter (inRange tr . fst)) (linesData p)} +constrainTime tr@(t0,t1) p@PlotDotsData{} = p {dotsData = map (filter (inRange tr . fst)) (dotsData p)} + +inRange (t0,t1) t = t>=t0 && t<=t1 +eventTimes e = [eventStart e, eventEnd e] + +dataToPlot' commonTimeAxis p@PlotBarsData{} = withAnyOrdinate $ layoutWithTitle commonTimeAxis [plotBars plot] (plotName p) (length (barsTitles p) > 1) where plot = plot_bars_values ^= barsValues p $ plot_bars_item_styles ^= barsStyles p $ plot_bars_style ^= barsStyle p $ plot_bars_titles ^= barsTitles p $ ourPlotBars -dataToPlot commonTimeAxis tr p@PlotEventData{} = withAnyOrdinate $ layoutWithTitle commonTimeAxis tr [toPlot plot] (plotName p) False +dataToPlot' commonTimeAxis p@PlotEventData{} = withAnyOrdinate $ layoutWithTitle commonTimeAxis [toPlot plot] (plotName p) False where plot = plot_event_data ^= eventData p $ plot_event_long_fillstyle ^= toFillStyle $ plot_event_label ^= toLabel $ defaultPlotEvent toFillStyle s = solidFillStyle . opaque $ fromMaybe lightgray (readColourName (statusColor s)) toLabel s = statusLabel s -dataToPlot commonTimeAxis tr p@PlotLinesData{} = withAnyOrdinate $ layoutWithTitle commonTimeAxis tr (map toPlot plots) (plotName p) (length (linesData p) > 1) +dataToPlot' commonTimeAxis p@PlotLinesData{} = withAnyOrdinate $ layoutWithTitle commonTimeAxis (map toPlot plots) (plotName p) (length (linesData p) > 1) where plots = [plot_lines_values ^= [vs] $ plot_lines_title ^= title $ plot_lines_style ^= lineStyle $ @@ -44,7 +55,7 @@ | vs <- linesData p | title <- linesTitles p | lineStyle <- linesStyles p] -dataToPlot commonTimeAxis tr p@PlotDotsData{} = withAnyOrdinate $ layoutWithTitle commonTimeAxis tr (map toPlot plots) (plotName p) (length (dotsData p) > 1) +dataToPlot' commonTimeAxis p@PlotDotsData{} = withAnyOrdinate $ layoutWithTitle commonTimeAxis (map toPlot plots) (plotName p) (length (dotsData p) > 1) where plots = [plot_points_values ^= vs $ plot_points_style ^= hollowCircles 4 1 color $ plot_points_title ^= subtrack $ @@ -53,21 +64,17 @@ | color <- dotsColors p | vs <- dotsData p] --- TODO generate left axis from data fitting into t0..t1 -layoutWithTitle :: (PlotValue a) => AxisData LocalTime -> (LocalTime, LocalTime) -> [Plot LocalTime a] -> String -> Bool -> Layout1 LocalTime a -layoutWithTitle commonTimeAxis (t0,t1) plots name showLegend = +layoutWithTitle :: (PlotValue a, Show a) => AxisData LocalTime -> [Plot LocalTime a] -> String -> Bool -> Layout1 LocalTime a +layoutWithTitle commonTimeAxis plots name showLegend = layout1_title ^= "" $ layout1_plots ^= map Left plots $ (if showLegend then id else (layout1_legend ^= Nothing)) $ layout1_bottom_axis .> laxis_generate ^= (\_ -> commonTimeAxis) $ layout1_top_axis .> laxis_generate ^= (\_ -> commonTimeAxis) $ layout1_left_axis .> laxis_title ^= name $ - layout1_left_axis .> laxis_generate ^= (\_ -> autoAxis visibleValues) $ layout1_margin ^= 0 $ layout1_grid_last ^= True $ defaultLayout1 - where - visibleValues = [a | p <- plots, (t,a) <- uncurry zip $ plot_all_points_ p, t >= t0 && t <= t1] ourPlotBars :: (BarsPlotValue a) => PlotBars LocalTime a ourPlotBars = plot_bars_spacing ^= BarsFixGap 0 0 $
timeplot.cabal view
@@ -1,5 +1,5 @@ name: timeplot-version: 1.0.16+version: 1.0.17 cabal-version: >=1.6 build-type: Simple license: BSD3