|
5 | 5 | <link rel="icon" type="image/x-icon" href="./favicon.png">
|
6 | 6 | <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
|
7 | 7 | <link rel="stylesheet" href="./assets/css/examples.css" />
|
8 |
| - <link rel="stylesheet" href="./assets/prism/prism.css" /> |
9 | 8 | <script defer src="https://pyscript.net/latest/pyscript.js"></script>
|
10 |
| - <script defer src="./assets/prism/prism.js"></script> |
11 | 9 | </head>
|
12 | 10 | <body>
|
13 | 11 | <nav class="navbar" style="background-color: #000000;">
|
|
20 | 18 | </nav>
|
21 | 19 | <section class="pyscript">
|
22 | 20 | <div id="altair"></div>
|
23 |
| - <py-config> |
24 |
| - packages = [ |
25 |
| - "altair", |
26 |
| - "pandas", |
27 |
| - "vega_datasets" |
28 |
| - ] |
29 |
| - </py-config> |
30 |
| - <py-script> |
31 |
| - import altair as alt |
32 |
| - from vega_datasets import data |
| 21 | + <py-tutor> |
| 22 | + <py-config> |
| 23 | + packages = [ |
| 24 | + "altair", |
| 25 | + "pandas", |
| 26 | + "vega_datasets" |
| 27 | + ] |
| 28 | + plugins = [ |
| 29 | + "../build/plugins/python/py_tutor.py" |
| 30 | + ] |
| 31 | + </py-config> |
| 32 | + <py-script> |
| 33 | + import altair as alt |
| 34 | + from vega_datasets import data |
33 | 35 |
|
34 |
| - source = data.movies.url |
| 36 | + source = data.movies.url |
35 | 37 |
|
36 |
| - pts = alt.selection(type="single", encodings=['x']) |
| 38 | + pts = alt.selection(type="single", encodings=['x']) |
37 | 39 |
|
38 |
| - rect = alt.Chart(data.movies.url).mark_rect().encode( |
39 |
| - alt.X('IMDB_Rating:Q', bin=True), |
40 |
| - alt.Y('Rotten_Tomatoes_Rating:Q', bin=True), |
41 |
| - alt.Color('count()', |
42 |
| - scale=alt.Scale(scheme='greenblue'), |
43 |
| - legend=alt.Legend(title='Total Records') |
44 |
| - ) |
45 |
| - ) |
| 40 | + rect = alt.Chart(data.movies.url).mark_rect().encode( |
| 41 | + alt.X('IMDB_Rating:Q', bin=True), |
| 42 | + alt.Y('Rotten_Tomatoes_Rating:Q', bin=True), |
| 43 | + alt.Color('count()', |
| 44 | + scale=alt.Scale(scheme='greenblue'), |
| 45 | + legend=alt.Legend(title='Total Records') |
| 46 | + ) |
| 47 | + ) |
46 | 48 |
|
47 |
| - circ = rect.mark_point().encode( |
48 |
| - alt.ColorValue('grey'), |
49 |
| - alt.Size('count()', |
50 |
| - legend=alt.Legend(title='Records in Selection') |
51 |
| - ) |
52 |
| - ).transform_filter( |
53 |
| - pts |
54 |
| - ) |
| 49 | + circ = rect.mark_point().encode( |
| 50 | + alt.ColorValue('grey'), |
| 51 | + alt.Size('count()', |
| 52 | + legend=alt.Legend(title='Records in Selection') |
| 53 | + ) |
| 54 | + ).transform_filter( |
| 55 | + pts |
| 56 | + ) |
55 | 57 |
|
56
F41A
|
| - bar = alt.Chart(source).mark_bar().encode( |
57 |
| - x='Major_Genre:N', |
58 |
| - y='count()', |
59 |
| - color=alt.condition(pts, alt.ColorValue("steelblue"), alt.ColorValue("grey")) |
60 |
| - ).properties( |
61 |
| - width=550, |
62 |
| - height=200 |
63 |
| - ).add_selection(pts) |
| 58 | + bar = alt.Chart(source).mark_bar().encode( |
| 59 | + x='Major_Genre:N', |
| 60 | + y='count()', |
| 61 | + color=alt.condition(pts, alt.ColorValue("steelblue"), alt.ColorValue("grey")) |
| 62 | + ).properties( |
| 63 | + width=550, |
| 64 | + height=200 |
| 65 | + ).add_selection(pts) |
64 | 66 |
|
65 |
| - display(alt.vconcat( |
66 |
| - rect + circ, |
67 |
| - bar |
68 |
| - ).resolve_legend( |
69 |
| - color="independent", |
70 |
| - size="independent" |
71 |
| - ), target="altair") |
72 |
| - </py-script> |
| 67 | + display(alt.vconcat( |
| 68 | + rect + circ, |
| 69 | + bar |
| 70 | + ).resolve_legend( |
| 71 | + color="independent", |
| 72 | + size="independent" |
| 73 | + ), target="altair") |
| 74 | + </py-script> |
| 75 | + </py-tutor> |
73 | 76 | </section>
|
74 |
| - <section class="code"> |
75 |
| - <div id="view-code-button" role="button" aria-pressed="false" tabindex="0">View Code</div> |
76 |
| - <div id="code-section" class="code-section-hidden"> |
77 |
| - <p>index.html</p> |
78 |
| - <pre class="prism-code language-html"> |
79 |
| - <code class="language-html"> |
80 |
| - <py-config> |
81 |
| - packages = [ |
82 |
| - "altair", |
83 |
| - "pandas", |
84 |
| - "vega_datasets" |
85 |
| - ] |
86 |
| - </py-config> |
87 |
| - <py-script> |
88 |
| - import altair as alt |
89 |
| - from vega_datasets import data |
90 |
| - |
91 |
| - source = data.movies.url |
92 |
| - |
93 |
| - pts = alt.selection(type="single", encodings=['x']) |
94 |
| - |
95 |
| - rect = alt.Chart(data.movies.url).mark_rect().encode( |
96 |
| - alt.X('IMDB_Rating:Q', bin=True), |
97 |
| - alt.Y('Rotten_Tomatoes_Rating:Q', bin=True), |
98 |
| - alt.Color('count()', |
99 |
| - scale=alt.Scale(scheme='greenblue'), |
100 |
| - legend=alt.Legend(title='Total Records') |
101 |
| - ) |
102 |
| - ) |
103 |
| - |
104 |
| - circ = rect.mark_point().encode( |
105 |
| - alt.ColorValue('grey'), |
106 |
| - alt.Size('count()', |
107 |
| - legend=alt.Legend(title='Records in Selection') |
108 |
| - ) |
109 |
| - ).transform_filter( |
110 |
| - pts |
111 |
| - ) |
112 |
| - |
113 |
| - bar = alt.Chart(source).mark_bar().encode( |
114 |
| - x='Major_Genre:N', |
115 |
| - y='count()', |
116 |
| - color=alt.condition(pts, alt.ColorValue("steelblue"), alt.ColorValue("grey")) |
117 |
| - ).properties( |
118 |
| - width=550, |
119 |
| - height=200 |
120 |
| - ).add_selection(pts) |
121 |
| - |
122 |
| - display(alt.vconcat( |
123 |
| - rect + circ, |
124 |
| - bar |
125 |
| - ).resolve_legend( |
126 |
| - color="independent", |
127 |
| - size="independent" |
128 |
| - ), target="altair") |
129 |
| - </py-script> |
130 |
| - </code> |
131 |
| - </pre> |
132 |
| - </div> |
133 |
| - </section> |
134 | 77 | </body>
|
135 |
| - <script> |
136 |
| - const viewCodeButton = document.getElementById("view-code-button"); |
137 |
| - const codeSection = document.getElementById("code-section"); |
138 |
| - const handleClick = () => { |
139 |
| - if (codeSection.classList.contains("code-section-hidden")) { |
140 |
| - codeSection.classList.remove("code-section-hidden"); |
141 |
| - codeSection.classList.add("code-section-visible"); |
142 |
| - } else { |
143 |
| - codeSection.classList.remove("code-section-visible"); |
144 |
| - codeSection.classList.add("code-section-hidden"); |
145 |
| - } |
146 |
| - } |
147 |
| - viewCodeButton.addEventListener("click", handleClick) |
148 |
| - viewCodeButton.addEventListener("keydown", (e) => { |
149 |
| - if (e.key === " " || e.key === "Enter" || e.key === "Spacebar") { |
150 |
| - handleClick(); |
151 |
| - } |
152 |
| - }) |
153 |
| - </script> |
154 | 78 | </html>
|
0 commit comments