Histogram.js 2.67 KB
Ext.define('amdaPlotComp.plotFunction.Histogram', {
    extend: 'amdaPlotComp.plotFunction.BaseComponent',
    title: "Histogram Arguments",

    functionId: 'histo1d-function',
    binsId: 'histo1d-xbinnumber',
    xMinId: "histo1d-xmin",
    xMaxId: 'histo1d-xmax',

    initComponent: function () {
        const me = this;

        const comboStore = Ext.create('Ext.data.Store', {
            fields: ['label', 'value'],
            data: [
                { value: 'density', label: 'Density' },
                { value: 'normdensity', label: 'Normalised Density' }
            ]
        });

        const densityTypeCombo = Ext.create('Ext.form.field.ComboBox', {
            fieldLabel: 'Density Type',
            name: me.functionId,
            store: comboStore,
            queryMode: 'local',
            displayField: 'label',
            valueField: 'value',
            editable: false,
            value: 'density'
        });

        Ext.apply(me, {
            items: [
                {
                    xtype: 'numberfield',
                    fieldLabel: 'X Min',
                    name: me.xMinId,
                    allowDecimals: true,
                    hideTrigger: true,
                    keyNavEnabled: false,
                },
                {
                    xtype: 'numberfield',
                    fieldLabel: 'X Max',
                    name: me.xMaxId,
                    allowDecimals: true,
                    hideTrigger: true,
                    keyNavEnabled: false,
                },
                {
                    xtype: 'numberfield',
                    fieldLabel: 'Number of Bins',
                    name: me.binsId,
                    minValue: 1,
                    value: 100,
                    allowDecimals: false,
                    keyNavEnabled: false,
                },
                densityTypeCombo
            ]
        });

        me.callParent(arguments);
    },

    getValues: function () {
        const densityTypeCombo = this.query('[name=' + this.functionId + ']')[0];
        const densityTypeValue = densityTypeCombo.getValue();

        const numBinsField = this.query('[name=' + this.binsId + ']')[0];
        const numBinsValue = numBinsField.getValue();

        const xMinField = this.query('[name=' + this.xMinId + ']')[0];
        const xMinValue = xMinField.getValue();

        const xMaxField = this.query('[name=' + this.xMaxId + ']')[0];
        const xMaxValue = xMaxField.getValue();

        let out = {};

        out[this.functionId] = densityTypeValue;
        out[this.binsId] = numBinsValue;
        out[this.xMinId] = xMinValue;
        out[this.xMaxId] = xMaxValue;

        return out;
    }
});