PiDraw API
    Preparing search index...

    Class PiGraph

    A drawing in the page: a coordinate system with its grid and its axes (the layout), and the figures that are made in it.

    The figures are made by create, drawn again by update when what they depend on moves, and written in TikZ by tikz. A point is made draggable by draggable, and the graph tells what happens by events (on). dispose takes it out of the page.

    Hierarchy

    • EventTarget
      • PiGraph
    Index
    • Draw a graph in a container. A unit is a centimeter by default (see resolveGraphConfig).

      Parameters

      • id: string | HTMLElement

        the container, or the id of an element of the page.

      • Optionalconfig: IGraphConstructorConfig

      Returns PiGraph

      InvalidArgumentError if the container does not exist, or the size, the origin or an axis of config is not valid.

      NotImplementedError if the coordinate system of config is not the cartesian one. Nothing is left in the container in case of an error.

    • get axes(): { x: Axis; y: Axis }

      The axes of the coordinate system, named Ox and Oy: the lines y = 0 and x = 0, so that a figure can be built from them. They always exist, drawn or not (the display axis). They are not among the figures, which clear() removes.

      Returns { x: Axis; y: Axis }

    • get config(): IGraphConfig

      The size of the drawing, its origin and the vector of a unit of each axis, in pixels. The same object until updateLayout gives another one: the figures read it when they are drawn.

      Returns IGraphConfig

    • get controls(): Readonly<Partial<IControlsGraph>>

      What the themes keep on the graph (the titles of the slides...), by the name of the entry. The graph does not know what the entries mean: a theme writes its own with setControl and the controllers read them here.

      Returns Readonly<Partial<IControlsGraph>>

    • get drawnAxes(): { x: Axis; y: Axis }

      The axes that are drawn: the same as axes, except for an axis whose line is out of the drawing, which is drawn at a border (Ox-edge, Oy-edge) and has its graduation there. The options of the parameters of the graph are given to these.

      Returns { x: Axis; y: Axis }

    • get figures(): Record<string, AbstractFigure>

      The figures of the graph by name, in the order they were made. An object without a prototype: any text is a name. The layout (the grid and the axes) is not in it.

      Returns Record<string, AbstractFigure>

    • get layers(): Layers

      The groups of the svg that the figures are in, from the back of the drawing to the front (see LayerName).

      Returns Layers

    • get mainGrid(): Grid | null

      The grid of the layout (the display grid), null when the graph does not show one.

      Returns Grid | null

    • get rootSVG(): Svg

      The svg of the drawing.

      Returns Svg

    • The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

      MDN Reference

      Parameters

      • type: string
      • callback: EventListenerOrEventListenerObject | null
      • Optionaloptions: boolean | AddEventListenerOptions

      Returns void

    • Attach a controller to the graph: a module that acts on the drawing from outside (the animation, a zoom, the slides), made by the program with new Animate(graph). The graph tells it when figures are removed (remove, clear) and when it is taken out of the page (dispose), so that it stops what it does.

      Type Parameters

      Parameters

      • controller: T

      Returns T

      the controller.

      InvalidArgumentError if a controller of the same class is already attached: two of them would act on the same figures.

    • Remove every figure of the graph, but not the layout. The attached controllers are told which figures were removed (onFiguresRemoved).

      Returns void

    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

      MDN Reference

      Parameters

      • event: Event

      Returns boolean

    • Take the graph out of the page: remove every figure (the ones that keep a listener let it go) and the layout, and remove from its container the element that the graph made. The attached controllers are disposed, and detached. The graph is not used afterward; calling this again does nothing.

      Returns void

    • Make a point draggable with the mouse. The figures that depend on it, and on its target, are drawn again each time it moves, and the events dragstart, dragmove (with how many figures that reached) and dragend are emitted. It stays in the drawing.

      Parameters

      Returns Point

      InvalidArgumentError if figure is not a point, or is already draggable; if options.along is neither 'x' nor 'y'; options.target is not a point; a follow is neither a function nor a figure; or a bound is not a finite number. Nothing is changed in case of an error.

    • Put a point that can be dragged where it would be if the mouse had dragged it to pixels: the rules of its drag apply (along an axis, on the grid, in bounds, on a figure it follows), then the figures that depend on it are drawn again. No event is emitted.

      Parameters

      • point: Point

        the point that is held (the handle), or its target.

      • pixels: XY

        where the mouse would be, in pixels.

      Returns void

      InvalidArgumentError if the point cannot be dragged.

    • A figure of the graph tells that something changed in it that the controllers may care about (see IGraphController.onFigureChanged). It is what the figures call on their context, and it is not for a program to call.

      Parameters

      • name: string

      Returns void

    • Make a point draggable by a handle: a large pale disc, on the layer of the interactions, that follows the point and moves it when it is dragged. The user reaches a point that is small, or hidden.

      Parameters

      Returns Point

      the handle, which is a figure of the graph named <point>_drag.

      InvalidArgumentError as draggable does, or if the name of the handle is taken. Nothing is left in the graph in case of an error.

    • Call handler each time a point of the graph is dragged: dragstart, dragmove (with how many figures that reached) and dragend. The same handler given twice is called once.

      Type Parameters

      Parameters

      Returns this

      the graph, to chain.

    • Remove a figure of the graph: from the svg, and from the figures. The layout (the grid and the axes) is not a figure.

      Parameters

      • name: string
      • Optionaloptions: { cascade?: boolean }

        cascade: also remove the figures that depend on this one (a line built on a point...), which go first. Without it a figure that others depend on is not removed.

      Returns string[]

      the names of the figures that were removed, the ones that depend on others first.

      InvalidArgumentError if no figure has this name, or other figures depend on it and cascade is not true.

    • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

      MDN Reference

      Parameters

      • type: string
      • callback: EventListenerOrEventListenerObject | null
      • Optionaloptions: boolean | EventListenerOptions

      Returns void

    • Keep a value for a theme, or take it away with null. The attached controllers are told (onControlsChanged). The value is not checked: the theme does it.

      Type Parameters

      • K extends "titles"

      Parameters

      Returns this

    • The graph as a whole tikzpicture: the grid and the axes, then the figures, in the order they are drawn on screen (layer by layer, and in a layer in the order of its elements). The picture has the size of the part of the coordinate system that is drawn, which the commands are cut to (see tikzPicture). The handles of the points the user drags are not part of the drawing, and a figure that is hidden writes nothing. The packages it needs are in tikzPreamble.

      Returns string

      InvalidArgumentError if the appearance of a figure has no TikZ equivalent (a color that is neither hexadecimal nor a name of CSS).

      NotImplementedError if a figure cannot be written in TikZ, or the x axis does not go to the right or the y axis does not go up.

    • The lines to put before \begin{document} for the tikz of a graph: the packages and the libraries its figures need.

      Returns string

    • A length, a domain or a position in pixels in units of the coordinate system: the opposite of toPixels.

      Parameters

      • value: number
      • Optionalaxis: "x" | "y"

      Returns number

      InvalidArgumentError if value is none of a number, a domain and a position.

      MathError if a position is converted while the two axes of the graph are collinear.

    • A length, a domain or a position in pixels in units of the coordinate system: the opposite of toPixels.

      Parameters

      • value: Domain
      • Optionalaxis: "x" | "y"

      Returns Domain

      InvalidArgumentError if value is none of a number, a domain and a position.

      MathError if a position is converted while the two axes of the graph are collinear.

    • A length, a domain or a position in pixels in units of the coordinate system: the opposite of toPixels.

      Parameters

      • value: XY

      Returns XY

      InvalidArgumentError if value is none of a number, a domain and a position.

      MathError if a position is converted while the two axes of the graph are collinear.

    • A length, a domain or a position of the coordinate system in pixels, with the scale of the graph as it is now. A length or a domain is along axis ('x' by default); a domain comes back with its min below its max, even on the y axis, which points up.

      Parameters

      • value: number
      • Optionalaxis: "x" | "y"

      Returns number

      InvalidArgumentError if value is none of a number, a domain and a position.

    • A length, a domain or a position of the coordinate system in pixels, with the scale of the graph as it is now. A length or a domain is along axis ('x' by default); a domain comes back with its min below its max, even on the y axis, which points up.

      Parameters

      • value: Domain
      • Optionalaxis: "x" | "y"

      Returns Domain

      InvalidArgumentError if value is none of a number, a domain and a position.

    • A length, a domain or a position of the coordinate system in pixels, with the scale of the graph as it is now. A length or a domain is along axis ('x' by default); a domain comes back with its min below its max, even on the y axis, which points up.

      Parameters

      • value: XY

      Returns XY

      InvalidArgumentError if value is none of a number, a domain and a position.

    • Draw the figures again and put their labels at their place, to follow what changed.

      With changed, only the figures that depend on them, directly or not, are drawn again, each one once and after the ones it depends on: a figure that does not depend on them is left alone. The figures of changed are not drawn again, their position is the one they were given (a point that was dragged or animated): only their labels are. Without changed, every figure is drawn again.

      A figure that the user holds (see draggable) is never drawn again, only its label. A figure that is static is left as it is too, unless forceUpdate is true.

      Parameters

      Returns IGraphUpdate

      how many figures were reached: the ones drawn again (a figure left as it is, static, is not counted) and the ones that were moved, out of the figures of the graph.

      InvalidArgumentError if a figure that depends on changed depends on itself (a cycle).

    • Draw the layout again (the size of the drawing, the grid and the axes), and update every figure to follow it.

      Parameters

      • Optionalconfig: IGraphConfig

        the new configuration, whole. The one of the graph stays by default.

      • Optionaldisplay: IGraphDisplay

        what the layout shows, as it is (without the defaults of the constructor). The one of the graph stays by default.

      Returns void

      InvalidArgumentError if config is not valid (see checkGraphConfig), or display cannot be drawn.

      NotImplementedError if the coordinate system of config is not the cartesian one.

      MathError if the position of a moved point cannot be read in the coordinate system of the graph as it is now. The graph is left as it was in case of an error.

      A point that was moved (dragged, animated: see Point.isMoved) keeps its place in the coordinate system, not in pixels: it is put where the same coordinates are in the new layout, and what depends on it is drawn again. The attached controllers are told afterward (onLayoutChanged).