0.5.0 • Published 6 years ago

adm-math v0.5.0

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

adm-math

An AngularJS library for manipulating mathematical expressions

Installation

To install using yarn:

$ yarn add adm-math

Components

adm-math-input

A mathematical expression input field

Usage

First include the module files:

<link rel="stylesheet" href="node_modules/adm-math/css/adm-math.css">
<script type="text/javascript" src="node_modules/angular/angular.js"></script>
<script type="text/javascript" src="node_modules/angular-sanitize/angular-sanitize.js"></script>
<script type="text/javascript" src="node_modules/adm-math/js/adm-math-literal.js"></script>
<script type="text/javascript" src="node_modules/adm-math/js/adm-math-semantic.js"></script>
<script type="text/javascript" src="node_modules/adm-math/js/adm-math-parser.js"></script>
<script type="text/javascript" src="node_modules/adm-math/js/adm-math-input.js"></script>

Then include the module in your Angular.js module:

var myApp = angular.module("myApp", ["admMathInput"]);

And wherever you want a math input, add

<adm-math-input></adm-math-input>

Attributes

AttributeDescriptionTypeRequiredDefault
admFormatdefines output format - accepts "openmath", "latex" and "adm"STRINGno"openmath"
namethe name of the form element containing outputSTRINGno""
ngModela two-way-bound variable containing the mathematical expression in the format defined by admFormatVARno
admModelAdma read-only variable containing an admSemanticNode representation of the mathematical expressionVARno
admModelOma read-only variable containing an OpenMath representation of the mathematical expressionVARno
admModelLatexa read-only variable containing an LaTeX representation of the mathematical expressionVARno
admFunctionsan array (see format below) which will be parsed as functions rather than variablesSTRINGno""
admFocusa function (local to parent controller scope) which is called the the input field gains focusVARno
admBlura function (local to parent controller scope) which is called the the input field loses focusVARno
admHooka label used by and admInputControl to programmatically insert charactersVARno

Note: Using the format "adm" gives you an admSemanticNode object (verbose object literal, not for storage)

Note: The format for admFunctions is [f,g,df,...] - using this will interpret e.g. "f(x)" as a function, not as "f*x"

admHook usage

The following button would insert the character π into an admMathInput with admHook="field1"

<button adm-input-control adm-target="field1" adm-symbol="pi">&pi;</button>

A full list of supported values for adm-symbol follows:

TypeSymbols
circularsin cos tan arcsin arccos arctan
exponentialexponent ln log log10
relationsleq (≤) geq (≥)
constantse pi infinity
miscellaneousabsolute power root squareRoot
other symbols/^[0-9.a-zA-ZΑ-Ωα-ω+\-*()\^\/\|,='<>~]$/

Note: You can make a division button using adm-symbol="/".

Note: When tying primes a', due to the apparent lack of a standard format for primes in OpenMath, it will be stored as <OMV name='a_prime1'/>.

Note: Typing ~ is stored in OpenMath as the nonexistent symbol relation1.sim. To be fixed.


adm-math-plot

A canvas-based plotting tool

Usage

First include the module files:

<link rel="stylesheet" href="node_modules/adm-math/css/adm-math.css">
<script type="text/javascript" src="node_modules/angular/angular.js"></script>
<script type="text/javascript" src="node_modules/angular-sanitize/angular-sanitize.js"></script>
<script type="text/javascript" src="node_modules/adm-math/js/adm-math-literal.js"></script>
<script type="text/javascript" src="node_modules/adm-math/js/adm-math-semantic.js"></script>
<script type="text/javascript" src="node_modules/adm-math/js/adm-math-parser.js"></script>
<script type="text/javascript" src="node_modules/adm-math/js/adm-math-plot.js"></script>

Then include the module in your Angular.js module:

var myApp = angular.module("myApp", ["admMathPlot"]);

And wherever you want a plot, add

<canvas adm-plot></canvas>

Attributes

AttributeDescriptionTypeRequiredDefault
widthwidth of canvasINTyes
heightheight of canvasINTyes
admXMinleftmost x valueFLOATno-10
admXMaxrightmost x valueFLOATno10
admYMinbottommost y valueFLOATno-10
admYMaxtopmost y valueFLOATno10
admNoGridlinesdon't plot axes or gridBOOLEANnofalse

Subdirectives

These element-level directives go inside your adm-plot, and can be used to plot different things:

adm-plot-function

Plot a function described by expression in admRule.

AttributeDescriptionTypeRequiredDefault
admRulea description, of format admFormat, of the curve to plotSTRINGyes
admFormatformat of admRule, can be "latex" or "openmath"STRINGno"latex"
admColourcolour of the curveSTRINGno"#000000"
admDomainMinthe minimum value of the domainFLOATnoadmMathPlot.admXMin
admDomainMaxthe maximum value of the domainFLOATnoadmMathPlot.admXMax
adm-plot-label

Write the expression stored in admContent on the canvas.

AttributeDescriptionTypeRequiredDefault
admContentthe expression, of format admFormat, to be written on the canvasSTRINGyes
admPosthe position to write at, in the form "(x,y)" (in graph coordinates)STRING "(FLOAT, FLOAT)"yes
admFormatformat of admContent, can be "latex" or "openmath"STRINGno"latex"
admFunctionsan array (see format below) which will be parsed as functions rather than variablesSTRINGno""
admTextSizethe size of the text, in pixelsINTno25
admColourthe colour of the textSTRINGno"#000000"

Note: The format for admFunctions is [f,g,df,...] - using this will print e.g. "f(x)" as "f(x)", not as "f*x"

adm-plot-point

Mark a point at position adm-pos.

AttributeDescriptionTypeRequiredDefault
admPosthe position to write at, in the form "(x,y)" (in graph coordinates)STRING "(FLOAT, FLOAT)"yes
admColourthe colour of the pointSTRINGno"#000000"
adm-plot-asymptote

Draw an (vertical or horizontal) asymptote passing through either (admXIntercept, 0) or (0, admYIntercept).

AttributeDescriptionTypeRequiredDefault
admXInterceptthe x intercept of the, if defined, vertical asymptoteFLOATno
admYInterceptthe y intercept of the, if defined, horizontal asymptoteFLOATno
admColourthe colour of the asymptoteSTRINGno"#000000"

Note: One and only one of admXIntercept and admYIntercept must be defined.

adm-plot-unit-circle

Draw a circle of radius 1 at (0, 0) (in graph coordinates).

AttributeDescriptionTypeRequiredDefault
admColourthe colour of the circleSTRINGno"#000000"
adm-plot-radial-line

Draw a line out from (0, 0) (in graph coordinates) of length 1 at angle admAngle from the positive x direction.

Designed for use in conjunction with adm-plot-unit-circle.

AttributeDescriptionTypeRequiredDefault
admAnglethe angle (in radians), from the positive x direction, of the lineFLOATyes
admMarkAngleFromthe angle (in radians), from which the angle of the radial line will be markedFLOATno
admLabelthe label with which the angle will be markedSTRINGnoθ
admColourthe colour of the lineSTRINGno"#000000"

Note: The angle of the line will only be marked if admMarkAngleFrom is set.

adm-plot-line

Draw a line from admStart to admEnd.

Designed for use in conjunction with adm-plot-unit-circle.

AttributeDescriptionTypeRequiredDefault
admStartone end of the line, in the form "(x,y)" (in graph coordinates)STRING "(FLOAT, FLOAT)"yes
admStartthe other end of the line, in the form "(x,y)" (in graph coordinates)STRING "(FLOAT, FLOAT)"yes
admCongruencyMarkerthe number of strokes in the congruency marker, showing lines of equivanlent lengthINTno
admColourthe colour of the lineSTRINGno"#000000"

Note: No congruency marker will be drawn if admCongruencyMarker is left blank.

adm-plot-fill

Fill the space bordered by the child adm-plot-fill-borders.

AttributeDescriptionTypeRequiredDefault
admBordersthe number of child adm-plot-fill-bordersINTyes
admFormatformat of child adm-plot-fill-borders' admRules, can be "latex" or "openmath"STRINGno"latex"
admColourthe colour of the filled regionSTRINGno"#bce8f1"
admOpacitythe opacity of the filled regionFLOATno0.7
adm-plot-fill-border

One of the borders of parent adm-plot-fill.

AttributeDescriptionTypeRequiredDefault
admOrder1-indexed order in which these borders will be drawn (see note)INTyes
admRulea description, of format ^adm-plot-fill.admFormat, of the curve of the borderSTRINGno"latex"
admStartthe starting x value of the border (see note)STRINGno"#d9edf7"
admEndthe starting x value of the border (see note)INTno0.7

Note: Following these, in admOrder order, from admStart to admEnd, must form a contiguous line. Thus sometimes admStart will be to the right of admEnd. admStart cannot just be the leftpost point.

adm-plot-normal

Draw a normal curve of mean admMean and standard deviation admStdDev, filled between admMin and admMax to show some proportion of the curve.

AttributeDescriptionTypeRequiredDefault
admMeanthe mean of the distributionFLOATno0
admStdDevthe standard deviation of the distributionFLOATno1
admMinthe leftmost x value end of the filled sectionFLOATnoadmMathPlot.admXMin
admMaxthe rightmost x value end of the filled sectionFLOATnoadmMathPlot.admXMax
admCurveColourthe colour of the curveSTRINGno"#31708f"
admFillColourthe colour of the filled regionSTRINGno"#d9edf7"
admOpacitythe opacity of the filled regionFLOATno0.7
0.5.0

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago