@ecan-bi/tools 1.0.21 → 1.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecan-bi/tools",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "General tools",
5
5
  "main": "lib/index.es.js",
6
6
  "module": "lib/index.es.js",
@@ -19,7 +19,7 @@ export interface KeyTypeDataFieldNames {
19
19
  * @param data 数据
20
20
  * @param dataFieldNames 字段映射
21
21
  */
22
- export const useTransformChartDataByAttrKey = (data: Data = [], dataFieldNames: KeyTypeDataFieldNames) => {
22
+ export const useTransformChartDataByAttrKey = (data: Data = [], dataFieldNames: KeyTypeDataFieldNames, isIndicator: boolean = false) => {
23
23
  let { name = 'name', types = [] } = dataFieldNames || {}
24
24
  name = name?.trim() || name
25
25
  const set = new Set()
@@ -27,7 +27,7 @@ export const useTransformChartDataByAttrKey = (data: Data = [], dataFieldNames:
27
27
  const dataLen = data.length
28
28
  const typesLen = types.length
29
29
  // 只有一条记录
30
- if (dataLen === 1) {
30
+ if (dataLen === 1 && !isIndicator) {
31
31
  const vs: any = []
32
32
  // data 为一个值取第一个
33
33
  for (let i = 0; i < typesLen; i++) {
@@ -23,7 +23,7 @@ export const useTransformChartDataByAttrValue = (data: Data, dataFieldNames?: Va
23
23
  name = name?.trim()
24
24
  value = value?.trim()
25
25
  type = type?.trim()
26
- const set = new Set()
26
+ // const set = new Set()
27
27
  const map = new Map()
28
28
  const len = data.length
29
29
  for (let i = 0; i < len; i++) {
@@ -34,7 +34,7 @@ export const useTransformChartDataByAttrValue = (data: Data, dataFieldNames?: Va
34
34
  const y = item[value] || ''
35
35
  // 系列(类型)
36
36
  const t = item[type] || ''
37
- set.add(x)
37
+ // set.add(x)
38
38
  if (map.has(t)) {
39
39
  const arr = map.get(t)
40
40
  // @ts-ignore
@@ -45,13 +45,25 @@ export const useTransformChartDataByAttrValue = (data: Data, dataFieldNames?: Va
45
45
  map.set(t, [{ name: x, value: y, ...item }])
46
46
  }
47
47
  }
48
- const dimensions = Array.from(set)
48
+ // const dimensions = Array.from(set)
49
+ const dimensions = []
49
50
  const dataset: { [key:string]:any } [] = []
50
51
  for (const [name, data] of map) {
51
52
  dataset.push({
52
53
  name,
53
54
  data
54
55
  })
56
+ if (data?.length) {
57
+ if (dimensions.length) {
58
+ for (const d of data) {
59
+ if (!dimensions.includes(d.name)) {
60
+ dimensions.push(d.name)
61
+ }
62
+ }
63
+ } else {
64
+ dimensions.push(...data.map((v: any) => v.name))
65
+ }
66
+ }
55
67
  }
56
68
  return {
57
69
  dimensions,
@@ -5,6 +5,8 @@ export const useVariablesInText = (
5
5
  { useNewline = false, useSpace = false } = {}
6
6
  ) => {
7
7
  // 引入全局变量
8
+ // @ts-ignore
9
+ const config = window.config || {}
8
10
  const data = { ...textData }
9
11
  const variables = (formatter || '').match(/\{(.+?)\}/g)
10
12
  if (variables == null || variables.length === 0) {
@@ -18,7 +20,7 @@ export const useVariablesInText = (
18
20
  for (let j = 0; j < textVariables.length; j++) {
19
21
  const textVariable = textVariables[j]
20
22
  const usedVariable = data[textVariable]
21
- if (usedVariable != null) {
23
+ if (usedVariable != null && typeof usedVariable !== 'function') {
22
24
  // 使用的变量
23
25
  statement = statement.replace(textVariable, usedVariable)
24
26
  }
package/src/index.ts CHANGED
@@ -8,7 +8,7 @@ import useTransformChartDataByAttrValue from './hooks/useTransformChartDataByAtt
8
8
  import useValueFormatter from './hooks/useValueFormatter'
9
9
  import useVariablesInText from './hooks/useVariablesInText'
10
10
  import transformProps from './utils/transformProps'
11
- import { getIndicatorParams } from './utils/util'
11
+ import { getIndicatorParams, lowerCaseIncludes, hasOwn } from './utils/util'
12
12
 
13
13
  export {
14
14
  formatIndicatorParams,
@@ -18,5 +18,7 @@ export {
18
18
  useValueFormatter,
19
19
  useVariablesInText,
20
20
  transformProps,
21
- getIndicatorParams
21
+ getIndicatorParams,
22
+ lowerCaseIncludes,
23
+ hasOwn
22
24
  }