Module:ColinTheCat/Plotter/doc: Difference between revisions

From Resonite Wiki
No edit summary
No edit summary
Line 1: Line 1:
== Arguments ==
{| class="wikitable"
|-
! Argument !! Description !! Example !! Default
|-
| <u>Plots</u> || Plots as JSON || See [[#Example]] ||
|-
| From || Lowest x,y to plot || <code>-pi/2,0</code> || <code>0,0</code>
|-
| <u>To</u> || Highest x,y to plot || <code>10^2,2</code> ||
|-
| Origin || X/Y Axis origin || <code>0.5,0.5</code> || <code>0,0</code>
|-
| GridStep || Coordinate grid step size || <code>pi/2,1</code> || <code>1,1</code>
|-
| Inline || Display the plot inline instead of floating || <code>true</code> || (absent)
|-
| <s>LabelX, LabelY</s> || Axis label (not implemented) || ||
|-
| LabelStepX || Label for grid X-axis increments || <code>format("%sπ", dfrac(x/pi, 1))</code> || <code>format("%d", x)</code>
|-
| LabelStepY || Label for grid X-axis increments || <code>format("%.1f", y)</code> || <code>format("%d", x)</code>
|-
| ColorX || X-axis color || <code>#44f</code> || <code>#f44</code>
|-
| ColorY || Y-axis color || <code>#0f4</code> || <code>#0f0</code>
|}
<u>Underlined</u> Arguments are required.
== Available Functions and Constants in Expressions ==
* <code>printf(format, ...args)</code><br>See [https://www.lua.org/manual/5.3/manual.html#6.4 Lua ''string.format''].
* <code>dfrac(number, is_factor)</code><br>Formats a float as a fraction, if possible. If it is a factor, then the number 1 or -1 will only produce its sign as an output, useful when formatting as a factor of pi, for example. See [[#Example]] below.
* <code>sin,floor,abs,...</code><br>Any constant or function from the [https://www.lua.org/manual/5.3/manual.html#6.7 Lua math library] can be used directly (without the <code>math.</code> prefix).
== Example ==
== Example ==



Revision as of 22:54, 12 February 2024

Arguments

Argument Description Example Default
Plots Plots as JSON See #Example
From Lowest x,y to plot -pi/2,0 0,0
To Highest x,y to plot 10^2,2
Origin X/Y Axis origin 0.5,0.5 0,0
GridStep Coordinate grid step size pi/2,1 1,1
Inline Display the plot inline instead of floating true (absent)
LabelX, LabelY Axis label (not implemented)
LabelStepX Label for grid X-axis increments format("%sπ", dfrac(x/pi, 1)) format("%d", x)
LabelStepY Label for grid X-axis increments format("%.1f", y) format("%d", x)
ColorX X-axis color #44f #f44
ColorY Y-axis color #0f4 #0f0

Underlined Arguments are required.

Available Functions and Constants in Expressions

  • printf(format, ...args)
    See Lua string.format.
  • dfrac(number, is_factor)
    Formats a float as a fraction, if possible. If it is a factor, then the number 1 or -1 will only produce its sign as an output, useful when formatting as a factor of pi, for example. See #Example below.
  • sin,floor,abs,...
    Any constant or function from the Lua math library can be used directly (without the math. prefix).

Example

{{#invoke:ColinTheCat/Plotter|Plot2D
|From=-0.2, -1.2
|To=2 * pi + 0.2, 1.2
|GridStep=0.5 * pi, 1
|LabelStepX=format("%sπ", dfrac(x/pi, 1))
|Plots=
[
{"Type": "function", "Function": "sin(x)", "Samples": 100, "Label": "sin"},
{"Type": "function", "Function": "cos(x)", "Samples": 100, "Label": "cos"},
{"Type": "function", "Function": "tan(x)", "Samples": 35, "Label": "tan", "Ranges": [
  {"To": "(0.5-0.2)*pi"},
  {"From": "(0.5+0.2)*pi", "To": "(1.5-0.2)*pi"},
  {"From": "(1.5+0.2)*pi"}
]}
]
}}
½π π ³⁄₂π -1 1
sin
cos
tan