Request new features or modifications


Post by blackoverlord89 »

Current versions supports only one scale for gnt.panel.resourcehistogram.
I need to define different scaleMax, scaleMin, scaleStep for some resources. May be you add the support for scale-fields to gnt.model.resource and use it if defined, else use common scale.

For example, resource "Администратор ELMA" has own calendar with 3 working hours per day, but histogram using one scale for all resources, I cant properly see info about this resource (it's too small).
Attachments
screen1.png
screen1.png (44.43 KiB) Viewed 9372 times

Post by Terence »

You mean different adjustable scale per row? Could be nice but also confusing.

BTW: have you looked at scalepoints: https://www.bryntum.com/products/gantt-for-extjs/docs/ ... calePoints

Post by blackoverlord89 »

scalepoints just allow to define custom levels with defined cls (this scale is also common for all resources), but I mean to define own scale for each resource (row in hostogram), because the histogram bars are rendering according to common scalemax, scalestep, scalemin. I want to render 3 hours for one resource as full loaded histogram bar (now it draws too small by height, relative to scale)

Post by arcady »

I answered you already that it's a trivial thing. Just extend Gnt.column.Scale and override its defaultRenderer method. Use different scalePoints for different records that's all.

Post by blackoverlord89 »

overrided defaultRenderer, but histogram bars still rendering with height according to scalemax from Gnt.panel.ResourceHistogram
In function Gnt.view.ResourceHistogram.prepareBars :
tplItem.height = allocation >= histogram.scaleMin ? Math.round((allocation - histogram.scaleMin) * this.unitHeight) : 0;

unitHeight depends upon common scale

On the screenshot resource "Администратор ELMA" have own calendar with 10 working hours per day, but limit lines and bars are rendered according to common scaleMax = 24 (I need 10 hours = 100% = full bar height)
Ext.override(Gnt.column.Scale, {
    defaultRenderer: function (value, meta, record) {
        if (record.get('Type') == "Work") {
            this.scaleMin = 0;
            this.scaleMax = 8;
            this.scaleStep = 1;
            this.scaleStepHeight = this.availableHeight / (this.scaleMax - this.scaleMin + this.scaleStep);
            this.scaleLabelStep = 4;
            this.scalePoints = this.buildScalePoints();
        } else {
            this.scaleMin = 0;
            this.scaleMax = 24;
            this.scaleStep = 4;
            this.scaleStepHeight = this.availableHeight / (this.scaleMax - this.scaleMin + this.scaleStep);
            this.scaleLabelStep = 8;
            this.scalePoints = this.buildScalePoints();
        }
        var data = {
            record      : Ext.apply({}, record.data, record.getAssociatedData()),
            scaleHeight : this.availableHeight,
            scalePoints : this.scalePoints
        };

        return this.tpl.apply(data);
    }
});
Attachments
screen1.png
screen1.png (44.51 KiB) Viewed 9362 times

Post by arcady »

What version do you have? If you have 2.5.5 or 3.0.3 you can use Gnt.panel.ResourceHistogram.barRenderer to adjust bar coordinates and override Gnt.view.ResourceHistogram.pushLimitLine private method to adjust limit line coordinates.

Post by arcady »

Though you're right while scale column overriding is trivial overriding the histogram seems more tricky .

Post by arcady »

For bars and scale column it's quite easily doable:
    Ext.override(Gnt.column.Scale, {
        defaultRenderer: function (value, meta, record) {

            if (record.getId() % 2) {
                this.scaleMin = 0;
                this.scaleMax = 8;
                this.scaleStep = 1;
                this.scaleLabelStep = 4;
            } else {
                this.scaleMin = 0;
                this.scaleMax = 24;
                this.scaleStep = 4;
                this.scaleLabelStep = 8;
            }
            this.scaleStepHeight = this.availableHeight / (this.scaleMax - this.scaleMin + this.scaleStep);
            
            // this can be done better ..there might be a set of pre-built scale point arrays
            // to just pick a proper one here ..w/o calling buildScalePoints() every time
            this.scalePoints = this.buildScalePoints();

            var data = {
                record      : Ext.apply({}, record.data, record.getAssociatedData()),
                scaleHeight : this.availableHeight,
                scalePoints : this.scalePoints
            };

            return this.tpl.apply(data);
        }
    });

    Ext.override(Gnt.view.ResourceHistogram, {

        flipScale : function (resourceId) {
            if (resourceId % 2) {
                this.scaleMin = 0;
                this.scaleMax = 8;
                this.scaleStep = 1;
            } else {
                this.scaleMin = 0;
                this.scaleMax = 24;
                this.scaleStep = 4;
            }
        },

        prepareBars : function (histogram) {
            this.histogram = histogram;

            // backup default scale settings
            this._scaleBackup = {
                scaleMin    : histogram.scaleMin,
                scaleMax    : histogram.scaleMax,
                scaleStep   : histogram.scaleStep
            };

            return this.callParent(arguments);
        },

        barRenderer : function (resourceId, data, tplItem) {
            var histogram = this.histogram,
                rowHeight = this.getAvailableRowHeight(),
                barCls = this._barCls;

            this.flipScale(resourceId);

            this.unitHeight = rowHeight / (this.scaleMax - this.scaleMin + this.scaleStep);

            // get allocation in units (hours by default)
            var allocation  = histogram.calendar.convertMSDurationToUnit(data.allocationMS, histogram.scaleUnit);

            // if the bar fits in row height
            if (allocation <= this.scaleMax + this.scaleStep) {
                tplItem.height  = allocation >= this.scaleMin ? Math.round((allocation - this.scaleMin) * this.unitHeight) : 0;
                tplItem.top     = rowHeight - tplItem.height;
            // if bar is higher than row height
            } else {
                // add class to indicate it
                tplItem.cls     += ' '+barCls+'-partofbar';
            }

            // restore default scale settings and recalc unitHeight back
            Ext.apply(this, this._scaleBackup);
            this.unitHeight = rowHeight / (this.scaleMax - this.scaleMin + this.scaleStep);
        }

    });
And for maximum allocation lines it's tricky. We have an internal ticket for the histogram refactoring. I will make a note about this. So in the next release maximum allocation lines will probably be more customizable.

Post Reply