Published
Edited
Jan 20, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
{
// sequence: https://vega.github.io/vega/docs/transforms/sequence/
const sequence = vl.sequence(...arrSequences[trigFunction]).as("x");
// https://vega.github.io/vega/docs/expressions/#math-functions
const expression = trigFunction[0] != "a" ? `${trigFunction}(datum.x * PI / 180)`
: `${trigFunction}(datum.x) * 180 / PI`;
// https://vega.github.io/vega-lite/docs/calculate.html
const trigTransform = vl.calculate(expression).as("y");
const xTitle = trigFunction[0] != "a" ? `θ (degrees)` : trigFunction.substring(1,4) ;
const yTitle = trigFunction + "(" + ( trigFunction[0] != "a" ? "θ)" : trigFunction.substring(1,4) + ") (degrees)");
return vl.markLine()
.data(sequence)
.transform(trigTransform)
.width(width)
// https://vega.github.io/vega-lite/docs/size.html#autosize
.autosize({type: 'fit-x', contains: 'padding'})
.encode(
vl.x().fieldQ("x").title(xTitle),
vl.y().fieldQ("y").title(yTitle)
)
.render();

}
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more