def __init__(self, ipython):
        """Public constructor."""
        if VariableInspectorWindow.instance is not None:
            raise Exception(
                """Only one instance of the Variable Inspector can exist at a 
                time.  Call close() on the active instance before creating a new instance.
                If you have lost the handle to the active instance, you can re-obtain it
                via `VariableInspectorWindow.instance`.""")

        VariableInspectorWindow.instance = self
        self.closed = False
        self.namespace = NamespaceMagics()
        self.namespace.shell = ipython.kernel.shell

        self._popout = widgets.PopupWidget()
        self._popout.description = "Variable Inspector"
        self._popout.button_text = self._popout.description

        self._modal_body = widgets.ContainerWidget()
        self._modal_body.set_css('overflow-y', 'scroll')

        self._modal_body_label = widgets.HTMLWidget(value='Not hooked')
        self._modal_body.children = [self._modal_body_label]

        self._popout.children = [
            self._modal_body,
        ]

        self._ipython = ipython
        self._ipython.register_post_execute(self._fill)
Esempio n. 2
0
def display_chart_chartjs(sc_est2012_sex, show_javascript, show, div):
    sc_est2012_sex_template = jinja2.Template(
    """
    require(["chartjs"], function() {
        var data = {
            labels : {{ labels }},
            datasets : [
            {
                fillColor : "rgba(220,220,220,0.5)",
                strokeColor : "rgba(220,220,220,1)",
                data : {{ dataset_male }}
            },
            {
                fillColor : "rgba(151,187,205,0.5)",
                strokeColor : "rgba(151,187,205,1)",
                data : {{ dataset_female }}
            }
            ]
        }
    
    
        var ctx = $('#chart_chartjs')[0].getContext('2d');
        new Chart(ctx).Bar(data,{});
    });
    """
    )
    
    if show == 'by_region':
        data_frame = sc_est2012_sex.groupby(['REGION', 'SEX'], as_index=False)[['POPEST2012_CIV']].sum()
        labels = [region_codes[code] for code in data_frame['REGION'].drop_duplicates()]
    elif show == 'by_division':
        data_frame = sc_est2012_sex.groupby(['DIVISION', 'SEX'], as_index=False)[['POPEST2012_CIV']].sum()
        labels = [division_codes[code] for code in data_frame['DIVISION'].drop_duplicates()]
    elif show == 'by_state':
        data_frame = sc_est2012_sex.groupby(['STATE', 'SEX'], as_index=False)[['POPEST2012_CIV']].sum()
        data_frame = pd.merge(data_frame, state, left_on='STATE', right_on='STATE')
        labels = data_frame['STATE_NAME'].drop_duplicates().tolist()

    dataset_male = data_frame[data_frame.SEX == 1]['POPEST2012_CIV'].tolist()
    dataset_female = data_frame[data_frame.SEX == 2]['POPEST2012_CIV'].tolist()

    rendered_template = sc_est2012_sex_template.render(
        labels=dumps(labels),
        dataset_male=dumps(dataset_male),
        dataset_female=dumps(dataset_female),
    )

    if show_javascript:
        display(widgets.PopupWidget(children=(widgets.HTMLWidget(value='<div style="width:600px; height: 400px; overflow:scroll;"><pre>{}</pre></div>'.format(rendered_template)),)))
    
    display(Javascript(rendered_template))
Esempio n. 3
0
    def __init__(self, document):
        """Public constructor."""

        self.closed = False
        self.document = document

        self._popout = widgets.PopupWidget()
        self._popout.description = "Create %s" % self.document.__name__
        self._popout.button_text = self._popout.description

        self._modal_body = widgets.ContainerWidget()
        self._modal_body.set_css('overflow-y', 'scroll')


        self._popout.children = [
            self._modal_body,
        ]
        self.fill()
Esempio n. 4
0
    def __init__(self, df):

        Browse.instance = self
        self.closed = False

        self._popout = widgets.PopupWidget()
        self._popout.description = getattr(df, 'name', 'df')
        self._popout.button_text = self._popout.description
        self._modal_body = widgets.ContainerWidget()
        self._modal_body.set_css('overflow-y', 'scroll')

        self._modal_body_label = widgets.HTMLWidget(value='Not hooked')
        self._modal_body.children = [self._modal_body_label]

        self._popout.children = [
            self._modal_body,
        ]

        self._df = df
        self._ipython = get_ipython()
        self._ipython.register_post_execute(self._fill)

        self.ncols = len(df._info_axis)
        self.nrows = len(df)
Esempio n. 5
0
 def _create_popup(self):
     self._popup = widgets.PopupWidget()
     self._popup.description = "JHeatmap"
     self._popup.button_text = "Show heatmap"
     self._popup.children = [self]
Esempio n. 6
0
def display_chart_d3(data, show_javascript, states, div):
    sub_est_2012_df_by_state_template = jinja2.Template(
    """
    // Based on http://www.recursion.org/d3-for-mere-mortals/

    require(["d3"], function(d3) {
        var data = []

        {% for row in data %}
        data.push({ 'state': '{{ row[4] }}', 'population': {{ row[1] }} });
        {% endfor %}

        d3.select("#chart_d3_interactive svg").remove()

        var margin = {top: 20, right: 20, bottom: 30, left: 40},
            width = 800 - margin.left - margin.right,
            height = 400 - margin.top - margin.bottom;

        var x = d3.scale.ordinal()
            .rangeRoundBands([0, width], .25);

        var y = d3.scale.linear()
            .range([height, 0]);

        var xAxis = d3.svg.axis()
            .scale(x)
            .orient("bottom");

        var yAxis = d3.svg.axis()
            .scale(y)
            .orient("left")
            .ticks(10)
            .tickFormat(d3.format('.1s'));

        var svg = d3.select("#chart_d3_interactive").append("svg")
            .attr("width", width + margin.left + margin.right)
            .attr("height", height + margin.top + margin.bottom)
            .append("g")
            .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

        x.domain(data.map(function(d) { return d.state; }));
        y.domain([0, d3.max(data, function(d) { return d.population; })]);

        svg.append("g")
            .attr("class", "x axis")
            .attr("transform", "translate(0," + height + ")")
            .call(xAxis);

        svg.append("g")
            .attr("class", "y axis")
            .call(yAxis)
            .append("text")
            .attr("transform", "rotate(-90)")
            .attr("y", 6)
            .attr("dy", ".71em")
            .style("text-anchor", "end")
            .text("Population");

        svg.selectAll(".bar")
            .data(data)
            .enter().append("rect")
            .attr("class", "bar")
            .attr("x", function(d) { return x(d.state); })
            .attr("width", x.rangeBand())
            .attr("y", function(d) { return y(d.population); })
            .attr("height", function(d) { return height - y(d.population); });
    });
    """
    )
    rendered_template = sub_est_2012_df_by_state_template.render(
        data=data[data['STUSAB'].map(lambda v: v in states)].itertuples()
    )
    
    if show_javascript:
        display(widgets.PopupWidget(children=(widgets.HTMLWidget(value='<div style="width:600px; height: 400px; overflow:scroll;"><pre>{}</pre></div>'.format(rendered_template)),)))
        
    display(Javascript(rendered_template))
Esempio n. 7
0
    elif show == 'by_division':
        data_frame = sc_est2012_age.groupby(['DIVISION', 'AGE'], as_index=False)[['POPEST2012_CIV']].sum()
        categories = [division_codes[code] for code in data_frame['DIVISION'].drop_duplicates()]
        
    series_names = data_frame['AGE'].drop_duplicates().tolist()
    series = [{
        'name': series_name, 'data': data_frame[data_frame.AGE == series_name]['POPEST2012_CIV'].tolist()
    } for series_name in series_names]
    
    rendered_template = sc_est2012_age_template.render(
        categories=dumps(categories),
        series=dumps(series)
    )

    if show_javascript:
        display(widgets.PopupWidget(children=(widgets.HTMLWidget(value='<div style="width:600px; height: 400px; overflow:scroll;"><pre>{}</pre></div>'.format(rendered_template)),)))

    display(Javascript(rendered_template))


# In[ ]:

i = interact(
    display_chart_highcharts,
    sc_est2012_age=widgets.fixed(sc_est2012_age),
    show_javascript=widgets.CheckboxWidget(value=False),
    show=widgets.DropdownWidget(
        values={'By Region':'by_region', 'By Division': 'by_division'},
        value='by_region'
    ),
    div=widgets.HTMLWidget(value='<div id="chart_highcharts"></div>')
Esempio n. 8
0
    def __init__(
        self, panels, lma_ctrl, scatter_ctrl, charge_lasso, d
    ):  #, station_number_selection, charge_lasso_widget, draw_lasso_widget, color_field_widget, animation_time_widget, animate_button, label, LMA_Controlsa, LMA_Controlsb, tools_popup, number_of_stations):
        self.panels = panels
        self.lma_ctrl = lma_ctrl
        self.d = d
        self.scatter_ctrl = scatter_ctrl
        self.charge_lasso = charge_lasso

        #Max Chi2 Value:
        chi2_selection = widgets.BoundedFloatTextWidget(
            description='Max Chi2:', min='0.0', max='1000.0', value='1')
        chi2_selection.set_css({
            'max-width': '30px',
        })
        chi2_selection.on_trait_change(self.max_chi2, 'value')

        #Station Number Selection:
        station_number_selection = widgets.DropdownWidget(
            description='Number of Stations:',
            values=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
            value=7)
        station_number_selection.set_css({
            'background-dropdown': '#888888',
            'color': 'white',
        })
        station_number_selection.on_trait_change(self.number_of_stations,
                                                 'value')

        #Charge Lasso and Draw Button:
        charge_lasso_widget = widgets.RadioButtonsWidget(
            description='Charge Selection:',
            values=["-1", "0", "1"],
            value="-1")
        charge_lasso_widget.on_trait_change(self.change_lasso_charge, 'value')

        draw_lasso_widget = widgets.ButtonWidget(description='Draw')
        draw_lasso_widget.set_css({
            'background': '#888888',
            'color': 'white',
        })
        draw_lasso_widget.on_click(self.lasso_button)

        #Color Field Selection:
        color_field_widget = widgets.RadioButtonsWidget(
            description='Color By:',
            values=["chi2", "time", "charge"],
            value="time")
        color_field_widget.on_trait_change(self.change_color_field, 'value')

        #Animate (Slider and Button) Optional Manual Numerical Input commented out:
        animation_time_widget = widgets.IntSliderWidget(
            description='Animation Time:', min='0', max='30')
        animation_time_widget.value = '5'
        # animation_time_widget = widgets.TextWidget(Description='Animation Time')
        # animation_time_widget.placeholder = "value"
        animate_button = widgets.ButtonWidget(description="Animate")
        animate_button.set_css({
            'display': 'flex',
            'align-content': 'flex-end',
            'background': '#888888',
            'color': 'white',
        })
        animate_button.on_click(self.run_animation_button)

        #FOR CONTAINERS AND POPUP
        label = widgets.LatexWidget(value='LMA Tools')
        label.set_css({
            'font-size': '20px',
            'font-weight': 'bold',
            'align-self': 'center',
            'padding': '15px',
            'background': 'd8d8d8',
        })

        LMA_Controlsa = widgets.ContainerWidget()
        LMA_Controlsa.children = [
            station_number_selection, charge_lasso_widget, draw_lasso_widget,
            chi2_selection
        ]
        LMA_Controlsa.set_css({
            'display': 'flex',
            'flex-direction': 'column',
            # 'max-width': '300px',
            'flex-flow': 'row wrap',
            'align-content': 'flex-start',
            'padding': '10px',
            'background': '#e8e8e8',
            'font-weight': 'bold',
        })
        LMA_Controlsa.remove_class('vbox')
        LMA_Controlsa.add_class('hbox')

        LMA_Controlsb = widgets.ContainerWidget()
        LMA_Controlsb.children = [
            color_field_widget, animation_time_widget, animate_button
        ]
        LMA_Controlsb.set_css({
            'display': 'flex',
            'flex-flow': 'wrap',
            'align-items': 'right',
            'columns': '1',
            'padding': '10px',
            'background': '#e8e8e8',
            'font-weight': 'bold',
        })
        LMA_Controlsb.remove_class('vbox')
        LMA_Controlsb.add_class('hbox')

        tools_popup = widgets.PopupWidget(description='LMA Control Hub')
        tools_popup.set_css({
            'font-size': '14px',
            'align-self': 'center',
            'padding': '15px',
            'border': '5px ridge #989898',
            'background': '#e8e8e8',
        })
        tools_popup.children = [label, LMA_Controlsa, LMA_Controlsb]

        self.chi2_selection = chi2_selection
        self.station_number_selection = station_number_selection
        self.charge_lasso_widget = charge_lasso_widget
        self.draw_lasso_widget = draw_lasso_widget
        self.color_field_widget = color_field_widget
        self.animation_time_widget = animation_time_widget
        self.animate_button = animate_button
        self.label = label
        self.LMA_Controlsa = LMA_Controlsa
        self.LMA_Controlsb = LMA_Controlsb
        self.tools_popup = tools_popup