How to use the base/utils.isArray function in base

To help you get started, we’ve selected a few base 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 vizabi / vizabi / src / base / events.js View on Github external
traversePath: function(path) {

    // if there's no path to traverse
    if (typeof path === 'undefined' || utils.isArray(path) && path.length == 0) {
      return this;
    }

    // prepare path to array
    if (typeof path === 'string') {
      path = path.split('.');
    }

    // check if path is an array
    if (!utils.isArray(path)) {
      utils.error('Path is wrong type. Path should be a string or array but is ' + typeof path + '.');
      return null;
    }

    // descent to next child to find target object
    var currentTarget = path.shift();
    if (this[currentTarget] === undefined)
      utils.warn('Can\'t find child "' + currentTarget + '" of the model ' + this._name + '.');
    else
      return this.getModelObject(currentTarget).traversePath(path);
  },
github vizabi / vizabi / src / tools / bubblechart / bubblechart-component.js View on Github external
_rangeBump: function(arg, undo) {
    var bump = this.activeProfile.maxRadius;
    undo = undo?-1:1;
    if(utils.isArray(arg) && arg.length > 1) {
      var z1 = arg[0];
      var z2 = arg[arg.length - 1];

      //the sign of bump depends on the direction of the scale
      if(z1 < z2) {
        z1 += bump * undo;
        z2 -= bump * undo;
        // if the scale gets inverted because of bump, set it to avg between z1 and z2
        if(z1 > z2) z1 = z2 = (z1 + z2) / 2;
      } else if(z1 > z2) {
        z1 -= bump * undo;
        z2 += bump * undo;
        // if the scale gets inverted because of bump, set it to avg between z1 and z2
        if(z1 < z2) z1 = z2 = (z1 + z2) / 2;
      } else {
        utils.warn("rangeBump error: the input scale range has 0 length. that sucks");
github vizabi / vizabi / src / models / marker.js View on Github external
setHighlight(arg) {
    if (!utils.isArray(arg)) {
      this.setHighlight([].concat(arg));
      return;
    }
    this.getModelObject("highlight").set(arg, false, false); // highlights are always non persistent changes
  },
github vizabi / vizabi / src / base / datastorage.js View on Github external
_getUnique(dataId, attr) {
    let uniq;
    const items = this._collection[dataId].data;
    // if it's an array, it will return a list of unique combinations.
    if (utils.isArray(attr)) {
      const values = items.map(d => utils.clone(d, attr)); // pick attrs
      uniq = utils.unique(values, n => JSON.stringify(n));
    } // if it's a string, it will return a list of values
    else {
      const values = items.map(d => d[attr]);
      uniq = utils.unique(values);
    }
    return uniq;
  }
github vizabi / vizabi / src / base / events.js View on Github external
trigger: function(evtType, args) {
    var i;
    var size;

    // split up eventType-paremeter for multiple event-triggers
    if(utils.isArray(evtType)) {
      for(i = 0, size = evtType.length; i < size; i += 1) {
        this.trigger(evtType[i], args);
      }
      return;
    }

    // create an event-object if necessary
    var evt = this.createEventFromType(evtType);

    // if this eventType has no events registered
    if(!this._events.hasOwnProperty(evt.type)) {
      return;
    }

    // for each function registered to this eventType on this object
    var _this = this;
github vizabi / vizabi / src / base / events.js View on Github external
freeze: function(exceptions) {
    this._freeze = true;
    if(!exceptions) {
      return;
    }
    if(!utils.isArray(exceptions)) {
      exceptions = [exceptions];
    }
    for(var i = 0; i < exceptions.length; i += 1) {
      this._freezeExceptions[exceptions[i]] = true;
    }
  },
github vizabi / vizabi / src / base / data.js View on Github external
_getUnique: function(queryId, attr) {
    var uniq;
    var items = this._collection[queryId].data;
    //if it's an array, it will return a list of unique combinations.
    if(utils.isArray(attr)) {
      var values = items.map(function(d) {
        return utils.clone(d, attr); //pick attrs
      });
      uniq = utils.unique(values, function(n) {
        return JSON.stringify(n);
      });
    } //if it's a string, it will return a list of values
    else {
      var values = items.map(function(d) {
        return d[attr];
      });
      uniq = utils.unique(values);
    }
    return uniq;
  },
github vizabi / vizabi / src / components / colorlegend / colorlegend.js View on Github external
this.rainbowLegendEl = this.listColorsEl.append("div").attr("class", "vzb-cl-rainbow-legend");
    this.rainbowLegendSVG = this.rainbowLegendEl.append("svg");
    this.rainbowLegendG = this.rainbowLegendSVG.append("g");
    this.rainbowLegend = null;

    this.labelScaleEl = this.listColorsEl.append("div").attr("class", "vzb-cl-labelscale");
    this.labelScaleSVG = this.labelScaleEl.append("svg");
    this.labelScaleG = this.labelScaleSVG.append("g");
    this.subtitleDiv = this.listColorsEl.append("div").attr("class", "vzb-cl-subtitle");
    this.subtitleText = this.subtitleDiv.append("span").attr("class", "vzb-cl-subtitle-text");

    this.minimapSVG = this.minimapEl.append("svg");
    this.minimapG = this.minimapSVG.append("g");

    this.colorPicker = new ColorPicker(
      utils.isArray(this.root.element) ?
        this.root.element :
        d3.select(this.root.element)
    );

    this.colorPicker.translate(this.model.locale.getTFunction());
    this._initSelectDialog();
  },
github vizabi / vizabi / src / components / timeslider / timeslider.js View on Github external
readyOnce: function () {

    if(this._splash) return;

    var _this = this;

    //DOM to d3
    //TODO: remove this ugly hack
    this.element = utils.isArray(this.element) ? this.element : d3.select(this.element);
    this.element.classed(class_loading, false);

    //html elements
    this.slider_outer = this.element.select(".vzb-ts-slider");
    this.slider = this.slider_outer.select("g");
    this.axis = this.element.select(".vzb-ts-slider-axis");
    this.slide = this.element.select(".vzb-ts-slider-slide");
    this.handle = this.slide.select(".vzb-ts-slider-handle");
    this.valueText = this.slide.select('.vzb-ts-slider-value');
    //Scale
    this.xScale = d3.time.scale()
      .clamp(true);

    //Axis
    this.xAxis = d3.svg.axis()
      .orient("bottom")
github vizabi / vizabi / src / models / color.js View on Github external
      range = range.map(m => utils.isArray(m) ? m[0] : m);