import { scaleLinear } from "d3-scale";

var scaleConstructors = {
  linear: scaleLinear
  // TODO support all scales https://github.com/datavis-tech/reactive-vis/issues/26
};


export default function Scale (my, name, options){

  options = options || {};
  var type = options.type || "linear";
  var nice = options.nice || true;

  var scale = scaleConstructors[type]();


  // (name + "Domain") and (name + "Range")
  // must be defined on the model before incoking this mixin.
  // TODO throw an error if they are not defined at this point.
  // GitHub issue #25 https://github.com/datavis-tech/reactive-vis/issues/25

  my

    (name + "Scale", function(domain, range){

      scale
        .domain(domain)
        .range(range);

      // TODO test
      //if(nice){
      //  scale.nice();
      //}

      return scale;
    }, [name + "Domain", name + "Range"])

    (name + "Scaled", function(scale, accessor){
      return function (d){
        return scale(accessor(d));
      };
    }, [name + "Scale", name + "Accessor"]);
}

import { scaleLinear } from "d3-scale";

var scaleConstructors = {
  linear: scaleLinear
  // TODO support all scales https://github.com/datavis-tech/reactive-vis/issues/26
};


export default function Scale (my, name, options){

  options = options || {};
  var type = options.type || "linear";

  var scale = scaleConstructors[type]();

  my

    (name + "Scale", function(domain, range){
      return scale.domain(domain).range(range);
    }, [name + "Domain", name + "Range"])

    (name + "Scaled", function(scale, accessor){
      return function (d){
        return scale(accessor(d));
      };
    }, [name + "Scale", name + "Accessor"]);
}

Move issues out of comments and into GitHub issues.
Move issues out of comments and into GitHub issues.
