Skip to content

Commit 9b48c9c

Browse files
committed
Move function that gets letter rotations to util
1 parent 0783e8b commit 9b48c9c

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ circleType.radius(384);
199199
console.log(circleType.container);
200200
//=> <div style="position: relative; height: 3.18275em;">...</div>
201201

202-
// Disbale the force height option
202+
// Disable the force height option
203203
circleType.forceHeight(false);
204204

205205
console.log(circleType.container);

dist/circletype.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/class.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import radiansToDegrees from './utils/radiansToDegrees';
21
import getRect from './utils/getRect';
32
import splitNode from './utils/splitNode';
43
import sagitta from './utils/sagitta';
54
import chord from './utils/chord';
5+
import getLetterRotations from './utils/getLetterRotations';
66

77
const { PI, max, min } = Math;
88

@@ -235,7 +235,7 @@ class CircleType {
235235
* console.log(circleType.container);
236236
* //=> <div style="position: relative; height: 3.18275em;">...</div>
237237
*
238-
* // Disbale the force height option
238+
* // Disable the force height option
239239
* circleType.forceHeight(false);
240240
*
241241
* console.log(circleType.container);
@@ -314,18 +314,9 @@ class CircleType {
314314
_layout() {
315315
const { _radius, _dir } = this;
316316
const originY = _dir === -1 ? (-_radius + this._lineHeight) : _radius;
317-
318317
const origin = `center ${originY / this._fontSize}em`;
319-
320318
const innerRadius = _radius - this._lineHeight;
321-
const { rotations, θ } = this._metrics.reduce((data, { width }) => {
322-
const rotation = radiansToDegrees(width / innerRadius);
323-
324-
return {
325-
θ: data.θ + rotation,
326-
rotations: data.rotations.concat([ data.θ + (rotation / 2) ]),
327-
};
328-
}, { θ: 0, rotations: [] });
319+
const { rotations, θ } = getLetterRotations(this._metrics, innerRadius);
329320

330321
this._letters.forEach((letter, index) => {
331322
const { style } = letter;

src/utils/getLetterRotations.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import radiansToDegrees from './radiansToDegrees';
2+
3+
export default (metrics, r) => metrics.reduce((data, { width }) => {
4+
const rotation = radiansToDegrees(width / r);
5+
6+
return {
7+
θ: data.θ + rotation,
8+
rotations: data.rotations.concat([ data.θ + (rotation / 2) ]),
9+
};
10+
}, { θ: 0, rotations: [] });

0 commit comments

Comments
 (0)