Skip to content

Commit

Permalink
rng -> randomNumberGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
ownadi committed Mar 14, 2019
1 parent 23e83ce commit 2ec4ffe
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ const SimpleCloud = () => (

| Option | Type | Required | Note |
|-----------|----------|--------|---|
|`tags` |`Array` |`true`|Array of objects representing tags (see [Tag object](#tag-object))|
|`maxSize` |`Number` |`true` |Maximal font size (px) used in cloud|
|`minSize` |`Number` |`true` |Minimal font size (px) used in cloud|
|`shuffle` |`Boolean` |`false`|If true, tags are shuffled. When `tags` are modified, cloud is re-shuffled. Default: `true`|
|`rng` |`Function`|`false`|Specifies a custom random number generator. Default: `Math.random`
|`colorOptions` |`Object` |`false`|Random color options (see [randomColor#options](https://github.com/davidmerfield/randomColor#options))|
|`disableRandomColor`|`Boolean` |`false`|If `true`, random color is not used|
|`renderer` |`Function`|`false`|Function used to render each tag|
|`tags` |`Array` |`true`|Array of objects representing tags (see [Tag object](#tag-object))|
|`maxSize` |`Number` |`true` |Maximal font size (px) used in cloud|
|`minSize` |`Number` |`true` |Minimal font size (px) used in cloud|
|`shuffle` |`Boolean` |`false`|If true, tags are shuffled. When `tags` are modified, cloud is re-shuffled. Default: `true`|
|`randomNumberGenerator`|`Function`|`false`|Specifies a custom random number generator that is being used by shuffle algorithm. Default: `Math.random`
|`colorOptions` |`Object` |`false`|Random color options (see [randomColor#options](https://github.com/davidmerfield/randomColor#options))|
|`disableRandomColor` |`Boolean` |`false`|If `true`, random color is not used|
|`renderer` |`Function`|`false`|Function used to render each tag|

*Note:* Furthermore you can pass any other option and it will be passed forward to the wrapping `<div />` component (e.g. `style`, `className`).

Expand Down
2 changes: 1 addition & 1 deletion __tests__/TagCloud-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('TagCloud', () => {
it('should use custom rng', () => {
const rng = jest.fn();
TestUtils.renderIntoDocument(
<TagCloud minSize={12} maxSize={30} tags={data} shuffle={true} rng={rng} />
<TagCloud minSize={12} maxSize={30} tags={data} shuffle={true} randomNumberGenerator={rng} />
);

expect(rng).toHaveBeenCalled();
Expand Down
2 changes: 1 addition & 1 deletion examples/src/shuffle-with-seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ export default () => (
<TagCloud minSize={12}
maxSize={35}
tags={data}
rng={random} />
randomNumberGenerator={random} />
);

8 changes: 4 additions & 4 deletions lib/TagCloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var eventHandlers = ['onClick', 'onDoubleClick', 'onMouseMove'];
var cloudProps = ['tags', 'shuffle', 'renderer', 'maxSize', 'minSize', 'colorOptions', 'disableRandomColor', 'rng'];
var cloudProps = ['tags', 'shuffle', 'renderer', 'maxSize', 'minSize', 'colorOptions', 'disableRandomColor', 'randomNumberGenerator'];

var generateColor = function generateColor(tag, _ref) {
var disableRandomColor = _ref.disableRandomColor,
Expand Down Expand Up @@ -117,7 +117,7 @@ var TagCloud = exports.TagCloud = function (_React$Component) {
shuffle = props.shuffle,
minSize = props.minSize,
maxSize = props.maxSize,
rng = props.rng;
randomNumberGenerator = props.randomNumberGenerator;

var counts = tags.map(function (tag) {
return tag.count;
Expand All @@ -131,7 +131,7 @@ var TagCloud = exports.TagCloud = function (_React$Component) {
fontSize: (0, _helpers.fontSizeConverter)(tag.count, min, max, minSize, maxSize)
};
});
this._data = shuffle ? (0, _shuffleArray2.default)(data, { copy: true, rng: rng }) : data;
this._data = shuffle ? (0, _shuffleArray2.default)(data, { copy: true, rng: randomNumberGenerator }) : data;
}
}]);

Expand All @@ -147,7 +147,7 @@ TagCloud.propTypes = {
disableRandomColor: _propTypes2.default.bool,
renderer: _propTypes2.default.func,
className: _propTypes2.default.string,
rng: _propTypes2.default.func
randomNumberGenerator: _propTypes2.default.func
};

TagCloud.defaultProps = {
Expand Down
8 changes: 4 additions & 4 deletions src/TagCloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import randomColor from 'randomcolor';
import { omitProps, includeProps, fontSizeConverter, arraysEqual, propertiesEqual } from './helpers';

const eventHandlers = ['onClick', 'onDoubleClick', 'onMouseMove'];
const cloudProps = ['tags', 'shuffle', 'renderer', 'maxSize', 'minSize', 'colorOptions', 'disableRandomColor', 'rng'];
const cloudProps = ['tags', 'shuffle', 'renderer', 'maxSize', 'minSize', 'colorOptions', 'disableRandomColor', 'randomNumberGenerator'];

const generateColor = (tag, {disableRandomColor, colorOptions}) => {
if (tag.color) {
Expand Down Expand Up @@ -59,7 +59,7 @@ export class TagCloud extends React.Component {
}

_populate(props) {
const { tags, shuffle, minSize, maxSize, rng } = props;
const { tags, shuffle, minSize, maxSize, randomNumberGenerator } = props;
const counts = tags.map(tag => tag.count),
min = Math.min(...counts),
max = Math.max(...counts);
Expand All @@ -68,7 +68,7 @@ export class TagCloud extends React.Component {
color: generateColor(tag, props),
fontSize: fontSizeConverter(tag.count, min, max, minSize, maxSize)
}));
this._data = shuffle ? arrayShuffle(data, { copy: true, rng: rng }) : data;
this._data = shuffle ? arrayShuffle(data, { copy: true, rng: randomNumberGenerator }) : data;
}

}
Expand All @@ -82,7 +82,7 @@ TagCloud.propTypes = {
disableRandomColor: PropTypes.bool,
renderer: PropTypes.func,
className: PropTypes.string,
rng: PropTypes.func,
randomNumberGenerator: PropTypes.func,
};

TagCloud.defaultProps = {
Expand Down

0 comments on commit 2ec4ffe

Please sign in to comment.