@feds01/graphika / utils/coordinates
utils/coordinates
Interfaces
GraphLike
Defined in: utils/coordinates.ts:118
Properties
| Property | Type | Defined in |
|---|---|---|
axisManager | { xAxis: CoordinateAxis; yAxis: CoordinateAxis; } | utils/coordinates.ts:129 |
axisManager.xAxis | CoordinateAxis | utils/coordinates.ts:130 |
axisManager.yAxis | CoordinateAxis | utils/coordinates.ts:131 |
gridRectSize | { x: number; y: number; } | utils/coordinates.ts:125 |
gridRectSize.x | number | utils/coordinates.ts:126 |
gridRectSize.y | number | utils/coordinates.ts:127 |
lengths | { xBegin: number; xEnd: number; yBegin: number; yLength: number; } | utils/coordinates.ts:119 |
lengths.xBegin | number | utils/coordinates.ts:120 |
lengths.xEnd | number | utils/coordinates.ts:121 |
lengths.yBegin | number | utils/coordinates.ts:122 |
lengths.yLength | number | utils/coordinates.ts:123 |
Type Aliases
CoordinateAxis
type CoordinateAxis = {
roundedMin: number;
scaleStep: number;
yStart: number;
};Defined in: utils/coordinates.ts:15
Required axis properties for coordinate conversion.
Properties
| Property | Type | Defined in |
|---|---|---|
roundedMin | number | utils/coordinates.ts:16 |
scaleStep | number | utils/coordinates.ts:17 |
yStart | number | utils/coordinates.ts:18 |
CoordinateContext
type CoordinateContext = {
gridRectSize: {
x: number;
y: number;
};
lengths: {
xBegin: number;
xEnd: number;
yBegin: number;
yLength: number;
};
xAxis: CoordinateAxis;
yAxis: CoordinateAxis;
};Defined in: utils/coordinates.ts:22
Required graph properties for coordinate conversion.
Properties
| Property | Type | Defined in |
|---|---|---|
gridRectSize | { x: number; y: number; } | utils/coordinates.ts:29 |
gridRectSize.x | number | utils/coordinates.ts:30 |
gridRectSize.y | number | utils/coordinates.ts:31 |
lengths | { xBegin: number; xEnd: number; yBegin: number; yLength: number; } | utils/coordinates.ts:23 |
lengths.xBegin | number | utils/coordinates.ts:24 |
lengths.xEnd | number | utils/coordinates.ts:25 |
lengths.yBegin | number | utils/coordinates.ts:26 |
lengths.yLength | number | utils/coordinates.ts:27 |
xAxis | CoordinateAxis | utils/coordinates.ts:33 |
yAxis | CoordinateAxis | utils/coordinates.ts:34 |
Functions
canvasXToDataX()
function canvasXToDataX(ctx, canvasX): number;Defined in: utils/coordinates.ts:88
Convert canvas X coordinate to data X value.
This is the inverse of dataXToCanvasX.
Parameters
| Parameter | Type | Description |
|---|---|---|
ctx | CoordinateContext | The coordinate context containing graph measurements. |
canvasX | number | The canvas X coordinate to convert. |
Returns
number
The data X value.
createCoordinateContext()
function createCoordinateContext(graph): CoordinateContext;Defined in: utils/coordinates.ts:144
Create a coordinate context from a graph instance.
This helper extracts the necessary properties from a graph to create a CoordinateContext that can be used with the coordinate conversion functions.
Parameters
| Parameter | Type | Description |
|---|---|---|
graph | GraphLike | An object with lengths, gridRectSize, and axisManager properties. |
Returns
A CoordinateContext for use with coordinate conversion functions.
dataXToCanvasX()
function dataXToCanvasX(ctx, dataX): number;Defined in: utils/coordinates.ts:44
Convert data X value to canvas X coordinate.
Parameters
| Parameter | Type | Description |
|---|---|---|
ctx | CoordinateContext | The coordinate context containing graph measurements. |
dataX | number | The data X value to convert. |
Returns
number
The canvas X coordinate.
dataYToCanvasY()
function dataYToCanvasY(ctx, dataY): number;Defined in: utils/coordinates.ts:65
Convert data Y value to canvas Y coordinate.
Parameters
| Parameter | Type | Description |
|---|---|---|
ctx | CoordinateContext | The coordinate context containing graph measurements. |
dataY | number | The data Y value to convert. |
Returns
number
The canvas Y coordinate.
isWithinGraphArea()
function isWithinGraphArea(
ctx,
canvasX,
canvasY): boolean;Defined in: utils/coordinates.ts:107
Check if canvas coordinates are within the graph plotting area.
Parameters
| Parameter | Type | Description |
|---|---|---|
ctx | CoordinateContext | The coordinate context containing graph measurements. |
canvasX | number | The canvas X coordinate to check. |
canvasY | number | The canvas Y coordinate to check. |
Returns
boolean
True if the coordinates are within the graph area.