Gantt.config.scales not working on angular

Hi,

I am using the scaling with a switch/case to be able changing the “zoom”. Until now it kinda worked well but since you’ve deprecated subscales i now have to use the gantt.config.scales but it does not work as expected.

The parameters i’m adding are not working and the gantt does not render with the updated scales. I would like to know if there is any thing like a config to make it work.

I figured out it looks like the property scales does not work in angular, i saw a post about it from december 2019.

Do you know if it has been fixed or else ?

As i said in my comment on this page https://docs.dhtmlx.com/gantt/desktop__configuring_time_scale.html
I even tried copy paste the code from the scaling guide page and it does not work at all. Below, the code i’m using to do my scaling :

    public setScaleConfig(level: string) {
        let year = new Date().getFullYear();
        this.translate.get('date').subscribe((locale: any) => {
            const weekScaleTemplate =  (date: any) => {
                const dateToStr = gantt.date.date_to_str(locale.format.ganttShortScaleDate);
                const endDate = gantt.date.add(gantt.date.add(date, 1, 'week'), -1, 'day');
                return dateToStr(date) + ' - ' + dateToStr(endDate);
            };
            const quarterTemplate = (date: any) => {
                const quarterStr = locale.format.ganttShortQuarter + 
                    (Math.floor((date.getMonth() / 3)) + 1) + ' ' + date.getFullYear();
                return quarterStr;
            };
            switch (level) {
                case 'day':
                    this.zoomString = 'day';
                    gantt.config.scales = [ {unit: 'day', step: 1, date: locale.format.ganttShortScaleDate}];
                    gantt.config.scale_height = 27;
                    gantt.config.start_date = this.ganttActualStartDate;
                    gantt.config.end_date = this.ganttActualEndDate;
                    break;
                case 'week':
                    this.zoomString = 'week';
                    gantt.config.scales = [ { unit: 'week', step: 7, format: weekScaleTemplate}];
                    gantt.config.scale_height = 50;

                    gantt.config.subscales = [
                        {unit: 'day', step: 1, date: '%D'}
                    ];
                    gantt.config.start_date = this.ganttActualStartDate;
                    gantt.config.end_date = this.ganttActualEndDate;
                    break;
                case 'month':
                    this.zoomString = 'month';
                    gantt.config.scales = [{ unit: 'month', step: 1, format: '%F %Y'}];
                    gantt.config.scale_height = 50;

                    gantt.config.subscales = [{ unit: 'month', step: 1, format: '%F %Y'},
                        {unit: 'week', step: 1, format: weekScaleTemplate}
                    ];
                    gantt.config.start_date = this.ganttActualStartDate;
                    gantt.config.end_date = this.ganttActualEndDate;
                    break;
                case 'quarter': 
                    this.zoomString = 'quarter';
                    gantt.config.scales = [ { unit: 'quarter', step: 1, format: quarterTemplate} ];
                    gantt.config.subscales = [
                        {unit: 'month', step: 1, date: '%F, %Y'}
                    ];
                    gantt.config.scale_height = 50;
                    this.quarterZoom(this.quarterZoomString);
                    break;
                case 'year':
                    this.zoomString = 'year';
                    gantt.config.scales = [ { unit: 'year', step: 1, format: '%Y'} ];

                    gantt.config.min_column_width = 50;
                    gantt.config.scale_height = 90;

                    gantt.config.subscales = [
                        {unit: 'month', step: 1, date: '%M'},
                    ];
                    gantt.config.start_date = moment('01-01' + this.ganttActualStartDate.getFullYear(), 'DD-MM-YYYY')
                        .toDate();
                    gantt.config.end_date = moment('31-12' + this.ganttActualEndDate.getFullYear(), 'DD-MM-YYYY')
                        .toDate();
                    break;
            }
        });
    }

(this code is not working properly in my gantt, i tried removing the subscales and put the code in the scales but it changed nothing). my gantt version is 7.0.2

I don’t see anything that could be the reason why it does not work before using gantt.config.scale i used the gantt.config.scale_unit and all and the gantt.config.subscales which were working pretty nicely.

So if you have any idea to help me please !
Thanks !

Hello @Florian,

I tried to reproduce this issue in the demo based on angular 8 + gantt v.7.0.2, with documentation examples as a code reference:
https://docs.dhtmlx.com/gantt/desktop__zooming.html

But the scales config worked as expected:
https://recordit.co/treL795BrLhttps://recordit.co/treL795BrL

I attached the archive with a demo to this post(I removed node_modules, so you should install them and install gantt after that):
angular8 gantt_7.0.2 zoom.zip (122 KB)

For now, I only can suppose that the issue is connected with your additional code. Unfortunately, I’m not specialized in angular and may miss some things from your code example.

If it doesn’t help, you can send me a simplified demo, which I will be able to run locally and reproduce the issue.

Thanks for your answer.

Sadly even with your code i couldn’t find a working fix with gantt.config.scales but i found a way to make it work until i have time to find a better way.

I can not send you a local demo but thanks for your help.