-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Additional curve support #1503
Conversation
Deploying with Cloudflare Pages
|
± Registry diff
📊 PerformanceKeyNote that each bar component rounds up to the nearest 100ms, so each full bar is an overestimate by up to 400ms.
If a row has only one bar instead of four, that means it's not a trio and the bar just shows the total time spent for that example, again rounded up to the nearest 100ms. Data
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it. Thanks, @keenancrane!
Merged—thanks all! |
This PR expands on support for curves/paths in Style by adding several functions to
Functions.ts
:interpolatingSpline()
— provides path data for an (open or closed) Catmull-Rom spline interpolating a given set of points, with optionaltension
value. This method provides an easy way to draw a smooth curve through a list of points without having to explicitly think about tangents.diffusionProcess()
— provides a way to generate a common type of "random" curve, namely, those that arise from Brownian motion. This functionality mirrors functionality provided by other packages—for instance, Mathematica provides a similar collection of functions under the heading Stochastic Differential Equation Processes. I decided against simply calling this methodrandomCurve()
which, while a bit more accessible, we might want to reserve for other notions of "random curve."firstPoint()/lastPoint()
— readable convenience methods to access the first and last point of a list of points in Style. Much like our other nomenclature choices, these methods are named as a readable alternative to expressions likemyList[0]
ormyList[ length(myList) - 1 ]
(which we may or may not even currently support).averagePoint()
— returns the average (mean) of all points in a list. This function extends existing list processing functionality likesumVectors()
,maxList()
, andminList()
(which is heavily used incollect
statements). It could perhaps be emulated in Style via something likesumVectors(list)/length(list)
, but again, a convenience function provides more readable code; it's also not clear right now that we provide a mechanism for determining list length outside ofcollect
statements (the plainlength()
function currently has an extremely special functionality—measuring the length of aLine
shape—which should probably be renamed).In general, more sophisticated list processing in Style, and the ability to interpret lists as various kinds of curves seems pretty essential for real diagramming. The most significant functionality missing from this PR is the ability to concatenate multiple paths to generate another path—e.g., using several curves from different parts of a diagram to make a single region boundary of a shaded shape. This PR can be viewed as sort of "dipping our toes" into the waters of more real-world path manipulation.
Examples
The features above are demonstrated/tested using two new examples (shown above):
curve-examples/catmull-rom
: demonstrates theinterpolatingSpline()
function, including several parameter values fortension
.stochastic-process
: demonstrates thediffusionProcess()
,lastPoint()
, andaveragePoint()
functions. This example also shows compositionality of the PR functions—here for instance the point list generated bydiffusionProcess()
is fed tointerpolatingSpline()
to get a smoother curve.Implementation
Some methods were refactors as local computation functions (rather than only being exported to Style), which also helps make them usable through the API. In particular, generation of normally-distributed random numbers, construction of Catmull-Rom splines, and generation of stochastic curves.