Skip to content

Commit

Permalink
DOC: specify gallery charts by name
Browse files Browse the repository at this point in the history
  • Loading branch information
jakevdp committed Apr 12, 2018
1 parent 40814f3 commit b1f24f8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
23 changes: 16 additions & 7 deletions altair/sphinxext/altairgallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class AltairMiniGalleryDirective(Directive):
has_content = False

option_spec = {'size': int,
'names': str,
'indices': lambda x: list(map(int, x.split())),
'shuffle': flag,
'seed': int,
Expand All @@ -168,6 +169,7 @@ class AltairMiniGalleryDirective(Directive):

def run(self):
size = self.options.get('size', 15)
names = [name.strip() for name in self.options.get('names', '').split(',')]
indices = self.options.get('indices', [])
shuffle = 'shuffle' in self.options
seed = self.options.get('seed', 42)
Expand All @@ -181,13 +183,20 @@ def run(self):

examples = populate_examples()

if indices:
examples = [examples[i] for i in indices]
if shuffle:
random.seed(seed)
random.shuffle(examples)
if size:
examples = examples[:size]
if names:
if len(names) < size:
raise ValueError("altair-minigallery: if names are specified, "
"the list must be at least as long as size.")
mapping = {example['name']: example for example in examples}
examples = [mapping[name] for name in names]
else:
if indices:
examples = [examples[i] for i in indices]
if shuffle:
random.seed(seed)
random.shuffle(examples)
if size:
examples = examples[:size]

include = MINIGALLERY_TEMPLATE.render(image_dir='/_static',
gallery_dir=gallery_dir,
Expand Down
3 changes: 1 addition & 2 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ Altair: Declarative Visualization in Python
===========================================

.. altair-minigallery::
:names: one_dot_per_zipcode, horizon_graph, world_projections, candlestick_chart, falkensee, scatter_linked_brush, layered_heatmap_text, natural_disasters, streamgraph, multiline_tooltip, select_detail, choropleth, interactive_cross_highlight, seattle_weather_interactive, london_tube
:size: 15
:shuffle:
:seed: 31415

Altair is a declarative statistical visualization library for Python, based on
Vega_ and Vega-Lite_, and the source is available on
Expand Down

0 comments on commit b1f24f8

Please sign in to comment.