Our state of the art Gantt chart


Post by leanit »

Hello,
we would like to know if it’s possible to configure the Resource Utilization widget to use a custom field instead of the default effort field.

In our implementation, each assignment includes a custom field called manualEffort, which serves the same purpose as effort but is manually entered by the user, and not calculated based on units. This allows users to define the number of hours they want to allocate to a resource directly.

Is there a way to achieve this customization, or would it require significant changes to the widget's behavior?

Thank you, Luca.


Post by alex.l »

Hi Luca,

That's not configurable, but you can manage it on DataModel level. You can set https://bryntum.com/products/gantt/docs/api/Gantt/model/ProjectModel#config-assignmentModelClass to use your custom field as a https://bryntum.com/products/gantt/docs/api/Core/data/field/DataField#config-dataSource for effort.

class MyAssignmentModel extends AssignmentModel {
  static get fields() {
      return [
          { name: 'effort', dataSource: 'manualEffort' }
      ]
  }
  

new ResourceUtilization({ project : { assignmentModelClass : MyAssignmentModel } });

Full guide about ResourceUtilization is her https://bryntum.com/products/gantt/docs/guide/SchedulerPro/resourceviews/resourceutilization#resource-utilization

All the best,
Alex Lazarev

How to ask for help? Please read our Support Policy

We do not write the code in bounds of forum support. If you need help with development, contact us via bryntum.com/services


Post by leanit »

Hello Alex,
thank you for your reply. Unfortunately, after applying your suggestion, I'm getting errors in the console. I'm not sure what's causing them. We are using version 6.2.1.

Below is the code where I followed your instructions:

AssignmentModel.png
AssignmentModel.png (268.99 KiB) Viewed 169 times

And here are the console errors I'm seeing:

Errors.png
Errors.png (109.83 KiB) Viewed 174 times

Thank you, Luca.


Post by arcady »

Hello,

You'll have to extend ResourceAllocationInfo class that is used by the resource utilization widget to implement that customization (mentioned here briefly https://bryntum.com/products/gantt/docs/guide/SchedulerPro/resourceviews/resourceutilization#customizing-series-data-and-performance ..the guide also has a chapter describing how data calculation works there https://bryntum.com/products/gantt/docs/guide/SchedulerPro/resourceviews/resourceutilization#data-calculations-under-the-hood).

You'll have to change calculateAllocation method code. It iterates over working time intervals and collects effort. And you should change it to accrue provided effort values across the intervals duration.

Best regards,
Arcady


Post by leanit »

Hello Arcady,
we're trying the solution you suggested, but we've encountered an issue: ResourceAllocationInfo is a type, not a class, so we can't extend it as described in your message and in the documentation.
Are we missing something?

image.png
image.png (53.3 KiB) Viewed 126 times

EDIT: I found this open ticket from another forum post (https://github.com/bryntum/support/issues/7628)

Thank you, Luca.


Post by arcady »

Hello,

Yes, the ticket is not resolved yet I'm afraid. So proper type definition is not available for that class until the ticket is done.
That means so far TypeScript will be angry with such subclassing. You can try @ts-ignore some code to workaround the problem.
The class is there but it's just its *.d.ts interface is messed up. Sorry for the inconvenience!
Please let us know if ts-ignore helped.

Best regards,
Arcady


Post by leanit »

Hello Arcady, unfortunately it doesn't work. It throws this error in console when using //@ts-ignore:

ReferenceError: ResourceAllocationInfo is not defined

This is how I imported it:

	import { ResourceAllocationInfo } from '@bryntum/gantt';

Thank you, Luca.


Post by arcady »

Hello,

Then I'm afraid you'll have to wait till the ticket is resolved.

Well you can of course edit @bryntum/gantt/gantt.d.ts file manually and replace ResourceAllocatioInfo type definition with
export class ResourceAllocationInfo {
but that's a bad practice since you'll loose the change after any further upgrade.

Best regards,
Arcady


Post by arcady »

Hello,

It seems I've found a workaround that at least should unblock you.

The idea is you make a proxy js-file that re-exports ResourceAllocationInfo and then you make a *.d.ts file for that js-file that declares ResourceAllocationInfo as a class. For example:

  1. I've made foo.js file looking like this:
    export { ResourceAllocationInfo } from '@bryntum/gantt';
  2. I've made foo.d.ts file next the foo.js:
    import { SchedulerProResourceModel, ResourceAllocation, SchedulerProCalendarModel } from '@bryntum/gantt';
    
    export class ResourceAllocationInfo {
        /**
         * Resource model.
         */
        resource: SchedulerProResourceModel
        /**
         * The collected allocation info.
         */
        allocation: ResourceAllocation
        /**
         * A calendar specifying intervals to group the collected
         * allocation by. <strong>Working</strong> time intervals of the calendars will be used for grouping.
         * This also specifies the time period to collect allocation for.
         * So the first interval `startDate` is treated as the period start and the last interval `endDate` is the period end.
         */
        ticks: SchedulerProCalendarModel
        /**
         * `true` indicates inactive events allocation is included
         * and `false` - it's skipped.
         */
        includeInactiveEvents: boolean
    }
  3. Then in my test application I import ResourceAllocationInfo from that foo.js:
    import { ResourceAllocationInfo } from './foo.js';

And it allows to re-declare is as a class ignoring wrong declaration in the distribution.

Best regards,
Arcady


Post Reply