How to use the vega-util.isArray function in vega-util

To help you get started, we’ve selected a few vega-util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vega / vega-lite / src / compile / repeater.ts View on Github external
function replaceRepeater(mapping: EncodingOrFacet, repeater: RepeaterValue): EncodingOrFacet {
  const out: EncodingOrFacet = {};
  for (const channel in mapping) {
    if (hasOwnProperty(mapping, channel)) {
      const channelDef: ChannelDef> | ChannelDef>[] = mapping[channel];

      if (isArray(channelDef)) {
        // array cannot have condition
        out[channel] = channelDef.map(cd => replaceRepeaterInChannelDef(cd, repeater)).filter(cd => cd);
      } else {
        const cd = replaceRepeaterInChannelDef(channelDef, repeater);
        if (cd !== undefined) {
          out[channel] = cd;
        }
      }
    }
  }
  return out;
}
github vega / vega-lite / build / src / compile / facet.js View on Github external
const outputName = facetSortFieldName(fieldDef, sort);
                    if (row && column) {
                        // For crossed facet, use pre-calculate field as it requires a different groupby
                        // For each calculated field, apply max and assign them to the same name as
                        // all values of the same group should be the same anyway.
                        fields.push(outputName);
                        ops.push('max');
                        as.push(outputName);
                    }
                    else {
                        fields.push(field);
                        ops.push(op);
                        as.push(outputName);
                    }
                }
                else if (isArray(sort)) {
                    const outputName = sortArrayIndexField(fieldDef, channel);
                    fields.push(outputName);
                    ops.push('max');
                    as.push(outputName);
                }
            }
        }
        const cross = !!row && !!column;
        return Object.assign({ name,
            data,
            groupby }, (cross || fields.length
            ? {
                aggregate: Object.assign({}, (cross ? { cross } : {}), (fields.length ? { fields, ops, as } : {}))
            }
            : {}));
    }
github vega / vega-lite / src / compile / repeat.ts View on Github external
private _initChildren(
    spec: NormalizedRepeatSpec,
    repeat: RepeatMapping | string[],
    repeater: RepeaterValue,
    config: Config
  ): Model[] {
    const children: Model[] = [];

    const row = (!isArray(repeat) && repeat.row) || [repeater ? repeater.row : null];
    const column = (!isArray(repeat) && repeat.column) || [repeater ? repeater.column : null];
    const repeatValues = (isArray(repeat) && repeat) || [repeater ? repeater.repeat : null];

    // cross product
    for (const repeatValue of repeatValues) {
      for (const rowValue of row) {
        for (const columnValue of column) {
          const name =
            (repeatValue ? `__repeat_repeat_${repeatValue}` : '') +
            (rowValue ? `__repeat_row_${rowValue}` : '') +
            (columnValue ? `__repeat_column_${columnValue}` : '');

          const childRepeat = {
            repeat: repeatValue,
            row: rowValue,
            column: columnValue
github vega / vega-lite / build / src / compile / mark / mark.js View on Github external
case 'latitude':
            case 'longitude':
            case 'latitude2':
            case 'longitude2':
            // TODO: case 'cursor':
            // text, shape, shouldn't be a part of line/trail/area
            case 'text':
            case 'shape':
            // tooltip fields should not be added to group by
            case 'tooltip':
                return details;
            case 'detail':
            case 'key':
                const channelDef = encoding[channel];
                if (isArray(channelDef) || isFieldDef(channelDef)) {
                    (isArray(channelDef) ? channelDef : [channelDef]).forEach(fieldDef => {
                        if (!fieldDef.aggregate) {
                            details.push(vgField(fieldDef, {}));
                        }
                    });
                }
                return details;
            case 'size':
                if (mark === 'trail') {
                    // For trail, size should not group trail lines.
                    return details;
                }
            // For line, it should group lines.
            /* tslint:disable */
            // intentional fall through
            case 'color':
            case 'fill':
github vega / vega-lite / build / src / compile / legend / encode.js View on Github external
if (fill) {
                    out.fill = { value: fill };
                }
            }
        }
    }
    if (out.stroke) {
        if (channel === 'stroke' || (!filled && channel === COLOR)) {
            delete out.stroke;
        }
        else {
            if (out.stroke['field']) {
                // For others, remove stroke field
                delete out.stroke;
            }
            else if (isArray(out.stroke)) {
                const stroke = getFirstDefined(getFirstConditionValue(encoding.stroke || encoding.color), markDef.stroke, filled ? markDef.color : undefined);
                if (stroke) {
                    out.stroke = { value: stroke };
                }
            }
        }
    }
    if (channel !== SHAPE) {
        const shape = getFirstConditionValue(encoding.shape) || markDef.shape;
        if (shape) {
            out.shape = { value: shape };
        }
    }
    if (channel !== OPACITY) {
        if (opacity) {
            // only apply opacity if it is neither zero or undefined
github vega / vega-lite / src / compile / legend / encode.ts View on Github external
getFirstConditionValue(encoding.fill ?? encoding.color) ?? markDef.fill ?? (filled && markDef.color);
        if (fill) {
          out.fill = {value: fill} as ColorValueRef;
        }
      }
    }
  }

  if (out.stroke) {
    if (channel === 'stroke' || (!filled && channel === COLOR)) {
      delete out.stroke;
    } else {
      if (out.stroke['field']) {
        // For others, remove stroke field
        delete out.stroke;
      } else if (isArray(out.stroke)) {
        const stroke = getFirstDefined(
          getFirstConditionValue(encoding.stroke || encoding.color),
          markDef.stroke,
          filled ? markDef.color : undefined
        );
        if (stroke) {
          out.stroke = {value: stroke} as ColorValueRef;
        }
      }
    }
  }

  if (channel !== OPACITY) {
    if (condition) {
      out.opacity = [{test: condition, value: opacity ?? 1}, {value: config.legend.unselectedOpacity}];
    } else if (opacity) {
github vega / vega / packages / vega-parser / src / parsers / codegen.js View on Github external
invert: function(name, range, group) {
    var s = getScale(name, (group || this).context);
    return !s ? undefined
      : isArray(range) ? (s.invertRange || s.invert)(range)
      : (s.invert || s.invertExtent)(range);
  },
github vega / vega-lite / src / compile / axis / assemble.ts View on Github external
keys(axis).forEach(prop => {
    const propType = AXIS_PROPERTY_TYPE[prop];
    const propValue = axis[prop];
    if (propType && propType !== kind && propType !== 'both') {
      delete axis[prop];
    } else if (isConditionalAxisValue(propValue)) {
      const {vgProp, part} = CONDITIONAL_AXIS_PROP_INDEX[prop];
      const {condition, value} = propValue;

      const vgRef = [
        ...(isArray(condition) ? condition : [condition]).map(c => {
          const {value: v, test} = c;
          return {
            test: expression(null, test),
            value: v
          };
        }),
        {value}
      ];

      setAxisEncode(axis, part, vgProp, vgRef);

      delete axis[prop];
    }
  });
github vega / vega-lite / build / src / compile / header / assemble.js View on Github external
function getSort(facetFieldDef, channel) {
    const { sort } = facetFieldDef;
    if (isSortField(sort)) {
        return {
            field: vgField(sort, { expr: 'datum' }),
            order: sort.order || 'ascending'
        };
    }
    else if (isArray(sort)) {
        return {
            field: sortArrayIndexField(facetFieldDef, channel, { expr: 'datum' }),
            order: 'ascending'
        };
    }
    else {
        return {
            field: vgField(facetFieldDef, { expr: 'datum' }),
            order: sort || 'ascending'
        };
    }
}
export function assembleLabelTitle(facetFieldDef, channel, config) {
github vega / vega-lite / src / encoding.ts View on Github external
export function channelHasField(encoding: EncodingWithFacet, channel: Channel): boolean {
  const channelDef = encoding && encoding[channel];
  if (channelDef) {
    if (isArray(channelDef)) {
      return some(channelDef, fieldDef => !!fieldDef.field);
    } else {
      return isFieldDef(channelDef) || hasConditionalFieldDef(channelDef);
    }
  }
  return false;
}