# Lavizu: web-based visualisation for robots

## Table of contents

- [Lavizu: web-based visualisation for robots](#lavizu-web-based-visualisation-for-robots)
  - [Table of contents](#table-of-contents)
  - [Purpose](#purpose)
  - [Dependencies](#dependencies)
  - [D3 integration with React](#d3-integration-with-react)
  - [Create a new widget type](#create-a-new-widget-type)
  - [Run in test environment](#run-in-test-environment)
  - [Available Javascript Scripts](#available-javascript-scripts)
    - [`npm start`](#npm-start)
    - [`npm test`](#npm-test)
    - [`npm run build`](#npm-run-build)
    - [`npm run eject`](#npm-run-eject)
  - [Reading material](#reading-material)
    - [Refreshing your memory on Javascript](#refreshing-your-memory-on-javascript)
    - [Some reading on SVG](#some-reading-on-svg)
    - [About D3 and React](#about-d3-and-react)
  - [Sizing of the Widgets](#sizing-of-the-widgets)

## Purpose

Lavizu is a graphical user interface for [ROS][]-based systems. IT aims at letting you easily build custom user interface components for your own needs, using the many libraries and tools available for the web, such as [D3][] and SVG for visualisation. 

[ROS]: http://www.ros.org/

## Dependencies

- NodeJS (for compilation)
- NPM or YARN (for the dependency managment)

## D3 integration with React

We experimented on how to make charts and diagrams that exploit the power of [D3][] but within the context of [React][]. The challenge resides in both libraries wanting to modify the [DOM][] (basically, the web page) at the same time.

As an illustration of this experiment, you can compare a pure D3 line chart and a version integrated in React. To do so, install the dependencies of this repository, open a terminal and change directory to this folder. Then, type `npm start` (or `yarn start`, if you have Yarn). This will open a web page containing a few "tabs" or widgets, among which a line chart. This is the React integrated version of the line chart. To view the pure D3 version, go to [http://localhost:3000/LineChart.html](http://localhost:3000/LineChart.html).

Now, the main interest of these two versions, is to see how they are implemented. The code for the former is in the folder `src/LineChart`, whereas for the latter it lies in `public/LineChart.html`.

[D3]: http://d3js.org/
[React]: http://reactjs.org/
[DOM]: https://en.wikipedia.org/wiki/Document_Object_Model

## Create a new widget type

Lavizu has little value as a general purpose ROS tool, compared to the feature-rich [rqt][https://wiki.ros.org/rqt]. Actually, we do not intend to make a contender to rqt nor reinvent too many kinds of wheels. Conversely, Lavizu is meant to ease the creation of custom visualisation and user interface, thanks to the web technologies.

## Run in test environment

We recorded a learning session so that the visualisation tool can be tested alone. To replay this learning session in a loop, run the following commend _form this repository's folder_:

```
rosbag play --clock --loop test-data/rd-dai-1.bag
```

## Available Javascript Scripts

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.<br>
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br>
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.<br>
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.<br>
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br>
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Reading material

### Refreshing your memory on Javascript

[A re-introduction to Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript) (Mozilla Developper Network)

### Some reading on SVG

[An SVG Primer for Today's Browsers](https://www.w3.org/Graphics/SVG/IG/resources/svgprimer.html)

### About D3 and React

- [Silky smooth Piechart transitions with React and D3.js](https://swizec.com/blog/silky-smooth-piechart-transitions-react-d3js/swizec/8258) is key to the question of integration of D3 charts in React. It also mentions a $50 book that just discusses this matter
- [How (and why) to use D3 with React](https://hackernoon.com/how-and-why-to-use-d3-with-react-d239eb1ea274) is more generic, on how to use D3 and React. It also lists the D3 modules that want to affect the DOM (just 8/30).
- [https://github.com/joelburget/d4](https://github.com/joelburget/d4) also copes with animations and goes further with the idea that React might as well do most of the job

## Sizing of the Widgets

Some of the widgets might have a prefered size, in which case we should make Flex Layout aware of it. [Documentation on prefered size](https://github.com/caplin/FlexLayout#tabset-attributes).

Some other widgets might adapt to the available space and take it all. [Determining the dimensiosn of elements](https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Determining_the_dimensions_of_elements).

Other links:

- https://medium.com/@caspg/responsive-chart-with-react-and-d3v4-afd717e57583
- https://blog.webkid.io/responsive-chart-usability-d3/
- https://tympanus.net/codrops/2014/08/19/making-svgs-responsive-with-css/