Skip to content

Commit

Permalink
add annotation for tx nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
myrho committed Oct 22, 2024
1 parent e9ed964 commit a88d2b7
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 183 deletions.
3 changes: 1 addition & 2 deletions review/suppressed/NoImportingEverything.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
{ "count": 4, "filePath": "src/View/Graph/Tag.elm" },
{ "count": 4, "filePath": "src/View/Graph/Tool.elm" },
{ "count": 4, "filePath": "src/View/Locale.elm" },
{ "count": 4, "filePath": "src/View/Notification.elm" },
{ "count": 4, "filePath": "src/View/Pathfinder/Tx/AccountTx.elm" },
{ "count": 4, "filePath": "src/View/Pathfinder/Tx/Utxo.elm" },
{ "count": 4, "filePath": "src/View/Search.elm" },
Expand All @@ -49,6 +48,7 @@
{ "count": 3, "filePath": "src/View/Graph/Table/TxsUtxoTable.elm" },
{ "count": 3, "filePath": "src/View/Graph/Table/UserAddressTagsTable.elm" },
{ "count": 3, "filePath": "src/View/Landingpage.elm" },
{ "count": 3, "filePath": "src/View/Notification.elm" },
{ "count": 3, "filePath": "src/View/Pathfinder/Tx/Path.elm" },
{ "count": 3, "filePath": "themes/Iknaio.elm" },
{ "count": 2, "filePath": "src/Css/Reset.elm" },
Expand Down Expand Up @@ -124,7 +124,6 @@
{ "count": 1, "filePath": "src/Update/Graph/Address.elm" },
{ "count": 1, "filePath": "src/Update/Graph/Search.elm" },
{ "count": 1, "filePath": "src/Update/Graph/Table.elm" },
{ "count": 1, "filePath": "src/Update/Notification.elm" },
{ "count": 1, "filePath": "src/Update/Search.elm" }
]
}
6 changes: 5 additions & 1 deletion src/Update/Pathfinder/Node.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module Update.Pathfinder.Node exposing (Node, move, release)

import Animation exposing (Animation)
import Animation exposing (Animation, Clock)
import Model.Graph.Coords exposing (Coords)
import Model.Pathfinder.Id exposing (Id)


type alias Node a =
Expand All @@ -10,6 +11,9 @@ type alias Node a =
, dy : Float
, x : Float
, y : Animation
, clock : Clock
, opacity : Animation
, id : Id
}


Expand Down
80 changes: 79 additions & 1 deletion src/Util/Annotations.elm
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
module Util.Annotations exposing (AnnotationItem, AnnotationModel, empty, getAnnotation, set, setColor, setLabel, toList)
module Util.Annotations exposing (AnnotationItem, AnnotationModel, annotationToAttrAndLabel, empty, getAnnotation, set, setColor, setLabel, toList)

import Animation as A
import Color exposing (Color)
import Css
import Dict exposing (Dict)
import Html.Styled
import Model.Pathfinder.Id exposing (Id)
import Msg.Pathfinder exposing (Msg(..))
import RecordSetter as Rs
import Svg.Styled as Svg exposing (Svg, text)
import Svg.Styled.Attributes as Svg exposing (css, opacity, transform)
import Theme.Html.GraphComponents as HtmlGraphComponents
import Theme.Svg.GraphComponents as GraphComponents
import Update.Pathfinder.Node exposing (Node)
import Util.Graph exposing (translate)
import Util.View exposing (onClickWithStop)


type AnnotationModel
Expand Down Expand Up @@ -54,3 +65,70 @@ setColor item clr (Annotation m) =
getAnnotation : Id -> AnnotationModel -> Maybe AnnotationItem
getAnnotation item (Annotation m) =
Dict.get item m.annotations


annotationToAttrAndLabel : Node a -> { b | height : Float, width : Float } -> Float -> AnnotationItem -> ( List (Svg.Attribute Msg), List (Svg Msg) )
annotationToAttrAndLabel node details offset ann =
let
colorAttributes prop =
case ann.color of
Just c ->
Color.toCssString c
|> Css.property prop
|> Css.important
|> List.singleton
|> css
|> List.singleton

_ ->
[]
in
( colorAttributes "fill"
, (if String.length ann.label > 0 then
HtmlGraphComponents.annotationLabelWithAttributes
(HtmlGraphComponents.annotationLabelAttributes
|> Rs.s_annotationLabel
(css
[ Css.display Css.inlineBlock
]
:: colorAttributes "border-color"
)
)
{ annotationLabel = { labelText = ann.label } }
|> List.singleton
|> Html.Styled.div
[ css
[ Css.pct 100 |> Css.width
, Css.textAlign Css.center
]
]
|> List.singleton
|> Svg.foreignObject
[ translate
0
(details.height
+ offset
)
|> transform
, details.width
|> String.fromFloat
|> Svg.width
, (GraphComponents.annotationLabel_details.height
+ GraphComponents.annotationLabel_details.strokeWidth
* 2
)
* (1 + (toFloat <| String.length ann.label // 13))
|> String.fromFloat
|> Svg.height
, A.animate node.clock node.opacity
|> String.fromFloat
|> opacity
, UserOpensAddressAnnotationDialog node.id |> onClickWithStop
, css [ Css.cursor Css.pointer ]
]

else
text ""
)
|> List.singleton
)
8 changes: 7 additions & 1 deletion src/View/Pathfinder.elm
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ topCenterPanel plugins ms vc gc model =
Pathfinder.SelectedAddress _ ->
False

Pathfinder.SelectedTx _ ->
False

_ ->
True
, pointerTool = model.pointerTool
Expand Down Expand Up @@ -263,6 +266,9 @@ toolbarHovercardView vc m ( hcid, hc ) =
( Annotation, Pathfinder.SelectedAddress id ) ->
annotationHovercardView vc id (Annotations.getAnnotation id m.annotations) hc

( Annotation, Pathfinder.SelectedTx id ) ->
annotationHovercardView vc id (Annotations.getAnnotation id m.annotations) hc

_ ->
none

Expand Down Expand Up @@ -1369,7 +1375,7 @@ graphSvg plugins _ vc gc model bbox =
, gradient "account" { outgoing = False, reverse = True }
]
, Svg.lazy7 Network.addresses plugins vc gc model.colors model.clusters model.annotations model.network.addresses
, Svg.lazy4 Network.txs plugins vc gc model.network.txs
, Svg.lazy5 Network.txs plugins vc gc model.annotations model.network.txs
, Svg.lazy5 Network.edges plugins vc gc model.network.addresses model.network.txs
, drawDragSelector vc model

Expand Down
96 changes: 18 additions & 78 deletions src/View/Pathfinder/Address.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Color
import Config.Pathfinder as Pathfinder
import Config.View as View
import Css
import Html.Styled
import Html.Styled.Attributes as Html
import Html.Styled.Events exposing (onMouseLeave)
import Init.Pathfinder.Id as Id
Expand All @@ -23,13 +22,12 @@ import Msg.Pathfinder exposing (Msg(..))
import Plugin.View exposing (Plugins)
import RecordSetter as Rs
import RemoteData
import Svg.Styled exposing (Svg, g, image, text)
import Svg.Styled as Svg exposing (Svg, g, image, text)
import Svg.Styled.Attributes as Svg exposing (css, opacity, transform)
import Svg.Styled.Events exposing (onMouseOver, preventDefaultOn, stopPropagationOn)
import Theme.Html.GraphComponents as HtmlGraphComponents
import Theme.Svg.GraphComponents as GraphComponents
import Theme.Svg.Icons as Icons
import Util.Annotations as Annotations
import Util.Annotations as Annotations exposing (annotationToAttrAndLabel)
import Util.Data exposing (isAccountLike)
import Util.Graph exposing (decodeCoords, translate)
import Util.View exposing (onClickWithStop, truncateLongIdentifierWithLengths)
Expand Down Expand Up @@ -113,81 +111,23 @@ view _ vc _ colors address getCluster annotation =
Nothing
)

offset =
2 +
if nodeLabel == Nothing then
-GraphComponents.addressNodeExchangeLabel_details.height

else
0

( annAttr, label ) =
case annotation of
Just ann ->
let
colorAttributes prop =
case ann.color of
Just c ->
Color.toCssString c
|> Css.property prop
|> Css.important
|> List.singleton
|> css
|> List.singleton

_ ->
[]
in
( colorAttributes "fill"
, (if String.length ann.label > 0 then
HtmlGraphComponents.annotationLabelWithAttributes
(HtmlGraphComponents.annotationLabelAttributes
|> Rs.s_annotationLabel
(css
[ Css.display Css.inlineBlock
]
:: colorAttributes "border-color"
)
)
{ annotationLabel = { labelText = ann.label } }
|> List.singleton
|> Html.Styled.div
[ css
[ Css.pct 100 |> Css.width
, Css.textAlign Css.center
]
]
|> List.singleton
|> Svg.Styled.foreignObject
[ translate
0
(GraphComponents.addressNode_details.height
+ (if nodeLabel == Nothing then
-GraphComponents.addressNodeExchangeLabel_details.height

else
0
)
+ 2
)
|> transform
, GraphComponents.addressNode_details.width
|> String.fromFloat
|> Svg.width
, (GraphComponents.annotationLabel_details.height
+ GraphComponents.annotationLabel_details.strokeWidth
* 2
)
* (1 + (toFloat <| String.length ann.label // 13))
|> String.fromFloat
|> Svg.height
, A.animate address.clock address.opacity
|> String.fromFloat
|> opacity
, UserOpensAddressAnnotationDialog address.id |> onClickWithStop
, css [ Css.cursor Css.pointer ]
]

else
text ""
)
|> List.singleton
annotation
|> Maybe.map
(annotationToAttrAndLabel
address
GraphComponents.addressNode_details
offset
)

_ ->
( [], [] )
|> Maybe.withDefault ( [], [] )
in
g
[ translate
Expand Down Expand Up @@ -337,7 +277,7 @@ toNodeIconHtml address cluster =
Icons.iconsUntagged {}
)
|> List.singleton
|> Svg.Styled.svg
|> Svg.svg
[ Svg.width "24"
, Svg.height "24"
]
Expand Down
10 changes: 6 additions & 4 deletions src/View/Pathfinder/Network.elm
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@ addresses plugins vc gc colors clusters annotations =
Dict.foldl
(\id address svg ->
( Id.toString id
, Svg.lazy7 Address.view plugins vc gc colors address (flip Dict.get clusters) (Annotations.getAnnotation id annotations)
, (Annotations.getAnnotation id annotations)
|> Svg.lazy7 Address.view plugins vc gc colors address (flip Dict.get clusters)
)
:: svg
)
[]
>> Keyed.node "g" []


txs : Plugins -> View.Config -> Pathfinder.Config -> Dict Id Tx -> Svg Msg
txs plugins vc gc =
txs : Plugins -> View.Config -> Pathfinder.Config -> Annotations.AnnotationModel -> Dict Id Tx -> Svg Msg
txs plugins vc gc annotations =
Dict.foldl
(\id tx svg ->
( Id.toString id
, Svg.lazy4 Tx.view plugins vc gc tx
, (Annotations.getAnnotation id annotations)
|> Svg.lazy5 Tx.view plugins vc gc tx
)
:: svg
)
Expand Down
11 changes: 7 additions & 4 deletions src/View/Pathfinder/Tx.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ import Msg.Pathfinder exposing (Msg)
import Plugin.View exposing (Plugins)
import Svg.Styled exposing (Svg)
import Svg.Styled.Lazy as Svg
import Util.Annotations as Annotations
import View.Pathfinder.Tx.AccountTx as AccountTx
import View.Pathfinder.Tx.Utxo as Utxo


view : Plugins -> View.Config -> Pathfinder.Config -> Tx -> Svg Msg
view plugins vc gc tx =
view : Plugins -> View.Config -> Pathfinder.Config -> Tx -> Maybe Annotations.AnnotationItem -> Svg Msg
view plugins vc gc tx annotation =
case tx.type_ of
Utxo t ->
Utxo.view plugins vc gc tx t
annotation
|> Utxo.view plugins vc gc tx t

Account t ->
AccountTx.view plugins vc gc tx t
annotation
|> AccountTx.view plugins vc gc tx t


edge : Plugins -> View.Config -> Pathfinder.Config -> Dict Id Address -> Tx -> ( String, Svg Msg )
Expand Down
Loading

0 comments on commit a88d2b7

Please sign in to comment.