Skip to content

Refactor annotations to be another type of datum. #358

Open

Description

@mauriciopoppe

The current API looks like this:

functionPlot({
  target: '#tip',
  annotations: [
    {
      x: -1
    },
    {
      x: 1,
      text: 'x = 1'
    },
    {
      y: 2,
      text: 'y = 2'
    }
  ]
  data: [
    { fn: 'x^2' },
  ]
})

Ideas for API

Move the annotation to be another type of datum.

functionPlot({
  target: '#tip',
  yDomain: [-1, 9],
  data: [
    { fn: 'x^2' },
    { fn: 'x', skipTip: true },
    functionPlot.Annotation({ x: -1 }),
    functionPlot.Annotation({ y: 2, text: 'y = 2' }),
  ]
})

Activity

  1. added this to the Road to 2.0.0 milestone on Jun 7, 2025
  2. mauriciopoppe commented on Jul 3, 2025

    @mauriciopoppe
    OwnerAuthor

    Pros/Cons of the new API:

    • Pro: annotation is another type of datum
    • Con: annotation is included even if the caller doesn't want it because it's a property of functionPlot

    Example:

    functionPlot({
      target: '#playground',
      y: { domain: [-1, 9] },
      data: [
        {
          fn: 'x^2'
        },
        functionPlot.annotation({ x: -1 }),
        functionPlot.annotation({ x: 1, label: 'x = 1' }),
        functionPlot.annotation({ y: 2, label: 'y = 2' })
      ],
    })

    The legacy API still works, I have to decide if it should be deprecated.

    functionPlot({
      target: '#playground',
      y: { domain: [-1, 9] },
      data: [{
        fn: 'x^2'
      } as LinearFunction],
      annotations: [{
        x: -1
      }, {
        x: 1,
        label: 'x = 1'
      }, {
        y: 2,
        label: 'y = 2'
      }]
    })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions