-- Module to draw clusters of time series data. -- by Scot Drysdale on 10/14/07 module DrawClusters(dataset2Polylines, drawClustersScreen, drawProtoClustersScreen, module Clusters, module DrawX) where import Clusters import DrawX -- Converts a list of ProtoClusters to a list of Series, with the -- prototypes as a separate Series added to the END. (This -- way all of the prototypes will plot in the same color, and -- they will be drawn on top of the others.) groupPrototypes :: [ProtoCluster] -> [[Series]] groupPrototypes clusters = (map extractSeries (map snd clusters)) ++ [map fst clusters] -- Converts a list of Datasets to a list of colored polylines. -- Assumes that there are at least as many colors as clusters. dataset2Polylines :: [[Series]] -> [Color] -> ColoredShapes dataset2Polylines clusters colors = concat coloredClusters where polyData = (map (map Polyline) . map (map (zip [1.0, 2.0..]))) clusters coloredClusters = zipWith (\x y -> [(x, z) | z <- y]) colors polyData -- Draws a list of [[Series]], with each [[Series]] drawn in a different color. -- Must be at least as many colors as [Series] -- The last three parameters are the window size and title drawSeriesScreen :: [[Series]] -> [Color] -> Int -> Int -> String -> IO () drawSeriesScreen series colors winX winY title = runGraphics ( do uw <- openUserWindow uXmin uXmax uYmin uYmax winX winY title drawShapes uw (dataset2Polylines series colors) spaceClose (win uw) ) where uXmin = 1 uXmax = (intToFloat . length . head . head) series values = flatten series uYmin = minimum values uYmax = maximum values -- Draw a list of protoclusters, with the protoypes grouped and colored with the -- last color and the clusters colored with the rest. -- The length of colors must be at least one greater than the number of clusters. -- The last three parameters are the window size and title drawProtoClustersScreen :: [ProtoCluster] -> [Color] -> Int -> Int -> String -> IO () drawProtoClustersScreen protoClusters = drawSeriesScreen (groupPrototypes protoClusters) drawClustersScreen :: [Dataset] -> [Color] -> Int -> Int -> String -> IO () drawClustersScreen ds = drawSeriesScreen (map extractSeries ds) -- Creates a list of all values that appear as data in a [Series] flatten :: [[Series]] -> [Float] flatten = concat . map concat