Exemplo n.º 1
0
def update_adhoc_graphs(selected_plotlevel, selected_plotarea, json_params):
    ''' Update Interactive graphs when plot level and plot area selected '''

    print('ADHOC CALLBACK selplotlevel:', selected_plotlevel, 'sel area:',
          selected_plotarea)

    # Get current plot parameters from hidden intermediate-value div
    plotparams = json.loads(json_params)

    if selected_plotarea.replace(
            '%20', ' ') not in cases.hierachy[selected_plotlevel]:
        print('Warning, area doesnt exist')
        area = ''
    else:
        area = selected_plotarea

    plotparams['plotlevel'] = selected_plotlevel
    plotparams['plotareas'] = area

    # Update charts
    chart1 = Chart(plotparams, cases)
    plotparams['plotdays'] = 0
    chart2 = Chart(plotparams, cases)

    return chart1.figure, chart2.figure
Exemplo n.º 2
0
def display_mapchart(clickData):
    '''  Plot trend charts when map area is clicked '''

    print('MAP TREND CALLBACK')

    # Initial default line chart options - England
    plotparams = {
        'plotlevel': cases.levels[0],
        'plotareas': 'England',
        'plotvars': 'Cases|Average',
        'plottitle': '',
        'plotdays': 28,
        'showtitle': False,
        'periodicity': 'daily'
    }

    if clickData is not None:
        # Get plot parameters from clicked map area

        print(clickData)
        data = clickData['points'][0]['customdata']
        plotparams['plotareas'] = data[1]
        plotparams['plotlevel'] = cases.get_plot_level(data[1])

    else:
        # Use initial default parameters, if nothing selected on map
        data = pd.Series(cases.summarydf.loc[
            (cases.summarydf['Area type'] == plotparams['plotlevel']) &
            (cases.summarydf['Area name'] == plotparams['plotareas'])].iloc[0])

    # Create daily trend chart next to map
    daily_chart = Chart(plotparams, cases)

    # Create weekly bar chart below map
    plotparams[
        'plottitle'] = 'Weekly Change in Cases - ' + plotparams['plotareas']
    plotparams['plotvars'] = 'Cases:bar'
    plotparams['periodicity'] = 'weekly'
    plotparams['showtitle'] = True
    plotparams['plotdays'] = 0

    weekly_chart = Chart(plotparams, cases)

    map_card = MapCardLayout(plotparams=plotparams,
                             cases=cases,
                             cardfigs=data,
                             chart=daily_chart.figure)

    return weekly_chart.figure, map_card.layout
Exemplo n.º 3
0
 def draw_angle(self):
     chart = Chart(minified=self.min,
                   points=self.data,
                   cp=self.cp,
                   z_col='z_angle',
                   z_title='Cp',
                   series_name='Angle')
     return chart.draw()
Exemplo n.º 4
0
 def draw_eff(self):
     chart = Chart(minified=self.min,
                   points=self.data,
                   cp=None,
                   z_col='z_eff',
                   z_title='Eff',
                   series_name='Efficiency')
     return chart.draw()
Exemplo n.º 5
0
    def __init__(self, data, request):
        """
            Constructor for Coin Superclass

            :arg data: current wallet data for coin
            :type data: dict
            :arg request: Required to perform the necessary requests
            :type request: <Request>
        """
        from charts import Chart

        self.code = data["coin"]
        self.name = data["name"]
        self.free = data["free"]
        self.locked = data["locked"]
        self.amount = self.free + self.locked
        self.chart = Chart(self.code, request)
        self.support = self.chart.getSupportLevels(request)
        self.resistance = self.chart.getResistanceLevels(request)
Exemplo n.º 6
0
    def _add_chart_cb(self, widget, type="vbar"):
        self.current_chart = Chart(type)

        self.update_chart()
Exemplo n.º 7
0
from charts import Chart, ChartTypes

chart_instance = Chart()

chart_instance.render(ChartTypes.COLUMN_CHART, "dados para grafico coluna")
chart_instance.render(ChartTypes.LINE_CHART, "dados para grafico linha")
chart_instance.render(ChartTypes.PIE_CHART, "dados para grafico torta")

print("\n\n\nAplicando OCP\n")
from refatorado import ChartOC, ColumnChart, LineChart, PieChart

instance_column_chart = ColumnChart()
instance_line_chart = LineChart()
instance_pie_chart = PieChart()

ChartOC.render(instance_column_chart, "dados para grafico coluna")
ChartOC.render(instance_line_chart, "dados para grafico linha")
ChartOC.render(instance_pie_chart, "dados para grafico torta")
Exemplo n.º 8
0
 def setUpClass(cls):
     cls.chart = Chart()
Exemplo n.º 9
0
    def __init__(self, handle):

        activity.Activity.__init__(self, handle)

        self.current_chart = None
        self.x_label = ""
        self.y_label = ""
        self.chart_data = []
        self.mime_types = [
            'image/bmp', 'image/gif', 'image/jpeg', 'image/png', 'image/tiff',
            'application/pdf', 'application/vnd.olpc-sugar', 'application/rtf',
            'text/rtf', 'application/epub+zip', 'text/html',
            'application/x-pdf'
        ]
        self.is_updated = False

        # toolbar with the new toolbar redesign
        toolbar_box = ToolbarBox()

        activity_button = ActivityToolbarButton(self)
        toolbar_box.toolbar.insert(activity_button, 0)
        activity_button.show()

        refresh_button = ToolButton('view-refresh')
        refresh_button.set_tooltip_text(_("Refresh Data"))
        refresh_button.connect('clicked', self._load_data)
        toolbar_box.toolbar.insert(refresh_button, -1)
        refresh_button.show()

        separator = Gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_expand(True)
        toolbar_box.toolbar.insert(separator, -1)
        separator.show()

        stop_button = StopButton(self)
        toolbar_box.toolbar.insert(stop_button, -1)
        stop_button.show()

        self.set_toolbar_box(toolbar_box)
        toolbar_box.show()

        # notify when activity is back in focus
        self.connect('notify::active', self._notify_active_cb)

        # Detect if device is a XO
        if os.path.exists('/etc/olpc-release') or \
           os.path.exists('/sys/power/olpc-pm'):
            COLUMN_SPACING = 1
            STATS_WIDTH = 30
            TP_WIDTH = 45
            HMAP_WIDTH = 90
        else:
            COLUMN_SPACING = 2
            STATS_WIDTH = 50
            TP_WIDTH = 75
            HMAP_WIDTH = 150

        # ScrolledWindow as the main container
        scrolled_window_main = Gtk.ScrolledWindow()
        scrolled_window_main.set_can_focus(False)
        scrolled_window_main.set_policy(Gtk.PolicyType.AUTOMATIC,
                                        Gtk.PolicyType.AUTOMATIC)
        scrolled_window_main.set_shadow_type(Gtk.ShadowType.NONE)
        scrolled_window_main.show()
        self.set_canvas(scrolled_window_main)

        grid = Gtk.Grid(column_spacing=6, row_spacing=3.5)
        grid.set_border_width(20)
        grid.set_halign(Gtk.Align.CENTER)
        scrolled_window_main.add_with_viewport(grid)

        # VBoxes for total activities, journal entries and total files
        vbox_total_activities = Gtk.VBox()
        vbox_journal_entries = Gtk.VBox()
        vbox_total_contribs = Gtk.VBox()
        vbox_tree = Gtk.VBox()
        vbox_heatmap = Gtk.VBox()
        self.vbox_pie = Gtk.VBox()

        eb_total_activities = Gtk.EventBox()
        eb_journal_entries = Gtk.EventBox()
        eb_total_contribs = Gtk.EventBox()
        eb_heatmap = Gtk.EventBox()
        eb_tree = Gtk.EventBox()
        eb_pie = Gtk.EventBox()

        eb_total_activities.add(vbox_total_activities)
        eb_journal_entries.add(vbox_journal_entries)
        eb_total_contribs.add(vbox_total_contribs)
        eb_pie.add(self.vbox_pie)
        eb_tree.add(vbox_tree)

        # change eventbox color
        eb_total_activities.modify_bg(Gtk.StateType.NORMAL,
                                      Gdk.color_parse("#ffffff"))
        eb_journal_entries.modify_bg(Gtk.StateType.NORMAL,
                                     Gdk.color_parse("#ffffff"))
        eb_total_contribs.modify_bg(Gtk.StateType.NORMAL,
                                    Gdk.color_parse("#ffffff"))
        eb_heatmap.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#ffffff"))
        eb_pie.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#ffffff"))
        eb_tree.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#ffffff"))

        label_dashboard = Gtk.Label()
        text_dashboard = "<b>{0}</b>".format(_("Dashboard"))
        label_dashboard.set_markup(text_dashboard)

        # label for total activities
        label_TA = Gtk.Label()
        text_TA = "<b>{0}</b>".format(_("Activities Installed"))
        label_TA.set_markup(text_TA)
        vbox_total_activities.add(label_TA)

        self.label_total_activities = Gtk.Label()
        vbox_total_activities.add(self.label_total_activities)

        # label for total journal entries
        label_JE = Gtk.Label()
        text_JE = "<b>{0}</b>".format(_("Journal Entries"))
        label_JE.set_markup(text_JE)
        vbox_journal_entries.add(label_JE)

        self.label_journal_entries = Gtk.Label()
        vbox_journal_entries.add(self.label_journal_entries)

        # label for files
        label_CE = Gtk.Label()
        text_CE = "<b>{0}</b>".format(_("Total Files"))
        label_CE.set_markup(text_CE)
        vbox_total_contribs.add(label_CE)

        # label for pie
        label_PIE = Gtk.Label()
        text_PIE = "<b>{0}</b>".format(_("Most used activities"))
        label_PIE.set_markup(text_PIE)
        self.vbox_pie.pack_start(label_PIE, False, True, 5)

        self.label_contribs = Gtk.Label()
        vbox_total_contribs.add(self.label_contribs)

        # pie chart
        self.labels_and_values = ChartData(self)
        self.eventbox = Gtk.EventBox()
        self.charts_area = ChartArea(self)
        self.charts_area.connect('size-allocate', self._chart_size_allocate_cb)
        self.eventbox.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("white"))
        self.eventbox.add(self.charts_area)
        self.vbox_pie.pack_start(self.eventbox, True, True, 0)
        self.eventbox.connect('button-press-event', self._pie_opened)
        self.charts_area.set_tooltip_text(_("Click for more information"))

        # pie chart window
        self.window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
        self.window.set_border_width(2)
        self.window.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        self.window.set_decorated(True)
        self.window.set_resizable(False)
        self.window.set_modal(True)
        self.window.set_keep_above(True)
        self.window.set_size_request(800, 600)
        self.window.set_title("Pie Chart")
        self.window.connect('delete-event', self._hide_window)

        eb_image_holder = Gtk.EventBox()
        eb_image_holder.modify_bg(Gtk.StateType.NORMAL,
                                  Gdk.color_parse("ffffff"))
        self.window.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#282828"))

        vbox_image = Gtk.VBox()
        eb_image_holder.add(vbox_image)

        # scrolled window for details window
        scrolled_window = Gtk.ScrolledWindow()
        scrolled_window.set_can_focus(False)
        scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC,
                                   Gtk.PolicyType.AUTOMATIC)
        scrolled_window.set_shadow_type(Gtk.ShadowType.NONE)
        scrolled_window.show()

        # load pie image
        # not using get_activity_root for now
        self.image = Gtk.Image()
        vbox_image.add(self.image)

        self.vbox_holder = Gtk.VBox()
        self.vbox_holder.pack_start(eb_image_holder, True, True, 0)
        self.vbox_holder.pack_start(self.labels_and_values, False, False, 0)
        self.window.add(scrolled_window)
        scrolled_window.add_with_viewport(self.vbox_holder)

        reader = JournalReader()
        self._graph_from_reader(reader)
        self.current_chart = Chart("pie")
        self.update_chart()

        # font
        font_main = Pango.FontDescription("Granada 12")
        label_JE.modify_font(font_main)
        label_CE.modify_font(font_main)
        label_TA.modify_font(font_main)

        font_actual = Pango.FontDescription("12")
        self.label_journal_entries.modify_font(font_actual)
        self.label_total_activities.modify_font(font_actual)
        self.label_contribs.modify_font(font_actual)
        label_dashboard.modify_font(font_actual)

        self.treeview_list = []
        self.files_list = []
        self.old_list = []
        self.heatmap_list = []
        self.journal_entries = 0

        # treeview for Journal entries
        self.liststore = Gtk.ListStore(str, str, str, object, str,
                                       datastore.DSMetadata, str, str)
        self.treeview = Gtk.TreeView(self.liststore)
        self.treeview.set_headers_visible(False)
        self.treeview.set_grid_lines(Gtk.TreeViewGridLines.HORIZONTAL)
        self._load_data()

        for i, col_title in enumerate(["Recently Opened Activities"]):

            renderer_title = Gtk.CellRendererText()
            renderer_time = Gtk.CellRendererText()
            icon_renderer = CellRendererActivityIcon()

            renderer_title.set_property('ellipsize', Pango.EllipsizeMode.END)
            renderer_title.set_property('ellipsize-set', True)

            column1 = Gtk.TreeViewColumn("Icon")
            column1.pack_start(icon_renderer, True)
            column1.add_attribute(icon_renderer, 'file-name', 1)
            column1.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
            column1.add_attribute(icon_renderer, 'xo-color', 3)
            column2 = Gtk.TreeViewColumn(col_title, renderer_title, text=0)
            column2.set_min_width(200)
            column3 = Gtk.TreeViewColumn(col_title, renderer_time, text=6)

            self.treeview.set_tooltip_column(0)
            self.treeview.append_column(column1)
            self.treeview.append_column(column2)
            self.treeview.append_column(column3)

        # combobox for sort selection
        self.cbox_store = Gtk.ListStore(str)
        cbox_entries = [_("Newest"), _("Files"), _("Oldest")]

        for item in cbox_entries:
            self.cbox_store.append([item])

        self.combobox = Gtk.ComboBox.new_with_model(self.cbox_store)
        self.combobox.set_halign(Gtk.Align.END)
        self.combobox.connect('changed', self._on_name_combo_changed_cb)
        renderer_text = Gtk.CellRendererText()
        self.combobox.pack_start(renderer_text, True)
        self.combobox.add_attribute(renderer_text, "text", 0)
        self.combobox.set_active(0)

        self._add_to_treeview(self.treeview_list)

        selected_row = self.treeview.get_selection()
        selected_row.connect('changed', self._item_select_cb)

        scrolled_window = Gtk.ScrolledWindow()
        scrolled_window.set_can_focus(False)
        scrolled_window.set_policy(Gtk.PolicyType.NEVER,
                                   Gtk.PolicyType.AUTOMATIC)
        scrolled_window.set_shadow_type(Gtk.ShadowType.NONE)
        scrolled_window.show()

        hbox_tree2 = Gtk.HBox()
        text_treeview = "<b>{0}</b>".format(_("Journal Entries"))
        self.label_treeview = Gtk.Label()
        self.label_treeview.set_markup(text_treeview)
        hbox_tree2.pack_start(self.label_treeview, False, True, 10)
        hbox_tree2.pack_start(self.combobox, True, True, 10)

        vbox_tree.pack_start(hbox_tree2, False, False, 5)
        scrolled_window.add_with_viewport(self.treeview)

        # label for recent activities
        label_rec = Gtk.Label(expand=False)
        text_treeview = "{0}".format(_("Recently Opened Activities"))
        label_rec.set_markup(text_treeview)

        vbox_tree.add(scrolled_window)

        # heatmap
        label_heatmap = Gtk.Label()
        text_HE = "<b>{0}</b>".format(_("User Activity"))
        label_heatmap.set_markup(text_HE)
        grid_heatmap = Gtk.Grid(column_spacing=COLUMN_SPACING, row_spacing=2)
        grid_heatmap.set_halign(Gtk.Align.CENTER)
        vbox_heatmap.pack_start(label_heatmap, False, True, 5)
        vbox_heatmap.pack_start(grid_heatmap, False, True, 5)

        self.dates, self.dates_a, months = self._generate_dates()
        self._build_heatmap(grid_heatmap, self.dates, self.dates_a, months)

        eb_heatmap.add(vbox_heatmap)

        # add views to grid
        grid.attach(label_dashboard, 1, 2, 1, 1)
        grid.attach_next_to(eb_total_activities, label_dashboard,
                            Gtk.PositionType.BOTTOM, STATS_WIDTH, 35)
        grid.attach_next_to(eb_journal_entries, eb_total_activities,
                            Gtk.PositionType.RIGHT, STATS_WIDTH, 35)
        grid.attach_next_to(eb_total_contribs, eb_journal_entries,
                            Gtk.PositionType.RIGHT, STATS_WIDTH, 35)
        grid.attach_next_to(eb_heatmap, eb_total_activities,
                            Gtk.PositionType.BOTTOM, HMAP_WIDTH, 75)
        grid.attach_next_to(eb_tree, eb_heatmap, Gtk.PositionType.BOTTOM,
                            TP_WIDTH, 90)
        grid.attach_next_to(eb_pie, eb_tree, Gtk.PositionType.RIGHT, TP_WIDTH,
                            90)

        grid.show_all()