Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
color: function() {
// i am cool with dc.js's color accessor
if(_.has(defn, 'color'))
chart.colorAccessor(key_value(accessor(defn.color)));
// however i don't understand why dc chooses to use a
// "color calculator" when a d3 scale seems like it ought
// to serve the purpose. so just plug a d3 scale into colors
// and override the calculator to use it
// also default to category10 which seems better for discrete colors
var scale = defn['color.scale'] || d3.scale.category10();
if(_.has(defn, 'color.domain'))
scale.domain(defn['color.domain']);
else if(mhas(defn, 'color', 'attrs', 'levels'))
scale.domain(defn.color.attrs.levels);
if(_.has(defn, 'color.range'))
scale.range(defn['color.range']);
chart.colors(scale);
chart.colorCalculator(function(x) { return chart.colors()(x); });
},
stackable: function() {
infer: function(definition, name, frame, defn, dims, groups, errors) {
if(!defn['color.scale']) {
// note stackable bleeds in here: since they are on different branches
// of the hierarchy, there is no sensible way for stackable to override
// color here
var levels = dcplot.get_levels(frame, dims, defn.stack || defn.dimension);
defn['color.scale'] = (levels !== null && levels.length>10) ?
d3.scale.category20() : d3.scale.category10();
}
if(!defn['color.domain']) {
// this also should be abstracted out into a plugin (RCloud-specific)
if(dcplot.mhas(defn, 'color', 'attrs', 'r_attributes', 'levels'))
defn['color.domain'] = defn.color.attrs.r_attributes.levels;
}
},
create: function(definition, object, groupname, frame, defn, dims, groups, errors) {
color: function() {
// i am cool with dc.js's color accessor
if(_.has(defn, 'color'))
chart.colorAccessor(key_value(accessor(defn.color)));
// however i don't understand why dc chooses to use a
// "color calculator" when a d3 scale seems like it ought
// to serve the purpose. so just plug a d3 scale into colors
// and override the calculator to use it
// also default to category10 which seems better for discrete colors
var scale = defn['color.scale'];
if(_.has(defn, 'color.domain'))
scale.domain(defn['color.domain']);
if(_.has(defn, 'color.range'))
scale.range(defn['color.range']);
chart.colors(scale);
chart.colorCalculator(function(x) { return chart.colors()(x); });
},
stackable: function() {
color: function() {
if(!defn['color.scale']) {
// note stackable bleeds in here: since they are on different branches
// of the hierarchy, there is no sensible way for stackable to override
// color here
var levels = get_levels(defn.stack || defn.dimension);
defn['color.scale'] = (levels !== null && levels.length>10) ?
d3.scale.category20() : d3.scale.category10();
}
if(!defn['color.domain']) {
// this also should be abstracted out into a plugin (RCloud-specific)
if(mhas(defn, 'color', 'attrs', 'r_attributes', 'levels'))
defn['color.domain'] = defn.color.attrs.r_attributes.levels;
}
},
stackable: function() {
infer: function(definition, name, frame, defn, dims, groups, errors) {
/* in practice, dc's xUnits seem to be based on either the bin width
for a histogram, or the set of ordinals */
if(!('x.units' in defn) && defn.group) {
var group = groups[defn.group];
if(dcplot.mhas(group, 'group', 'binwidth'))
defn['x.units'] = dc.units.fp.precision(group.group.binwidth);
}
if(!_.has(defn, 'color.domain')) {
var levels;
if(this.one_stack(defn)) {
if(defn['color.x']) {
levels = dcplot.get_levels(frame, dims, defn.dimension);
if(levels)
defn['color.domain'] = levels;
}
}
else {
levels = dcplot.get_levels(frame, dims, defn.stack);
if(levels)
defn['color.domain'] = levels;
}
}
},
create: function(definition, object, groupname, frame, defn, dims, groups, errors) {
create: function(definition, object, groupname, frame, defn, dims, groups, errors) {
if(_.has(defn, 'color'))
object.chart.colorAccessor(dcplot.key_value(dcplot.accessor(frame, defn.color)));
var scale = defn['color.scale'];
if(_.has(defn, 'color.domain'))
scale.domain(defn['color.domain']);
if(_.has(defn, 'color.range'))
scale.range(defn['color.range']);
object.chart.colors(scale);
}
},
if(mhas(group, 'group', 'binwidth'))
defn['x.units'] = dc.units.fp.precision(group.group.binwidth);
}
if(!_.has(defn, 'color.domain')) {
var levels;
if(one_stack(defn)) {
if(defn['color.x']) {
levels = get_levels(defn.dimension);
if(levels)
defn['color.domain'] = levels;
}
}
else {
levels = get_levels(defn.stack);
if(levels)
defn['color.domain'] = levels;
}
}
},
line: function() {