lodash#forIn TypeScript Examples

The following examples show how to use lodash#forIn. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: pivot-facet.ts    From S2 with MIT License 6 votes vote down vote up
private getColLabelLength(col: Node) {
    // 如果 label 字段形如 "["xx","xxx"]",直接获取其长度
    const labels = safeJsonParse(col?.value);
    if (isArray(labels)) {
      return labels.length;
    }

    // 否则动态采样前50条数据,如果数据value是数组类型,获取其长度
    const { dataSet } = this.cfg;
    const multiData = dataSet.getMultiData(
      col.query,
      col.isTotals || col.isTotalMeasure,
    );
    // 采样前50,根据指标个数获取单元格列宽
    const demoData = multiData?.slice(0, 50) ?? [];
    const lengths = [];
    forEach(demoData, (value) => {
      forIn(value, (v: MultiData) => {
        if (isObject(v) && v?.values) {
          lengths.push(size(v?.values[0]));
        }
      });
    });
    return max(lengths) || 1;
  }
Example #2
Source File: custom-data-set.ts    From S2 with MIT License 6 votes vote down vote up
processDataCfg(dataCfg: S2DataConfig): S2DataConfig {
    dataCfg.fields.rows = [EXTRA_FIELD];
    dataCfg.fields.valueInCols = false;
    const { data, ...restCfg } = dataCfg;
    const transformedData = [];
    forEach(data, (dataItem) => {
      let isPushed = false;
      forIn(dataItem, (value, key) => {
        if (isObject(value)) {
          transformedData.push({
            ...dataItem,
            [EXTRA_FIELD]: key,
            [VALUE_FIELD]: value,
          });
          isPushed = true;
        }
      });
      if (!isPushed) {
        transformedData.push(dataItem);
      }
    });
    return {
      data: uniq(transformedData),
      ...restCfg,
    };
  }
Example #3
Source File: use-hooks.tsx    From erda-ui with GNU Affero General Public License v3.0 6 votes vote down vote up
convertFilterParamsToUrlFormat =
  (fullRange?: boolean, dateFormat?: string) =>
  (
    condition: { [prop: string]: any },
    fieldConvertor?: {
      [k: string]: (value: any, allQuery?: any) => string | string[] | undefined;
    },
  ) => {
    const formatCondition = {};
    forIn(condition, (v, k) => {
      const fieldConvertFunc = get(fieldConvertor, k);
      if (Array.isArray(v) && v.length === 2 && every(v, (item) => moment.isMoment(item))) {
        // handle date range
        const [start, end] = v as [Moment, Moment];
        const format = dateFormat || 'YYYY-MM-DD HH:mm:ss';
        let startName = `${k}From`;
        let endName = `${k}To`;
        const rangeNames = k.split(',');
        if (rangeNames.length === 2) {
          [startName, endName] = rangeNames;
        }
        const startMoment = fullRange ? start.startOf('day') : start;
        const endMoment = fullRange ? end.endOf('day') : end;
        set(formatCondition, startName, format === 'int' ? startMoment.valueOf() : startMoment.format(format));
        set(formatCondition, endName, format === 'int' ? endMoment.valueOf() : endMoment.format(format));
      } else if (fieldConvertFunc) {
        // handle custom field
        set(formatCondition, k, fieldConvertFunc(v, condition));
      } else {
        set(formatCondition, k, v);
      }
    });
    return formatCondition;
  }
Example #4
Source File: spread-sheet.ts    From S2 with MIT License 5 votes vote down vote up
private clearCanvasEvent() {
    const canvasEvents = this.getEvents();
    forIn(canvasEvents, (_, event: keyof EmitterType) => {
      this.off(event);
    });
  }