Skip to content

Commit ef0186e

Browse files
authored
Merge pull request #11 from thclark/v0.0.1
v0.0.1
2 parents 315cef8 + 9cf5665 commit ef0186e

34 files changed

+724
-103
lines changed

.pre-commit-config.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
exclude: 'build|docs|node_modules|.git|.tox|dist'
2+
default_stages: [commit]
3+
fail_fast: true
4+
default_language_version:
5+
python: python3 # force all unspecified python hooks to run python3
6+
repos:
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: master
9+
hooks:
10+
- id: trailing-whitespace
11+
- id: end-of-file-fixer
12+
- id: check-yaml
13+
language_version: python3
14+
15+
- repo: https://github.com/thclark/pre-commit-sphinx
16+
rev: 0.0.1
17+
hooks:
18+
- id: build-docs
19+
language_version: python3

CMakeSettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"cmakeCommandArgs": "-T host=x64",
2828
"buildCommandArgs": "-m -v:minimal",
2929
"ctestCommandArgs": ""
30-
30+
3131
},
3232
{
3333
"name": "x64-Release",
@@ -39,4 +39,4 @@
3939
"ctestCommandArgs": ""
4040
}
4141
]
42-
}
42+
}

README.md

Lines changed: 23 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,50 @@
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+
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
2+
[![black-girls-code](https://img.shields.io/badge/black%20girls-code-f64279.svg)](https://www.blackgirlscode.com/)
393

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).
434

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
536

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).
559

56-
### Plotly Online
10+
Full documentation is at [https://cpplot.readthedocs.io](https://cpplot.readthedocs.io)
5711

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).
5912

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.
6213

6314

6415
## For Developers
6516

17+
You should only need to read the following if you plan to develop on `cpplot`.
18+
6619
### Style guide
6720

6821
We use the [Google C++ style guide](https://google.github.io/styleguide/cppguide.html) with the following exceptions:
6922
- Don't care about line width so long as its within reason
7023
- 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).
7124

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
7526

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+
```
8432

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:
8634

87-
[**googletest**](https://github.com/google/googletest) for unit testing.
35+
- valid github repo and files
36+
- code style
37+
- documentation builds correctly
8838

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!!).
9041

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:
9243
```
93-
git clone --recurse-submodules https://github.com/thclark/cpplot
44+
pre-commit run build-docs
9445
```
46+
which is useful to locally build documents without crazy efforts setting up an environment for sphinx.
9547

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-
```
10248

10349
### Compilation with cmake
10450

docs/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
doctrees
2+
html
3+
source/doxyoutput*
4+
source/library_api*

docs/requirements.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
# Required by the python script for building documentation. You probably won't have to install this (because you can
3+
# pre-commit hook builds docs for you and manages the environment).
4+
Sphinx==1.8.3
5+
sphinx-rtd-theme==0.4.2
6+
sphinx-tabs==1.1.10
7+
breathe==4.11.1
8+
exhale==0.2.1

docs/source/about.rst

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
.. _about:
2+
3+
=====
4+
About
5+
=====
6+
7+
.. _why:
8+
9+
Why?
10+
====
11+
12+
For most engineering and scientific applications that come across my
13+
desk, it's a case of "prototype in MATLAB or Python, rewrite in C++".
14+
But: - I'm getting really sick of MATLAB in terms of deployability
15+
(there's no CI option to build it, the slug size of the runtime library
16+
is 3.7Gb, etc etc). - I'm getting really really sick of writing the damn
17+
code twice. - Most of my engineering and science apps are now getting
18+
deployed to cloud services. So displaying natively generated figures
19+
in-browser is a nightmare.
20+
21+
What I need is a solution where I can prototype straight into a language
22+
which is fast, capable and has a pretty good ecosystem of third party
23+
libraries to help me.
24+
25+
Now, with: - the great improvements to C++ in the C++11 and 14 standards
26+
(which make it much easier to handle threading and generally connect
27+
APIs of various libraries together), - availability of libraries like
28+
Eigen, cpr, ceres-solver, Intel MKL, cxxopts (I could go on and on), -
29+
great utilities like googletest and Cmake to remove all the old-skool
30+
build and test agony...
31+
32+
C++ is really getting there. The one thing missing is a plotting
33+
library, which allows me to: - quickly and easily prototype new
34+
algorithms (visually diagnose what's wrong etc etc) - display analysis
35+
results on the web - produce the same figures on different platforms -
36+
save publication quality figures easily
37+
38+
In all the other languages I use, I now use ``plotly`` to do those
39+
things. So now it's here for C++ too.
40+
41+
42+
.. _about_plotly:
43+
44+
About Plotly
45+
============
46+
47+
**cpplot** is based on the plot.ly json schema for figures and charts.
48+
49+
Plotly figure json schema
50+
-------------------------
51+
52+
At the core of plotly is a set of open specifications for JSON data
53+
which can be rendered into various figure types. The plotly team
54+
have hung a lot of services and offerings around it,
55+
but basically everything boils down to a `json schema <https://plotly.com/chart-studio-help/json-chart-schema/>__`.
56+
57+
**cpplot** helps generate JSON which is compliant with that schema.
58+
59+
Plotly Offline
60+
--------------
61+
62+
``Plotly.js`` is an excellent javascript library for rendering figures, which can
63+
be used offline or in any third party app. This is what's used by the browser viewer.
64+
65+
Plotly Online
66+
-------------
67+
68+
Plot.ly have a range of online services, and anything produced by **cpplot** will be
69+
importable there, since it's compliant with their schema.
70+
71+
I'm not a marketing person for plotly, so how to do that is out of scope here (check their docs)!!
72+
73+
I have a branch that has some code using the Plotly API,
74+
which might be the very early beginning of a client SDK for C++,
75+
enabling direct manipulation of online data. However, I have very little
76+
appetite for this (I personally don't use plotly online, because I've
77+
found the support to be appalling in the past) but collaborators
78+
committed to developing and maintaining that would be welcome. File an issue if you're interested.
79+
80+

0 commit comments

Comments
 (0)