Skip to content

Commit

Permalink
instead of iteratively assigning colors to categories, make it consis…
Browse files Browse the repository at this point in the history
…tent
  • Loading branch information
Tommel71 committed Mar 22, 2024
1 parent dbfc2fe commit 03bb271
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ src/sw.mjs
gen/*
# ignore elm.json for it's generated at build time from elm.json.base via generate.js
elm.json
.idea
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "GraphSense Pathfinder",
"author": "Iknaio Cryptoasset Analytics",
"description": "Web application for the GraphSense Cryptoasset Analyitcs Platform",
"description": "Web application for the GraphSense Cryptoasset Analytics Platform",
"version": "1.1.2",
"license": "MIT",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions src/Config/Update.elm
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
module Config.Update exposing (Config)

import Color exposing (Color)
import Dict exposing (Dict)
import Model.Graph.Coords exposing (BBox)
import Model.Locale as Locale


type alias Config =
{ defaultColor : Color
, colorScheme : List Color
, categoryToColorIndex : Dict String Int
, highlightsColorScheme : List Color
, locale : Locale.Model
, size : Maybe BBox -- position and size of the main pane
Expand Down
1 change: 1 addition & 0 deletions src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ main =
uc =
{ defaultColor = config.theme.graph.defaultColor
, colorScheme = config.theme.graph.colorScheme
, categoryToColorIndex = config.theme.graph.categoryToColorIndex
, highlightsColorScheme = config.theme.graph.highlightsColorScheme
, locale = Locale.init default |> first
, size = Nothing
Expand Down
3 changes: 3 additions & 0 deletions src/Theme/Graph.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Theme.Graph exposing (Graph, default)

import Color exposing (Color)
import Css exposing (Style)
import Dict exposing (Dict)
import Model.Graph exposing (NodeType)
import Model.Graph.Tool as Tool

Expand Down Expand Up @@ -41,6 +42,7 @@ type alias Graph =
, navbarRight : List Style
, tool : Bool -> Tool.Status -> List Style
, colorScheme : List Color
, categoryToColorIndex : Dict String Int
, highlightsColorScheme : List Color
, lightnessFactor :
Bool
Expand Down Expand Up @@ -114,6 +116,7 @@ default =
, navbarRight = []
, tool = \_ _ -> []
, colorScheme = []
, categoryToColorIndex = Dict.empty
, highlightsColorScheme = []
, lightnessFactor =
\_ ->
Expand Down
22 changes: 22 additions & 0 deletions src/Update/Graph/Color.elm
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,25 @@ update { defaultColor, colorScheme } colors category =
colors
)
|> Maybe.withDefault colors



-- Additionally, this one receives a categoryToColorIndex dictionary
-- this way, we can update the colors of the graph based on the category
-- instead of iterating over all the colors, also it doesnt need the colors dict


updateWithIndex : Update.Config -> Dict String Color -> Maybe String -> Dict String Color
updateWithIndex { defaultColor, colorScheme, categoryToColorIndex } colors category =
case category of
Just cat ->
let
color =
Dict.get cat categoryToColorIndex
|> Maybe.andThen (\index -> List.Extra.getAt index colorScheme)
|> Maybe.withDefault defaultColor
in
Dict.insert cat color colors

Nothing ->
colors
2 changes: 1 addition & 1 deletion src/Update/Graph/Entity.elm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ addAddressToEntity plugins uc colors address entity =
Address.init plugins entity address

newColors =
Color.update uc colors newAddress.category
Color.updateWithIndex uc colors newAddress.category
in
{ updatedEntity =
{ entity
Expand Down
2 changes: 1 addition & 1 deletion src/Update/Graph/Layer.elm
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ addEntityHere plugins uc position entity { layer, colors, new, repositioned } =
}
, new = Set.insert newEntity.id new
, repositioned = Set.union newRepositioned repositioned
, colors = Color.update uc colors newEntity.category
, colors = Color.updateWithIndex uc colors newEntity.category
}


Expand Down
1 change: 1 addition & 0 deletions tests/Graph/Update/TestLayer.elm
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ config : Update.Config
config =
{ defaultColor = Color.grey
, colorScheme = [ Color.red, Color.blue, Color.green ]
, categoryToColorIndex = Dict.fromList [("exchange", 0)]
}


Expand Down
1 change: 1 addition & 0 deletions tests/Setup.elm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ start locale =
uc =
{ defaultColor = Theme.default.graph.defaultColor
, colorScheme = Theme.default.graph.colorScheme
, categoryToColorIndex = Theme.default.graph.categoryToColorIndex
}

plugins =
Expand Down
30 changes: 30 additions & 0 deletions themes/Iknaio.elm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Iknaio exposing (theme)

import Dict exposing (Dict)
import Color exposing (rgb255)
import Css exposing (..)
import Css.Transitions
Expand Down Expand Up @@ -667,6 +668,35 @@ theme =
, rgb255 184 176 172
, rgb255 87 120 164
]
|> s_categoryToColorIndex
(Dict.fromList
[ ( "exchange", 0 )
, ( "coinjoin", 3 )
, ( "perpetrator", 1)
, ( "defi", 2)
, ( "miner", 4)
, ( "payment_processor", 0)
, ( "user", 5)
, ( "gambling", 6)
, ( "defi_lending", 7)
, ( "market", 8)
, ( "mixing_service", 9)
, ( "defi_dex", 9)
, ( "donation", 9)
, ( "service", 9)
, ( "wallet_service", 9)
, ( "hosting", 9)
, ( "shop", 9)
, ( "entity", 9)
, ( "organization", 9)
, ( "vpn", 9)
, ( "faucet", 9)
, ( "defi_bridge", 9)
, ( "ico_wallet", 9)
, ( "atm", 9)
, ( "mining_service", 9)
]
)
|> (\graph ->
s_highlightsColorScheme
(graph.colorScheme
Expand Down

0 comments on commit 03bb271

Please sign in to comment.