<div id="div-example" style="width:600px; border:2px solid #CCC"></div>
document.addEventListener("jvgeo-ready", evt => {
const jvgeo = new evt.detail.JvGeo()
jvgeo.Init("div-example", 0, 6, 0, 4)
jvgeo.AddDragPoint("A", 4, 1)
jvgeo.AddDragPoint("B", 1, 2)
jvgeo.AddDragPoint("C", 3, 3)
jvgeo.AddInputRange("Thickness", 0, 200, 70, "Thickness = {} px")
jvgeo.MainLoop(({A,B,C,Thickness}) => {
jvgeo.DrawSegment(A.x, A.y, B.x, B.y, "#0004", Thickness)
jvgeo.DrawSegment(B.x, B.y, C.x, C.y, "#0004", Thickness)
})
})
The "jvgeo-ready"
event is raised on the global document
instance.
Instead of directly accessing the global JvGeo
class,
you should use the constructor given as event.detail.JvGeo
:
document.addEventListener("jvgeo-ready", evt => {
const jvgeo = new evt.detail.JvGeo()
...
})
Main class providing the functionality. To be instantiated
by invoking the constructor evt.detail.JvGeo
in “jvgeo-ready” event.
Setup the UI inside the DOM container identified by divId
.
The container’s aspect-ratio
is forced to (xMax-xMin)/(yMax-yMin)
.
The size of the container determines the drawing area.
Returns [x,y]
, the corresponding coordinates in pixels.
JvGeo API uses logical coordinates, thus this method is for rendering stuff on your own.
Returns [x,y]
, the corresponding logical coordinates.
JvGeo API uses logical coordinates, thus this method is helpful for sending your own events.
Converts a distance from pixel units to logical units. JvGeo API uses logical coordinates, thus this may be useful if you have your own pixel logic.
Converts a distance from logical units to pixel units. JvGeo API uses logical coordinates, thus this may be useful if you have your own pixel logic.
Adds a point draggable by user to interact with the drawings.
Adds an input range to the drawing, such that the user can interact with.
text (*String | null*): Label used for display, where {} is replaced by the range’s value. |
Adds a checkbox to the drawing, such that the user can interact with.
text (*String | null*): Label used for display. |
Reinitializes the values of interactive elements (checkboxes, input ranges, draggable points…).
Setup the main loop which updates the drawing according to the user interactions.
name
given to
AddDragPoint()
, AddInputRange()
, AddCheckbox
…
The positions of the draggable points are expressed in logical coordinate.Draws a segment between the given coordinates. This function must
be called from inside the userfuncDraw
given to MainLoop()
.
"#000"
): CSS color to be used for the stroke.2
): Thickness, in pixels.Draws a point at given coordinates. This function must
be called from inside the userfuncDraw
given to MainLoop()
.
Draws a line passing through the given coordinates. This function must
be called from inside the userfuncDraw
given to MainLoop()
.
"#000"
): CSS color to be used for the stroke.2
): Thickness, in pixels.Draws the triangle defined by the given coordinates. This function must
be called from inside the userfuncDraw
given to MainLoop()
.
"#000"
): CSS color to be used for the stroke."#0004"
): CSS color to be used for the filling.2
): Thickness, in pixels.Draws the cartesian coordinate system grid and axes.
Returns [xI, yI] the coordinates of the intersection point between two lines, or [NaN, NaN] if the two lines never cross (ie. they are parallel).
Returns [xV, yV] the components of a vector of same direction than (x,y)
,
but with given length.
1.0
): Length of the returned vector.
By default, returns a unit vector.Returns [xV, yV] the components of a vector perpendicular to (x,y)
,
with given length.
1.0
): Length of the returned vector.
By default, returns a unit vector.