Forum Discussion

philipfvbell's avatar
philipfvbell
Copper Contributor
Apr 07, 2025

PowerPoint JS API: Can't Create Lines with Negative Slope Using addLine

We are encountering a technical issue with the PowerPoint JavaScript API when attempting to create lines with negative slope (lines that go upward from left to right). Despite various approaches, we can only create lines with a positive slope (going downward from left to right).

Reproduction Steps:

  • Using the ShapeCollection.addLine method to create lines
  • Attempting to create a line that goes upward (with a negative slope)
  • Regardless of the parameters passed, the lines always render with a positive slope

Code Examples and Results

Example 1: Attempt to create an upward sloping line

const upLine = shapes.addLine(PowerPoint.ConnectorType.straight, { left: 250, top: 300, width: 100, height: -200 // Negative height should create upward slope });

Result: Line appears to go downward with a positive slope despite the negative height value

Example 2: Attempt to create two connecting lines (a V shape)

// First line - downward const leftLine = shapes.addLine(PowerPoint.ConnectorType.straight, { left: 150, top: 100, width: 100, height: 200 }); // Second line - intended to go upward const rightLine = shapes.addLine(PowerPoint.ConnectorType.straight, { left: 250, top: 300, width: 100, height: -200 });

Logged Coordinates:

  • Left line: start(150,100), end(250,300)
  • Right line: start(250,300), end(350,100)

Result: While the coordinates look correct, the actual line rendering doesn't match these coordinates. Both lines appear to have positive slopes.

Expected Behavior:
We expect to be able to create lines with negative slopes (going upward from left to right) by specifying a negative height value, which should represent a decrease in the Y coordinate as X increases.

Actual Behavior:
The API seems to normalize or ignore the negative height value, resulting in lines that always have a positive slope regardless of the height parameter's sign.

Technical Environment:

  • PowerPoint Add-in
  • Using PowerPoint JavaScript API

Impact:
This limitation prevents us from creating basic geometric shapes like V, triangles, or other shapes that require lines with different slopes in our add-in.

Additional Information:
We've ruled out simple parameter errors by logging the actual coordinates of the lines. The coordinates appear correct in the logs but don't match what's rendered on screen.

Thank you for your assistance in resolving this issue.

Let me know if you'd like to include your version/platform info or tweak any part before posting!

 

 

 

No RepliesBe the first to reply

Resources