Skip to content

Commit

Permalink
v0.4.2 compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
madox2 committed May 23, 2016
1 parent 3ffcd5c commit f9b4969
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 67 deletions.
61 changes: 26 additions & 35 deletions lib/TagCloud.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use strict";
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
Expand All @@ -7,20 +7,18 @@ exports.TagCloud = undefined;

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require("react");
var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _defaultRenderer = require("./defaultRenderer");
var _defaultRenderer = require('./defaultRenderer');

var _objectAssign2 = require("object-assign");

var _objectAssign3 = _interopRequireDefault(_objectAssign2);

var _arrayShuffle = require("array-shuffle");
var _arrayShuffle = require('array-shuffle');

var _arrayShuffle2 = _interopRequireDefault(_arrayShuffle);

var _helpers = require('./helpers');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Expand All @@ -29,44 +27,37 @@ 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; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

var omitted = ['tags', 'shuffle', 'renderer', 'maxSize', 'minSize', 'onClick'];
var omittedProps = omitted.reduce(function (r, k) {
return (0, _objectAssign3.default)(r, _defineProperty({}, k, undefined));
}, {});

var fontSizeConverter = function fontSizeConverter(count, min, max, minSize, maxSize) {
return Math.round((count - min) * (maxSize - minSize) / (max - min) + minSize);
};

var createTags = function createTags(_ref) {
var tags = _ref.tags;
var minSize = _ref.minSize;
var maxSize = _ref.maxSize;
var renderer = _ref.renderer;
var onClick = _ref.onClick;
var createTags = function createTags(props) {
var tags = props.tags;
var minSize = props.minSize;
var maxSize = props.maxSize;
var renderer = props.renderer;

var handlers = (0, _helpers.includeProps)(props, eventHandlers);
var counts = tags.map(function (tag) {
return tag.count;
}),
min = Math.min.apply(Math, counts),
max = Math.max.apply(Math, counts);
min = Math.min.apply(Math, _toConsumableArray(counts)),
max = Math.max.apply(Math, _toConsumableArray(counts));
var computeFontSize = function computeFontSize(tag) {
return {
tag: tag,
fontSize: fontSizeConverter(tag.count, min, max, minSize, maxSize)
fontSize: (0, _helpers.fontSizeConverter)(tag.count, min, max, minSize, maxSize)
};
};
var handlers = { onClick: onClick };
var createComponent = function createComponent(_ref2, key) {
var tag = _ref2.tag;
var fontSize = _ref2.fontSize;
var createComponent = function createComponent(_ref, key) {
var tag = _ref.tag;
var fontSize = _ref.fontSize;
return renderer(tag, fontSize, key, handlers);
};
return tags.map(computeFontSize).map(createComponent);
};

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

var TagCloud = exports.TagCloud = function (_React$Component) {
_inherits(TagCloud, _React$Component);

Expand All @@ -77,12 +68,12 @@ var TagCloud = exports.TagCloud = function (_React$Component) {
}

_createClass(TagCloud, [{
key: "render",
key: 'render',
value: function render() {
var props = (0, _objectAssign3.default)({}, this.props, omittedProps);
var props = (0, _helpers.omitProps)(this.props, [].concat(cloudProps, eventHandlers));
var tags = createTags(this.props);
return _react2.default.createElement(
"div",
'div',
props,
this.props.shuffle ? (0, _arrayShuffle2.default)(tags) : tags
);
Expand All @@ -104,5 +95,5 @@ TagCloud.propTypes = {
TagCloud.defaultProps = {
renderer: (0, _defaultRenderer.defaultRenderer)(),
shuffle: true,
className: "tag-cloud"
className: 'tag-cloud'
};
62 changes: 32 additions & 30 deletions lib/defaultRenderer.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,47 @@
"use strict";
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.defaultRenderer = undefined;

var _react = require("react");
var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _randomcolor = require("randomcolor");
var _randomcolor = require('randomcolor');

var _randomcolor2 = _interopRequireDefault(_randomcolor);

var _objectAssign = require("object-assign");
var _objectAssign = require('object-assign');

var _objectAssign2 = _interopRequireDefault(_objectAssign);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var defaultClassName = "tag-cloud-tag";

var defaultStyles = {
margin: "0px 3px",
verticalAlign: "middle",
display: "inline-block"
};

var defaultTagRenderer = function defaultTagRenderer(tag) {
return tag.value;
};

var defaultRenderer = exports.defaultRenderer = function defaultRenderer() {
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

var _ref$tagRenderer = _ref.tagRenderer;
var tagRenderer = _ref$tagRenderer === undefined ? defaultTagRenderer : _ref$tagRenderer;
var _ref$colorOptions = _ref.colorOptions;
var colorOptions = _ref$colorOptions === undefined ? {} : _ref$colorOptions;
var _ref$props = _ref.props;
var props = _ref$props === undefined ? {} : _ref$props;
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
return function (tag, size, key) {
var handlers = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];

var className = defaultClassName,
fontSize = size + "px",
color = props.disableRandomColor ? tag.color || 'black' : (0, _randomcolor2.default)(colorOptions);
var _options$tagRenderer = options.tagRenderer;
var tagRenderer = _options$tagRenderer === undefined ? function (tag) {
return tag.value;
} : _options$tagRenderer;
var _options$colorOptions = options.colorOptions;
var colorOptions = _options$colorOptions === undefined ? {} : _options$colorOptions;
var _options$disableRando = options.disableRandomColor;
var disableRandomColor = _options$disableRando === undefined ? false : _options$disableRando;
var _options$props = options.props;
var props = _options$props === undefined ? {} : _options$props;


var className = 'tag-cloud-tag';
var fontSize = size + 'px';
if (props.disableRandomColor) {
// eslint-disable-next-line no-console
console.warn("Using deprecated property 'disableRandomColor' passed to prop option of defaultRenderer. " + "It will be removed in the next major release and replaced with it's own option 'disableRandomColor'.");
}
var color = props.disableRandomColor || disableRandomColor ? tag.color || undefined : (0, _randomcolor2.default)(colorOptions);

var eventHandlers = {};
Object.keys(handlers).forEach(function (key) {
Expand All @@ -55,12 +51,18 @@ var defaultRenderer = exports.defaultRenderer = function defaultRenderer() {
});

var elementProps = (0, _objectAssign2.default)({}, { className: className }, eventHandlers, props, { key: key });
elementProps.style = (0, _objectAssign2.default)({}, defaultStyles, { color: color }, props.style, { fontSize: fontSize });
elementProps.style = (0, _objectAssign2.default)({}, styles, { color: color }, props.style, { fontSize: fontSize });

return _react2.default.createElement(
"span",
'span',
elementProps,
tagRenderer(tag)
);
};
};

var styles = {
margin: '0px 3px',
verticalAlign: 'middle',
display: 'inline-block'
};
35 changes: 35 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
/**
* Creates new object from target excluding given properties.
*/
var omitProps = exports.omitProps = function omitProps(target, props) {
return Object.keys(target).reduce(function (r, key) {
if (! ~props.indexOf(key)) {
r[key] = target[key];
}
return r;
}, {});
};

/**
* Creates new object from target including all available properties.
*/
var includeProps = exports.includeProps = function includeProps(target, props) {
return Object.keys(target).reduce(function (r, key) {
if (~props.indexOf(key) && key in target) {
r[key] = target[key];
}
return r;
}, {});
};

/**
* Computes appropriate font size of tag.
*/
var fontSizeConverter = exports.fontSizeConverter = function fontSizeConverter(count, min, max, minSize, maxSize) {
return Math.round((count - min) * (maxSize - minSize) / (max - min) + minSize);
};
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var _defaultRenderer = require('./defaultRenderer');

var deprecatedRendererExport = function deprecatedRendererExport() {
// eslint-disable-next-line no-console
console.warn('Using deprecated \'DefaultRenderer\' import, it will be removed in the next release and replaced with \'defaultRenderer\'.');
console.warn('Using deprecated \'DefaultRenderer\' import, it will be removed in the next major release and replaced with \'defaultRenderer\'.');
return _defaultRenderer.defaultRenderer.apply(undefined, arguments);
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-tagcloud",
"version": "0.4.1",
"version": "0.4.2",
"description": "Tag/word cloud component for react",
"main": "lib/index.js",
"scripts": {
Expand Down

0 comments on commit f9b4969

Please sign in to comment.