Skip to content

Commit

Permalink
fix(api): fix api mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte authored and Raphaël Benitte committed Apr 17, 2019
1 parent de3e8b3 commit 80b281c
Show file tree
Hide file tree
Showing 34 changed files with 277 additions and 148 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ define clean-source-all
rm -rf $(1)/*/package-lock.json
endef

lint: ##@0 run eslint & tslint
@$(MAKE) packages-lint
@$(MAKE) packages-tslint

########################################################################################################################
#
# PACKAGES
Expand Down
14 changes: 6 additions & 8 deletions api/src/mapping/bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
const Joi = require('joi')
const { Bar } = require('@nivo/bar')
const common = require('./common')
const { dimensions } = require('./commons/dimensions')
const { inheritedColor, ordinalColors } = require('./commons/colors')

module.exports = {
component: Bar,
schema: Joi.object().keys(
Object.assign({}, common.dimensions, common.axes, {
// data
Object.assign({}, dimensions, common.axes, {
data: Joi.array()
.min(1)
.required(),
Expand All @@ -42,22 +43,19 @@ module.exports = {

borderRadius: Joi.number().min(0),
borderWidth: Joi.number().min(0),
borderColor: Joi.string(),
borderColor: inheritedColor,

// grid
enableGridX: Joi.boolean(),
enableGridY: Joi.boolean(),

// labels
enableLabel: Joi.boolean(),
label: Joi.string(),
labelSkipWidth: Joi.number(),
labelSkipHeight: Joi.number(),
labelLinkColor: Joi.string(),
labelTextColor: Joi.string(),
labelTextColor: inheritedColor,

// theming
colors: Joi.string(),
colors: ordinalColors,
colorBy: Joi.string(),
})
),
Expand Down
12 changes: 6 additions & 6 deletions api/src/mapping/bubble.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@

const Joi = require('joi')
const { Bubble } = require('@nivo/circle-packing')
const common = require('./common')
const { dimensions } = require('./commons/dimensions')
const { inheritedColor, ordinalColors } = require('./commons/colors')

module.exports = {
component: Bubble,
schema: Joi.object().keys(
Object.assign({}, common.dimensions, {
Object.assign({}, dimensions, {
root: Joi.object().required(),
identity: Joi.string().required(),
value: Joi.string().required(),
padding: Joi.number(),
leavesOnly: Joi.boolean(),
borderWidth: Joi.number(),
borderColor: Joi.string(),
borderColor: inheritedColor,
enableLabel: Joi.boolean(),
label: Joi.string(),
labelFormat: Joi.string(),
labelTextColor: Joi.string(),
labelTextColor: inheritedColor,
labelTextDY: Joi.number(),
labelSkipRadius: Joi.number(),

// theming
colors: Joi.string(),
colors: ordinalColors,
colorBy: Joi.string(),
})
),
Expand Down
4 changes: 2 additions & 2 deletions api/src/mapping/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

const Joi = require('joi')
const { Calendar } = require('@nivo/calendar')
const common = require('./common')
const { dimensions } = require('./commons/dimensions')

module.exports = {
component: Calendar,
schema: Joi.object().keys(
Object.assign({}, common.dimensions, {
Object.assign({}, dimensions, {
from: Joi.string().required(),
to: Joi.string().required(),
data: Joi.array()
Expand Down
15 changes: 7 additions & 8 deletions api/src/mapping/chord.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

const Joi = require('joi')
const { Chord } = require('@nivo/chord')
const common = require('./common')
const { ordinalColors, inheritedColor } = require('./commons/colors')
const { dimensions } = require('./commons/dimensions')

module.exports = {
component: Chord,
schema: Joi.object().keys(
Object.assign({}, common.dimensions, {
Object.assign({}, dimensions, {
matrix: Joi.array().required(),
keys: Joi.array().required(),

Expand All @@ -31,23 +32,21 @@ module.exports = {
.min(0)
.max(1),
ribbonBorderWidth: Joi.number().min(0),
ribbonBorderColor: Joi.string(),
ribbonBorderColor: inheritedColor,

arcOpacity: Joi.number()
.min(0)
.max(1),
arcBorderWidth: Joi.number().min(0),
arcBorderColor: Joi.string(),
arcBorderColor: inheritedColor,

// labels
enableLabel: Joi.boolean(),
label: Joi.string(),
labelOffset: Joi.number(),
labelRotation: Joi.number(),
labelTextColor: Joi.string(),
labelTextColor: inheritedColor,

// theming
colors: Joi.string(),
colors: ordinalColors,
colorBy: Joi.string(),
})
),
Expand Down
34 changes: 0 additions & 34 deletions api/src/mapping/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,6 @@

const Joi = require('joi')

exports.dimensions = {
width: Joi.number()
.integer()
.required(),
height: Joi.number()
.integer()
.required(),
margin: Joi.object().keys({
top: Joi.number().integer(),
right: Joi.number().integer(),
bottom: Joi.number().integer(),
left: Joi.number().integer(),
}),
}

exports.axis = Joi.object()
.keys({
orient: Joi.any().valid('top', 'right', 'bottom', 'left'),
Expand Down Expand Up @@ -64,22 +49,3 @@ exports.blendMode = Joi.valid([
'color',
'luminosity',
])

exports.linearScale = Joi.object().keys({
type: Joi.valid('linear').required(),
min: Joi.alternatives().try(Joi.valid('auto'), Joi.number()),
max: Joi.alternatives().try(Joi.valid('auto'), Joi.number()),
stacked: Joi.boolean(),
})

exports.pointScale = Joi.object().keys({
type: Joi.valid('point').required(),
})

exports.timeScale = Joi.object().keys({
type: Joi.valid('time').required(),
format: Joi.string().required(),
precision: Joi.string().required(),
})

exports.scale = Joi.alternatives().try(exports.linearScale, exports.pointScale, exports.timeScale)
34 changes: 34 additions & 0 deletions api/src/mapping/commons/colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* This file is part of the nivo project.
*
* (c) 2016-today 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 Joi = require('joi')
const { colorSchemeIds } = require('@nivo/colors')

exports.ordinalColors = Joi.alternatives().try(
Joi.array().items(Joi.string()),
Joi.object().keys({
scheme: Joi.valid(...colorSchemeIds).required(),
size: Joi.number(),
}),
Joi.object().keys({
datum: Joi.string().required(),
})
)

exports.inheritedColor = Joi.alternatives().try(
Joi.string(),
Joi.object().keys({
theme: Joi.string().required(),
}),
Joi.object().keys({
from: Joi.string().required(),
modifiers: Joi.array(),
})
)
26 changes: 26 additions & 0 deletions api/src/mapping/commons/dimensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* This file is part of the nivo project.
*
* (c) 2016-today 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 Joi = require('joi')

exports.dimensions = {
width: Joi.number()
.integer()
.required(),
height: Joi.number()
.integer()
.required(),
margin: Joi.object().keys({
top: Joi.number().integer(),
right: Joi.number().integer(),
bottom: Joi.number().integer(),
left: Joi.number().integer(),
}),
}
30 changes: 30 additions & 0 deletions api/src/mapping/commons/scales.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file is part of the nivo project.
*
* (c) 2016-today 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 Joi = require('joi')

exports.linearScale = Joi.object().keys({
type: Joi.valid('linear').required(),
min: Joi.alternatives().try(Joi.valid('auto'), Joi.number()),
max: Joi.alternatives().try(Joi.valid('auto'), Joi.number()),
stacked: Joi.boolean(),
})

exports.pointScale = Joi.object().keys({
type: Joi.valid('point').required(),
})

exports.timeScale = Joi.object().keys({
type: Joi.valid('time').required(),
format: Joi.string().required(),
precision: Joi.string().required(),
})

exports.scale = Joi.alternatives().try(exports.linearScale, exports.pointScale, exports.timeScale)
13 changes: 5 additions & 8 deletions api/src/mapping/heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@

const Joi = require('joi')
const { HeatMap } = require('@nivo/heatmap')
const { dimensions } = require('./commons/dimensions')
const { inheritedColor } = require('./commons/colors')
const common = require('./common')

module.exports = {
component: HeatMap,
schema: Joi.object().keys(
Object.assign({}, common.dimensions, common.axes, {
// data
Object.assign({}, dimensions, common.axes, {
data: Joi.array()
.min(1)
.required(),
Expand All @@ -40,23 +41,19 @@ module.exports = {
.max(1),
padding: Joi.number(),

// cells
cellShape: Joi.any().valid(['rect', 'circle']),
cellOpacity: Joi.number()
.min(0)
.max(1),
cellBorderWidth: Joi.number().min(0),
cellBorderColor: Joi.string(),
cellBorderColor: inheritedColor,

// grid
enableGridX: Joi.boolean(),
enableGridY: Joi.boolean(),

// labels
enableLabels: Joi.boolean(),
labelTextColor: Joi.string(),
labelTextColor: inheritedColor,

// theming
colors: Joi.string(),
})
),
Expand Down
20 changes: 9 additions & 11 deletions api/src/mapping/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
const Joi = require('joi')
const { Line } = require('@nivo/line')
const { curvePropKeys } = require('@nivo/core')
const { scale } = require('./commons/scales')
const { ordinalColors, inheritedColor } = require('./commons/colors')
const { dimensions } = require('./commons/dimensions')
const common = require('./common')

module.exports = {
component: Line,
schema: Joi.object().keys(
Object.assign({}, common.dimensions, common.axes, {
Object.assign({}, dimensions, common.axes, {
data: Joi.array()
.items(
Joi.object()
Expand All @@ -43,34 +46,30 @@ module.exports = {
.min(1)
.required(),

xScale: common.scale,
yScale: common.scale,
xScale: scale,
yScale: scale,

curve: Joi.any().valid(curvePropKeys),

// grid
enableGridX: Joi.boolean(),
enableGridY: Joi.boolean(),

lineWidth: Joi.number().min(0),

// dots
enableDots: Joi.boolean(),
dotSize: Joi.number().min(0),
dotColor: Joi.string(),
dotColor: inheritedColor,
dotBorderWidth: Joi.number().min(0),
dotBorderColor: Joi.string(),
dotBorderColor: inheritedColor,
enableDotLabel: Joi.boolean(),
dotLabel: Joi.string(),
dotLabelYOffset: Joi.number(),

// areas
enableArea: Joi.boolean(),
areaBlendMode: common.blendMode,
areaBaselineValue: Joi.alternatives().try(Joi.string(), Joi.number()),
areaOpacity: Joi.number(),

// markers
markers: Joi.array().items(
Joi.object().keys({
axis: Joi.any()
Expand All @@ -83,8 +82,7 @@ module.exports = {
})
),

// theming
colors: Joi.string(),
colors: ordinalColors,
colorBy: Joi.string(),
})
),
Expand Down
Loading

0 comments on commit 80b281c

Please sign in to comment.