Skip to content

Commit 622b532

Browse files
committed
Tweening the arcs
1 parent 8439c6a commit 622b532

File tree

11 files changed

+93
-26
lines changed

11 files changed

+93
-26
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
"raf": "3.4.0",
157157
"react-annotation": "1.3.1",
158158
"roughjs-es5": "0.1.0",
159-
"semiotic-mark": "0.2.12",
159+
"semiotic-mark": "0.3.0",
160160
"svg-path-bounding-box": "1.0.4",
161161
"whatwg-fetch": "2.0.3"
162162
},

src/components/NetworkFrame.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@ class NetworkFrame extends React.Component<Props, State> {
14451445
}
14461446

14471447
const nodeLabelAnnotations = []
1448-
if (this.props.nodeLabels && projectedNodes) {
1448+
if (currentProps.nodeLabels && projectedNodes) {
14491449
projectedNodes.forEach((node, nodei) => {
14501450
if (nodeLabels === true || (nodeLabels && nodeLabels(node, nodei))) {
14511451
const actualLabel =

src/components/svg/SvgHelper.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,39 @@ import React from "react"
33
import { select } from "d3-selection"
44
import { arc, line, curveLinearClosed } from "d3-shape"
55
import { Mark } from "semiotic-mark"
6+
import { interpolateNumber } from "d3-interpolate"
67

78
const twoPI = Math.PI * 2
89

10+
export const arcTweener = (oldProps, newProps) => {
11+
const innerRadiusInterpolator = interpolateNumber(
12+
oldProps.innerRadius,
13+
newProps.innerRadius
14+
)
15+
const outerRadiusInterpolator = interpolateNumber(
16+
oldProps.outerRadius,
17+
newProps.outerRadius
18+
)
19+
const startAngleInterpolator = interpolateNumber(
20+
oldProps.startAngle,
21+
newProps.startAngle
22+
)
23+
const endAngleInterpolator = interpolateNumber(
24+
oldProps.endAngle,
25+
newProps.endAngle
26+
)
27+
28+
return t => {
29+
const sliceGenerator = arc()
30+
.innerRadius(innerRadiusInterpolator(t))
31+
.outerRadius(outerRadiusInterpolator(t))
32+
return sliceGenerator({
33+
startAngle: startAngleInterpolator(t),
34+
endAngle: endAngleInterpolator(t)
35+
})
36+
}
37+
}
38+
939
export const drawAreaConnector = ({
1040
x1,
1141
x2,
@@ -71,10 +101,10 @@ export const hexToRgb = hex => {
71101
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
72102
return result
73103
? [
74-
parseInt(result[1], 16),
75-
parseInt(result[2], 16),
76-
parseInt(result[3], 16)
77-
]
104+
parseInt(result[1], 16),
105+
parseInt(result[2], 16),
106+
parseInt(result[3], 16)
107+
]
78108
: [0, 0, 0]
79109
}
80110

src/components/svg/networkDrawing.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { interpolateNumber } from "d3-interpolate"
1212

1313
import { scaleLinear } from "d3-scale"
1414

15+
import { arcTweener } from "./SvgHelper"
16+
1517
function sankeyEdgeSort(a, b, direction) {
1618
if (a.circular && !b.circular) return -1
1719
if (b.circular && !a.circular) return 1
@@ -223,6 +225,15 @@ export const radialRectNodeGenerator = (size, center, type) => {
223225
startAngle: adjustedPct(d.x0 / size[0]) * Math.PI * 2,
224226
endAngle: adjustedPct(d.x1 / size[0]) * Math.PI * 2
225227
})}
228+
customTween={{
229+
fn: arcTweener,
230+
props: {
231+
startAngle: adjustedPct(d.x0 / size[0]) * Math.PI * 2,
232+
endAngle: adjustedPct(d.x1 / size[0]) * Math.PI * 2,
233+
innerRadius: d.y0 / 2,
234+
outerRadius: d.y1 / 2
235+
}
236+
}}
226237
style={styleFn(d, i)}
227238
renderMode={renderMode ? renderMode(d, i) : undefined}
228239
className={className}

src/components/svg/pieceLayouts.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { /*area, curveCatmullRom,*/ arc } from "d3-shape"
44
import pathBounds from "svg-path-bounding-box"
55
import { Mark } from "semiotic-mark"
66
import { scaleLinear } from "d3-scale"
7+
import { arcTweener } from "./SvgHelper"
78

89
const twoPI = Math.PI * 2
910

@@ -72,7 +73,6 @@ const radialBarFeatureGenerator = ({
7273
: Math.max(startAngle, startAngle + angle - ordset.pct_padding / 2)
7374

7475
const startAngleFinal = startAngle * twoPI
75-
7676
const endAngleFinal = endAngle * twoPI
7777

7878
const markD = arcGenerator({
@@ -115,7 +115,16 @@ const radialBarFeatureGenerator = ({
115115
d: markD,
116116
tx: xOffset,
117117
ty: yOffset,
118-
transform: translate
118+
transform: translate,
119+
customTween: {
120+
fn: arcTweener,
121+
props: {
122+
startAngle: startAngleFinal,
123+
endAngle: endAngleFinal,
124+
innerRadius: innerSize,
125+
outerRadius: outerSize
126+
}
127+
}
119128
}
120129
}
121130
}

src/docs/components/DonutChart.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ export default class PieDonutDocs extends React.Component {
7575
{paddingOptions}
7676
</Select>
7777
</FormControl>
78+
</div>,
79+
<div key="button-3">
80+
<button
81+
onClick={() => this.setState({ changeData: !this.state.changeData })}
82+
>
83+
Change Data
84+
</button>
7885
</div>
7986
]
8087

src/docs/components/DonutChartRaw.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import ProcessViz from "./ProcessViz"
44

55
const colors = ["#00a2ce", "#4d430c", "#b3331d", "#b6a756"]
66
const data = [5, 8, 10, 15]
7+
const data2 = [15, 8, 5, 10]
78

89
export default state => {
910
const donutSettings = {
1011
size: [400, 400],
11-
data: data,
12+
data: state.changeData ? data2 : data,
1213
projection: "radial",
1314
style: (d, i) => ({
1415
fill: colors[i],

src/docs/components/Sunburst.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
1-
import React from 'react'
2-
import DocumentComponent from '../layout/DocumentComponent'
3-
import SunburstRaw from './SunburstRaw'
4-
1+
import React from "react"
2+
import DocumentComponent from "../layout/DocumentComponent"
3+
import SunburstRaw from "./SunburstRaw"
54
const components = []
65

76
components.push({
8-
name: 'Sunburst'
7+
name: "Sunburst"
98
})
109

1110
export default class Sunburst extends React.Component {
1211
constructor(props) {
1312
super(props)
1413

1514
this.state = {
16-
type: 'partition',
17-
projection: 'radial'
15+
type: "partition",
16+
projection: "radial"
1817
}
1918
}
2019
render() {
21-
const buttons = []
20+
const buttons = [
21+
<button
22+
key="button"
23+
onClick={() => this.setState({ zoom: !this.state.zoom })}
24+
>
25+
Zoom
26+
</button>
27+
]
2228

2329
const examples = []
2430

2531
examples.push({
26-
name: 'Basic',
27-
demo: SunburstRaw,
32+
name: "Basic",
33+
demo: SunburstRaw(this.state.zoom),
2834
source: `
2935
const data = {
3036
name: "flare",
@@ -88,4 +94,4 @@ export default class Sunburst extends React.Component {
8894
}
8995
}
9096

91-
Sunburst.title = 'Sunburst'
97+
Sunburst.title = "Sunburst"

src/docs/components/SunburstRaw.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ const sunburstSettings = {
4444
margin: 10,
4545
filterRenderedNodes: d => d.depth !== 0
4646
}
47-
export default (
47+
export default zoom => (
4848
<div>
4949
<ProcessViz frameSettings={sunburstSettings} frameType="NetworkFrame" />
50-
<NetworkFrame {...sunburstSettings} />
50+
<NetworkFrame
51+
{...sunburstSettings}
52+
edges={zoom ? { name: "flare", children: [data.children[9]] } : data}
53+
/>
5154
</div>
5255
)

0 commit comments

Comments
 (0)