Skip to content

Commit

Permalink
Merge pull request #66 from ncusi/visualization - Sankey diagrams (pa…
Browse files Browse the repository at this point in the history
…rt 1)

Visualization: Add Sankey diagram to show distribution on contributions based on directory hierarchy (part 1)
  • Loading branch information
jnareb authored Dec 9, 2024
2 parents 351230a + 0341d79 commit cdb59f8
Show file tree
Hide file tree
Showing 9 changed files with 640 additions and 33 deletions.
41 changes: 27 additions & 14 deletions src/diffinsights_web/apps/contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
import panel as pn

import diffinsights_web.utils.notifications as notifications
from diffinsights_web.datastore.timeline import TimelineDataStore, find_dataset_dir
from diffinsights_web.datastore.linesstats import LinesStatsDataStore
from diffinsights_web.datastore.timeline import TimelineDataStore
from diffinsights_web.datastore import find_dataset_dir
from diffinsights_web.utils.notifications import onload_callback
from diffinsights_web.views.authorsgrid import AuthorInfo, AuthorsGrid
from diffinsights_web.views.dataexplorer import TimelineJSONViewer, TimelinePerspective, \
TimelineDataFrameEnum, perspective_pane
from diffinsights_web.views.info import ContributorsHeader, RepoPlotHeader, ContributionsPercHeader
from diffinsights_web.views.plots.sankey import SankeyPlot
from diffinsights_web.views.plots.timeseries import TimeseriesPlot
from diffinsights_web.widgets.caching import ClearCacheButton

Expand All @@ -27,33 +30,43 @@
pn.state.onload(onload_callback)

dataset_dir = find_dataset_dir()
data_store = TimelineDataStore(dataset_dir=dataset_dir)
timeline_data_store = TimelineDataStore(dataset_dir=dataset_dir)
lines_stats_data_store = LinesStatsDataStore(
dataset_dir=dataset_dir,
timeseries_file=timeline_data_store.select_file_widget,
repo_name=timeline_data_store.select_repo_widget,
)

page_header = ContributorsHeader(
repo=data_store.select_repo_widget,
freq=data_store.resample_frequency_widget,
end_date=data_store.timeline_max_date_rx,
repo=timeline_data_store.select_repo_widget,
freq=timeline_data_store.resample_frequency_widget,
end_date=timeline_data_store.timeline_max_date_rx,
)
sankey_plot = SankeyPlot(
data_store=lines_stats_data_store,
from_date_str=page_header.select_period_from_widget,
)
timeseries_plot = TimeseriesPlot(
data_store=data_store,
data_store=timeline_data_store,
column_name=page_header.select_contribution_type_widget,
from_date_str=page_header.select_period_from_widget,
sankey_plot=sankey_plot,
)
timeseries_plot_header = RepoPlotHeader(
freq=data_store.resample_frequency_widget,
freq=timeline_data_store.resample_frequency_widget,
column_name=page_header.select_contribution_type_widget,
plot=timeseries_plot,
)
contributions_perc_header = ContributionsPercHeader(
data_store=data_store,
data_store=timeline_data_store,
from_date_str=page_header.select_period_from_widget,
)
authors_info_panel = AuthorInfo(
data_store=data_store,
data_store=timeline_data_store,
authors_info_df=timeseries_plot.authors_info_df_rx,
)
authors_grid = AuthorsGrid(
data_store=data_store,
data_store=timeline_data_store,
main_plot=timeseries_plot,
authors_info_df=timeseries_plot.authors_info_df_rx,
top_n=authors_info_panel.top_n_widget,
Expand All @@ -65,7 +78,7 @@
title="Contributors Graph", # TODO: make title dynamic
favicon="favicon.svg",
sidebar=[
data_store,
timeline_data_store,
*authors_info_panel.widgets(),

pn.layout.Divider(), # - - - - - - - - - - - - -
Expand All @@ -88,11 +101,11 @@
authors_grid,
],
)
timeline_perspective = TimelinePerspective(data_store=data_store)
timeline_perspective = TimelinePerspective(data_store=timeline_data_store)
template.main.extend([
pn.layout.Divider(),
pn.Tabs(
('JSON', TimelineJSONViewer(data_store=data_store)),
('JSON', TimelineJSONViewer(data_store=timeline_data_store)),
('data', timeline_perspective.panel(TimelineDataFrameEnum.TIMELINE_DATA)),
('resampled', timeline_perspective.panel(TimelineDataFrameEnum.RESAMPLED_DATA)),
('by author+resampled', timeline_perspective.panel(TimelineDataFrameEnum.BY_AUTHOR_DATA)),
Expand All @@ -101,7 +114,7 @@
perspective_pane(
df=timeseries_plot.authors_info_df_rx,
title=pn.rx("Authors info for repo={repo!r}, from={from_date!r}") \
.format(repo=data_store.select_repo_widget,
.format(repo=timeline_data_store.select_repo_widget,
from_date=page_header.select_period_from_widget)
)
),
Expand Down
17 changes: 17 additions & 0 deletions src/diffinsights_web/datastore/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from pathlib import Path
from typing import Optional

import panel as pn

DATASET_DIR = 'data/examples/stats'


@pn.cache
def find_dataset_dir() -> Optional[Path]:
for TOP_DIR in ['', '..', '../..']:
full_dir = Path(TOP_DIR).joinpath(DATASET_DIR)

if full_dir.is_dir():
return full_dir

return None
Loading

0 comments on commit cdb59f8

Please sign in to comment.