Documentation Snippets & Code Sandbox – Creating the best experience for JS Devs
Tags: javascript, webdev, sandbox
Published: 2024-03-13 15:10:25

Earlier this year we blogged about enabling SciChart.js to work out of the box in sandbox environments like JSFiddle, Codepen.io and CodeSandbox.io. Take a look at the blog if you haven't seen it already which gives a run-down of what you can do in these environments.

https://www.scichart.com/blog/codepen-codesandbox-and-jsfiddle-support-in-scichart-js/?nocache=1

Using that, we've now built upon it and added two major enhancements to the SciChart.js developer experience. These are:
<ul>
 	<li>A re-work of key documentation pages embedding live codepen samples</li>
 	<li>Allowing you to extract any demo into a stand-alone codesandbox</li>
</ul>
Read on to find out what this means &amp; how it will level up your developer experience with SciChart.js
<h2>Documentation Snippets with Codepens</h2>
SciChart.js has over 200 hand-written documentation pages. In addition, over a thousand TypeDoc generated docs. You can view the SciChart.js documentation at <a href="https://scichart.com/javascript-chart-documentation">scichart.com/javascript-chart-documentation</a>.

One of the problems with keeping docs updated is that simple typo on page could result in a runtime or compilation error. Docs have to have up to date code samples that are tested and embedded in the page. Bonus points for a runnable sample (like JSFiddle or Codepen) in the page. The last problem is you can copy-paste the code sample, miss something and it still doesn't work.

So what have we done to solve this?
<ul>
 	<li>We've open sourced the docs and all the example code to go with it. Find this at <a href="https://github.com/ABTSoftware/SciChart.JS.Examples/tree/master/Documentation">github.com/abtsoftware/scichart.js.examples</a> - under Documentation.</li>
 	<li>We've created a number of example snippets with both the traditional SciChart API and the Builder API in this folder.</li>
 	<li>Lastly, we've embedded the example snippets in the documentation itself using Codepen.</li>
</ul>
Try it out!

<img class="alignnone size-full wp-image-7396" src="https://www.scichart.com/wp-content/uploads/2023/03/codepen-embeds-scichart-js-documentation.gif" alt="" width="1366" height="900" />

Head over to <a href="https://scichart.com/javascript-chart-documentation">scichart.com/javascript-chart-documentation</a>, click on any documentation page under 2D Charts API or Axis APIs and you should see embedded samples like this.

So far we've completed all the pages under 2D Chart Types and Axis APIs. We intend to complete all the pages plus add new ones. This is a long process so bear with us!
<h2>Showcase Demos &amp; CodeSandbox integration</h2>
Head over to any showcase demo on <a href="https://demo.scichart.com">demo.scichart.com</a>. Click on the <strong>'Code Sandbox'</strong> button at the top of the page. This will open the demo in a stand-alone app inside <a href="https://codesandbox.io/">Codesandbox</a> - a brand new in-browser IDE that will let you edit the code, try new things and share results with your colleagues.

You'll notice as well there's a <strong>Docs</strong> button. This opens contextual documentation for the current example. Try it out!

[caption id="attachment_7428" align="alignnone" width="1409"]<img class="wp-image-7428 size-full" src="https://www.scichart.com/wp-content/uploads/2023/03/codesandbox-demo-app-2.gif" alt="Codesandbox integration and context sensitive documentation in the SciChart.js demo (see demo.scichart.com)" width="1409" height="994" /> Codesandbox integration and context sensitive documentation in the SciChart.js demo (see <a href="https://demo.scichart.com">demo.scichart.com</a>)[/caption]
<blockquote>CodeSandbox integration means we can extract each showcase demo as a standalone app. From there you can click Fork to save your own version of the sandbox. Try editing the code and see how it affects the chart!</blockquote>
<span style="font-size: 16px;">We've integrated the codesandbox toolbar into examples found on the main website as well.</span>If you see this toolbar, hover over and you can do the same thing (open in codesandbox), as well as jump to contextual documentation for the example or demo.

[caption id="attachment_7411" align="alignnone" width="1506"]<img class="wp-image-7411 size-full" src="https://www.scichart.com/wp-content/uploads/2023/03/js-example-toolbar-scichart.jpg" alt="Example Toolbar in all SciChart.js showcases. Click to open contextual documentation or this example in a Code Sandbox. See scichart.com/javascript-chart-examples" width="1506" height="1067" /> Example Toolbar in all SciChart.js showcases. Click to open contextual documentation or this example in a Code Sandbox (See <a href="https://scichart.com/javascript-chart-examples">scichart.com/javascript-chart-examples</a>)[/caption]
<h2>Got an error?</h2>
Codesandbox plus this integration is relatively new. Some of the examples are showing an error like this:
<blockquote>
<div><em>RangeError</em></div>
<div><em>Potential infinite loop: exceeded 10001 iterations. You can disable this check by creating a sandbox.config.json file.</em></div></blockquote>
<div>This is easily resolved by adding a <a href="https://codesandbox.io/docs/learn/sandboxes/configuration">sandbox.config.json</a> file and disabling infiniteLoopProtection. We will update our showcase demo app soon to do this automatically.</div>
<h2>What's Next?</h2>
These are the items on our roadmap to improve the developer experience with SciChart.js
<ul>
 	<li>In the next few weeks we will be releasing a new Getting Started page with embedded tutorials, codepens and sandboxes to help you get started with SciChart fast.</li>
 	<li>In the next 3 months we plan a community edition of SciChart.js, which will require a signup &amp; have special T&amp;C, and will work with watermark for non-commercial projects &amp; applications.</li>
 	<li>We're continuing to work through the documentation pages, updating all code samples and embedded codepens. There's a lot to do! Almost 200 pages and we've completed 30% so far.</li>
 	<li>Finally, improvements to our support systems to handle the volume of requests we are getting.</li>
</ul>
Keep watching this space!

Best regards,
Andrew
<blockquote>
<h2>Start using SciChart.js Today</h2>
SciChart.js is now available with a <a href="https://www.scichart.com/getting-started/scichart-javascript"><strong>FREE community edition</strong></a> (no trial, sign-up or credit card required) where you can try out the library commercially or use it in a non-commercial application. If you have a question, or would like to give feedback, contact us.
<p style="text-align: center;"><a class="button" href="https://scichart.com/contact-us">CONTACT US</a><a class="button" href="https://www.scichart.com/getting-started/scichart-javascript/">GET SCICHART.JS FREE</a></p>
</blockquote>