-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ignores): fix git ignore misconfiguration
- Loading branch information
Raphael Benitte
committed
Apr 22, 2016
1 parent
45d318c
commit 41e278a
Showing
3 changed files
with
164 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ logs | |
*.log | ||
node_modules | ||
.idea | ||
lib | ||
/lib | ||
npm-debug.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import d3 from 'd3'; | ||
import { degreesToRadians, midAngle, findNeighbor } from '../../../ArcUtils'; | ||
import { getColorRange } from '../../../ColorUtils'; | ||
|
||
|
||
const PieD3Svg = domRoot => { | ||
|
||
// DOM elements | ||
const element = d3.select(domRoot); | ||
const outline = element.append('path').attr('class', 'nivo_pie_outline'); | ||
const slices = element.append('g').attr('class', 'nivo_pie_slices'); | ||
|
||
// d3 generators | ||
const pie = d3.layout.pie(); | ||
const arc = d3.svg.arc(); | ||
|
||
// used to store previous state for smart transitions | ||
let previousData = []; | ||
|
||
// an array to store decorator functions | ||
let decorators = []; | ||
|
||
return { | ||
draw(props) { | ||
const { | ||
data, | ||
width, height, | ||
sort, | ||
keyProp, valueProp, | ||
startAngle, endAngle, padAngle, | ||
colors, | ||
innerRadius, | ||
transitionDuration, transitionEasing | ||
} = props; | ||
|
||
const identity = d => d.data[keyProp]; | ||
const color = getColorRange(colors); | ||
|
||
element.attr('transform', `translate(${width / 2}, ${height / 2})`); | ||
|
||
pie | ||
.sort(sort) | ||
.value(d => d[valueProp]) | ||
.startAngle(degreesToRadians(startAngle)) | ||
.endAngle(degreesToRadians(endAngle)) | ||
.padAngle(degreesToRadians(padAngle)) | ||
; | ||
|
||
let radius = Math.min(width / 2, height / 2); | ||
|
||
arc | ||
.outerRadius(radius) | ||
.innerRadius(radius * innerRadius) | ||
; | ||
|
||
outline.attr('d', arc({ | ||
startAngle: degreesToRadians(startAngle), | ||
endAngle: degreesToRadians(endAngle) | ||
})); | ||
|
||
let slice = slices.selectAll('.nivo_pie_slice'); | ||
|
||
const newData = pie(data.map((d, i) => { | ||
if (!d.color) { | ||
d.color = color(i); | ||
} | ||
|
||
return d; | ||
})); | ||
|
||
//console.log(_.cloneDeep(newData)); | ||
|
||
function arcTween(a) { | ||
const i = d3.interpolate(this._current, a); | ||
this._current = i(0); | ||
|
||
return t => arc(i(t)); | ||
} | ||
|
||
slice = slice.data(newData, identity); | ||
|
||
// ————————————————————————————————————————————————————————————————————————————————————————————————————————— | ||
// ENTER: creates new elements | ||
// ————————————————————————————————————————————————————————————————————————————————————————————————————————— | ||
slice.enter().append('path') | ||
.attr('class', 'nivo_pie_slice') | ||
.style('fill', d => d.data.color) | ||
.each(function (d, i) { | ||
const angle = midAngle(d); | ||
|
||
this._current = findNeighbor(i, identity, previousData, newData) || _.assign({}, d, { | ||
startAngle: 0, | ||
endAngle: 0 | ||
}); | ||
}) | ||
; | ||
|
||
// ————————————————————————————————————————————————————————————————————————————————————————————————————————— | ||
// UPDATE: updates existing elements | ||
// ————————————————————————————————————————————————————————————————————————————————————————————————————————— | ||
slice | ||
.transition() | ||
.duration(transitionDuration) | ||
.ease(transitionEasing) | ||
.attrTween('d', arcTween) | ||
; | ||
|
||
// ————————————————————————————————————————————————————————————————————————————————————————————————————————— | ||
// EXIT: removes stale elements | ||
// ————————————————————————————————————————————————————————————————————————————————————————————————————————— | ||
slice.exit() | ||
.attr('class', 'nivo_exit') | ||
.datum((d, i) => { | ||
return findNeighbor(i, identity, newData, previousData) || d; | ||
}) | ||
.transition() | ||
.duration(transitionDuration) | ||
.ease(transitionEasing) | ||
.attrTween('d', arcTween) | ||
.remove() | ||
; | ||
|
||
const pieContext = { | ||
element, | ||
pie, arc, radius, | ||
identity, previousData, newData, | ||
transitionDuration, transitionEasing | ||
}; | ||
|
||
decorators.forEach(legend => { | ||
legend(pieContext); | ||
}); | ||
|
||
previousData = newData; | ||
}, | ||
|
||
decorate(newDecorators = []) { | ||
decorators = newDecorators; | ||
} | ||
}; | ||
}; | ||
|
||
|
||
export default PieD3Svg; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
|
||
|
||
const decoratorsFromReactChildren = (children, type) => { | ||
const decorators = []; | ||
|
||
React.Children.forEach(children, element => { | ||
if (React.isValidElement(element)) { | ||
if (element.type[type]) { | ||
decorators.push(element.type[type](element)); | ||
} | ||
} | ||
}); | ||
|
||
return decorators; | ||
}; | ||
|
||
|
||
export default decoratorsFromReactChildren; |