Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sanand0 committed Jun 25, 2020
1 parent b4ee901 commit 727c8c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
26 changes: 20 additions & 6 deletions pptxhandler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,22 @@ rules:
This repeats slide 1 three times, with titles "Copy 0: A", "Copy 1: B" and "Copy 2: C".

`copy-slide:` must be an [expression](#expressions) that returns one of these types. When copying,
the values of (`copy.key`, `copy.val`) are set as follows -- like [`clone-shape:`](#clone-shapes).
the values of (`copy.key`, `copy.val`) are set as follows (just like [`clone-shape:`](#clone-shapes)):

- tuple, list or pandas Index, e.g. `[x, y]` -> `(0, 'x'), (1, 'y')`
- dict, e.g. `{x: 1, y: 2}` -> `(1, 'x'), (2, 'y')`
- pandas Series, e.g. `pd.Series(['x', 'y'], index=[3, 4])` -> `(3, 'x'), (4, 'y')`
- pandas DataFrame, e.g. `pd.DataFrame({'x': row1, 'y': row2})` -> `('x', row1)), ('y', row2)`
- pandas GroupBy, e.g. `data.groupby('key')` -> [GroupBy iterator](https://pandas.pydata.org/pandas-docs/stable/reference/groupby.html) with group name and subsetted data

The `copy` variable has these attributes:

- `copy.pos`: 0, 1, 2, ... for each copied slide
- `copy.key`: For lists or tuples, this is the same as `copy.pos`. For dicts, Series, DataFrames, etc, it's the key or index
- `copy.val`: Value corresponding to `copy.key`
- `copy.parent`: If a group was copied, and a slide inside the group was copied too, `copy.parent` returns the `copy` object of the parent group
- `copy.slides`: Currently copied list of slides

<div class="example">
<a class="example-demo" href="copy-slide/">Copy slides examples</a>
<a class="example-src" href="https://github.com/gramexrecipes/gramex-guide/blob/tree/pptxhandler/copy-slide/">Source</a>
Expand Down Expand Up @@ -464,27 +472,33 @@ rules:
This repeats the shape three times, with text "Clone 0: A", "Clone 1: B" and "Clone 2: C".

`clone-shape:` must be an [expression](#expressions) that returns one of these types. When cloning,
the variables (`clone.key`, `clone.val`) are set as follows. Just like
[`copy-slide:`](#copy-slides).
the variables (`clone.key`, `clone.val`) are set as follows (just like [`copy-slide:`](#copy-slides)):

- tuple or list, e.g. `[x, y]` -> `(0, 'x'), (1, 'y')`
- dict, e.g. `{x: 1, y: 2}` -> `(1, 'x'), (2, 'y')`
- pandas Series, e.g. `pd.Series(['x', 'y'], index=[3, 4])` -> `(3, 'x'), (4, 'y')`
- pandas DataFrame, e.g. `pd.DataFrame({'x': row1, 'y': row2})` -> `('x', row1)), ('y', row2)`
- pandas GroupBy, e.g. `data.groupby('key')` -> [GroupBy iterator](https://pandas.pydata.org/pandas-docs/stable/reference/groupby.html) with group name and subsetted data

[EXAMPLE]
The `clone` variable has these attributes:

- `clone.pos`: 0, 1, 2, ... for each cloned shape
- `clone.key`: For lists or tuples, this is the same as `clone.pos`. For dicts, Series, DataFrames, etc, it's the key or index
- `clone.val`: Value corresponding to `clone.key`
- `clone.parent`: If a group was cloned, and a shape inside the group was cloned too, `clone.parent` returns the `clone` object of the parent group
- `clone.shape`: Currently cloned shape

[EXAMPLE]

TODO: Document clone.index and copy.index


### Debug

- `name:` changes the name of the shape, e.g. `name: !!Bar` lets "morph" [transitions](#transition)
match shape names beginning with `!!`.
[Source](https://support.microsoft.com/en-us/office/morph-transition-tips-and-tricks-bc7f48ff-f152-4ee8-9081-d3121788024f)
- `print:` prints the current value of [data](#data), e.g. `print: shape.name` prints the current shape name
- `print:` prints the result of an expression using [data](#data), e.g. `print: shape.name` prints
the current shape name. Print multiple values as a list, e.g. `print: [shape.name, clone.key]`


### Animation: TODO
Expand Down
9 changes: 5 additions & 4 deletions pptxhandler/bar-chart-race/gramex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ url:
url: $YAMLPATH/covid-comments.csv
transform: data.set_index('period')
rules:
- copy-slide: covid.columns
-
copy-slide: covid.columns
transition: f'morph'
Period:
text: copy.val
Expand All @@ -25,14 +26,14 @@ url:
# TODO: allow iterating over enumerate as well as any other iterable
clone-shape: covid[copy.val]
text: clone.key
add-top: clone.index
add-top: clone.pos
Bar:
clone-shape: covid[copy.val]
text: clone.val
add-top: clone.index
add-top: clone.pos
width: clone.val / 30000
name: f'!!Bar-{clone.key}'
debug: copy
print: [copy, copy.pos, clone, shape.name]
headers:
Content-Disposition: attachment; filename=output.pptx
# cache:
Expand Down

0 comments on commit 727c8c1

Please sign in to comment.