![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
canvas-curve
Advanced tools
Directly in the browser:
<script src="dist/CanvasSpliner.min.js"></script>
Or with a bundler
npm install --save jonathanlurie/CanvasSpliner
// create a new CanvasSpliner, with a parent DIV id, a width and a heigh
var cs = new CanvasSpliner("parent", 300, 300);
// Optional: Add points (with unit coordinates)
cs.add( {x:0, y: 0, xLocked: true, yLocked: true, safe: true} );
cs.add( {x:0.1, y: 0.4} );
cs.add( {x:0.3, y: 0.45} );
cs.add( {x:0.6, y: 1} );
cs.add( {x:1, y: 0.6, xLocked: true, safe: true} );
As shown above, we can add points directly from the code. Those points can have other attributes than (x, y) coordinates.
s.add( {x:0.1, y: 0.5, xLocked: true} );
s.add( {x:0.12, y: 0.6, yLocked: true} );
s.add( {x:0.8, y: 0.4, safe: true} );
cs.add( {x:0.4, y: 0.1, xLocked: true, yLocked: true, safe: true} );
CanvasSpliner allows two kinds of cubic spline: natural and monotonic. The math behind does not matter, just remember the natural is a bit curvyer and the monotonic is a bit stiffer. You can enable one mode or the other two diferent ways:
var cs = new CanvasSpliner("parent", 300, 300, "natural");
Note that this is the default mode when the argument is omited.
cs.setSplineType( "monotonic" );
// or
cs.setSplineType( "natural" );
xLocked
or yLocked
)safe
)Get an interpolated value, in unit coordinates:
var interpolatedY = cs.getValue( 0.15 );
Get all the spectrum of x coordinates, in a normalized space:
var arrayOfX = cs.getXSeriesInterpolated();
Note that if your canvas is 500px wide, you will get 500 values from 0 to 1 with regular spacing.
Along with this regular x go the interpolated y array:
var interpolatedYs = cs.getYSeriesInterpolated();
CanvasSpliner can trigger two events:
cs.on( "movePoint", function( csObj ){
// here, csObj is the same object as cs. We can then call
// cs.getXSeriesInterpolated() or
// cs.getYSeriesInterpolated()
})
cs.on( "releasePoint", function( csObj ){
// here, csObj is the same object as cs. We can then call
// cs.getXSeriesInterpolated() or
// cs.getYSeriesInterpolated()
})
If you want to adapt the styling of CanvasSpliner to match you own project, you can. After changing the styling, be sure you call the method cs.draw()
to refresh!
cs.setControlPointRadius( 6 )
cs.setControlPointColor( state, color )
cs.setCurveColor( state, color )
cs.setGridColor( color )
cs.setGridStep( gs )
cs.setTextColor( color )
cs.setCurveThickness( t )
null
/ false
or 0
to have a transparent background.cs.setBackgroundColor( color )
CanvasSpliner uses George MacKerron's splines, wrapped in a propper npm package by Marcio Augusto Guimarães.
FAQs
A spline widget
The npm package canvas-curve receives a total of 1 weekly downloads. As such, canvas-curve popularity was classified as not popular.
We found that canvas-curve demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.