Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing demo dashboard #282

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions scripts/dashboard-demo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import panel as pn
from gremlin_python.driver.client import Client
from bokeh.palettes import Iridescent, Iridescent
from bokeh.palettes import TolRainbow
from bokeh.plotting import figure
from bokeh.transform import cumsum
import nest_asyncio
Expand Down Expand Up @@ -208,12 +208,19 @@ def display(self):
styles=dict(background='whitesmoke'),
)

# Only print the top x attacks
def BokehPieChart(raw_data):
data = pd.Series(raw_data).reset_index(name='value').rename(columns={'index':'attacks'})
sorted_data = dict(sorted(raw_data.items(), key=lambda item: item[1], reverse = True))
q = len(sorted_data) // TOP_ATTACKS
iter = len(sorted_data) % TOP_ATTACKS * q
for i in range(1, iter):
sorted_data.popitem()

data = pd.Series(sorted_data).reset_index(name='value').rename(columns={'index':'attacks'})
data['angle'] = data['value']/data['value'].sum() * 2*pi
data['color'] = Iridescent[len(raw_data)]
data['color'] = TolRainbow[len(sorted_data)]

p = figure( title="Attacks distribution", toolbar_location=None,
p = figure( title=f"Attacks distribution (top{TOP_ATTACKS})", toolbar_location=None,
tools="hover", tooltips="@attacks: @value", x_range=(-0.5, 1.0))

r = p.wedge(x=0, y=1, radius=0.4,
Expand All @@ -238,6 +245,9 @@ def GetClusterName():
return res[0]

ACCENT = "teal"
# Number of attacks to print out in the attack distribution graph
# max value is 23 as the palette has only 23 colors (https://docs.bokeh.org/en/latest/docs/reference/palettes.html#accessible-palettes)
TOP_ATTACKS = 15

styles = {
"box-shadow": "rgba(50, 50, 93, 0.25) 0px 6px 12px -2px, rgba(0, 0, 0, 0.3) 0px 3px 7px -3px",
Expand Down
Loading