Skip to content
Snippets Groups Projects
Commit b5549d15 authored by Sabed Ger's avatar Sabed Ger
Browse files

interaktion mit visualisierung 2 abgeschlossen - visualisierung 2 fertig implementiert

parent 56e0a7d9
No related branches found
No related tags found
No related merge requests found
module Plots exposing ( XyData,MultiDimData,Msg
, pointConstructor,pointsConstructor,qValuesToQQValues,qValuesToMultiDimQQValues
, viewScatterplot,viewQQPlot,viewParallelCoordsPlot
)
module Plots exposing (..)
-- Html
import Html exposing (Html)
......@@ -28,12 +25,14 @@ import Util exposing (..)
type alias Model =
{ scatterplotType : ScatterplotType
, powertransformation: String
, plotChange : PlotChangeModel
}
init : Model
init = { scatterplotType = None ""
, powertransformation = ""
, plotChange = initPlotChange
}
-- UPDATE
......@@ -42,6 +41,7 @@ type Msg
= ScatterplotChange ScatterplotType
| Powertransformation String
| ParallelCoordsSwapD_list Int Int
| PlotChange PlotChangeMsg
noUpdate : Model -> Model
noUpdate model = model
......@@ -59,8 +59,47 @@ update msg model =
None _ -> None "Exception: triggered CarType2Change with PlotType None"
QQ_Plot -> None "Exception: triggered ParallelCoordsSwapD_list with PlotType QQ_Plot"
Parallel_Coords b d_list -> Parallel_Coords b (list_swap d_list {i1=i1,i2=i2})
, plotChange = let plotChange = model.plotChange
in
if List.member i1 model.plotChange.selectedDims
&& not (List.member i2 model.plotChange.selectedDims)
then { plotChange | selectedDims = List.reverse (updatePlotChange (SelectDim i2) <| updatePlotChange (SelectDim i1) model.plotChange).selectedDims }
else if List.member i2 model.plotChange.selectedDims
&& not (List.member i1 model.plotChange.selectedDims)
then { plotChange | selectedDims = List.reverse (updatePlotChange (SelectDim i1) <| updatePlotChange (SelectDim i2) model.plotChange).selectedDims }
else if List.member i1 model.plotChange.selectedDims
&& List.member i2 model.plotChange.selectedDims
then { plotChange | selectedDims = List.reverse plotChange.selectedDims }
else model.plotChange
}
PlotChange plotChangeMsg -> { model | plotChange = updatePlotChange plotChangeMsg model.plotChange }
-- update plotChange
type alias PlotChangeModel = { selectedDims : List Int }
initPlotChange : PlotChangeModel
initPlotChange = { selectedDims = [] }
type PlotChangeMsg
= SelectDim Int
updatePlotChange : PlotChangeMsg -> PlotChangeModel -> PlotChangeModel
updatePlotChange msg model =
case msg of
SelectDim dim -> { model | selectedDims =
case model.selectedDims of
[] -> [dim]
[x] -> if dim == x
then []
else [x,dim]
[x,y] -> if dim == x
then [y]
else if dim == y
then [x]
else [x,y]
x::(y::xs) -> [x,y]
}
-- Types
type alias Point =
......@@ -360,17 +399,17 @@ viewPowertransformedScatterplot power scatterplotName model line =
in viewScatterplot ("Powertransformed - "++power++" - "++scatterplotName)
newModel Nothing Nothing Nothing newLine ""
viewParallelCoordsPlot : String -> MultiDimData -> Bool -> Html Msg
viewParallelCoordsPlot name model doXRay =
viewParallelCoordsPlot : String -> MultiDimData -> Bool -> Bool -> List Int -> Html Msg
viewParallelCoordsPlot name model doXRay doSameScale selectedDims =
Html.div []
[ Html.h4 [] [Html.text name]
, if List.length model.data /= 0 then parallelCoordsPlot model doXRay
, if List.length model.data /= 0 then parallelCoordsPlot model doXRay doSameScale selectedDims
else Html.text "Unable to show the parallel coords plot, because the input data is empty!"
]
-- Plots
parallelCoordsPlot : MultiDimData -> Bool -> Svg Msg
parallelCoordsPlot model doXRay =
parallelCoordsPlot : MultiDimData -> Bool -> Bool -> List Int -> Svg Msg
parallelCoordsPlot model doXRay doSameScale selectedDims =
let listDimValues : List (List Float)
listDimValues = multiDimDataToListDimValues model.data
......@@ -385,8 +424,14 @@ parallelCoordsPlot model doXRay =
frontgroundColor = if doXRay then Color.white else Color.black
backgroundColor = if doXRay then Color.black else Color.white
sameScaleValues : List Float
sameScaleValues = List.concat listDimValues
sameScale : ContinuousScale Float
sameScale = yScale sameScaleValues
in
svg [ viewBox 0 0 w h, TypedSvg.Attributes.width <| TypedSvg.Types.Percent 100, TypedSvg.Attributes.height <| TypedSvg.Types.Percent 100 ]
svg [ viewBox 0 0 (w*1.1) (h*1.1), TypedSvg.Attributes.width <| TypedSvg.Types.Percent 90, TypedSvg.Attributes.height <| TypedSvg.Types.Percent 90 ]
(List.concat
[[ style [] [ TypedSvg.Core.text """
.HoverDescription g > text { display: none; }
......@@ -402,17 +447,30 @@ parallelCoordsPlot model doXRay =
] [] ]
, List.map3
(\dimValues dimDescription index ->
let usedColor = if List.member index selectedDims then Color.green else frontgroundColor
in
g [ transform [ Translate (padding - 1 + (xCoordOfDim index)) padding ]
, class [ "HoverDescription" ]
, TypedSvg.Attributes.stroke (TypedSvg.Types.Paint frontgroundColor)
, TypedSvg.Attributes.fill (TypedSvg.Types.Paint frontgroundColor)
, TypedSvg.Attributes.stroke (TypedSvg.Types.Paint usedColor)
, TypedSvg.Attributes.fill (TypedSvg.Types.Paint usedColor)
, TypedSvg.Attributes.strokeWidth (Px 0.5)
] [ yAxis dimValues
, TypedSvg.Events.onClick (PlotChange <| SelectDim index)
] [ yAxis <| if doSameScale then sameScaleValues else dimValues
, text_ [ fontFamily [ "sans-serif" ]
, fontSize <| TypedSvg.Types.Px 10
, x -(padding/2)
, y -(padding/5)
, y ((-(padding/5))-((toFloat <| modBy 2 index)*padding/5))
] [ TypedSvg.Core.text dimDescription ]
, if List.member index selectedDims then
text_ [ fontFamily [ "sans-serif" ]
, fontSize <| TypedSvg.Types.Px 10
, x -(padding/2)
, y (h-9/5*padding)
] [ TypedSvg.Core.text <| "Selection "++(if index == (Maybe.withDefault -1 <|List.head selectedDims)
then "1" else "2"
)
]
else text_ [] []
]
) listDimValues model.dimDescription (List.range 0 <| numberDims-1)
, let triangle_left: {x:Float,y:Float} -> Int -> Svg Msg
......@@ -442,6 +500,8 @@ parallelCoordsPlot model doXRay =
in
List.map
(\dimIndex ->
let usedColor = if List.member dimIndex selectedDims then Color.green else frontgroundColor
in
g [ transform [ Translate padding padding ]
] ( List.append
( if not (dimIndex > 0) then [] else
......@@ -459,7 +519,7 @@ parallelCoordsPlot model doXRay =
(List.map3
(\pDimValue dimScaleLocal index ->
( xCoordOfDim index
, Scale.convert dimScaleLocal pDimValue
, Scale.convert (if doSameScale then sameScale else dimScaleLocal) pDimValue
)
)
point_ listDimScaleLocal (List.range 0 <| numberDims-1)
......@@ -491,7 +551,7 @@ scatterplot model lowModel highModel otherModel line styleKind =
half : ( Float, Float ) -> Float
half t = (Tuple.second t - Tuple.first t) / 2
in
svg [ viewBox 0 0 w h, TypedSvg.Attributes.width <| TypedSvg.Types.Percent 100, TypedSvg.Attributes.height <| TypedSvg.Types.Percent 100 ]
svg [ viewBox 0 0 w h, TypedSvg.Attributes.width <| TypedSvg.Types.Percent 90, TypedSvg.Attributes.height <| TypedSvg.Types.Percent 90 ]
(List.concat
[[ style [] [ TypedSvg.Core.text ("""
.point circle { stroke: rgba(0, 0, 0, 0.4); fill: rgba(255, 255, 255,0.3); }
......@@ -920,10 +980,8 @@ qValuesToQQValues qValues1 qValues2 =
qValuesToMultiDimQQValues : List XyData -> MultiDimData
qValuesToMultiDimQQValues qList =
let qListSortedByLength : List XyData
qListSortedByLength = List.sortBy (\xyData -> List.length <| xyData.data) qList
smallestDimData : XyData
smallestDimData = Maybe.withDefault (XyData "Error: There is no Data" "Error: There is no Data" []) <| List.head qListSortedByLength
let smallestDimData : XyData
smallestDimData = list_get (List.sortBy (\xyData -> List.length <| xyData.data) qList) 0
-- gets all values and description for one dimension
getOneDimData : XyData -> {description : String, value : List Float}
getOneDimData dimension_data =
......@@ -935,7 +993,7 @@ qValuesToMultiDimQQValues qList =
}
-- gets all the data that is nessesary
multiDimValues : List {description : String, value : List Float}
multiDimValues = List.map (\xyData -> getOneDimData xyData) qListSortedByLength
multiDimValues = List.map (\xyData -> getOneDimData xyData) qList
in MultiDimData (List.map .description multiDimValues) <| listDimValuesToMultiDimData <| List.map .value multiDimValues
{-- other converts
......@@ -1014,6 +1072,26 @@ decode2Points string =
then Nothing
else Just {p1 = Point "" x1 y1, p2 = Point "" x2 y2}
getDoXRayFromPlotType : ScatterplotType -> Bool
getDoXRayFromPlotType p_type = case p_type of
None _ -> False
QQ_Plot -> False
Parallel_Coords doXRay _ -> doXRay
getD_listFromPlotType : ScatterplotType -> List XyData
getD_listFromPlotType p_type = case p_type of
None _ -> []
QQ_Plot -> []
Parallel_Coords _ d_list -> d_list
msgToString : Msg -> String
msgToString msg =
case msg of
ScatterplotChange _ -> "ScatterplotChange"
Powertransformation _ -> "Powertransformation"
ParallelCoordsSwapD_list _ _ -> "ParallelCoordsSwapD_list"
PlotChange _ -> "PlotChange"
-- Constructors
pointConstructor : String -> Float -> Float -> Point
pointConstructor name x y = Point name x y
......
This diff is collapsed.
......@@ -40,6 +40,9 @@ list_set list i e =
[] -> []
x::xs -> if i==0 then e::xs else x::(list_set xs (i-1) e)
list_remove : List a -> a -> List a
list_remove list e = List.filter (\x -> x/=e) list
-- Working with Errors
httpErrorToString : Http.Error -> String
httpErrorToString err =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment