def _image_widget_new(self, image_data, colors=None):
        b64_data = base64.b64encode(image_data)
        if colors is None:
            html_str = '<img src="data:image/png;base64,'+b64_data+'" width="100%" />'
        else:
            html_str = '''
<style>.col1 {display: none; }
.col2 {display: none; }
.col3 {display: none; }
table.show1 .col1 { display: table-cell; }
table.show2 .col2 { display: table-cell; }
table.show3 .col3 { display: table-cell; }
</style>
<script>
function toggleColumn(el, n) {
    var currentClass = el.parentElement.parentElement.parentElement.parentElement.className;
    if (currentClass.indexOf("show"+n) != -1) {
        el.parentElement.parentElement.parentElement.parentElement.className = currentClass.replace("show"+n, "");
    }
    else {
        el.parentElement.parentElement.parentElement.parentElement.className += " " + "show"+n;
    }
}
</script>
'''
            html_str += '<table style="border:0;" width="100%"><tr>'
            html_str += '<th><button onclick="toggleColumn(this,2)">Toggle Colorbar</button></th><th></th></tr>'
            html_str += '<tr style="border:0;paddding-right:5px;"><td style="border:0;">'
            html_str += '<img src="data:image/png;base64,'+b64_data+'" / width="100%"></td>'
            html_str += '<td style="border:0;" class="col2">'+self.colorbar_tabs_html(colors)+'</td></tr></table>'
        image_widget = HTML(value=html_str)
        image_widget.width='100%'
        return image_widget
 def update_global_tolerances(self):
     controller = self.controller 
     case = self.case
     pvals = self.pvals
     if pvals is None:
         self.tolerances_table.children = []
         return
     if case.is_valid(p_bounds=pvals) is False:
         self.tolerances_table.children = []
         return            
     table = HTML()
     html_str = '<div><table>\n<caption>Global tolerances determined for Case ' + case.case_number + ' (' + case.signature + ') showing fold-difference to a large qualitative change{0}. </caption>\n'.format(' in log-coordinates' if self.log_coordinates is True else '') 
     html_str += '<tr ><th align=center  rowspan=2 style="padding:0 15px 0 15px;"> Parameters </th><th colspan=2> Tolerance </th></tr>'
     html_str += '<tr><td style="padding:0 15px 0 15px;"><b> Lower bound</b></td><td style="padding:0 15px 0 15px;"><b> Upper bound</b></td></tr>'
     tolerances = case.measure_tolerance(pvals, log_out=self.log_coordinates)
     for xi in sorted(pvals.keys()):
         lower_th = 1e-15 if self.log_coordinates is False else -15
         upper_th = 1e15 if self.log_coordinates is False else 15
         lower, upper = tolerances[xi]
         html_str += '<tr><td style="padding:0 15px 0 15px;"><b>{0}</b></td><td style="padding:0 15px 0 15px;">{1}</td><td style="padding:0 15px 0 15px;">{2}</td></tr>'.format(
                      xi,
                      lower if lower > lower_th else '-&infin;',
                      upper if upper < upper_th else '&infin;')
     html_str += '</table><caption>'
     html_str += 'Note: Global tolerance calculated based on the following values for the parameters: ' 
     html_str += '; '.join([i + ' = ' + str(pvals[i]) for i in sorted(pvals.keys())]) + '.'
     html_str += '</caption></div>'
     table.value = html_str
     save_button = Button(description='Save Global Tolerance Table')
     save_button.table_data = html_str
     save_button.on_click(self.save_table)
     self.tolerances_table.children = [HTML(value='<br>'),
                                       save_button,
                                       table]
     return
 def update_parameter_table(self):
     controller = self.controller 
     case = self.case
     pvals = self.pvals
     if pvals is None:
         self.parameter_table.children = []
         return
     if case.is_valid(p_bounds=pvals) is False:
         self.parameter_table.children = []
         return
     make_nominal = Button(description='Make Nominal Parameter Set')
     make_nominal.on_click(self.save_parameters)
     table = HTML()
     html_str = '<div><table>\n<caption>Value for the parameters automatically determined for Case ' + case.case_number + ' (' + case.signature + '). </caption>\n'
     html_str += '<tr ><th align=center  style="padding:0 15px 0 15px;"> Parameters </th><th> Value </th>'
     for xi in sorted(pvals.keys()):
             html_str += '<tr><td><b>{0}</b></td><td>{1}</td></tr>'.format(
                          xi,
                          pvals[xi])
     html_str += '</table></div>'
     table.value = html_str
     save_button = Button(description='Save Parameter Table')
     save_button.table_data = html_str
     save_button.on_click(self.save_table)
     self.parameter_table.children = [HTML(value='<br>'),
                                      save_button,
                                      table,
                                      make_nominal
                                      ]
     return
 def update_bounding_box(self):
     controller = self.controller 
     case = self.case
     pvals = self.pvals
     if case.is_valid(p_bounds=pvals) is False:
         self.bounding_box_table.children = []
         return
     if case.is_cyclical is True:
         self.bounding_box_table.children = []
         return            
     table = HTML()
     html_str = '<div><table>\n<caption>Bounding box determined for Case ' + case.case_number + ' (' + case.signature + '){0}. </caption>\n'.format(' in log-coordinates' if self.log_coordinates is True else '') 
     html_str += '<tr ><th align=center  rowspan=2 style="padding:0 15px 0 15px;"> Parameters </th><th colspan=2> Tolerance </th></tr>'
     html_str += '<tr><td style="padding:0 15px 0 15px;"><b> Lower bound</b></td><td style="padding:0 15px 0 15px;"><b> Upper bound</b></td></tr>'
     tolerances = case.bounding_box(log_out=self.log_coordinates)
     for xi in sorted(tolerances.keys()):
         lower_th = 1e-15 if self.log_coordinates is False else -15
         upper_th = 1e15 if self.log_coordinates is False else 15
         lower, upper = tolerances[xi]
         html_str += '<tr><td style="padding:0 15px 0 15px;"><b>{0}</b></td><td style="padding:0 15px 0 15px;">{1}</td><td style="padding:0 15px 0 15px;">{2}</td></tr>'.format(
                      xi,
                      lower if lower > lower_th else '-&infin;',
                      upper if upper < upper_th else '&infin;')
     html_str += '</table></div>'
     table.value = html_str
     save_button = Button(description='Save Bounding Box Table')
     save_button.table_data = html_str
     save_button.on_click(self.save_table)
     self.bounding_box_table.children = [HTML(value='<br>'),
                                         save_button,
                                         table]
     return
 def update_log_gains(self):
     controller = self.controller 
     case = self.case
     if case.ssystem.solution is None:
         self.log_gains.children = []
         return
     table = HTML()
     html_str = '<div><table>\n<caption>Logarithmic gains and parameter sensitivities for Case ' + case.case_number + ' (' + case.signature + '). </caption>\n'
     html_str += '<tr ><th rowspan="2" align=center  style="padding:0 15px 0 15px;"> Dependent<br> Variables </th>'
     html_str += '<th colspan="' + str(len(case.independent_variables)) + '" align=center  style="padding:0 15px 0 15px;"> Independent Variables and Parameters</th></tr><tr align=center>'
     for xi in case.independent_variables:
             html_str += '<td><b>{0}</b></td>'.format(xi)
     html_str += '</tr>\n'
     for xd in case.dependent_variables:
         html_str += '<tr><td align=center  style="padding:0 15px 0 15px;"><b>{0}</b></td>'.format(xd)
         for xi in case.independent_variables:
             html_str += '<td align=center  style="padding:0 15px 0 15px;">{0}</td>'.format(str(case.ssystem.log_gain(xd, xi)))
         html_str += '</tr>\n'
     html_str += '</table></div><br>'
     save_button = Button(description='Save Log-Gain Table')
     save_button.table_data = html_str
     save_button.on_click(self.save_table)
     table.value = html_str
     self.log_gains.children = [HTML(value='<br>'),
                                save_button, 
                                table]
     return
 def make_options_menu(self, b):
     wi = b.wi
     b.visible = False
     b.name.visible = False
     b.load.visible = False
     actions = [('Enumerate Phenotypes', self.enumerate_phenotypes_menu),
                ('Analyze Case', self.case_report_menu),
                ('Intersect Phenotypes', self.case_intersect_menu),
                ('Co-localize Phenotypes', self.co_localize_menu),
                ('Create Plot', self.create_plot_menu)]
     actions_h = HTML(value='<b>Actions</b>')
     options_h = HTML(value='<b>Options</b>')
     options = [('Edit Symbols', self.create_edit_symbols),
                ('Edit Parameters', self.create_edit_parameters),
                ('Save Data', self.save_widget_data)]
     actions_w = Tab()
     options_w = []
     for name, method in options:
         button = Button(description=name)
         button.on_click(method)
         ## button.version = b.version
         if method is None:
             button.disabled = True
         options_w.append(button)
     edit = Button(description='Modify System')
     edit.on_click(self.modify_equations_widget)
     warning = HTML()
     warning.value = '<font color="red"><b>Warning! Modifying system erases saved figures and tables.</b></font>'
     wi.children = [actions_h, actions_w] + [options_h] + options_w + [edit, warning]
     for title, method in actions:
         title, widget = method(self)
         children = [i for i in actions_w.children] + [widget]
         actions_w.children = children
         actions_w.set_title(len(children)-1, title)
     self.widget.selected_index = 1
 def update_info(self):
     controller = self.controller 
     html = HTML()
     html_string = '<b>Name:</b> ' + controller.name + '<br>'
     html_string += '<b>Case Number:</b> ' + self.case.case_number + '<br>'
     html_string += '<b>Case Signature:</b> (' + self.case.signature + ')<br>'
     html_string += '<b>Valid:</b> ' + str(self.case.is_valid()) + '<br>'
     html_string += '<b>Is Cyclical:</b> ' + str(self.case.is_cyclical) + '<br><hr>'
     check_box = Checkbox(description='Logarithmic coordinates', 
                                        value=self.log_coordinates)
     check_box.on_trait_change(self.change_logarithmic, 'value')
     html.value = html_string
     self.info.children = [html, check_box]
示例#8
0
    def display(self, n):  # Hack!
        def add_selector(_):
            g.children = g.children[:-2] + tuple(
                make_selector(self.sels, add_selector)) + g.children[-2:]

        def get_data():
            x_val, y_val = [f.value for f in c.children]
            if self.debug: print(x_val, y_val)
            pairs = self.pairs + [(self.x, x_val), (self.y, y_val)]
            if self.debug: pprint(pairs)
            return pairs

        def out_sents(_):
            pairs = get_data()
            display(
                sentences(pairs,
                          debug=self.debug,
                          limit=self.limit,
                          kind=self.kind))

        s_l = HTMLWidget(value='Query')
        self.sels = [make_selector(self.sels, add_selector) for _ in range(n)]
        sels = [s_l] + self.sels

        a_l = HTMLWidget(value='Aggregations')
        self.aggs = make_aggregator(self.aggs, self.aggs)
        aggs = [a_l] + [self.aggs]

        chart_button = Button(description=' Show Chart ')
        chart_button.on_click(self.chart4)

        self.field_chooser = c = make_field_chooser('', [], '', [])
        #         clear_output(wait=True)
        #        display(c)

        self.sent_button = sent_button = Button(description=' Show LMs ')
        sent_button.on_click(out_sents)
        #       display(sent_button)

        g = self.group = make_vgroup(sels + aggs +
                                     [chart_button, c, sent_button])

        display(self.group)

        return self.group
示例#9
0
 def __init__(self, container, caption=None, ylabel='', xlabel='', height=300, width=900):
     cell_header = HTMLWidget(value=('<h3 class="chart-header">' + caption + '</h3>' if caption is not None else ''))
     yaxis = HTMLWidget(value=ylabel)
     area_chart = StackedAreaWidget(width=width, height=height, hide_xaxis=xlabel=='')
     chart_columns = ContainerWidget(children=[yaxis, area_chart])
     chart_columns.set_css('width', '100%')
     xaxis = HTMLWidget(value=xlabel)
     chart = ContainerWidget(children=[chart_columns, xaxis])
     
     container.children = container.children + tuple([cell_header, chart])
     
     chart_columns.remove_class('vbox')
     chart_columns.add_class('hbox align-center center')
     xaxis.add_class('x axis-label')
     yaxis.add_class('y axis-label pack-center')
     area_chart.add_class('area-chart')
     chart.add_class('pack-center center chart-area')
     
     self.plot = area_chart