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

idea: positioning #79

Open
MP70 opened this issue Oct 26, 2023 · 4 comments
Open

idea: positioning #79

MP70 opened this issue Oct 26, 2023 · 4 comments
Labels
question Further information is requested tip Hints and best practices

Comments

@MP70
Copy link
Collaborator

MP70 commented Oct 26, 2023

Hi,

We know we can set positioning using this lib e.g

modify.setPosition({
      // set position from the left to 5 cm
      x: CmToDxa(5),
      // or use a number in DXA unit
      h: 5000000,
      w: 5000000,
    }),

But is there a way (using this lib) of getting existing position of elements, so we could move them e.g 1cm to the right (or whatever) programatically. I'm thinking, could this be added to getInfo, or we just add a helper;

getSizesAndPositions([elementIds]) which returns an object with the id,name, current position and dimensions or similar?

or slide.getAllElementPositions(), bonus points for us using internal helpers similar to the backend workings of my old slide.getAllTextElementIds() (or whatever it was) to tell the user if it is a textbox, image or chart (further support for element types added as we go, this could be a type ElementTypeIfKnown: "text" | "chart" ...

This would hook in with your recent support for replacing images with external files and so on, now we can move them in a relative rather than absolute way.

Thoughts?

@singerla
Copy link
Owner

Hi! You could try:

modify.updatePosition({
      // move right by 1cm
      x: CmToDxa(1),
      // and reduce width by 1cm
      w: CmToDxa(1) * -1,
    }),

Additional info for each shape coordinates will bring pres.getInfo to you:

const myTemplates = await pres.getInfo();
const shapeInfo = myTemplates.elementByName(`SlideWithShapes.pptx`, 1, 'Cloud 1');
// will return:
/*
{
  name: 'Cloud 1',
  type: 'sp',
  id: '{B37A9009-27E0-43C3-8542-60F760C1FB47}',
  position: { x: 9525000, y: 5240337, cx: 1820333, cy: 990600 }
}
*/

Have fun! 😄

@singerla singerla added question Further information is requested tip Hints and best practices labels Oct 26, 2023
@singerla
Copy link
Owner

or slide.getAllElementPositions(), bonus points for us using internal helpers similar to the backend workings of my old slide.getAllTextElementIds() (or whatever it was) to tell the user if it is a textbox, image or chart (further support for element types added as we go, this could be a type ElementTypeIfKnown: "text" | "chart" ...

While setCreationIds was designed to retrieve basic information about loaded templates (and save them to database, in my case), it is not able to analyze slide contents at runtime. I would highly appreciate getAllTextElementIds to evolve a bit. It will also be very useful to formulate expections for testing, which is really poor at the moment.

@MP70
Copy link
Collaborator Author

MP70 commented Oct 26, 2023

modify.updatePosition({
      // move right by 1cm
      x: CmToDxa(1),

I'm so, so sorry, I don't know how I didn't find this!

Seems this is redundant in that case!

@MP70
Copy link
Collaborator Author

MP70 commented Oct 26, 2023

While setCreationIds was designed to retrieve basic information about loaded templates (and save them to database, in my case), it is not able to analyze slide contents at runtime. I would highly appreciate getAllTextElementIds to evolve a bit. It will also be very useful to formulate expections for testing, which is really poor at the moment.

I don't think getAllTextElementIds uses setCreationIds does it? Regardless, I don't disagree, getAllTextElementIds and getAllSlideNumbers I just popped in because it enables the replace text on random arbitrary PPTXs which to me was invaluable as a feature, and I needed it asap. I just had a peek at the getAllTextElementIds test and yeah, aha, that was clearly written 'quickly'. At the least it should check for the actual elementIds (not just length), a check for creationIds on and off, and also a check for if it would work for text elements we add to the slide ourselves before using it (possibly not, but so long as that's documented not the end of the world as you can keep track of those yourself).

I think more generally it would be really nice to have a chat about if it's worth expanding this "discovery" concept in general, we could then get a general method in place we're both happy with. The roots for what I did already appear to be in a new class that more methods could be added to.

For example I could imagine a use for (and these might not be one helper, may be separated into a slide.getAll[$shape]Ids and a element.getX);

Slide.getAllImages() returning [{id, name, imagePath}]
-- allows us to find the image called clientlogo.png ready for replacement without knowing its element name/id upfront

Slide.getAllCharts() - [{id, name, dataObject}]
-- allows us to see what the current data object is so we can append to it, rather than overwrite it.

Slide.getAllTables()- [{id, name, dataObject}]
-- same as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested tip Hints and best practices
Projects
None yet
Development

No branches or pull requests

2 participants