Skip to content

Ability to extend Shapes #2

Closed
Closed

Description

@bpioge

You provide a way to extend components or to change controllers behavior but there is no way to extend Shape (RectangleShape, PolygonShape etc..) since we can't override the dataToShape function used in the ShapeManager.

I fixed it by adding
public shapeFactory: { dataToShape : ((s: ShapeData) => Shape) } = { dataToShape : dataToShape };
as a property in the ShapeManager class
and then, by changing the two
const obj = dataToShape(s);
to
const obj = this.shapeFactory.dataToShape(s);
in the constructor of ShapeManager (line 530 and 553 of /packages/graphics-2d/src/shapes-manager.ts)

These 3 changes make me able to set my own dataToShape method when I extend pixano webcomponents.
this.shManager.shapeFactory.dataToShape = myOwnDataToShape;

Do you think you can make this kind of changes so we will be able to extend Shapes ?

Thank you for your help.

Activity

  1. camilledupont commented on Jul 29, 2020

    @camilledupont
    Collaborator

    Hi @bpioge
    it is a great idea to expose the dataToShape function, thanks ! Is there a particular reason why you suggest a shapeFactory property ? If not, we can directly use a dataToShape member function in ShapesManager that can be changed into your own conversion function:

    public dataToShape: ((s: ShapeData) => Shape) = dataToShape;
    

    Then use:

    this.shManager.dataToShape = myOwnDataToShape;
    

    In any case, this is a small change and can be done/published within the week

  2. bpioge commented on Jul 29, 2020

    @bpioge
    ContributorAuthor

    Yes sure, you're right. I was probably doing some tests, i don't know why I did it :-)

  3. bpioge commented on Jul 29, 2020

    @bpioge
    ContributorAuthor

    Thank you !

  4. camilledupont commented on Jul 30, 2020

    @camilledupont
    Collaborator

    Ok ! I'll probably push/publish tomorrow :)

  5. camilledupont commented on Jul 31, 2020

    @camilledupont
    Collaborator

    @bpioge I closed the issue, thanks again ! don't hesitate to open a new one if you have other suggestions to simplify customization of shapes in terms of usage

  6. added 3 commits that reference this issue on Nov 15, 2021
    aee8085
    427b124
    4763e34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions