A set of classes and a cli for generating plots roughly according to the guiding ideas behind Principiae. This video presents a quick discussion on the types of plots that this tool is meant to capture. The command for generating plots is meant to be minimal, and extended mostly through a public css api, including most translations. Due to this being entirely without rendering, some features are impossible, i.e. aligning items based off of their size, since their size is inherently unknown. If you desire more than basic svg generation, use the base principia tool that includes various rendering options.
npm i -g principia-plot
principia-plot -i <spec.json> -o <result.svg> -c <style.css>
will take a plot specification as json and write the compiled svg to the result. Optional styles can be applied via user supplied styling. Since this is meant to operate without rendering, some alignment may be necessary via custom css transforms.
The spec file is a json file describing the plot.
Many of the items will be common between each plot type, but each josn starts with a a type
field with a string indicating what chart type ot produce
Each plot starts with a root group with several classes, princ--root
, princ--<type>
, and optionally a user specified set of classes for global style tweaking.
Different plotting types will default with a theme which will be replaced with user specified classes.
Each plotted set of data will be in a group with the class princ--item
any user specified classes.
Each plotted item with be successive child elements of their parent container, so the .princ--item:nth-child
pseudo-selector will pick succesive plotted elements.
In order to make default plotting easier, there are several color themes that take advantage of this to style each item with a new color, however due to css prescience that often means that the selector for an item specific class will get overridden in prescidence by a color theme.
To overcome operator prescidence, styling a specific item should have the following selector .princ--root .princ--item.<user-class> .princ--<type>
.
The command line api will pull default styles from the built-in style, as well as any css in "\$HOME/.princ_style.css" and ".princ_style.css". The built in location can be used an example of how to use the css api.
This type of plot is meant to capture comparisons between different labeled numbers, where their absolute magnitude is relevant. The ultimate representation is a bar style graph, sideways for legibility.
The base json specification for a zero comparison plot is:
{
type: "comparizonz",
width?: number,
format?: string,
classed?: string,
axis?: {
format?: string,
max?: number,
ticks: number[]
},
data: [...]
}
Each element of data is:
{
name: string,
value: number,
classed?: string
}
This plot has one xaxis on the bottom following the standard axis api.
Inside each princ--item
are three groups:
princ--name
.princ--value
.princ--num
.The width of each line is controlled by the font size to make things adjustable.
Thus the size and width of the bars and labels are also set via the font size.
To shrink the relative height of the bar, just adjust the font-size in princ--value
accordingly.
This type of plot is meant to capture how one or many variables changes as another evolves. Its representation is as a line graph.
The base json specification for an evolution plot is:
{
type: "evolution",
width?: number,
height?: number,
classed?: string,
xaxis?: ...
yaxis?: ...
data: [...]
}
Each axis has the following structure:
{
label?: string,
format?: string,
min?: number,
max?: number,
ticks?: number[]
}
Each data object can be a line or a span. Lines are simple line evolutions showing hove the y variable changes with the x variable. Lines have the following structure:
{
type: "line",
data: [number, number][],
classed?: string,
label?: string,
curve?: string,
point?: string
}
linear
, step
, step_before
, step_after
, basis
, cardinal
, monotone
, catmull_rom
.circle
, cross
, diamond
, square
, star
, triangle
, wye
.Spans show how a range of y values changes with x values. They can also be used to show error around a line. Spans have the following structure:
{
type: "span",
data: [number, number, number][],
classed?: string,
label?: string,
curve?: string,
point?: string
}
This plot has an x and a y axis following the standard axis api.
Each princ--item
will also have another class indicating whether it's a princ--line-item
or a princ--span-item
.
Inside each princ--item
are three groups:
princ--labels
followed by princ--label
with the label for the item.princ--point
.princ--span
or princ--line
.The size of points can be adjusted by scaling up or down the princ--point
class.
If a line has one of the classes princ--{dash,dot,dash-dot}
it will get the default styling for those types of line styles.
Labels can be moved away from the data by x translating princ--labels
or individually separated by translating princ--label
.
Many plots have axes showing the data, although some tweak presentation slightly.
The axes come in a root group with the class princ--axis
.
This potentially contains two groups: princ--xaxis
and princ--yaxis
.
Each axis is composed of four elements:
princ--tick-line
.princ--ticks
and then a separate princ--tick
for each tick.
Each princ-tick
will be the nth-child
in its container and in sorted order, so the selector princ--tick:nth-child(1)
will get the lowest tick.princ--tick-labels
and the separate princ--tick-label
for each individual label.
Like ticks, a princ--tick-label
will be its nth-child
.princ--axis-label
.The length of axis ticks can be set by x or y scaling the princ--tick
class.
Translating princ--tick-labels
and princ--axis-label
allows adjusting the spacing of those labels.
In order to make quick styling easier, a number of built in classes exist to change colors.
Color themes set the default coloring for successive items.
Each theme is a class that should be applied to the root element, prefixed by princ--
.
The available themes are:
In addition there are a number of default colors.
If a color class is applied to an item with the prefix princ--
it will change the color of that item, if it's applied to the root it will function as a one color theme.
The available colors are:
There a number of npm run scripts to aid with development.
npm run lint
will lint the typescript.npm run docs
will build the docs for github pages.npm run style
will update the default style sheet from base_style.css
and themes.json
.Generated using TypeDoc