File size: 2,319 Bytes
de0df56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import panel as pn
import pandas as pd
import numpy as np
from bokeh.plotting import figure

# Dashboard Page
class CyberIndexDashboard:
    np.random.seed(7)
    pn.extension('tabulator')
    #static variable: df
    df=pd.read_csv("cyber-security-indexes.csv")
    def __init__(self,index_col,values_col,values_header):
        self.id = values_col
        pivot_table=pd.pivot_table(self.df, index=index_col, values=values_col, aggfunc='mean')
        #db = self.do_bokeh(np.array(pivot_table.index.values),
        #                    np.array(pivot_table[values_col].values), 
        #                    values_header)
        #bar_chart = pn.pane.Bokeh(db, theme="dark_minimal")
        bar_chart = self.echarts_bar_chart(np.array(pivot_table.index.values),
                                           np.array(pivot_table[values_col].values), 
                                           values_header)
        #a_dataframe = pn.widgets.DataFrame(pivot_table)
        self.a_dataframe = self.dataframe_show(pivot_table)
        row = [pn.Row(pn.Column(self.a_dataframe)), pn.Column(bar_chart)]
        col = pn.Column(row[0],row[1])
        self.content = col

    def dataframe_show(self,pivot_table):
        #return pn.widgets.DataFrame(pivot_table)
        return pn.widgets.Tabulator(pivot_table)

    def do_bokeh(self,x,y,y_title):
        #x=np.array(pivot_table.index.values)
        #y = np.array(pivot_table.CEI.values)
        fig = figure(x_range=x, height=350, title=y_title,
                toolbar_location=None, tools="")
        fig.vbar(x=x, top=y, width=0.9)

        fig.xgrid.grid_line_color = None
        fig.y_range.start = 0

        return fig
    
    def echarts_bar_chart(self,x,y,y_title):
        echart_bar = {
            'title': {
                'text': y_title
            },
            'tooltip': {},
            'legend': {
                'data':['Index']
            },
            'xAxis': {
                'data': x.tolist()
            },
            'yAxis': {},
            'series': [{
                'name': 'Index',
                'type': 'bar',
                'data': y.tolist()
            }],
        };
        echart_pane = pn.pane.ECharts(echart_bar, height=480, width=640)
        return echart_pane


    def view(self):
        return self.content