|
export class Board { |
|
private readonly $points = new PointDefaults() |
|
private readonly $lines = new LineDefaults() |
|
|
|
constructor(public readonly jxgBoard: JXG.Board) { |
|
// Do nothing |
|
} |
|
|
|
/** |
|
* |
|
* @param centerPoint |
|
* @param radiusPoint |
|
* @param anglePoint |
|
* @param attributes |
|
*/ |
|
addAngle(centerPoint: JXG.PointSpecification, radiusPoint: JXG.PointSpecification, anglePoint: JXG.PointSpecification, attributes?: JXG.AngleAttributes): JXG.Angle { |
|
return this.jxgBoard.create('angle', [centerPoint, radiusPoint, anglePoint], attributes) |
|
} |
|
|
|
/** |
|
* |
|
* @param centerPoint |
|
* @param radiusPoint |
|
* @param anglePoint |
|
* @param attributes |
|
*/ |
|
addArc(centerPoint: JXG.PointSpecification, radiusPoint: JXG.PointSpecification, anglePoint: JXG.PointSpecification, attributes?: JXG.ArcAttributes): JXG.Arc { |
|
return this.jxgBoard.create('arc', [centerPoint, radiusPoint, anglePoint], attributes) |
|
} |
|
|
|
/** |
|
* |
|
* @param point1 |
|
* @param point2 |
|
* @param attributes |
|
*/ |
|
addAxis(point1: JXG.PointSpecification, point2: JXG.PointSpecification, attributes?: JXG.AxisAttributes): JXG.Axis { |
|
return this.jxgBoard.create('axis', [point1, point2], attributes) |
|
} |
|
|
|
/** |
|
* |
|
* @param centerPoint |
|
* @param radiusOrPoint |
|
*/ |
|
addCircle(centerPoint: JXG.PointSpecification, radiusOrPoint: number | JXG.PointSpecification, attributes?: JXG.CircleAttributes): JXG.Circle { |
|
const options = attributes ? attributes : this.$lines.attributes |
|
return this.jxgBoard.create('circle', [centerPoint, radiusOrPoint], options) |
|
} |
|
|
|
/** |
|
* |
|
* @param dataX |
|
* @param dataY |
|
* @param attributes |
|
*/ |
|
addCurve(dataX: number[] | JXG.CurveFunction, dataY: number[] | JXG.CurveFunction, attributes?: JXG.CurveAttributes): JXG.Curve { |
|
return this.jxgBoard.create('curve', [dataX, dataY], attributes) |
|
} |
|
|
|
/** |
|
* |
|
* @param curveFunction |
|
* @param a |
|
* @param b |
|
* @param attributes |
|
*/ |
|
addFunctionGraph(curveFunction: JXG.CurveFunction, a?: number | JXG.NumberFunction, b?: number | JXG.NumberFunction, attributes?: JXG.FunctiongraphAttributes): JXG.Functiongraph { |
|
return this.jxgBoard.create('functiongraph', [curveFunction, a, b], attributes) |
|
} |
|
|
|
/** |
|
* |
|
* @param glideObject |
|
* @param attributes |
|
*/ |
|
addGlider(glideObject: JXG.GeometryElement, attributes?: JXG.GliderAttributes): JXG.Glider { |
|
return this.jxgBoard.create('glider', [glideObject], attributes) |
|
} |
|
|
|
/** |
|
* Creates an Intersection and adds it to the board. |
|
* @param element1 a Line or Circle that constrains the intersection. |
|
* @param element2 a Line or Circle that constrains the intersection. |
|
* @param attributes Modify the Intersection. |
|
* @returns and Intersection. |
|
*/ |
|
addIntersection(element1: JXG.Line | JXG.Circle, element2: JXG.Line | JXG.Circle, attributes?: JXG.IntersectionAttributes): JXG.Intersection { |
|
return this.jxgBoard.create('intersection', [element1, element2], attributes) |
|
} |
|
|
|
/** |
|
* |
|
* @param point1 |
|
* @param point2 |
|
* @param attributes |
|
*/ |
|
addLine(point1: JXG.PointSpecification, point2: JXG.PointSpecification, attributes?: JXG.LineAttributes): JXG.Line { |
|
return this.jxgBoard.create('line', [point1, point2], attributes) |
|
} |
|
|
|
/** |
|
* Creates a Midpoint object and adds it to the Board. |
|
* @param p1 defines a reference point for the midpoint. |
|
* @param p2 defines a reference point for the midpoint. |
|
* @param attributes Modify the Midpoint. |
|
* @returns the Midpoint that was created. |
|
*/ |
|
addMidpoint(p1: JXG.Point, p2: JXG.Point, attributes: JXG.MidpointAttributes): JXG.Midpoint { |
|
return this.jxgBoard.create('midpoint', [p1, p2], attributes) |
|
} |
|
|
|
/** |
|
* Creates a Perpendicular and adds it to the Board. |
|
* @param line the line that the Perpendicular must be orthogonal to. |
|
* @param point a point that the Perpendicular must pass through. |
|
* @attributes Modify the Perpendicular. |
|
* @returns the created Perpendicular. |
|
*/ |
|
addPerpendicular(line: JXG.Line, point: JXG.Point, attributes?: JXG.PerpendicularAttributes): JXG.Perpendicular { |
|
if (attributes) { |
|
return this.jxgBoard.create('perpendicular', [line, point], attributes) |
|
} |
|
else { |
|
const options = this.$lines.attributes |
|
console.log(JSON.stringify(this.$lines.attributes)) |
|
return this.jxgBoard.create('perpendicular', [line, point], options) |
|
} |
|
} |
|
|
|
/** |
|
* Creates a Point and adds it to the Board. |
|
* @param coords The coordinates of the point that will be added to the board. |
|
* @param attributes Modify the point. |
|
* @returns the Point that was created. |
|
*/ |
|
addPoint(coords: [x: JXG.CoordSpecification, y: JXG.CoordSpecification], attributes?: JXG.PointAttributes): JXG.Point { |
|
const options = attributes ? attributes : this.$points.attributes |
|
return this.jxgBoard.create('point', [coords[0], coords[1]], options) |
|
} |
|
|
|
/** |
|
* |
|
* @param f |
|
* @param n |
|
* @param type |
|
* @param a |
|
* @param b |
|
* @param attributes |
|
*/ |
|
addRiemannsum(f: JXG.CurveFunction, n: JXG.NumberFunction, type: JXG.RiemannSumType | JXG.RiemannSumTypeFunction, a: JXG.BorderSpecification, b: JXG.BorderSpecification, attributes?: JXG.CurveAttributes): JXG.Riemannsum { |
|
return this.jxgBoard.create('riemannsum', [f, n, type, a, b], attributes) |
|
} |
|
|
|
/** |
|
* Creates a Segment and adds it to the Board |
|
* @param point1 a point at one end of the segment. |
|
* @param point2 a point at the other end of the segment. |
|
* @param attributes Modify the segment. |
|
* @returns the Segment that was created. |
|
*/ |
|
addSegment(point1: JXG.Point, point2: JXG.Point, attributes?: JXG.SegmentAttributes): JXG.Segment { |
|
const options = attributes ? attributes : this.$lines.attributes |
|
return this.jxgBoard.create('segment', [point1, point2], options) |
|
} |
|
|
|
/** |
|
* |
|
* @param beginPoint |
|
* @param endPoint |
|
* @param min |
|
* @param start |
|
* @param max |
|
* @param attributes |
|
*/ |
|
addSlider(beginPoint: JXG.PointSpecification, endPoint: JXG.PointSpecification, min: number, start: number, max: number, attributes?: JXG.SliderAttributes): JXG.Slider { |
|
return this.jxgBoard.create('slider', [beginPoint, endPoint, [min, start, max]], attributes) |
|
} |
|
|
|
/** |
|
* |
|
* @param tangent |
|
* @param attributes |
|
*/ |
|
addSlopetriangleFromTangent(tangent: JXG.Tangent, attributes?: JXG.SlopetriangleAttributes): JXG.Slopetriangle { |
|
return this.jxgBoard.create('slopetriangle', [tangent], attributes) |
|
} |
|
|
|
/** |
|
* |
|
* @param line |
|
* @param point |
|
* @param attributes |
|
*/ |
|
addSlopetriangleFromLineAndPoint(line: JXG.Line, point: JXG.Point, attributes?: JXG.SlopetriangleAttributes): JXG.Slopetriangle { |
|
return this.jxgBoard.create('slopetriangle', [line, point], attributes) |
|
} |
|
|
|
/** |
|
* |
|
* @param dataX |
|
* @param dataY |
|
* @param attributes |
|
*/ |
|
addStepfunction(dataX: JXG.CoordSpecification[], dataY: JXG.CoordSpecification[], attributes?: JXG.StepfunctionAttributes): JXG.Stepfunction { |
|
return this.jxgBoard.create('stepfunction', [dataX, dataY], attributes) |
|
} |
|
|
|
/** |
|
* |
|
* @param glider |
|
* @param attributes |
|
*/ |
|
addTangent(glider: JXG.Glider, attributes?: JXG.TangentAttributes): JXG.Tangent { |
|
return this.jxgBoard.create('tangent', [glider], attributes) |
|
} |
|
|
|
/** |
|
* |
|
* @param x |
|
* @param y |
|
* @param s |
|
* @param attributes |
|
*/ |
|
addText(x: number | JXG.NumberFunction, y: number | JXG.NumberFunction, text: string | JXG.StringFunction, attributes?: JXG.TextAttributes): JXG.Text { |
|
return this.jxgBoard.create('text', [x, y, text], attributes) |
|
} |
|
|
|
get points(): PointAttributes { |
|
return this.$points |
|
} |
|
|
|
get lines(): LineAttributes { |
|
return this.$lines |
|
} |
|
} |
|
|
|
export function initBoard(elementId: string, attributes?: JXG.BoardAttributes): Board { |
|
return new Board(JXG.JSXGraph.initBoard(elementId, attributes)) |
|
} |
|
|
|
export interface PointAttributes { |
|
clear(): this |
|
setColor(color: string): this |
|
} |
|
|
|
class PointDefaults implements PointAttributes { |
|
private $attributes: JXG.PointAttributes = {} |
|
constructor() { |
|
} |
|
clear(): this { |
|
this.$attributes = {} |
|
return this |
|
} |
|
setColor(color: string): this { |
|
this.$attributes.color = color |
|
return this |
|
} |
|
get attributes(): JXG.PointAttributes { |
|
return this.$attributes |
|
} |
|
} |
|
|
|
export interface LineAttributes { |
|
clear(): this |
|
setDash(dash: Dash): this |
|
setStrokeColor(strokeColor: string): this |
|
setStrokeWidth(strokeWidth: number): this |
|
} |
|
|
|
class LineDefaults implements LineAttributes { |
|
private $attributes: JXG.LineAttributes = {} |
|
constructor() { |
|
} |
|
clear(): this { |
|
this.$attributes = {} |
|
return this |
|
} |
|
setDash(dash: Dash): this { |
|
console.log(typeof dash) |
|
this.$attributes.dash = dash |
|
return this |
|
} |
|
setStrokeColor(strokeColor: string): this { |
|
this.$attributes.strokeColor = strokeColor |
|
return this |
|
} |
|
setStrokeWidth(strokeWidth: number): this { |
|
this.$attributes.strokeWidth = strokeWidth |
|
return this |
|
} |
|
get attributes(): JXG.LineAttributes { |
|
return this.$attributes |
|
} |
|
} |
|
|
|
export enum Dash { |
|
Solid = 0, |
|
Dotted = 1, |
|
Small = 2, |
|
Medium = 3, |
|
Large = 4, |
|
LargeGaps = 5, |
|
SmallGaps = 6 |
|
} |