The goal of ink.js
is to provide web-components for interactive scientific writing, reactive documents and ink.js
are ways to create, update and display variables as text, equations and charts.
ink.js
is heavily inspired by html
markup.
To get an idea of what that looks like, let's take the canonical example of
When you eat
When you eat
That's
Check out the table of contents on the right, or scroll on:
Ink is based on web components, which create custom HTML tags so that they can make writing documents easier. To get started, copy the built javascript file to the head of your page.
npm
The Taylor series of a real or complex-valued function $f(x)$ that is infinitely differentiable at a real or complex number $a$ is the power series
The sine function is closely approximated by its Taylor polynomial of
Try expanding the Taylor series:
:max="p_f_choices.length-1"
format=".2%" :map="p_f_array[p_f_pick]"
, not sure if this is a map, transform, or something else?According to Northern Gateway risk assessments, the probability of a tanker spill of any size would be about 0.4 per cent in any given year. The company estimated the return period (average interval between events) would be 250 years for a marine spill.
National Energy Board & Canadian Environmental Assessment Agency (2013-12-19) Joint Review PanelNorthern Gateway said the probability of a full-bore rupture on the oil pipeline would be 0.2 per cent in a given year, based on an estimated return period of 464 years.
In order to gain insight into the potential risk of an oil spill, you can play with the parameters below! You can drag the blue highlighted numbers to adjust the interactive graph.
Let's say the probability of a spill is
When the probability of a spill is
Figure 1: Probability of no spill when the failure rate is
Table 1: Northern Gateway's summary of representative parameters for oil spill probabilities. Click a row to change the graph above.
Spill Type | Return Period | Annual Probability | Page Reference |
Oil Pipeline, Other Spills | 4 years | page 67 (html) | |
Marine Terminal Spill | 61 years | page 67 (html) | |
Oil Pipeline, Full-bore Rupture | 240 years | page 67 (html) | |
Tanker Spill (any size) | 250 years | page 60 (html) | |
Full-Bore Rupture, Oil Pipeline | 464 years | page 60 (html) |
The function $\operatorname{atan2}(y,x)$ (from "2-argument arctangent") is defined as the angle in the Euclidean plane, given in radians, between the positive x-axis and the ray to the point $(x,y)$.
$\operatorname{atan2}(y,x)$ returns a single value $\theta$ such that $-\pi < \theta \le \pi$ and, for some $r > 0$,
ink-scope
Variables need to be defined to drive your dynamic document, the ink-var
web component can specify a name, description and a value.
These variables are hidden in the DOM
, you can use a ink-var-list
to see them all.
You can also create reactive variables which get execute a user-inputed string in an iframe
with access to all other variables. Note here that the :value
has a
ink-var
:
name
description
value
:value
format
To display an element create an ink-display
, which will just render the named variable as text.
This is a number that is dynamic:
Try setting the value of $x$ with the range input:
You can also transform
the value of a variable before you format it.
For example, you might want to say that the admission to a park is 'free'
when the
You can also use this transform
to say that the park admission is
This is also quite useful if you want to use the transform to index into an array
ink-display
:
name
format
transform
format(transform(value))
. If the value is a string after transformation, it will not be formatted.What gets slightly more exciting is when you can bring these together with inputs that can be ranges or dynamic text elements that you can drag.
This allows you to set the value of $x$ inline:
Notice how it is linked to the above ink-range
and ink-display
.
You can also add inside of the html tag, to have custom formatting that also is dynamic.
For example, °C
is inside of the <ink-dynamic>
tags, so it is also has a blue underline.
You can also create ranges, as see above, notice that we can create a lot of these and name to different values.
$x_{1.0}:$
$y_{1.0}:$
$y_{0.5}:$
name
:value="name"
and bind="{name:value}"
.value
:value
.bind
(value) => {x: value}
.format
min
max
step
sensitivity
dynamic
text input.transform
format(transform(value))
. If the value is a string after transformation, it will not be formatted.periodic
name
, :value
& bind
There are times where you want more control over how your data gets displayed, updated or informs other variables.
There are three properties to consider: name
, :value
, and bind
.
The most common use is through the name
property, which is used to both set the control's value, and bind the change to the named variable.
This amounts to a two way connection:
x
updates, the value
is set, and when the control updates the value, the result updates the variable!
Under the hood, when name
is defined, the :value
and the bind
functions are automatically set.
:
syntax for the value
property recomputes every time there is a change.
For example, if you put :value="x"
then anytime the variable x
changes, the value of the control updates.
However, this is not the case in reverse!
You have to explicitly bind
the control to the variable (or variables) you want to update. This is done using a JSON dictionary of the form {variable: value}
.
Note that you can update multiple variables at a time.
If you choose to explicitly set these, and not just use the name
property, you can do some interesting things!
A good example of this is changing from a radial coordinate system to Cartesian. In this case we will have two variables:
Cartesian Coordinate System
Use the eqn.math
property to change the math dynamically:
Most of the content on this page uses the <ink-demo>
component:
This is a demo of a demo!!
Ink has Tufte style sidenotes to add sarcastic or poignant insights. These asides can include figures and equations.
Sometimes you need to say things on the side.
The render
function of the chart loops through all of the children and renders the SVG template. Each ink-chart
child has to return an SVG namespaced string to add to the chart. In this way, they keep the same ordering as the dom
Each child component has a renderSVG
function that returns an svg template string.
ink-chart-circle
x
and y
location, color, radius and other standard svg circle properties..ink-chart-path
data
(an array of [x, y]
), stroke and other standard svg path properties..ink-chart-text
x
and y
location, color and other standard svg text properties..ink-chart-eqn
eqn
) and controls stroke, color and other standard svg path properties..ink-chart-node
The ink-chart-eqn
component allows you to create dynamic lines or points based on an equation.
This allows you to create and show equations like (x) => Math.sin(x)
.
You can also parameterize
the function over x
, y
or t
.
When parameterizing in terms of t
you must supply a domain
(e.g. [0, 1]
) and the function
should return a length-two list. Both x
and y
parameterizations provide the other coordinate
so the function should only return a number.