123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- import { parseDate, numericToNumber } from '../../util/number.js';
- import { createHashMap, trim, hasOwn, isString, isNumber } from 'zrender/lib/core/util.js';
- import { throwError } from '../../util/log.js';
- export function parseDataValue(value,
- // For high performance, do not omit the second param.
- opt) {
-
- var dimType = opt && opt.type;
- if (dimType === 'ordinal') {
-
- return value;
- }
- if (dimType === 'time'
-
- && !isNumber(value) && value != null && value !== '-') {
- value = +parseDate(value);
- }
-
-
-
-
-
- return value == null || value === '' ? NaN
-
-
- : Number(value);
- }
- ;
- var valueParserMap = createHashMap({
- 'number': function (val) {
-
-
-
- return parseFloat(val);
- },
- 'time': function (val) {
-
- return +parseDate(val);
- },
- 'trim': function (val) {
- return isString(val) ? trim(val) : val;
- }
- });
- export function getRawValueParser(type) {
- return valueParserMap.get(type);
- }
- var ORDER_COMPARISON_OP_MAP = {
- lt: function (lval, rval) {
- return lval < rval;
- },
- lte: function (lval, rval) {
- return lval <= rval;
- },
- gt: function (lval, rval) {
- return lval > rval;
- },
- gte: function (lval, rval) {
- return lval >= rval;
- }
- };
- var FilterOrderComparator = function () {
- function FilterOrderComparator(op, rval) {
- if (!isNumber(rval)) {
- var errMsg = '';
- if (process.env.NODE_ENV !== 'production') {
- errMsg = 'rvalue of "<", ">", "<=", ">=" can only be number in filter.';
- }
- throwError(errMsg);
- }
- this._opFn = ORDER_COMPARISON_OP_MAP[op];
- this._rvalFloat = numericToNumber(rval);
- }
-
- FilterOrderComparator.prototype.evaluate = function (lval) {
-
- return isNumber(lval) ? this._opFn(lval, this._rvalFloat) : this._opFn(numericToNumber(lval), this._rvalFloat);
- };
- return FilterOrderComparator;
- }();
- var SortOrderComparator = function () {
-
- function SortOrderComparator(order, incomparable) {
- var isDesc = order === 'desc';
- this._resultLT = isDesc ? 1 : -1;
- if (incomparable == null) {
- incomparable = isDesc ? 'min' : 'max';
- }
- this._incomparable = incomparable === 'min' ? -Infinity : Infinity;
- }
-
-
- SortOrderComparator.prototype.evaluate = function (lval, rval) {
-
- var lvalFloat = isNumber(lval) ? lval : numericToNumber(lval);
- var rvalFloat = isNumber(rval) ? rval : numericToNumber(rval);
- var lvalNotNumeric = isNaN(lvalFloat);
- var rvalNotNumeric = isNaN(rvalFloat);
- if (lvalNotNumeric) {
- lvalFloat = this._incomparable;
- }
- if (rvalNotNumeric) {
- rvalFloat = this._incomparable;
- }
- if (lvalNotNumeric && rvalNotNumeric) {
- var lvalIsStr = isString(lval);
- var rvalIsStr = isString(rval);
- if (lvalIsStr) {
- lvalFloat = rvalIsStr ? lval : 0;
- }
- if (rvalIsStr) {
- rvalFloat = lvalIsStr ? rval : 0;
- }
- }
- return lvalFloat < rvalFloat ? this._resultLT : lvalFloat > rvalFloat ? -this._resultLT : 0;
- };
- return SortOrderComparator;
- }();
- export { SortOrderComparator };
- var FilterEqualityComparator = function () {
- function FilterEqualityComparator(isEq, rval) {
- this._rval = rval;
- this._isEQ = isEq;
- this._rvalTypeof = typeof rval;
- this._rvalFloat = numericToNumber(rval);
- }
-
- FilterEqualityComparator.prototype.evaluate = function (lval) {
- var eqResult = lval === this._rval;
- if (!eqResult) {
- var lvalTypeof = typeof lval;
- if (lvalTypeof !== this._rvalTypeof && (lvalTypeof === 'number' || this._rvalTypeof === 'number')) {
- eqResult = numericToNumber(lval) === this._rvalFloat;
- }
- }
- return this._isEQ ? eqResult : !eqResult;
- };
- return FilterEqualityComparator;
- }();
- export function createFilterComparator(op, rval) {
- return op === 'eq' || op === 'ne' ? new FilterEqualityComparator(op === 'eq', rval) : hasOwn(ORDER_COMPARISON_OP_MAP, op) ? new FilterOrderComparator(op, rval) : null;
- }
|