How to use datalib - 10 common examples

To help you get started, we’ve selected a few datalib 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 / lyra / src / js / model / primitives / marks / Scene.js View on Github external
Scene.defaultProperties = function(props) {
  // Note that scene has no "properties" property
  return dl.extend({
    // Containers for child marks
    scales: [],
    legends: [],
    axes: [],
    marks: [],
    // type will be removed later on, but is used to generate an appropriate name
    type: 'scene',
    // Scene has no Vega properties object, but we mock it for now to avoid
    // distrupting the export functionality
    properties: {
      update: {}
    },
    // Scene-specific visual properties
    width: 610,
    height: 610,
    padding: 'auto',
github vega / lyra / src / js / model / primitives / marks / Group.js View on Github external
Group.defaultProperties = function(props) {
  return dl.extend({
    type: 'group',
    // name: 'group' + '_' + counter.type('group'); // Assign name in the reducer
    // _id: assign ID in the reducer
    properties: Mark.mergeProperties(Mark.defaultProperties(), {
      update: {
        x: {value: 0},
        y: {value: 0},
        width: {signal: ns('vis_width')},
        height: {signal: ns('vis_height')},
        fill: {value: 'transparent'}
      }
    }),
    // Containers for child marks
    scales: [],
    legends: [],
    axes: [],
github vega / lyra / src / js / model / primitives / marks / Area.js View on Github external
Area.defaultProperties = function(props) {
  return dl.extend({
    type: 'area',
    // name: 'area' + '_' + counter.type('area'); // Assign name in the reducer
    // _id: assign ID in the reducer
    properties: Mark.mergeProperties(Mark.defaultProperties(), {
      update: {
        x2: {value: 0},
        y2: {value: 0},
        xc: {value: 60, _disabled: true},
        yc: {value: 60, _disabled: true},
        tension: {value: 13},
        interpolate: {value: 'monotone'},
        fill: {value: '#55498D'},
        stroke: {value: '#55498D'},
        orient: {value: 'vertical'},
        width: {value: 30, _disabled: true},
        height: {value: 30, _disabled: true}
github vega / lyra / src / js / model / primitives / marks / Line.js View on Github external
Line.defaultProperties = function(props) {
  var defaults = {
    type: 'line',
    // name: 'line' + '_' + counter.type('line'); // Assign name in the reducer
    // _id: assign ID in the reducer
    properties: Mark.mergeProperties(Mark.defaultProperties(), {
      update: {
        stroke: {value: '#000000'},
        strokeWidth: {value: 3}
      }
    })
  };
  // Mark gives us two defaults we do not want
  delete defaults.properties.update.fill;
  delete defaults.properties.update.fillOpacity;
  return dl.extend(defaults, props);
};
github vega / vega / src / parse / properties.js View on Github external
}

  if (hasPath(mark, vars)) code += "\n  d += (item.touch(), 1);";
  code += "\n  if (trans) trans.interpolate(item, o);";
  code += "\n  return d > 0;";

  try {
    /* jshint evil:true */
    var encoder = Function('item', 'group', 'trans', 'db',
      'signals', 'predicates', code);

    encoder.tpl  = Tuple;
    encoder.exprs = exprs;
    encoder.util = dl;
    encoder.d3   = d3; // For color spaces
    dl.extend(encoder, dl.template.context);
    return {
      encode:  encoder,
      signals: dl.keys(deps.signals),
      scales:  dl.keys(deps.scales),
      data:    dl.keys(deps.data),
      fields:  dl.keys(deps.fields),
      nested:  deps.nested,
      reflow:  deps.reflow
    };
  } catch (e) {
    log.error(e);
    log.log(code);
  }
}
github vega / vega / src / parse / properties.js View on Github external
function properties(model, mark, spec) {
  var config = model.config(),
      code = "",
      names = dl.keys(spec),
      exprs = [], // parsed expressions injected in the generated code
      i, len, name, ref, vars = {},
      deps = {
        signals: {},
        scales:  {},
        data:    {},
        fields:  {},
        nested:  [],
        _nRefs:  {},  // Temp stash to de-dupe nested refs.
        reflow:  false
      };

  code += "var o = trans ? {} : item, d=0, exprs=this.exprs, set=this.tpl.set, tmpl=signals||{}, t;\n" +
          // Stash for dl.template
          "tmpl.datum  = item.datum;\n" +
          "tmpl.group  = group;\n" +
github vega / lyra / src / js / model / primitives / Scale.js View on Github external
field = lookup(ref);
    return {
      data: getParent(field).name,
      field: field._name
    };
  }

  // More than one ref
  for (i = 0, len = ref.length; i < len; ++i) {
    field = lookup(ref[i]);
    data = getParent(field);
    sets[data._id] = sets[data._id] || (sets[data._id] = []);
    sets[data._id].push(field);
  }

  keys = dl.keys(sets);
  if (keys.length === 1) {
    ref = {
      data: data.name,
      field: sets[data._id].map(fmap)
    };
  } else {
    ref = {fields: []};
    for (i = 0, len = keys.length; i < len; ++i) {
      data = lookup(keys[i]);
      ref.fields.push({
        data: data.name,
        field: sets[data._id].map(fmap)
      });
    }
  }
}
github vega / lyra / src / js / actions / guideActions.js View on Github external
function addGuide(guideProps) {
  var props = dl.extend({
    _id: guideProps._id || counter.global(),
  }, guideProps);

  return {
    id: props._id,
    type: ADD_GUIDE,
    props: props
  };
}
github vega / vega / src / parse / interactors.js View on Github external
function nsProperties(propset) {
    dl.keys(propset).forEach(function(k) {
      var p = propset[k];
      if (p.signal) p.signal = ns(p.signal, sg);
      else if (p.rule) {
        p.rule.forEach(function(r) {
          if (r.signal) r.signal = ns(r.signal, sg);
          if (r.predicate) nsOperand(r);
        });
      }
    });
  }
github vega / vega / src / core / View.js View on Github external
prototype.data = function(data) {
  var v = this;
  if (!arguments.length) return v._model.values();
  else if (dl.isString(data)) return streaming.call(v, data);
  else if (dl.isObject(data)) {
    dl.keys(data).forEach(function(k) {
      var api = streaming.call(v, k);
      data[k](api);
    });
  }
  return this;
};

datalib

JavaScript utilites for loading, summarizing and working with data.

BSD-3-Clause
Latest version published 4 years ago

Package Health Score

47 / 100
Full package analysis

Popular datalib functions