Comparing version 1.1.1 to 1.1.2
@@ -1,3 +0,2 @@ | ||
export * from './emphasizer'; | ||
export * from './i2-number'; | ||
export * from './tag-cloud'; |
@@ -1,186 +0,4 @@ | ||
import { Color, toHex } from 'jolor'; | ||
import React from 'react'; | ||
import { emphasizeStyle } from 'emphasizer'; | ||
var SizePatterns = { | ||
length: /\d+[a-z%]*/gi, | ||
number: /\d+/gi, | ||
dimension: /[a-z%]+/gi, | ||
lenght1: /^\s*(\s*\d+[a-z%]*\s*){1}\s*(;)?\s*$/gi, | ||
lenght2: /^\s*(\s*\d+[a-z%]*\s*){2}\s*(;)?\s*$/gi, | ||
lenght3: /^\s*(\s*\d+[a-z%]*\s*){3}\s*(;)?\s*$/gi, | ||
lenght4: /^\s*(\s*\d+[a-z%]*\s*){4}\s*(;)?\s*$/gi, | ||
}; | ||
var SizeValue = /** @class */ (function () { | ||
function SizeValue(p) { | ||
this.units = []; | ||
if (typeof p === 'string') { | ||
if (SizeValue.isSize(p)) { | ||
this.units = this.parseUnits(p); | ||
var dimensionUnit = this.units.find(function (x) { return x.dimension; }); | ||
if (dimensionUnit) { | ||
this.dimension = dimensionUnit.dimension; | ||
} | ||
} | ||
} | ||
else if (Array.isArray(p)) { | ||
this.units = p; | ||
var dimensionUnit = this.units.find(function (x) { return x.dimension; }); | ||
if (dimensionUnit) { | ||
this.dimension = dimensionUnit.dimension; | ||
} | ||
} | ||
} | ||
SizeValue.isSize = function (raw) { | ||
return SizeValue.isSingle(raw) || SizeValue.isDouble(raw) || SizeValue.isTriple(raw) || SizeValue.isQuadro(raw); | ||
}; | ||
SizeValue.isSingle = function (raw) { | ||
return SizeValue.isMatched(SizePatterns.lenght1, raw); | ||
}; | ||
SizeValue.isDouble = function (raw) { | ||
return SizeValue.isMatched(SizePatterns.lenght2, raw); | ||
}; | ||
SizeValue.isTriple = function (raw) { | ||
return SizeValue.isMatched(SizePatterns.lenght3, raw); | ||
}; | ||
SizeValue.isQuadro = function (raw) { | ||
return SizeValue.isMatched(SizePatterns.lenght4, raw); | ||
}; | ||
SizeValue.isMatched = function (pattern, raw) { | ||
return typeof raw === 'string' && raw.match(pattern) !== null; | ||
}; | ||
SizeValue.prototype.toString = function () { | ||
var result = ''; | ||
for (var _i = 0, _a = this.units; _i < _a.length; _i++) { | ||
var unit = _a[_i]; | ||
result += "" + unit.value + this.dimension + " "; | ||
} | ||
return result.replace(/\s*$/g, ''); | ||
}; | ||
SizeValue.prototype.isMatched = function (instance) { | ||
return this.units.length === instance.units.length && this.dimension === instance.dimension; | ||
}; | ||
SizeValue.prototype.parseUnits = function (raw) { | ||
var result = []; | ||
var matches = raw.match(SizePatterns.length); | ||
if (matches) { | ||
for (var _i = 0, matches_1 = matches; _i < matches_1.length; _i++) { | ||
var match = matches_1[_i]; | ||
var unit = { | ||
value: parseFloat(this.firstMatch(SizePatterns.number, match) || '0'), | ||
dimension: this.firstMatch(SizePatterns.dimension, match), | ||
}; | ||
result.push(unit); | ||
} | ||
} | ||
return result; | ||
}; | ||
SizeValue.prototype.firstMatch = function (pattern, raw) { | ||
var result; | ||
var matches = raw.match(pattern); | ||
if (matches) { | ||
result = matches[0]; | ||
} | ||
return result; | ||
}; | ||
return SizeValue; | ||
}()); | ||
var Emphasizer = /** @class */ (function () { | ||
function Emphasizer() { | ||
} | ||
// todo: test from == to, fromRate == toRate | ||
// returns rated value | ||
Emphasizer.number = function (fromValue, toValue, fromRate, toRate, rate) { | ||
var valueDirection = fromValue <= toValue; | ||
var minValue = Math.min(fromValue, toValue); | ||
var maxValue = Math.max(fromValue, toValue); | ||
var valueRange = maxValue - minValue; | ||
var rateDirection = fromRate <= toRate; | ||
var minRate = Math.min(fromRate, toRate); | ||
var maxRate = Math.max(fromRate, toRate); | ||
var rateRange = maxRate - minRate; | ||
var valueDelta = (valueRange / rateRange) * (rate - minRate); | ||
// to fixed 2 | ||
valueDelta = Math.round(valueDelta * 100) / 100; | ||
if (valueDirection === rateDirection) { | ||
return Emphasizer.keepRange(fromValue, toValue, minValue + valueDelta); | ||
} | ||
else { | ||
return Emphasizer.keepRange(fromValue, toValue, maxValue - valueDelta); | ||
} | ||
}; | ||
Emphasizer.keepRange = function (from, to, value) { | ||
var max = Math.max(from, to); | ||
var min = Math.min(from, to); | ||
if (value < min) { | ||
return min; | ||
} | ||
else if (value > max) { | ||
return max; | ||
} | ||
else { | ||
return value; | ||
} | ||
}; | ||
Emphasizer.color = function (fromValue, toValue, fromRate, toRate, rate) { | ||
var from = new Color(fromValue); | ||
var to = new Color(toValue); | ||
var r = Math.round(Emphasizer.number(from.rgbObject.r, to.rgbObject.r, fromRate, toRate, rate)); | ||
var g = Math.round(Emphasizer.number(from.rgbObject.g, to.rgbObject.g, fromRate, toRate, rate)); | ||
var b = Math.round(Emphasizer.number(from.rgbObject.b, to.rgbObject.b, fromRate, toRate, rate)); | ||
var a = Math.round(Emphasizer.number(from.opacity, to.opacity, fromRate, toRate, rate)); | ||
return toHex(r, g, b, a) || fromValue; | ||
}; | ||
Emphasizer.colorRange = function (fromValue, toValue, count) { | ||
var result = []; | ||
for (var i = 1; i <= count; i++) { | ||
result.push(Emphasizer.color(fromValue, toValue, 1, count, i)); | ||
} | ||
return result; | ||
}; | ||
Emphasizer.sizeValue = function (fromValue, toValue, fromRate, toRate, rate) { | ||
if (fromValue.isMatched(toValue)) { | ||
var dimension = fromValue.dimension; | ||
var units = []; | ||
for (var i = 0; i < fromValue.units.length; i++) { | ||
var fromUnit = fromValue.units[i]; | ||
var toUnit = toValue.units[i]; | ||
units.push({ | ||
dimension: dimension, | ||
value: Emphasizer.number(fromUnit.value, toUnit.value, fromRate, toRate, rate), | ||
}); | ||
} | ||
return new SizeValue(units).toString(); | ||
} | ||
return undefined; | ||
}; | ||
Emphasizer.styleProperty = function (from, to, fromRate, toRate, rate) { | ||
if (typeof from === 'number' && typeof to === 'number') { | ||
return Emphasizer.number(from, to, fromRate, toRate, rate); | ||
} | ||
else if (typeof from === 'string' && typeof to === 'string') { | ||
if (Color.isColor(from)) { | ||
return Emphasizer.color(from, to, fromRate, toRate, rate); | ||
} | ||
else if (SizeValue.isSize(from)) { | ||
return Emphasizer.sizeValue(new SizeValue(from), new SizeValue(to), fromRate, toRate, rate); | ||
} | ||
else { | ||
return from; | ||
} | ||
} | ||
return undefined; | ||
}; | ||
Emphasizer.style = function (from, to, fromRate, toRate, rate) { | ||
var result = {}; | ||
for (var key in from) { | ||
if (from.hasOwnProperty(key) && to.hasOwnProperty(key)) { | ||
result[key] = Emphasizer.styleProperty(from[key], to[key], fromRate, toRate, rate); | ||
} | ||
} | ||
return result; | ||
}; | ||
return Emphasizer; | ||
}()); | ||
/*! ***************************************************************************** | ||
@@ -284,6 +102,6 @@ Copyright (c) Microsoft Corporation. All rights reserved. | ||
} | ||
return (React.createElement("div", { className: className, style: __assign({}, rootStyle, style) }, | ||
return (React.createElement("div", { className: className, style: __assign(__assign({}, rootStyle), style) }, | ||
React.createElement("div", { style: contentStyle }, splits.map(function (_a, i) { | ||
var text = _a.text, separator = _a.separator; | ||
return (React.createElement("div", { key: i, style: __assign({}, Emphasizer.style(from, to, 1, maxRate, splits.length - i), numberPartStyle) }, "" + (separator || '') + text)); | ||
return (React.createElement("div", { key: i, style: __assign(__assign({}, emphasizeStyle(from, to, 1, maxRate, splits.length - i)), numberPartStyle) }, "" + (separator || '') + text)); | ||
})))); | ||
@@ -364,8 +182,8 @@ }; | ||
var tagStyle = {}; | ||
return (React.createElement("div", { className: className, style: __assign({}, rootStyle, style) }, orderData.map(function (x, i) { | ||
var itemStyle = Emphasizer.style(fromStyle, toStyle, min, max, x.rate); | ||
return (React.createElement("div", { key: i, style: __assign({}, tagStyle, itemStyle) }, x.text)); | ||
return (React.createElement("div", { className: className, style: __assign(__assign({}, rootStyle), style) }, orderData.map(function (x, i) { | ||
var itemStyle = emphasizeStyle(fromStyle, toStyle, min, max, x.rate); | ||
return (React.createElement("div", { key: i, style: __assign(__assign({}, tagStyle), itemStyle) }, x.text)); | ||
}))); | ||
}; | ||
export { Emphasizer, I2Number, SizeValue, TagCloud }; | ||
export { I2Number, TagCloud }; |
@@ -1,378 +0,1 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var jolor = require('jolor'); | ||
var React = _interopDefault(require('react')); | ||
var SizePatterns = { | ||
length: /\d+[a-z%]*/gi, | ||
number: /\d+/gi, | ||
dimension: /[a-z%]+/gi, | ||
lenght1: /^\s*(\s*\d+[a-z%]*\s*){1}\s*(;)?\s*$/gi, | ||
lenght2: /^\s*(\s*\d+[a-z%]*\s*){2}\s*(;)?\s*$/gi, | ||
lenght3: /^\s*(\s*\d+[a-z%]*\s*){3}\s*(;)?\s*$/gi, | ||
lenght4: /^\s*(\s*\d+[a-z%]*\s*){4}\s*(;)?\s*$/gi, | ||
}; | ||
var SizeValue = /** @class */ (function () { | ||
function SizeValue(p) { | ||
this.units = []; | ||
if (typeof p === 'string') { | ||
if (SizeValue.isSize(p)) { | ||
this.units = this.parseUnits(p); | ||
var dimensionUnit = this.units.find(function (x) { return x.dimension; }); | ||
if (dimensionUnit) { | ||
this.dimension = dimensionUnit.dimension; | ||
} | ||
} | ||
} | ||
else if (Array.isArray(p)) { | ||
this.units = p; | ||
var dimensionUnit = this.units.find(function (x) { return x.dimension; }); | ||
if (dimensionUnit) { | ||
this.dimension = dimensionUnit.dimension; | ||
} | ||
} | ||
} | ||
SizeValue.isSize = function (raw) { | ||
return SizeValue.isSingle(raw) || SizeValue.isDouble(raw) || SizeValue.isTriple(raw) || SizeValue.isQuadro(raw); | ||
}; | ||
SizeValue.isSingle = function (raw) { | ||
return SizeValue.isMatched(SizePatterns.lenght1, raw); | ||
}; | ||
SizeValue.isDouble = function (raw) { | ||
return SizeValue.isMatched(SizePatterns.lenght2, raw); | ||
}; | ||
SizeValue.isTriple = function (raw) { | ||
return SizeValue.isMatched(SizePatterns.lenght3, raw); | ||
}; | ||
SizeValue.isQuadro = function (raw) { | ||
return SizeValue.isMatched(SizePatterns.lenght4, raw); | ||
}; | ||
SizeValue.isMatched = function (pattern, raw) { | ||
return typeof raw === 'string' && raw.match(pattern) !== null; | ||
}; | ||
SizeValue.prototype.toString = function () { | ||
var result = ''; | ||
for (var _i = 0, _a = this.units; _i < _a.length; _i++) { | ||
var unit = _a[_i]; | ||
result += "" + unit.value + this.dimension + " "; | ||
} | ||
return result.replace(/\s*$/g, ''); | ||
}; | ||
SizeValue.prototype.isMatched = function (instance) { | ||
return this.units.length === instance.units.length && this.dimension === instance.dimension; | ||
}; | ||
SizeValue.prototype.parseUnits = function (raw) { | ||
var result = []; | ||
var matches = raw.match(SizePatterns.length); | ||
if (matches) { | ||
for (var _i = 0, matches_1 = matches; _i < matches_1.length; _i++) { | ||
var match = matches_1[_i]; | ||
var unit = { | ||
value: parseFloat(this.firstMatch(SizePatterns.number, match) || '0'), | ||
dimension: this.firstMatch(SizePatterns.dimension, match), | ||
}; | ||
result.push(unit); | ||
} | ||
} | ||
return result; | ||
}; | ||
SizeValue.prototype.firstMatch = function (pattern, raw) { | ||
var result; | ||
var matches = raw.match(pattern); | ||
if (matches) { | ||
result = matches[0]; | ||
} | ||
return result; | ||
}; | ||
return SizeValue; | ||
}()); | ||
var Emphasizer = /** @class */ (function () { | ||
function Emphasizer() { | ||
} | ||
// todo: test from == to, fromRate == toRate | ||
// returns rated value | ||
Emphasizer.number = function (fromValue, toValue, fromRate, toRate, rate) { | ||
var valueDirection = fromValue <= toValue; | ||
var minValue = Math.min(fromValue, toValue); | ||
var maxValue = Math.max(fromValue, toValue); | ||
var valueRange = maxValue - minValue; | ||
var rateDirection = fromRate <= toRate; | ||
var minRate = Math.min(fromRate, toRate); | ||
var maxRate = Math.max(fromRate, toRate); | ||
var rateRange = maxRate - minRate; | ||
var valueDelta = (valueRange / rateRange) * (rate - minRate); | ||
// to fixed 2 | ||
valueDelta = Math.round(valueDelta * 100) / 100; | ||
if (valueDirection === rateDirection) { | ||
return Emphasizer.keepRange(fromValue, toValue, minValue + valueDelta); | ||
} | ||
else { | ||
return Emphasizer.keepRange(fromValue, toValue, maxValue - valueDelta); | ||
} | ||
}; | ||
Emphasizer.keepRange = function (from, to, value) { | ||
var max = Math.max(from, to); | ||
var min = Math.min(from, to); | ||
if (value < min) { | ||
return min; | ||
} | ||
else if (value > max) { | ||
return max; | ||
} | ||
else { | ||
return value; | ||
} | ||
}; | ||
Emphasizer.color = function (fromValue, toValue, fromRate, toRate, rate) { | ||
var from = new jolor.Color(fromValue); | ||
var to = new jolor.Color(toValue); | ||
var r = Math.round(Emphasizer.number(from.rgbObject.r, to.rgbObject.r, fromRate, toRate, rate)); | ||
var g = Math.round(Emphasizer.number(from.rgbObject.g, to.rgbObject.g, fromRate, toRate, rate)); | ||
var b = Math.round(Emphasizer.number(from.rgbObject.b, to.rgbObject.b, fromRate, toRate, rate)); | ||
var a = Math.round(Emphasizer.number(from.opacity, to.opacity, fromRate, toRate, rate)); | ||
return jolor.toHex(r, g, b, a) || fromValue; | ||
}; | ||
Emphasizer.colorRange = function (fromValue, toValue, count) { | ||
var result = []; | ||
for (var i = 1; i <= count; i++) { | ||
result.push(Emphasizer.color(fromValue, toValue, 1, count, i)); | ||
} | ||
return result; | ||
}; | ||
Emphasizer.sizeValue = function (fromValue, toValue, fromRate, toRate, rate) { | ||
if (fromValue.isMatched(toValue)) { | ||
var dimension = fromValue.dimension; | ||
var units = []; | ||
for (var i = 0; i < fromValue.units.length; i++) { | ||
var fromUnit = fromValue.units[i]; | ||
var toUnit = toValue.units[i]; | ||
units.push({ | ||
dimension: dimension, | ||
value: Emphasizer.number(fromUnit.value, toUnit.value, fromRate, toRate, rate), | ||
}); | ||
} | ||
return new SizeValue(units).toString(); | ||
} | ||
return undefined; | ||
}; | ||
Emphasizer.styleProperty = function (from, to, fromRate, toRate, rate) { | ||
if (typeof from === 'number' && typeof to === 'number') { | ||
return Emphasizer.number(from, to, fromRate, toRate, rate); | ||
} | ||
else if (typeof from === 'string' && typeof to === 'string') { | ||
if (jolor.Color.isColor(from)) { | ||
return Emphasizer.color(from, to, fromRate, toRate, rate); | ||
} | ||
else if (SizeValue.isSize(from)) { | ||
return Emphasizer.sizeValue(new SizeValue(from), new SizeValue(to), fromRate, toRate, rate); | ||
} | ||
else { | ||
return from; | ||
} | ||
} | ||
return undefined; | ||
}; | ||
Emphasizer.style = function (from, to, fromRate, toRate, rate) { | ||
var result = {}; | ||
for (var key in from) { | ||
if (from.hasOwnProperty(key) && to.hasOwnProperty(key)) { | ||
result[key] = Emphasizer.styleProperty(from[key], to[key], fromRate, toRate, rate); | ||
} | ||
} | ||
return result; | ||
}; | ||
return Emphasizer; | ||
}()); | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var NumberUtil = /** @class */ (function () { | ||
function NumberUtil() { | ||
} | ||
NumberUtil.splitNumber = function (value, options) { | ||
var decimalDigits = options.decimalDigits, groupSeparator = options.groupSeparator, decimalSeparator = options.decimalSeparator, groupDigits = options.groupDigits; | ||
var result = []; | ||
var stringValue = value.toFixed(decimalDigits || 0); | ||
var splits = stringValue.split('.'); | ||
if (splits.length > 0) { | ||
var groups = NumberUtil.toGroups(splits[0], groupDigits); | ||
for (var i = 0; i < groups.length; i++) { | ||
result.push({ | ||
text: groups[i], | ||
separator: i > 0 ? groupSeparator || ',' : undefined, | ||
}); | ||
} | ||
if (splits.length === 2) { | ||
var fraction = splits[1]; | ||
if (fraction) { | ||
result.push({ | ||
text: fraction, | ||
isFraction: true, | ||
separator: decimalSeparator || '.', | ||
}); | ||
} | ||
} | ||
} | ||
return result; | ||
}; | ||
NumberUtil.toGroups = function (integer, groupDigits) { | ||
if (groupDigits === 0) { | ||
return [integer]; | ||
} | ||
var digits = Math.abs(groupDigits || 3); | ||
var output = integer.match(new RegExp("(\\d+?)(?=(\\d{" + digits + "})+(?!\\d)|$)", 'g')); | ||
// integer.match(/(\d+?)(?=(\d{3})+(?!\d)|$)/g); | ||
return output ? output : []; | ||
}; | ||
return NumberUtil; | ||
}()); | ||
var rootStyle = { | ||
display: 'inline-block', | ||
}; | ||
var defaultContentStyle = { | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'flex-end', | ||
}; | ||
var numberPartStyle = { | ||
lineHeight: '1em', | ||
}; | ||
var I2Number = function (props) { | ||
var value = props.value, fromStyle = props.fromStyle, toStyle = props.toStyle, decimalDigits = props.decimalDigits, basicMaxValue = props.basicMaxValue, align = props.verticalAlign, className = props.className, style = props.style, groupSeparator = props.groupSeparator, decimalSeparator = props.decimalSeparator, groupDigits = props.groupDigits; | ||
var numberOptions = { | ||
decimalDigits: decimalDigits, | ||
decimalSeparator: decimalSeparator, | ||
groupSeparator: groupSeparator, | ||
groupDigits: groupDigits, | ||
}; | ||
var splits = NumberUtil.splitNumber(value, numberOptions); | ||
var basicSplits = NumberUtil.splitNumber(basicMaxValue || value, numberOptions); | ||
var from = __assign({ fontSize: '1em' }, fromStyle); | ||
var to = __assign({ fontSize: '2em' }, toStyle); | ||
var maxRate = Math.max(basicSplits.length); | ||
var contentStyle = __assign({}, defaultContentStyle); | ||
if (align === 'top') { | ||
contentStyle.alignItems = 'flex-start'; | ||
} | ||
else if (align === 'center') { | ||
contentStyle.alignItems = 'center'; | ||
} | ||
return (React.createElement("div", { className: className, style: __assign({}, rootStyle, style) }, | ||
React.createElement("div", { style: contentStyle }, splits.map(function (_a, i) { | ||
var text = _a.text, separator = _a.separator; | ||
return (React.createElement("div", { key: i, style: __assign({}, Emphasizer.style(from, to, 1, maxRate, splits.length - i), numberPartStyle) }, "" + (separator || '') + text)); | ||
})))); | ||
}; | ||
var TagUtil = /** @class */ (function () { | ||
function TagUtil() { | ||
} | ||
TagUtil.order = function (data, order) { | ||
if (order === 'desc' || order === 'middle') { | ||
var result = data.sort(function (a, b) { | ||
if (a.rate > b.rate) { | ||
return -1; | ||
} | ||
else if (a.rate < b.rate) { | ||
return 1; | ||
} | ||
return 0; | ||
}); | ||
if (order === 'middle') { | ||
var temp_1 = []; | ||
result.forEach(function (x, i) { | ||
if (i % 2 === 0) { | ||
temp_1.push(x); | ||
} | ||
else { | ||
temp_1.unshift(x); | ||
} | ||
}); | ||
result = temp_1; | ||
} | ||
return result; | ||
} | ||
else if (order === 'asc' || order === 'edge') { | ||
var result = data.sort(function (a, b) { | ||
if (a.rate < b.rate) { | ||
return -1; | ||
} | ||
else if (a.rate > b.rate) { | ||
return 1; | ||
} | ||
return 0; | ||
}); | ||
if (order === 'edge') { | ||
var temp_2 = []; | ||
result.forEach(function (x, i) { | ||
if (i % 2 === 0) { | ||
temp_2.push(x); | ||
} | ||
else { | ||
temp_2.unshift(x); | ||
} | ||
}); | ||
result = temp_2; | ||
} | ||
return result; | ||
} | ||
return data; | ||
}; | ||
return TagUtil; | ||
}()); | ||
var TagCloud = function (props) { | ||
var data = props.options, fromStyle = props.fromStyle, toStyle = props.toStyle, order = props.order, className = props.className, style = props.style; | ||
var rates = data.map(function (x) { return x.rate; }); | ||
var min = Math.min.apply(Math, rates); | ||
var max = Math.max.apply(Math, rates); | ||
var orderData = TagUtil.order(data, order); | ||
var rootStyle = { | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
justifyItems: 'center', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
alignContent: 'center', | ||
}; | ||
var tagStyle = {}; | ||
return (React.createElement("div", { className: className, style: __assign({}, rootStyle, style) }, orderData.map(function (x, i) { | ||
var itemStyle = Emphasizer.style(fromStyle, toStyle, min, max, x.rate); | ||
return (React.createElement("div", { key: i, style: __assign({}, tagStyle, itemStyle) }, x.text)); | ||
}))); | ||
}; | ||
exports.Emphasizer = Emphasizer; | ||
exports.I2Number = I2Number; | ||
exports.SizeValue = SizeValue; | ||
exports.TagCloud = TagCloud; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var React=_interopDefault(require("react")),emphasizer=require("emphasizer"),__assign=function(){return(__assign=Object.assign||function(e){for(var t,r=1,a=arguments.length;r<a;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}).apply(this,arguments)},NumberUtil=function(){function p(){}return p.splitNumber=function(e,t){var r=t.decimalDigits,a=t.groupSeparator,n=t.decimalSeparator,i=t.groupDigits,s=[],l=e.toFixed(r||0).split(".");if(0<l.length){for(var o=p.toGroups(l[0],i),u=0;u<o.length;u++)s.push({text:o[u],separator:0<u?a||",":void 0});if(2===l.length){var c=l[1];c&&s.push({text:c,isFraction:!0,separator:n||"."})}}return s},p.toGroups=function(e,t){if(0===t)return[e];var r=Math.abs(t||3),a=e.match(new RegExp("(\\d+?)(?=(\\d{"+r+"})+(?!\\d)|$)","g"));return a||[]},p}(),rootStyle={display:"inline-block"},defaultContentStyle={display:"flex",flexDirection:"row",alignItems:"flex-end"},numberPartStyle={lineHeight:"1em"},I2Number=function(e){var t=e.value,r=e.fromStyle,a=e.toStyle,n=e.decimalDigits,i=e.basicMaxValue,s=e.verticalAlign,l=e.className,o=e.style,u=e.groupSeparator,c={decimalDigits:n,decimalSeparator:e.decimalSeparator,groupSeparator:u,groupDigits:e.groupDigits},p=NumberUtil.splitNumber(t,c),f=NumberUtil.splitNumber(i||t,c),m=__assign({fontSize:"1em"},r),g=__assign({fontSize:"2em"},a),d=Math.max(f.length),y=__assign({},defaultContentStyle);return"top"===s?y.alignItems="flex-start":"center"===s&&(y.alignItems="center"),React.createElement("div",{className:l,style:__assign(__assign({},rootStyle),o)},React.createElement("div",{style:y},p.map(function(e,t){var r=e.text,a=e.separator;return React.createElement("div",{key:t,style:__assign(__assign({},emphasizer.emphasizeStyle(m,g,1,d,p.length-t)),numberPartStyle)},""+(a||"")+r)})))},TagUtil=function(){function e(){}return e.order=function(e,t){if("desc"===t||"middle"===t){var r=e.sort(function(e,t){return e.rate>t.rate?-1:e.rate<t.rate?1:0});if("middle"===t){var a=[];r.forEach(function(e,t){t%2==0?a.push(e):a.unshift(e)}),r=a}return r}if("asc"!==t&&"edge"!==t)return e;r=e.sort(function(e,t){return e.rate<t.rate?-1:e.rate>t.rate?1:0});if("edge"===t){var n=[];r.forEach(function(e,t){t%2==0?n.push(e):n.unshift(e)}),r=n}return r},e}(),TagCloud=function(e){var t=e.options,a=e.fromStyle,n=e.toStyle,r=e.order,i=e.className,s=e.style,l=t.map(function(e){return e.rate}),o=Math.min.apply(Math,l),u=Math.max.apply(Math,l),c=TagUtil.order(t,r),p={};return React.createElement("div",{className:i,style:__assign(__assign({},{display:"flex",flexWrap:"wrap",justifyItems:"center",alignItems:"center",justifyContent:"center",alignContent:"center"}),s)},c.map(function(e,t){var r=emphasizer.emphasizeStyle(a,n,o,u,e.rate);return React.createElement("div",{key:t,style:__assign(__assign({},p),r)},e.text)}))};exports.I2Number=I2Number,exports.TagCloud=TagCloud; |
{ | ||
"name": "i2ui", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "i2ui - Intuitively Understantable User Interface", | ||
@@ -53,4 +53,8 @@ "main": "dist/index.js", | ||
"tagcloud", | ||
"react-tag-cloud", | ||
"word-cloud", | ||
"wordcloud", | ||
"react", | ||
"number", | ||
"number-group", | ||
"emphase" | ||
@@ -68,4 +72,4 @@ ], | ||
"dependencies": { | ||
"emphasizer": "^1.1.1" | ||
"emphasizer": "^1.1.2" | ||
} | ||
} |
@@ -26,3 +26,3 @@ # i2ui | ||
<a href="https://i2ui-examples.now.sh" target="_blank">Live Demo</a> | ||
<a href="https://i2ui-examples.now.sh/tagcloud" target="_blank">Live Demo</a> | ||
@@ -29,0 +29,0 @@ <div align="center"> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22529
1
279
1
1
Updatedemphasizer@^1.1.2