clientIO / JointJS_plus

JointJS+ support
4 stars 9 forks source link

Filtering legend items in Charts. #38

Closed DavidDurman closed 9 years ago

DavidDurman commented 9 years ago

As per José's suggestion, it would be great to provide a facility to filter legend items in charts, for example, based on a max/min/thresholds in the series data. This is currently not support but can be easily added, e.g.:

joint.shapes.chart.PlotView.prototype.updateLegend = function() {

    var series = this.model.get('series');

    this.elLegendItems.textContent = '';

    var dy = 0;

    _.each(series, function(serie, i) {

        // An example of skipping a legend item if max value of 
        // a serie is less than 6.
        if (this.stats.bySerie[serie.name || i].maxY < 6) {
            return;
        }

        var elLegendItem = this.elLegendItem.clone();
        if (_.contains(this._disabledSeries, serie.name)) {
            elLegendItem.addClass('disabled');
        }
        elLegendItem.attr('data-serie', serie.name);
        elLegendItem.findOne('circle').attr({ fill: this.getSerieColor(serie.name) });
        elLegendItem.findOne('text').text(serie.label || serie.name);
        elLegendItem.translate(0, dy);
        V(this.elLegendItems).append(elLegendItem);

        dy += 16; // legend item line-height

    }, this);
};
DavidDurman commented 9 years ago

Implemented as part of the upcoming Rappid v1.5.