Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consistent use of term id across layout_properties(), ph_location_type(), plot_layout_properties() (#606) #608

Merged

Conversation

markheckmann
Copy link
Contributor

This PR closes the suggestions 1- 3 at the bottom of #606.

Suggestion 4 will be part of another PR.

Summary from NEWS.md:

  • layout_properties() gains a type_idx column to index phs of the same type on a layout. Indexing is performed based on ph position, following a top-to-bottom, left-to-right order.
  • plot_layout_properties() plots more information by default now: layout name, ph label, ph id, ph type + index by default.
  • ph_location_type(): new type_idx arg replaces the deprecated id arg.

1. layout_properties() gains a new type_idx column.

It is an index for placeholders of the same type on a layout. The index is sorted by ph position (top -> bottom, left -> right), for a user-friendly ordering logic (sorted by offy, then offx). (See change 2 below for a visual impression).

layout_properties(x, "Comparison")[, c(1:6, 8:9)]

    master_name       name   type type_idx id                   ph_label     offx      offy
22 Office Theme Comparison  title        1  2                    Title 1 0.500000 0.3003478
23 Office Theme Comparison   body        1  3         Text Placeholder 2 0.500000 1.6788200
24 Office Theme Comparison   body        2  5         Text Placeholder 4 5.079861 1.6788200
25 Office Theme Comparison   body        3  4      Content Placeholder 3 0.500000 2.3784722
26 Office Theme Comparison   body        4  6      Content Placeholder 5 5.079861 2.3784722
27 Office Theme Comparison     dt        1  7         Date Placeholder 6 0.500000 6.9513889
28 Office Theme Comparison    ftr        1  8       Footer Placeholder 7 3.416667 6.9513889
29 Office Theme Comparison sldNum        1  9 Slide Number Placeholder 8 7.166667 6.9513889

2. plot_layout_properties(): with more ph info by default

The function now prints the ph label, type, type index, and layout name by default. The new args type = T/F and id = T/F allow to show or hide them. The type index also has an intuitive order (top->bottom, left->right). Previously, the indexing was done along the ph ids, which may result in an arbitrary index order.

  • ph label (red, column ph_label from layout_properties()))
  • type + type_idx (blue, column type and type_index from layout_properties())
  • id (green, unique per ph) (, i.e. column id from layout_properties()).
plot_layout_properties(x, "Comparison")

image

3. ph_location_type() gains new type_idx argument.

type_idx will replace the id arg. id is preserved for now to avoid a breaking change, but throws a deprecation warning. The arg name is changed to avoid confusion with the id column from layout_properties() which has another meaning.

In the example below, both args (type_idx and id) are used. Note that only type_idxuses the new indexing order. The index order of id is unchanged (using the old indexing logic along the ph id) to avoid a breaking change.

x <- x |> add_slide("Comparison")

x |> ph_with("NEW: type_idx", ph_location_label("Title 1"))
for (type_idx in 1:4) {
  x |> ph_with(paste("type_idx:", type_idx), ph_location_type(type_idx = type_idx))
}

x <- x |> add_slide("Comparison")
x |> ph_with("OLD: id", ph_location_label("Title 1"))
for (id in 1:4) {
  x |> ph_with(paste("id:", id), ph_location_type(id = id))
}

file <- tempfile(fileext = ".pptx")
print(x, file)
file.show(file)
Warning:
1: ! The `id` argument in `ph_location_type()` is deprecated as of officer 0.6.7.
ℹ Please use the `type_idx` argument instead.
✖ Caution: new index logic in `type_idx` (see docs). 
2: ! The `id` argument in `ph_location_type()` is deprecated as of officer 0.6.7.
ℹ Please use the `type_idx` argument instead.
✖ Caution: new index logic in `type_idx` (see docs). 
3: ! The `id` argument in `ph_location_type()` is deprecated as of officer 0.6.7.
ℹ Please use the `type_idx` argument instead.
✖ Caution: new index logic in `type_idx` (see docs). 
4: ! The `id` argument in `ph_location_type()` is deprecated as of officer 0.6.7.
ℹ Please use the `type_idx` argument instead.
✖ Caution: new index logic in `type_idx` (see docs). 

image

- plots layout name, ph id, ph type + index by default now (davidgohel#606).
- also rammar correction in docs: 'functions for reading presentation information' => remove s
- xfrmize(): add `type_idx` column. Index is ordered by ph position top->bottom, left->right
- layout_properties(): add `type_idx` column, improve docs
- plot_layout_properties(): use new `type_idx` column for type index plotting. Changed index order.
- plots layout name, ph id, ph type + index by default now (davidgohel#606).
- also rammar correction in docs: 'functions for reading presentation information' => remove s
- xfrmize(): add `type_idx` column. Index is ordered by ph position top->bottom, left->right
- layout_properties(): add `type_idx` column, improve docs
- plot_layout_properties(): use new `type_idx` column for type index plotting. Changed index order.
The indexing logic for 'type_idx' is different than for 'id'.
To avoid a breaking change, both args and indexing logics can
be used.

type_idx:
   index along ph position (top->bottom,left->right => intuitive)
id:
   index along id column. Order of phs id is often arbitrary.
@davidgohel
Copy link
Owner

thank you again @markheckmann

@davidgohel davidgohel merged commit 865364c into davidgohel:master Sep 17, 2024
3 checks passed
@markheckmann markheckmann deleted the issue_606_consistent_id_term branch September 17, 2024 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants