Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added custom color word support #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions dist/TagCloud.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,31 @@ export interface TagCloudOptions {
useHTML?: boolean;
}

export interface TagEntity {
text: string;
color: string
}

export default function (
container: string,
texts: Array<string>,
texts: Array<string> | Array<TagEntity>,
options?: TagCloudOptions
): TagCloud;

export default function (
container: Element,
texts: Array<string>,
texts: Array<string> | Array<TagEntity>,
options?: TagCloudOptions
): TagCloud;

export default function (
container: [Element],
texts: Array<string>,
texts: Array<string> | Array<TagEntity>,
options?: TagCloudOptions
): TagCloud;

export default function (
container: Array<Element>,
texts: Array<string>,
texts: Array<string> | Array<TagEntity>,
options?: TagCloudOptions
): Array<TagCloud> | TagCloud;
140 changes: 70 additions & 70 deletions dist/TagCloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,37 @@
(global = global || self, global.TagCloud = factory());
}(this, (function () { 'use strict';

function _classCallCheck(a, n) {
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
}
function _defineProperties(e, r) {
for (var t = 0; t < r.length; t++) {
var o = r[t];
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
}
}
function _createClass(e, r, t) {
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
writable: !1
}), e;
}
function _defineProperty(e, r, t) {
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
function _extends() {
return _extends = Object.assign ? Object.assign.bind() : function (n) {
for (var e = 1; e < arguments.length; e++) {
var t = arguments[e];
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
}
return n;
}, _extends.apply(null, arguments);
}
function ownKeys(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
Expand All @@ -30,69 +61,28 @@
}
return e;
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a 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, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _defineProperty(obj, key, value) {
key = _toPropertyKey(key);
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
function _toPrimitive(t, r) {
if ("object" != typeof t || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != typeof i) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
return ("string" === r ? String : Number)(t);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == typeof i ? i : i + "";
}
function _typeof(o) {
"@babel/helpers - typeof";

return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}

/**
Expand Down Expand Up @@ -138,7 +128,7 @@

/* static method */
// all TagCloud list
_createClass(TagCloud, [{
return _createClass(TagCloud, [{
key: "_createElment",
value: /* instance property method */
// create elment
Expand All @@ -156,19 +146,19 @@

// create texts
self.items = [];
self.texts.forEach(function (text, index) {
var item = self._createTextItem(text, index);
self.texts.forEach(function (entity, index) {
var item = self._createTextItem(entity, index);
$el.appendChild(item.el);
self.items.push(item);
});
self.$container.appendChild($el);
self.$el = $el;
}

// create a text
// create a entity
}, {
key: "_createTextItem",
value: function _createTextItem(text) {
value: function _createTextItem(entity) {
var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var self = this;
var itemEl = document.createElement('span');
Expand All @@ -192,10 +182,16 @@
itemEl.style.OTransform = transform;
itemEl.style.transform = transform;
}
var _ref = _typeof(entity) === 'object' ? entity : {
text: entity
},
text = _ref.text,
color = _ref.color;
if (self.config.useHTML) {
itemEl.innerHTML = text;
} else {
itemEl.innerText = text;
color && (itemEl.style.color = color);
}
return _objectSpread2({
el: itemEl
Expand Down Expand Up @@ -295,7 +291,6 @@
self.mouseX = Math.abs(self.mouseX - self.mouseX0) < 1 ? self.mouseX0 : (self.mouseX + self.mouseX0) / 2; // reset distance between the mouse and rolling center x axis
self.mouseY = Math.abs(self.mouseY - self.mouseY0) < 1 ? self.mouseY0 : (self.mouseY + self.mouseY0) / 2; // reset distance between the mouse and rolling center y axis
}

var a = -(Math.min(Math.max(-self.mouseY, -self.size), self.size) / self.radius) * self.maxSpeed;
var b = Math.min(Math.max(-self.mouseX, -self.size), self.size) / self.radius * self.maxSpeed;

Expand Down Expand Up @@ -346,20 +341,26 @@
// params
self.texts = texts || [];
// judging and processing items based on texts
self.texts.forEach(function (text, index) {
self.texts.forEach(function (entity, index) {
var item = self.items[index];
if (!item) {
// if not had, then create
item = self._createTextItem(text, index);
item = self._createTextItem(entity, index);
_extends(item, self._computePosition(index, true)); // random place
self.$el.appendChild(item.el);
self.items.push(item);
}
// if had, replace text
// if had, replace entity
var _ref2 = _typeof(entity) === 'object' ? entity : {
text: entity
},
text = _ref2.text,
color = _ref2.color;
if (self.config.useHTML) {
item.el.innerHTML = text;
} else {
item.el.innerText = text;
color && (item.el.style.color = color);
}
});
// remove redundant self.items
Expand Down Expand Up @@ -415,7 +416,6 @@
}
}
}]);
return TagCloud;
}();
TagCloud.list = [];
// default config
Expand Down
Loading