|
1 |
| -# cpplot |
2 |
| - |
3 |
| -> **Work is in progress to refactor this out from other libraries. Watch this space.** |
4 |
| -
|
5 |
| -Interactive graphs and charts for C++ 11 upward, |
6 |
| -[interactively viewable in-browser using cpplot-viewer](https://cpplot.herokuapp.com). |
7 |
| - |
8 |
| -This library allows you to save figure files (in a *.json form compliant with the `plotly.js` library) to disk |
9 |
| -during program execution. |
10 |
| - |
11 |
| - |
12 |
| -## Why? |
13 |
| - |
14 |
| -For most engineering and scientific applications that come across my desk, it's a case of "prototype in MATLAB or Python, rewrite in C++". But: |
15 |
| - - I'm getting really sick of MATLAB in terms of deployability (there's no CI option to build it, the slug size of the runtime library is 3.7Gb, etc etc). |
16 |
| - - I'm getting really really sick of writing the damn code twice. |
17 |
| - - Most of my engineering and science apps are now getting deployed to cloud services. So displaying natively generated figures in-browser is a nightmare. |
18 |
| - |
19 |
| -What I need is a solution where I can prototype straight into a language which is fast, capable and has a pretty good ecosystem of third party libraries to help me. |
20 |
| - |
21 |
| -Now, with: |
22 |
| - - the great improvements to C++ in the C++11 and 14 standards (which make it much easier to handle threading and generally connect APIs of various libraries together), |
23 |
| - - availability of libraries like Eigen, cpr, ceres-solver, Intel MKL, cxxopts (I could go on and on), |
24 |
| - - great utilities like googletest and Cmake to remove all the old-skool build and test agony... |
25 |
| - |
26 |
| -C++ is really getting there. The one thing missing is a plotting library, which allows me to: |
27 |
| - - quickly and easily prototype new algorithms (visually diagnose what's wrong etc etc) |
28 |
| - - display analysis results on the web |
29 |
| - - produce the same figures on different platforms |
30 |
| - - save publication quality figures easily |
31 |
| - |
32 |
| -In all the other languages I use, I now use `plotly` to do those things. So now it's here for C++ too. |
33 |
| - |
34 |
| - |
35 |
| -## Viewing Figures |
36 |
| - |
37 |
| -A browser based utility is supplied at [https://cpplot.herokuapp.com](https://cpplot.herokuapp.com). |
38 |
| -Navigate to that link and you'll easily be able to view and export the figures created here. |
| 1 | +[](https://github.com/pre-commit/pre-commit) |
| 2 | +[](https://www.blackgirlscode.com/) |
39 | 3 |
|
40 |
| -The browser viewer is built in React (using the excellent `react-plotly.js`), is also open-source, free and it |
41 |
| -always keeps your data local (files are never uploaded to a server). Find the source |
42 |
| -at [https://github.com/thclark/cpplot-viewer](https://github.com/thclark/cpplot-viewer). |
43 | 4 |
|
44 |
| -**Some example figures to try out with the viewer are included in `/examples`**. |
45 |
| - |
46 |
| -## The Plotly Library |
47 |
| - |
48 |
| -### Plotly figure json specs |
49 |
| - |
50 |
| -At the core of plotly is a set of open specifications for JSON data which can be rendered into various figure types. The various figure classes available here |
51 |
| - |
52 |
| -### Plotly Offline |
| 5 | +# cpplot |
53 | 6 |
|
54 |
| -`Plotly.js` is a javascript library for rendering figures, which can be used offline. This is what's used by the browser viewer. |
| 7 | +Interactive graphs and charts for C++ 11 upward, |
| 8 | +[viewable in-browser using cpplot-viewer](https://cpplot.herokuapp.com). |
55 | 9 |
|
56 |
| -### Plotly Online |
| 10 | +Full documentation is at [https://cpplot.readthedocs.io](https://cpplot.readthedocs.io) |
57 | 11 |
|
58 |
| -Plotly have a range of online services for collaboration on data grids and figures. You can use their API or tools to take the contents of the files produced here (plotly compliant JSON strings) onto Plotly Online, but how to do that is out of scope here (check their docs). |
59 | 12 |
|
60 |
| -**HELP WANTED** - I have a branch that's starting to use the Plotly API, which might be the very early beginning of a |
61 |
| -client SDK for C++, enabling direct manipulation of online data. However, I have very little appetite for this (I personally don't use plotly online) so collaborators are welcome. |
62 | 13 |
|
63 | 14 |
|
64 | 15 | ## For Developers
|
65 | 16 |
|
| 17 | +You should only need to read the following if you plan to develop on `cpplot`. |
| 18 | + |
66 | 19 | ### Style guide
|
67 | 20 |
|
68 | 21 | We use the [Google C++ style guide](https://google.github.io/styleguide/cppguide.html) with the following exceptions:
|
69 | 22 | - Don't care about line width so long as its within reason
|
70 | 23 | - Use 4 space indenting, not 2 as suggested by the style guide, because we're not [total monsters](https://www.youtube.com/watch?v=SsoOG6ZeyUI) (just kidding xx).
|
71 | 24 |
|
72 |
| -### Threading |
73 |
| - |
74 |
| -Figure write-to-disk is called as an async task, so doesn't block the main computation thread. |
| 25 | +### Pre-Commit |
75 | 26 |
|
76 |
| -This delays program termination when the main program executes quicker than the figure write. |
77 |
| -TODO consider creating daemonised threads for writing figures. |
78 |
| - |
79 |
| -### Third party dependencies |
80 |
| - |
81 |
| -We are currently using: |
82 |
| - |
83 |
| -[**Eigen**](http://eigen.tuxfamily.org/) provides a linear algebra library. It isn't as consistent with MATLAB's API as armadillo (an alternative), but the API is very understandable and is used extensively in the C++ community. |
| 27 | +You need to install pre-commit to get the hooks working. Do: |
| 28 | +``` |
| 29 | +pip install pre-commit |
| 30 | +pre-commit install |
| 31 | +``` |
84 | 32 |
|
85 |
| -[**glog**](https://github.com/google/glog) google's asynchronous logging library, used for logging to file. |
| 33 | +Once that's done, each time you make a commit, the following checks are made: |
86 | 34 |
|
87 |
| -[**googletest**](https://github.com/google/googletest) for unit testing. |
| 35 | +- valid github repo and files |
| 36 | +- code style |
| 37 | +- documentation builds correctly |
88 | 38 |
|
89 |
| -### Submodule dependencies |
| 39 | +Upon failure, the commit will halt. **Re-running the commit will automatically fix most issues** except: |
| 40 | +- You'll have to fix documentation yourself prior to a successful commit (there's no auto fix for that!!). |
90 | 41 |
|
91 |
| -You'll need to clone the repository **and its submodules, cpr and json,** in order to build it. |
| 42 | +You can run pre-commit hooks without making a commit, like: |
92 | 43 | ```
|
93 |
| -git clone --recurse-submodules https://github.com/thclark/cpplot |
| 44 | +pre-commit run build-docs |
94 | 45 | ```
|
| 46 | +which is useful to locally build documents without crazy efforts setting up an environment for sphinx. |
95 | 47 |
|
96 |
| -### Third party library installation (OSX) |
97 |
| - |
98 |
| -**ceres-solver which includes eigen and glog dependencies:** |
99 |
| -```bash |
100 |
| -brew install homebrew/science/ceres-solver |
101 |
| -``` |
102 | 48 |
|
103 | 49 | ### Compilation with cmake
|
104 | 50 |
|
|
0 commit comments