How to use the color.scale function in color

To help you get started, we’ve selected a few color 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 att / rcloud / htdocs / lib / js / dcplot.js View on Github external
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() {
github att / rcloud / htdocs / lib / js / dcplot.js View on Github external
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() {
github att / rcloud.dcplot / inst / www / dcplot.js View on Github external
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) {
github att / rcloud / htdocs / lib / js / dcplot.js View on Github external
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() {
github att / rcloud.dcplot / inst / www / dcplot.js View on Github external
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) {
github att / rcloud / htdocs / lib / js / dcplot / dcplot.js View on Github external
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() {
github att / rcloud.dcplot / inst / www / dcplot.js View on Github external
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);
        }
    },