li-nguyen commited on
Commit
2e694e2
·
2 Parent(s): 9ff5bf5 487a9ac

Merge branch 'dev/add-initial-version'

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. Dockerfile +18 -0
  2. LICENSE.txt +21 -0
  3. README.md +103 -11
  4. app.py +111 -0
  5. assets/app.svg +9 -0
  6. assets/css/custom.css +71 -0
  7. assets/favicon.ico +0 -0
  8. assets/images/charts/arc.svg +25 -0
  9. assets/images/charts/area.svg +1 -0
  10. assets/images/charts/bar.svg +1 -0
  11. assets/images/charts/barcode.svg +136 -0
  12. assets/images/charts/beeswarm.svg +1 -0
  13. assets/images/charts/boxplot.svg +78 -0
  14. assets/images/charts/bubble-map.svg +0 -0
  15. assets/images/charts/bubble-timeline.svg +35 -0
  16. assets/images/charts/bubble.svg +32 -0
  17. assets/images/charts/bullet.svg +41 -0
  18. assets/images/charts/bump.svg +1 -0
  19. assets/images/charts/butterfly.svg +27 -0
  20. assets/images/charts/chord.svg +23 -0
  21. assets/images/charts/choropleth.svg +0 -0
  22. assets/images/charts/column-and-line.svg +20 -0
  23. assets/images/charts/column.svg +1 -0
  24. assets/images/charts/connected-scatter.svg +1 -0
  25. assets/images/charts/cumulative-curve.svg +18 -0
  26. assets/images/charts/diverging-bar.svg +21 -0
  27. assets/images/charts/diverging-stacked-bar.svg +1 -0
  28. assets/images/charts/donut.svg +25 -0
  29. assets/images/charts/dot-map.svg +0 -0
  30. assets/images/charts/dot-plot.svg +30 -0
  31. assets/images/charts/fan.svg +21 -0
  32. assets/images/charts/flow-map.svg +0 -0
  33. assets/images/charts/funnel.svg +19 -0
  34. assets/images/charts/gantt.svg +20 -0
  35. assets/images/charts/gridplot.svg +1 -0
  36. assets/images/charts/heatmap-matrix.svg +179 -0
  37. assets/images/charts/heatmap.svg +27 -0
  38. assets/images/charts/histogram.svg +25 -0
  39. assets/images/charts/line.svg +17 -0
  40. assets/images/charts/lollipop.svg +26 -0
  41. assets/images/charts/marimekko.svg +27 -0
  42. assets/images/charts/network.svg +44 -0
  43. assets/images/charts/ordered-bar.svg +20 -0
  44. assets/images/charts/ordered-bubble.svg +20 -0
  45. assets/images/charts/ordered-column.svg +20 -0
  46. assets/images/charts/paired-bar.svg +1 -0
  47. assets/images/charts/paired-column.svg +1 -0
  48. assets/images/charts/parallel-coordinates.svg +26 -0
  49. assets/images/charts/pictogram.svg +63 -0
  50. assets/images/charts/pie.svg +29 -0
Dockerfile ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.9
5
+
6
+ RUN useradd -m -u 1000 user
7
+
8
+ WORKDIR /app
9
+
10
+ COPY --chown=user ./requirements.txt requirements.txt
11
+
12
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
13
+
14
+ COPY --chown=user . /app
15
+
16
+ EXPOSE 7860
17
+
18
+ CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:server"]
LICENSE.txt ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 FT Interactive News
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md CHANGED
@@ -1,11 +1,103 @@
1
- ---
2
- title: Demo Visual Vocabulary
3
- emoji: 🌖
4
- colorFrom: indigo
5
- colorTo: indigo
6
- sdk: docker
7
- pinned: false
8
- license: apache-2.0
9
- ---
10
-
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Vizro - Visual vocabulary
2
+
3
+ This dashboard shows a gallery of charts. It includes guidance on when to use each chart type and sample Python code
4
+ to create them using [Plotly](https://plotly.com/python/) and [Vizro](https://github.com/mckinsey/vizro).
5
+
6
+ **Created by:**
7
+
8
+ - [Huong Li Nguyen](https://github.com/huong-li-nguyen) and [Antony Milne](https://github.com/antonymilne)
9
+
10
+ - Images created by QuantumBlack
11
+
12
+ **Inspired by:**
13
+
14
+ - [The FT Visual Vocabulary](https://github.com/Financial-Times/chart-doctor/blob/main/visual-vocabulary/README.md): Alan Smith, Chris Campbell, Ian Bott, Liz Faunce, Graham Parrish, Billy Ehrenberg, Paul McCallum,
15
+ Martin Stabe.
16
+
17
+ - [The Graphic Continuum](https://www.informationisbeautifulawards.com/showcase/611-the-graphic-continuum): Jon Swabish and Severino Ribecca
18
+
19
+ **Credits, tutorials and resources:**
20
+
21
+ - [Plotly](https://plotly.com/python/plotly-express/)
22
+ - [Guide to data chart mastery](https://www.atlassian.com/data/charts)
23
+
24
+ ## Chart types
25
+
26
+ The dashboard is still in development. Below is an overview of the chart types for which a completed page is available.
27
+
28
+ | Chart Type | Status | Category |
29
+ | --------------------- | ------ | ------------------------ |
30
+ | Arc | ❌ | Part-to-whole |
31
+ | Area | ✅ | Time |
32
+ | Bar | ✅ | Magnitude |
33
+ | Barcode | ❌ | Distribution |
34
+ | Beeswarm | ❌ | Distribution |
35
+ | Boxplot | ✅ | Distribution |
36
+ | Bubble | ✅ | Correlation |
37
+ | Bubble map | ❌ | Spatial |
38
+ | Bubble timeline | ❌ | Time |
39
+ | Bullet | ❌ | Magnitude |
40
+ | Bump | ❌ | Ranking |
41
+ | Butterfly | ✅ | Deviation, Distribution |
42
+ | Chord | ❌ | Flow |
43
+ | Choropleth | ✅ | Spatial |
44
+ | Column | ✅ | Magnitude, Time |
45
+ | Column and line | ✅ | Correlation, Time |
46
+ | Connected scatter | ✅ | Correlation, Time |
47
+ | Cumulative curve | ❌ | Distribution |
48
+ | Diverging bar | ❌ | Deviation |
49
+ | Diverging stacked bar | ❌ | Deviation |
50
+ | Donut | ✅ | Part-to-whole |
51
+ | Dot map | ❌ | Spatial |
52
+ | Dot plot | ❌ | Distribution |
53
+ | Fan | ❌ | Time |
54
+ | Flow map | ❌ | Spatial |
55
+ | Funnel | ✅ | Part-to-whole |
56
+ | Gantt | ❌ | Time |
57
+ | Gridplot | ❌ | Part-to-whole |
58
+ | Heatmap | ✅ | Time |
59
+ | Heatmap matrix | ❌ | Correlation |
60
+ | Histogram | ✅ | Distribution |
61
+ | Line | ✅ | Time |
62
+ | Lollipop | ❌ | Ranking, Magnitude |
63
+ | Marimekko | ❌ | Magnitude, Part-to-whole |
64
+ | Network | ❌ | Flow |
65
+ | Ordered bar | ✅ | Ranking |
66
+ | Ordered bubble | ❌ | Ranking |
67
+ | Ordered column | ✅ | Ranking |
68
+ | Paired bar | ✅ | Magnitude |
69
+ | Paired column | ✅ | Magnitude |
70
+ | Parallel coordinates | ✅ | Magnitude |
71
+ | Pictogram | ❌ | Magnitude |
72
+ | Pie | ✅ | Part-to-whole |
73
+ | Radar | ❌ | Magnitude |
74
+ | Radial | ❌ | Magnitude |
75
+ | Sankey | ✅ | Flow |
76
+ | Scatter | ✅ | Correlation |
77
+ | Scatter matrix | ✅ | Correlation |
78
+ | Slope | ❌ | Ranking, Time |
79
+ | Sparkline | ❌ | Time |
80
+ | Stacked bar | ✅ | Part-to-whole |
81
+ | Stacked column | ✅ | Part-to-whole |
82
+ | Stepped line | ✅ | Time |
83
+ | Surplus deficit line | ❌ | Deviation |
84
+ | Treemap | ✅ | Part-to-whole |
85
+ | Venn | ❌ | Part-to-whole |
86
+ | Violin | ✅ | Distribution |
87
+ | Waterfall | ❌ | Part-to-whole, Flow |
88
+
89
+ To contribute a chart, follow the steps below:
90
+
91
+ 1. Place an `svg` file named after the chart type in the `assets` folder if it doesn't already exist.
92
+ 2. Add the data set to `_pages_utils.py` if it doesn't already exist.
93
+ 3. Create a new page for the chart type and add it to the relevant category `.py` file such as `correlation.py`,
94
+ `deviation.py`, `distribution.py`, etc.
95
+ 4. Add a `.py` file containing a code example of the chart type in the `pages/examples` folder, for instance, `area.py`
96
+ 5. Remove the `IncompletePage(..)` entry for that chart type in `chart_groups.py`.
97
+ 6. Update this `README.md` with the new chart type.
98
+
99
+ ## How to run the example locally
100
+
101
+ 1. If you have `hatch` set up, run the example with the command `hatch run example _visual-vocabulary`.
102
+ Otherwise, with a virtual Python environment activated, run `pip install -r requirements.txt` and then `python app.py`.
103
+ 2. You should now be able to access the app locally via http://127.0.0.1:8050/.
app.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """App configuration for dashboard."""
2
+
3
+ from typing import List, Union
4
+
5
+ import vizro.models as vm
6
+ from chart_groups import ALL_CHART_GROUP, CHART_GROUPS, ChartGroup, IncompletePage
7
+ from custom_components import FlexContainer, Markdown
8
+ from vizro import Vizro
9
+
10
+
11
+ def make_chart_card(page: Union[vm.Page, IncompletePage]) -> vm.Card:
12
+ """Makes a card with svg icon, linked to the right page if page is complete.
13
+
14
+ Args:
15
+ page: page to make card for
16
+
17
+ Returns: card with svg icon, linked to the right page if page is complete.
18
+
19
+ """
20
+ # There's one SVG per chart title, so that e.g. pages distribution-butterfly and deviation-butterfly, which both
21
+ # have title "Butterfly", correspond to butterfly.svg.
22
+ # Incomplete pages have page.path = "" so won't be linked to here.
23
+ svg_name = page.title.lower().replace(" ", "-")
24
+ return vm.Card(
25
+ text=f"""
26
+ ![](assets/images/charts/{svg_name}.svg#chart-icon)
27
+
28
+ #### {page.title}
29
+ """,
30
+ href=page.path,
31
+ )
32
+
33
+
34
+ def make_homepage_container(chart_group: ChartGroup) -> vm.Container:
35
+ """Makes a container with cards for each completed and incomplete chart in chart_group.
36
+
37
+ Args:
38
+ chart_group: group of charts to make container for.
39
+
40
+ Returns: container with cards for each chart in chart_group.
41
+
42
+ """
43
+ # Pages are sorted in title's alphabetical order and deduplicated so that e.g. pages distribution-butterfly and
44
+ # deviation-butterfly, which both have title "Butterfly", correspond to a single card.
45
+ return vm.Container(
46
+ title=chart_group.name,
47
+ layout=vm.Layout(grid=[[0, 1, 1]], col_gap="40px"),
48
+ components=[
49
+ Markdown(text=chart_group.intro_text, classname="intro-text"),
50
+ FlexContainer(
51
+ components=[
52
+ make_chart_card(page)
53
+ for page in sorted(
54
+ _remove_duplicates(chart_group.pages + chart_group.incomplete_pages),
55
+ key=lambda page: page.title,
56
+ )
57
+ ],
58
+ ),
59
+ ],
60
+ )
61
+
62
+
63
+ def _remove_duplicates(pages: List[Union[vm.Page, IncompletePage]]) -> List[Union[vm.Page, IncompletePage]]:
64
+ # Deduplicate pages that have the same title. Using reversed means that the page that is kept is the first one
65
+ # in the dashboard. This will be the one that the card on the homepage links to.
66
+ return list({page.title: page for page in reversed(pages)}.values())
67
+
68
+
69
+ def make_navlink(chart_group: ChartGroup) -> vm.NavLink:
70
+ """Makes a navlink with icon and links to every complete page within chart_group.
71
+
72
+ Args:
73
+ chart_group: chart_group to make a navlink for.
74
+
75
+ Returns: navlink for chart_group.
76
+
77
+ """
78
+ # Pages are sorted in alphabetical order within each chart group.
79
+ return vm.NavLink(
80
+ label=chart_group.name,
81
+ pages={chart_group.name: [page.id for page in sorted(chart_group.pages, key=lambda page: page.title)]},
82
+ icon=chart_group.icon,
83
+ )
84
+
85
+
86
+ homepage = vm.Page(
87
+ title="Overview",
88
+ components=[
89
+ vm.Tabs(tabs=[make_homepage_container(chart_group) for chart_group in [ALL_CHART_GROUP, *CHART_GROUPS]]),
90
+ ],
91
+ )
92
+
93
+ # TODO: consider whether each chart group should have its own individual homepage,
94
+ # e.g. at http://localhost:8050/deviation/. This could just repeat the content of the tab from the homepage and would
95
+ # work nicely with the hierarchical navigation.
96
+ dashboard = vm.Dashboard(
97
+ # ALL_CHART_GROUP.pages has duplicated pages, e.g. both distribution-butterfly and deviation-butterfly.
98
+ title="Vizro - Visual Vocabulary",
99
+ pages=[homepage, *ALL_CHART_GROUP.pages],
100
+ navigation=vm.Navigation(
101
+ nav_selector=vm.NavBar(
102
+ items=[
103
+ vm.NavLink(label="Overview", pages=[homepage.id], icon="Home"),
104
+ ]
105
+ + [make_navlink(chart_group) for chart_group in CHART_GROUPS]
106
+ )
107
+ ),
108
+ )
109
+
110
+ if __name__ == "__main__":
111
+ Vizro().build(dashboard).run()
assets/app.svg ADDED
assets/css/custom.css ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #page-header {
2
+ padding-left: 8px;
3
+ }
4
+
5
+ #left-main {
6
+ width: 288px;
7
+ }
8
+
9
+ img[src*="#chart-icon"] {
10
+ width: 100%;
11
+ }
12
+
13
+ .code-clipboard {
14
+ font-size: 20px;
15
+ position: absolute;
16
+ right: 14px;
17
+ top: 12px;
18
+ }
19
+
20
+ .code-clipboard-container {
21
+ background: var(--surfaces-bg-card);
22
+ font-family: monospace;
23
+ max-height: 500px;
24
+ overflow: auto;
25
+ padding: 1rem;
26
+ position: relative;
27
+ }
28
+
29
+ .code-clipboard-container::-webkit-scrollbar-thumb {
30
+ border-color: var(--surfaces-bg-card);
31
+ }
32
+
33
+ .flex-container {
34
+ display: flex;
35
+ flex-wrap: wrap;
36
+ gap: 24px;
37
+ justify-content: flex-start;
38
+ }
39
+
40
+ .flex-container h4 {
41
+ color: var(--text-secondary);
42
+ margin: 0;
43
+ padding-top: 12px;
44
+ text-align: center;
45
+ }
46
+
47
+ .flex-container .card {
48
+ height: 232px;
49
+ margin: 0 0 auto;
50
+ opacity: 0.3;
51
+ width: 176px;
52
+ }
53
+
54
+ .flex-container .card-nav {
55
+ opacity: 1;
56
+ }
57
+
58
+ .flex-container .card img {
59
+ width: 100%;
60
+ }
61
+
62
+ .intro-text {
63
+ border-left: 4px solid var(--text-secondary);
64
+ padding: 4px 12px;
65
+ }
66
+
67
+ .intro-text p {
68
+ font-size: 16px;
69
+ line-height: 20px;
70
+ margin: 0;
71
+ }
assets/favicon.ico ADDED
assets/images/charts/arc.svg ADDED
assets/images/charts/area.svg ADDED
assets/images/charts/bar.svg ADDED
assets/images/charts/barcode.svg ADDED
assets/images/charts/beeswarm.svg ADDED
assets/images/charts/boxplot.svg ADDED
assets/images/charts/bubble-map.svg ADDED
assets/images/charts/bubble-timeline.svg ADDED
assets/images/charts/bubble.svg ADDED
assets/images/charts/bullet.svg ADDED
assets/images/charts/bump.svg ADDED
assets/images/charts/butterfly.svg ADDED
assets/images/charts/chord.svg ADDED
assets/images/charts/choropleth.svg ADDED
assets/images/charts/column-and-line.svg ADDED
assets/images/charts/column.svg ADDED
assets/images/charts/connected-scatter.svg ADDED
assets/images/charts/cumulative-curve.svg ADDED
assets/images/charts/diverging-bar.svg ADDED
assets/images/charts/diverging-stacked-bar.svg ADDED
assets/images/charts/donut.svg ADDED
assets/images/charts/dot-map.svg ADDED
assets/images/charts/dot-plot.svg ADDED
assets/images/charts/fan.svg ADDED
assets/images/charts/flow-map.svg ADDED
assets/images/charts/funnel.svg ADDED
assets/images/charts/gantt.svg ADDED
assets/images/charts/gridplot.svg ADDED
assets/images/charts/heatmap-matrix.svg ADDED
assets/images/charts/heatmap.svg ADDED
assets/images/charts/histogram.svg ADDED
assets/images/charts/line.svg ADDED
assets/images/charts/lollipop.svg ADDED
assets/images/charts/marimekko.svg ADDED
assets/images/charts/network.svg ADDED
assets/images/charts/ordered-bar.svg ADDED
assets/images/charts/ordered-bubble.svg ADDED
assets/images/charts/ordered-column.svg ADDED
assets/images/charts/paired-bar.svg ADDED
assets/images/charts/paired-column.svg ADDED
assets/images/charts/parallel-coordinates.svg ADDED
assets/images/charts/pictogram.svg ADDED
assets/images/charts/pie.svg ADDED