Post

计算刻度最大值最小值,链式 echarts 折柱混合 axisTick 不对齐

计算刻度最大值最小值,链式 echarts 折柱混合 axisTick 不对齐
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// max min 不能被链式调用
const maxCeil =
  Math.ceil(
    _.chain(yAxis)
      .filter({ type: "bar" })
      .map("data")
      .flatten()
      .max()
      .value() / 1000
  ) * 1000;
const maxCeil2 =
  Math.ceil(
    _.chain(yAxis)
      .filter({ type: "line" })
      .map("data")
      .flatten()
      .map((i) => Number(i))
      .max()
      .value() / 100
  ) * 100;
const min = _.chain(yAxis)
  .filter({ type: "line" })
  .map("data")
  .flatten()
  .min()
  .value();
const minCeil =
  min > 0 ? Math.ceil(min / 100) * 100 : Math.floor(min / 100) * 100;
const abs =
  Math.abs(minCeil) > Math.abs(maxCeil2)
    ? Math.abs(minCeil)
    : Math.abs(maxCeil2);

学习-链式调用

“Chain” 方法

_(value)

创建一个包含 value 的 lodash 对象以开启内置的方法链。方法链对返回数组、集合或函数的方法产生作用,并且方法可以被链式调用。那些获取单值或可能返回一个原始值的方法将自动结束方法链并且返回一个未包裹成 lodash 对象的值。如果明确需要链式调用可以使用 _.chain。链式调用的加载将是延迟加载,这表明调用将延迟到间接或直接调用 _#value 方法。

延迟计算支持一些方法快速合并。快速合并是一个最优合并迭代器调用的策略。这样做可以帮助避免一些计算中间生成的数据结构,并且能够大大降低迭代器的执行次数。

链式调用支持自定义生成结果。只要在生成的时候直接或间接的包含 _#value 方法。

此外,对于 lodash 的方法,包装集拥有 Array 和 String 的方法。

Array 包装集的方法有:

concat, join, pop, push, reverse, shift, slice, sort, splice 和 unshift

String 包装集的方法有:

replace 和 split

支持快速合并的包装集方法有:

compact, drop, dropRight, dropRightWhile, dropWhile, filter, first, initial, last, map, pluck, reject, rest, reverse, slice, take, takeRight, takeRightWhile, takeWhile, toArray 和 where

可链式调用的包装集方法有:

after, ary, assign, at, before, bind, bindAll, bindKey, callback, chain, chunk, commit, compact, concat, constant, countBy, create, curry, debounce, defaults, defaultsDeep, defer, delay, difference, drop, dropRight, dropRightWhile, dropWhile, fill, filter, flatten, flattenDeep, flow, flowRight, forEach, forEachRight, forIn, forInRight, forOwn, forOwnRight, functions, groupBy, indexBy, initial, intersection, invert, invoke, keys, keysIn, map, mapKeys, mapValues, matches, matchesProperty, memoize, merge, method, methodOf, mixin, modArgs, negate, omit, once, pairs, partial, partialRight, partition, pick, plant, pluck, property, propertyOf, pull, pullAt, push, range, rearg, reject, remove, rest, restParam, reverse, set, shuffle, slice, sort, sortBy, sortByAll, sortByOrder, splice, spread, take, takeRight, takeRightWhile, takeWhile, tap, throttle, thru, times, toArray, toPlainObject, transform, union, uniq, unshift, unzip, unzipWith, values, valuesIn, where, without, wrap, xor, zip, zipObject, zipWith

默认不能被链式调用的包装集方法有:

add, attempt, camelCase, capitalize, ceil, clone, cloneDeep, deburr, endsWith, escape, escapeRegExp, every, find, findIndex, findKey, findLast, findLastIndex, findLastKey, findWhere, first, floor, get, gt, gte, has, identity, includes, indexOf, inRange, isArguments, isArray, isBoolean, isDate, isElement, isEmpty, isEqual, isError, isFinite isFunction, isMatch, isNative, isNaN, isNull, isNumber, isObject, isPlainObject, isRegExp, isString, isUndefined, isTypedArray, join, kebabCase, last, lastIndexOf, lt, lte, max, min, noConflict, noop, now, pad, padLeft, padRight, parseInt, pop, random, reduce, reduceRight, repeat, result, round, runInContext, shift, size, snakeCase, some, sortedIndex, sortedLastIndex, startCase, startsWith, sum, template, trim, trimLeft, trimRight, trunc, unescape, uniqueId, value 和 words

包装集函数 sample 在参数提供 n 的情况下将返回包装集,其他情况下将返回未经包装过的值。

This post is licensed under CC BY 4.0 by the author.