コード例 #1
0
    def make_bump_chart(self):
        self.plot_df['year'] = pd.to_datetime(
            self.plot_df['year'].astype(str) + '-01-01')
        brush = alt.selection(type='interval', encodings=['x'])
        a = alt.Chart(self.plot_df).mark_line(
            point=True, interpolate='monotone').encode(
                x='year:T',
                y='rank:Q',
                color=alt.Color('Topic:N', sort='descending'),
                tooltip=['year:T', 'rank:Q', 'Topic:N', 'rate']).properties(
                    height=400,
                    width=800).transform_filter(brush).interactive()

        b = alt.Chart(self.plot_df).mark_area().encode(
            y='sum(rate):Q',
            x='year:T',
        ).properties(width=800, height=100).add_selection(brush)

        if self.add_data_names != ['All']:
            add_charts = [
                self.make_add_data_chart(i, brush) for i in self.add_data_names
            ]
            chart = alt.vconcat(a, *add_charts, b, padding=0,
                                spacing=0).configure_view(
                                    stroke=None).configure_axis(grid=False)
            return chart
        else:
            chart = alt.vconcat(a, b, padding=0, spacing=0).configure_view(
                stroke=None).configure_axis(grid=False)
            return chart
コード例 #2
0
    def make_ridge_chart(self):
        self.plot_df['year'] = pd.to_datetime(
            self.plot_df['year'].astype(str) + '-01-01')
        brush = alt.selection_interval(encodings=['x'])
        step = 18
        overlap = 7
        # Topic selection
        selection = alt.selection_multi(fields=['Topic'])

        # смена цвета на выборе темы -- всё что не выделили делается серым
        color = alt.condition(
            selection,
            alt.Color('Topic:N',
                      legend=None,
                      scale=alt.Scale(scheme="rainbow")),
            alt.value('lightgray'))

        a = alt.hconcat(
            alt.Chart(self.plot_df).mark_area(
                fillOpacity=0.6, interpolate='monotone').encode(
                    x=alt.X('year:T'),
                    y=alt.Y('rate:Q',
                            scale=alt.Scale(range=[0, -overlap * (step + 1)]),
                            axis=None),
                    row=alt.Row('Topic:N',
                                header=alt.Header(title=None,
                                                  labelPadding=0,
                                                  labelFontSize=0)),
                    color=color).add_selection(selection).properties(
                        width=800,
                        height=step,
                        bounds='flush',
                    ).transform_filter(brush),
            alt.Chart(self.plot_df,
                      height=500).mark_point().encode(
                          y=alt.Y('Topic:N', axis=alt.Axis(orient='right')),
                          color=color).add_selection(selection))

        b = alt.Chart(self.plot_df).mark_area(interpolate='monotone').encode(
            y='sum(rate):Q',
            x='year:T',
        ).properties(width=800, height=100).add_selection(brush)

        if self.add_data_names != ['All']:
            add_charts = [
                self.make_add_data_chart(i, brush) for i in self.add_data_names
            ]
            chart = alt.vconcat(a, *add_charts, b, padding=0,
                                spacing=0).configure_view(
                                    stroke=None).configure_axis(grid=False)
            return chart
        else:
            chart = alt.vconcat(a, b, padding=0, spacing=0).configure_view(
                stroke=None).configure_axis(grid=False)
            return chart
コード例 #3
0
def generate_channel_plot(df, A, min_date="2019-10-01", channel="release"):
    channel_release_disp_days = dict(release=30, beta=10, nightly=7,)
    max_days_post_pub = channel_release_disp_days[channel]

    od = OrderedDict()
    for os in ("Windows_NT", "Darwin", "Linux"):
        osdf = df.query("os == @os")
        pdf = (
            up.format_os_df_plot(osdf, pub_date_col=c.rls_date, channel=channel)
            .query(f"submission_date > '{min_date}'")
            .assign(os=os)
            .query("nth_recent_release == nth_recent_release")
        )
        ch = (
            up.os_plot_base_release(
                pdf,
                color="vers:O",
                separate=False,
                A=A,
                channel=channel,
                max_days_post_pub=max_days_post_pub,
            )
            .properties(height=500, width=700, title=f"OS = {os}")
            .interactive()
        )
        od[os] = ch
    generate_channel_plot.od = od
    return (
        A.vconcat(*od.values())
        .resolve_scale(color="independent")
        .resolve_axis(y="shared")
    )
コード例 #4
0
ファイル: datamanager.py プロジェクト: Erlemar/news-frontend
    def make_ridge_chart(self):
        self.plot_df['year'] = pd.to_datetime(self.plot_df['year'].astype(str) + '-01-01')
        brush = alt.selection(type='interval', encodings=['x'])
        step = 18
        overlap = 4
        a = alt.Chart(self.plot_df).mark_area(stroke='black', strokeWidth=0, fillOpacity=0.6).encode(
            x=alt.X('year:T'),
            y=alt.Y('rate:Q', scale=alt.Scale(range=[0, -overlap * (step + 1)]), axis=None),
            row=alt.Row('Topic:N', header=alt.Header(title=None, labelPadding=0, labelFontSize=0)),
            color='Topic:N'
        ).properties(
            width=800,
            height=step,
            bounds='flush',
        ).transform_filter(
            brush
        )
        b = alt.Chart(self.plot_df).mark_area().encode(
            y='sum(rate):Q',
            x='year:T',
        ).properties(
            width=800,
            height=100
        ).add_selection(
            brush
        )

        if self.add_data_names != ['All']:
            add_charts = [self.make_add_data_chart(i, brush) for i in self.add_data_names]
            chart = alt.vconcat(
                a, *add_charts, b, padding=0, spacing=0
            ).configure_view(
                stroke=None
            ).configure_axis(
                grid=False
            )
            return chart
        else:
            chart = alt.vconcat(
                a, b, padding=0, spacing=0
            ).configure_view(
                stroke=None
            ).configure_axis(
                grid=False
            )
            return chart