Skip to content

Commit

Permalink
feat(api): move api to main nivo repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte authored and Raphaël Benitte committed Nov 30, 2018
1 parent 07b1bad commit 5024596
Show file tree
Hide file tree
Showing 81 changed files with 2,709 additions and 24 deletions.
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Contributing

- [requirements](#requirements)
- [setup](#setup)
- [development](#development)
- [formatting](#formatting)
Expand All @@ -8,6 +9,12 @@
- [website](#website)
- [deploy](#deploy)

## Requirements

- **Node.js**
- **yarn**
- **Make** (you also have the option to run the commands manually though)

## Setup

Nivo is structured into multiple packages handled by [lerna](https://lernajs.io/).
Expand Down
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fmt: ##@0 global format code using prettier (js, css, md)
"packages/*/README.md" \
"website/src/**/*.{js,css}" \
"examples/*/src/**/*.{js,ts,tsx,css}" \
"api/**/*.{js,ts,tsx}" \
"README.md"

fmt-check: ##@0 global check if files were all formatted using prettier
Expand All @@ -69,6 +70,7 @@ fmt-check: ##@0 global check if files were all formatted using prettier
"packages/*/README.md" \
"website/src/**/*.{js,css}" \
"examples/*/src/**/*.{js,ts,tsx,css}" \
"api/**/*.{js,ts,tsx}" \
"README.md"

test-all: ##@0 global run all checks/tests (packages, website & examples)
Expand Down Expand Up @@ -208,6 +210,9 @@ website-install: ##@2 website install website dependencies
@echo "${YELLOW}Installing website dependencies${RESET}"
@cd website && yarn install

website-deps-up: ##@2 website interactive upgrade of website's dependencies
@yarn upgrade-interactive --latest

website: ##@2 website start website in dev mode
@echo "${YELLOW}Starting website dev server${RESET}"
@cd website && yarn start
Expand Down Expand Up @@ -273,6 +278,9 @@ example-install-%: ##@4 examples install example dependencies, eg. example-insta
@echo "${YELLOW}Installing ${WHITE}${*}${YELLOW} example dependencies${RESET}"
@cd examples/${*} && yarn install

example-deps-up-%: ##@4 examples interactive upgrade of example's dependencies
@cd examples/${*} && yarn upgrade-interactive --latest

example-start-%: ##@4 examples start example in dev mode, eg. example-start-retro
@echo "${YELLOW}Starting ${WHITE}${*}${YELLOW} example dev server${RESET}"
@cd examples/${*} && yarn start
Expand All @@ -284,3 +292,18 @@ examples-build: ##@4 examples build all examples
example-build-%: ##@4 examples build an example, eg. example-build-retro
@echo "${YELLOW}Building ${WHITE}${*}${YELLOW} example${RESET}"
@cd examples/${*} && yarn build

########################################################################################################################
#
# API
#
########################################################################################################################

api-dev: ##@5 API run API in dev mode (watcher)
@echo "${YELLOW}Starting API in dev mode${RESET}"
@cd api && yarn dev

api: ##@5 API run API in regular mode (no watcher)
@echo "${YELLOW}Starting API${RESET}"
@cd api && yarn start

19 changes: 19 additions & 0 deletions api/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) Raphaël Benitte

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions api/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node src/app.js
66 changes: 66 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# nivo-api

Rendering API for [nivo](https://github.com/plouc/nivo) dataviz React/d3 components.

A [demo](https://nivo-api.herokuapp.com/) is available on heroku, but may not respond depending on usage.

## How it works

The API expose some of the [nivo](https://github.com/plouc/nivo) charts by using
[React server side environment](https://facebook.github.io/react/docs/environments.html).

First you will have to make a post request on the desired endpoint, for example:

```sh
curl -X POST \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
-d '{ "width": 500, "height": 500, "data": [[223, 299, 345, 184], [123, 248, 65, 123], [412, 76, 187, 312], [97, 37, 502, 176]]}' \
'http://localhost:3030/charts/chord'

{
"id": "73633fea-160e-4118-a534-377c3ed85254",
"url": "http://localhost:3000/r/73633fea-160e-4118-a534-377c3ed85254"
}
```

The response contains a link to the chart

```
GET http://localhost:3000/r/73633fea-160e-4118-a534-377c3ed85254
```

## Charts endpoints

```
POST /charts/bar
POST /charts/bubble
POST /charts/calendar
POST /charts/chord
POST /charts/line
POST /charts/pie
POST /charts/radar
POST /charts/sankey
POST /charts/sunburst
POST /charts/treemap
```

## Charts samples

- https://nivo-api.herokuapp.com/samples/line.svg
- https://nivo-api.herokuapp.com/samples/bar.svg
- https://nivo-api.herokuapp.com/samples/bubble.svg
- https://nivo-api.herokuapp.com/samples/chord.svg
- https://nivo-api.herokuapp.com/samples/pie.svg
- https://nivo-api.herokuapp.com/samples/radar.svg
- https://nivo-api.herokuapp.com/samples/sankey.svg
- https://nivo-api.herokuapp.com/samples/sunburst.svg
- https://nivo-api.herokuapp.com/samples/treemap.svg

## Repositories

- [nivo](https://github.com/plouc/nivo) - the nivo library
- [nivo-api](https://github.com/plouc/nivo-api) - the nivo http api
- [nivo-api-docker](https://github.com/plouc/nivo-api-docker) - a Docker image for the nivo http api
- [nivo-generators](https://github.com/plouc/nivo-generators) - the data generators used for nivo-website and http API samples
- [nivo-website](https://github.com/plouc/nivo-website) - the source for the nivo website
53 changes: 53 additions & 0 deletions api/misc/README.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# nivo-api

Rendering API for [nivo](https://github.com/plouc/nivo) dataviz React/d3 components.

A [demo](https://nivo-api.herokuapp.com/) is available on heroku, but may not respond depending on usage.

## How it works

The API expose some of the [nivo](https://github.com/plouc/nivo) charts by using
[React server side environment](https://facebook.github.io/react/docs/environments.html).

First you will have to make a post request on the desired endpoint, for example:

```sh
curl -X POST \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
-d '{ "width": 500, "height": 500, "data": [[223, 299, 345, 184], [123, 248, 65, 123], [412, 76, 187, 312], [97, 37, 502, 176]]}' \
'http://localhost:3030/charts/chord'

{
"id": "73633fea-160e-4118-a534-377c3ed85254",
"url": "http://localhost:3000/r/73633fea-160e-4118-a534-377c3ed85254"
}
```

The response contains a link to the chart

```
GET http://localhost:3000/r/73633fea-160e-4118-a534-377c3ed85254
```

## Charts endpoints

```
{{#endpoints}}
POST {{{.}}}
{{/endpoints}}
```

## Charts samples

{{#samples}}
- https://nivo-api.herokuapp.com/samples/{{{.}}}.svg
{{/samples}}

## Repositories

- [nivo](https://github.com/plouc/nivo) - the nivo library
- [nivo-api](https://github.com/plouc/nivo-api) - the nivo http api
- [nivo-api-docker](https://github.com/plouc/nivo-api-docker) - a Docker image for the nivo http api
- [nivo-generators](https://github.com/plouc/nivo-generators) - the data generators used for nivo-website and http API samples
- [nivo-website](https://github.com/plouc/nivo-website) - the source for the nivo website
28 changes: 28 additions & 0 deletions api/misc/readmeData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* This file is part of the nivo project.
*
* (c) 2016 Raphaël Benitte
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
'use strict'

const _ = require('lodash')
const mapping = require('../src/mapping')
const samples = require('../src/samples')

const data = {
endpoints: [],
samples: [],
}

_.forOwn(mapping, (config, type) => {
data.endpoints.push(`/charts/${type}`)
})

_.forOwn(samples, (config, id) => {
data.samples.push(id)
})

console.log(JSON.stringify(data))
62 changes: 62 additions & 0 deletions api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "@nivo/api",
"version": "0.51.6",
"description": "Rendering API for nivo dataviz React/d3 components",
"main": "src/app.js",
"licenses": [
{
"type": "MIT",
"url": "https://github.com/plouc/nivo/blob/master/LICENSE.md"
}
],
"author": {
"name": "Raphaël Benitte",
"url": "https://github.com/plouc"
},
"engineStrict": true,
"engines": {
"node": ">=6.0.0"
},
"devDependencies": {
"mustache": "^2.3.0",
"nodemon": "^1.18.7"
},
"dependencies": {
"@nivo/bar": "0.51.6",
"@nivo/bullet": "0.51.0",
"@nivo/calendar": "0.51.0",
"@nivo/chord": "0.51.2",
"@nivo/circle-packing": "0.51.0",
"@nivo/core": "0.51.0",
"@nivo/generators": "0.51.0",
"@nivo/heatmap": "0.51.0",
"@nivo/legends": "0.51.0",
"@nivo/line": "0.51.6",
"@nivo/parallel-coordinates": "0.51.0",
"@nivo/pie": "0.51.0",
"@nivo/radar": "0.51.0",
"@nivo/sankey": "0.51.0",
"@nivo/scatterplot": "0.51.3",
"@nivo/stream": "0.51.5",
"@nivo/sunburst": "0.51.0",
"@nivo/treemap": "0.51.0",
"@nivo/voronoi": "0.51.0",
"@nivo/waffle": "0.51.0",
"body-parser": "^1.17.2",
"compression": "^1.7.0",
"cors": "^2.8.4",
"express": "^4.15.4",
"express-winston": "^2.4.0",
"joi": "^14.3.0",
"lodash": "^4.17.4",
"react": "16.2.0",
"react-dom": "16.2.0",
"uuid": "^3.1.0",
"winston": "^2.3.1"
},
"scripts": {
"readme": "node misc/readmeData.js | mustache - misc/README.mustache > README.md",
"start": "node src/app.js",
"dev": "nodemon src/app.js"
}
}
Loading

0 comments on commit 5024596

Please sign in to comment.