Skip to content

Commit

Permalink
factorise axis generation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicgirault committed Mar 12, 2017
1 parent 7c1e6cd commit db2f4a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
23 changes: 11 additions & 12 deletions src/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ import reduce from 'lodash/reduce'
import {arc} from 'd3-shape'
import logger from './logger'

const _buildAxisDta = (value, axesGroup, conf) => {
return {
value: value,
thickness: axesGroup.thickness || 1,
color: axesGroup.color || '#d3d3d3',
opacity: axesGroup.opacity || conf.opacity
}
}

const _buildAxesData = (conf) => {
return reduce(conf.axes, (aggregator, axesGroup) => {
if (!axesGroup.position && !axesGroup.spacing) {
logger.warn('Skipping axe group with no position and spacing defined')
return aggregator
}
if (axesGroup.position) {
aggregator.push({
value: axesGroup.position,
thickness: axesGroup.thickness || 1,
color: axesGroup.color || '#d3d3d3',
opacity: axesGroup.opacity || conf.opacity
})
aggregator.push(_buildAxisDta(axesGroup.position, axesGroup, conf))
}
if (axesGroup.spacing) {
const builtAxes = range(
Expand All @@ -24,12 +28,7 @@ const _buildAxesData = (conf) => {
axesGroup.spacing
)
.map((value) => {
return {
value: value,
thickness: axesGroup.thickness || 1,
color: axesGroup.color || '#d3d3d3',
opacity: axesGroup.opacity || conf.opacity
}
return _buildAxisDta(value, axesGroup, conf)
})
return aggregator.concat(builtAxes)
}
Expand Down
5 changes: 3 additions & 2 deletions src/axes.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { describe, it } from 'mocha'
import { expect, use } from 'chai'
import chai from 'chai'
import { spy } from 'sinon'
import sinonChai from 'sinon-chai'
import forEach from 'lodash/forEach'
import { _buildAxesData } from './axes'

use(sinonChai)
const expect = chai.expect
chai.use(sinonChai)

describe('Axes', () => {
it('should log an warning if no position and spacing are defined', () => {
Expand Down

0 comments on commit db2f4a1

Please sign in to comment.