AnyChart News How AnyChart Team Makes Use of Clojure and ClojureScript

How AnyChart Team Makes Use of Clojure and ClojureScript



The prime directive of AnyChart team is to develop the best interactive charts possible. While doing so, we create and use a number of different tools and technologies, and we always search for the new technologies that may help us and make our work more efficient. In this article, we want to talk about the way we make use of Clojure and ClojureScript, and why.

What Are Clojure and ClojureScript

Clojure is a dialect of the Lisp programming language; it is a dynamic, general-purpose language that combines the approachability and interactive development of a scripting language with an efficient and robust infrastructure for multithreaded programming. Clojure is now widely used in industry by firms such as Walmart, Puppet, and others. It is commercially supported by Cognitect, and though the company’s CTO Rich Hickey is the original author of the language, Clojure current development process is community-driven.

ClojureScript is a compiler for Clojure that targets JavaScript. It emits JavaScript code which is compatible with the advanced compilation mode of the Google Closure optimizing compiler.

As Wayne Douglas Gretzky said: “A good hockey player plays where the puck is. A great hockey player plays where the puck is going to be.” Clojure and ClojureScript coupling is a multifunctional and convenient development tool that becomes more and more popular, and AnyChart team decided to go for it.

AnyChart Clojure-based Projects

Now we will speak a little bit more about how exactly we are using Clojure in these projects and why.

AnyChart API Reference

AnyChart API Reference is an online reference of all namespaces, methods, classes, objects, enums, and events that are available in AnyChart libraries. Before we built our own parser and generator for AnyChart API Reference, we had used JSDoc3 for generating pages from code and had AngularJS-based frontend.

Now, we have our own Clojure-based parser that processes JSDoc descriptions of namespaces, classes, and libraries. And then there is a ClojureScript web part that displays the reference.

Both AnyChart API Reference Engine and AnyChart API are open and available on GitHub.

AnyChart Documentation

AnyChart Documentation is a set of articles and tutorials that users may need while working with AnyChart products. There are a number of ways to handle the documentation, and while there are a lot of commercial and free solutions for that, we decided to go on with our own so we could have the full control of the engine and the ability to maintain strict versioning.

The articles of AnyChart Documentation are stored in the AnyChart Documentation repository, in our special, slightly extended version of Markdown. Each branch of the repository is automatically processed by a Clojure-based parser, the parsing results are stored in the Postgresql database, and the content is indexed using the Sphinx search engine.

Both AnyChart Docs Engine and AnyChart API are open and available on GitHub.

AnyChart Playground

AnyChart Playground is an online tool for testing and showcasing any HTML, CSS and JavaScript code. Basically, it is a project similar to JSFiddle or CodePen but built specifically to handle AnyChart HTML5 charts right there and then easily share them.

AnyChart Playground is used to show samples from AnyChart Documentation, AnyChart API Reference, AnyChart Charts Gallery, and AnyChart Chartopedia. Users can modify and fork any samples, and save them in AnyChart Playground Cloud Storage.

Playground’s backend consists of three parts:

Web part, the site itself and the editor. Generator, a parser that is used to get samples from different repositories (API, Documentation, Gallery and so on). PhantomJS-based preview image generator.

Redis queues are used to handle interactions between the parts, and all this backend certainly can’t do without Clojure.

On the frontend, we are using ClojureScript along with Reagent and re-frame.

AnyChart Playground Engine repo is open on GitHub.

Link Checker

When creating articles in the AnyChart documentation, we often have to put in links to the pages on our website or in the API reference that do not exist yet. To avoid cases when such links go into production, we created Link Checker, a small Clojure library to check if there are any broken links on a site. Check out the Link Checker repository to find out how it works.

We love Clojure for the speed of development, for the ability to use a large number of libraries (because we deal with Java platform here) and to write common code that is used both on the backend and on the frontend. And of course, we love Clojure for the great pleasure it gives when we work with it. By the way, recently we’ve started using Specter and Instaparse libraries, which is a new step forward for us. The former is designed to operate complex data structures and the latter — to create parsers.

We hope you learned something interesting and helpful from this article. And maybe you already fell in love with Clojure as we did. Never stop growing, keep searching for new tools and new ideas that may make your work better. Stay tuned and thanks for your attention!