ResourceHistogram
This view displays a read-only timeline report of the workload for the resources in a project. The resource allocation is visualized as bars along the time axis with an optional line indicating the maximum available time for each resource. A ScaleColumn is also added automatically.
To create a standalone histogram, simply configure it with a Project instance:
const project = new ProjectModel({
autoLoad : true,
loadUrl : 'examples/schedulerpro/view/data.json'
});
const histogram = new ResourceHistogram({
project,
appendTo : 'targetDiv',
rowHeight : 60,
minHeight : '20em',
flex : '1 1 50%',
showBarTip : true,
columns : [
{
width : 200,
field : 'name',
text : 'Resource'
}
]
});
//<code-header>
fiddle.title = 'Resource histogram';
//</code-header>
const histogram = new ResourceHistogram({
project : {
loadUrl : 'data/SchedulerPro/examples/view/ResourceHistogram.json',
autoLoad : true
},
resourceImagePath : 'data/Scheduler/images/transparent-users/',
startDate : new Date(2020, 3, 19),
endDate : new Date(2020, 4, 15),
appendTo : targetElement,
rowHeight : 60,
autoHeight : true,
minHeight : '20em',
showBarTip : true,
columns : [
{
type : 'resourceInfo',
width : 200,
field : 'name',
text : 'Resource'
}
]
});Pairing the component
You can also pair the histogram with other timeline views such as the Gantt or Scheduler, using the partner config.
You can configure (or hide completely) the built-in scale column easily:
const histogram = new ResourceHistogram({
project,
appendTo : 'targetDiv',
columns : [
{
width : 200,
field : 'name',
text : 'Resource'
},
// Hide the scale column (or add any other column configs)
{
type : 'scale',
hidden : true
}
]
});
Changing displayed values
To change the histogram bar texts, supply a getBarText function. Here for example the provided function displays resources time left instead of allocated time
new ResourceHistogram({
getBarText(datum) {
const resourceHistogram = this.owner;
// get default bar text
let result = resourceHistogram.getBarTextDefault(...arguments);
// and if some work is done in the tick
if (result) {
const unit = resourceHistogram.getBarTextEffortUnit();
// display the resource available time
result = resourceHistogram.getEffortText(datum.maxEffort - datum.effort, unit);
}
return result;
},
...
})
Configs
245
Configs
245Common
Other
A function that if provided decides whether an assignment should be taken into account or not when collecting allocation.
The function is recommended to be a generator so it can attach to the Engine and track the involved field
changes automatically.
It accepts two arguments: assignment record and ResourceAllocationInfo class instance collecting
allocation. The instance has a special readField method that should be yielded to read
the needed field value. The method also subscribes to further changes of the field triggering
automatic allocation recollecting once the field gets changed:
new ResourceHistogram({
// custom filtering function
* assignmentFilterFn(assignment, allocationInfo) {
// get the assignment event
const event = yield assignment.$.event;
// include only allocation of events having "type" field set to "Meeting"
if (event) {
// get "type" field value and bind to its changes
// to refresh the histogram automatically
const type = yield* allocationInfo.readField(event, 'type');
return type === 'Meeting';
}
}
...
});
| Parameter | Type | Description |
|---|---|---|
assignment | AssignmentModel | Assignment to consider |
resourceAllocationInfo | ResourceAllocationInfo | Resource allocation instance |
true to include the assignment data and false to not
Default time unit used for displaying resources effort in bars. Yet the effective time unit used might change dynamically when zooming in the histogram so its ticks unit gets smaller than the default unit. Please use barTipEffortUnit to customize default units for tooltips (or effortUnit to customize both texts and tooltips default units).
Default time unit used when displaying resources effort in tooltips. Yet the effective time unit used might change dynamically when zooming in the histogram so its ticks unit gets smaller than the default unit. Please use barTextEffortUnit to customize default units for bar texts (or effortUnit to customize both texts and tooltips default units).
A Function which returns the tooltip text to display when hovering a bar. The following parameters are passed:
| Parameter | Type | Description |
|---|---|---|
context | Object | The tooltip context info |
context.datum | ResourceAllocationInterval | The histogram bar being hovered info |
context.tip | Tooltip | The tooltip instance |
context.element | HTMLElement | The Element for which the Tooltip is monitoring mouse movement |
context.activeTarget | HTMLElement | The target element that triggered the show |
context.event | Event | The raw DOM event |
context.record | ResourceModel | The record which effort the hovered bar displays. |
Tooltip HTML content
Specifies a format to use for displaying cost values. Default value is:
costFormat : {
style : 'currency',
currency : 'USD'
},
See NumberFormat docs for details on the supported config values.
Please keep in mind that currency value will be automatically set to the loaded
project currency.
Effort value format string. Must be a template supported by NumberFormat class.
Default time unit to display resources effort values. The value is used as default when displaying effort in tooltips and bars text. Yet the effective time unit used might change dynamically when zooming in the histogram so its ticks unit gets smaller than the default unit. Please use barTipEffortUnit to customize default units for tooltips only and barTextEffortUnit to customize default units in bar texts.
A Function which returns a CSS class name to add to a bar's rectangle element. The following parameters are passed:
| Parameter | Type | Description |
|---|---|---|
series | HistogramSeries | The series being rendered |
domConfig | DomConfig | The rectangle configuration object |
datum | ResourceAllocationInterval | The datum being rendered |
index | Number | The index of the datum being rendered |
renderData | ResourceHistogramRenderData | Current render data giving access to the record, row and cell being rendered. |
CSS classes of the rectangle element
A Function which if provided returns DOM configuration object for a bar
(a RECT element representing a single "bar"-type value).
The function accepts default prepared DOM configuration
in an argument which then can be processed and returned.
new ResourceHistogram({
// Let's add left & right margins to bars
getBarDOMConfig(series, domConfig) {
// margin size is 10% of the bar width
const xMargin = 0.1 * domConfig.width;
// adjust the bar x-coordinate
domConfig.x += xMargin;
// reduce the bar width respectively
domConfig.width -= 2 * xMargin;
// return the edited domConfig
return domConfig;
},
...
})
this will refer to the
Histogram instance, not this class instance.
To access the view please use this.owner in the function:
new ResourceHistogram({
getBarText(datum) {
// "this" in the method refers core Histogram instance
// get the view instance
const resourceHistogram = this.owner;
.....
},
...
})
The following parameters are passed:
| Parameter | Type | Description |
|---|---|---|
series | HistogramSeries | The series being rendered |
domConfig | DomConfig | The rectangle DOM configuration object |
datum | ResourceAllocationInterval | The datum being rendered |
index | Number | The index of the datum being rendered |
renderData | ResourceHistogramRenderData | Current render data giving access to the record, row and cell being rendered. |
Resulting DOM configuration object. If no value returned the bar is not displayed.
A Function which returns the text to render inside a bar.
Here for example the provided function displays resources time left instead of allocated time
new ResourceHistogram({
getBarText(datum) {
const resourceHistogram = this.owner;
const { showBarText } = resourceHistogram;
let result = '';
// respect existing API - show bar texts only when "showBarText" is true
// and if some work is done in the tick
if (showBarText && datum.effort) {
const unit = resourceHistogram.getBarTextEffortUnit();
// display the resource available time
result = resourceHistogram.getEffortText(datum.maxEffort - datum.effort, unit);
}
return result;
},
})
Please note that the function will be injected into the underlying
Histogram component that is used under the hood
to render actual charts.
So this will refer to the Histogram instance, not
this class instance.
To access the view please use this.owner in the function:
new ResourceHistogram({
getBarText(datum) {
// "this" in the method refers core Histogram instance
// get the view instance
const resourceHistogram = this.owner;
.....
},
})
The following parameters are passed:
| Parameter | Type | Description |
|---|---|---|
datum | ResourceAllocationInterval | The datum being rendered |
index | Number | The index of the datum being rendered |
series | HistogramSeries | The series (provided if histogram widget
singleTextForAllBars is |
renderData | ResourceHistogramRenderData | Current render data giving access to the record, row and cell being rendered. |
Text to render inside the bar
A Function which returns a DOM configuration object for text elements.
new ResourceHistogram({
getBarTextDOMConfig(domConfig, datum, index) {
// Place text at the top of the "effort" bar
// so calculate y-position in percents
domConfig.y = `${100 * (1 - datum.effort / this.topValue)}%`;
// also let's laid the text lines horizontally
domConfig.style = 'writing-mode: lr';
return domConfig;
},
...
})
this will refer to the Histogram instance, not
this class instance.
To access the view please use this.owner in the function:
new ResourceHistogram({
getBarTextDOMConfig(domConfig) {
// "this" in the method refers core Histogram instance
// get the view instance
const resourceHistogram = this.owner;
.....
return domConfig;
},
...
})
The following parameters are passed:
| Parameter | Type | Description |
|---|---|---|
domConfig | DomConfig | The |
datum | ResourceAllocationInterval | The datum being rendered |
index | Number | The index of the datum being rendered |
series | HistogramSeries | The series (provided if histogram widget
singleTextForAllBars is |
renderData | ResourceHistogramRenderData | Current render data giving access to the record, row and cell being rendered. |
The TEXT element DOM configuration object. If no value returned the text element is not
displayed.
A Function which returns a CSS class name to add to a path element
built for an outline type series.
The following parameters are passed:
| Parameter | Type | Description |
|---|---|---|
series | HistogramSeries | The series being rendered |
data | Object[] | The series data |
renderData | ResourceHistogramRenderData | Current render data giving access to the record, row and cell being rendered. |
CSS class name of the path element
A Function which if provided should return a DOM configuration object for
a path element built for an outline type series.
The function accepts a default prepared DOM configuration
in an argument which then can be processed and returned.
The following parameters are passed to the function:
| Parameter | Type | Description |
|---|---|---|
series | HistogramSeries | The series being rendered |
domConfig | DomConfig | The |
data | Object[] | The series data |
renderData | ResourceHistogramRenderData | Current render data giving access to the record, row and cell being rendered. |
Resulting DOM configuration object. If no value returned the path is not displayed.
Set to true to include inactive tasks allocation and false to not take such tasks into account.
Set to true to take task and assignment store filters into account when collecting allocation.
new ResourceHistogram({
// skip filtered out events/assignments
respectStoreFilters : true
...
});
Set to true if you want to display resources effort values in bars
(for example: 24h, 7d, 60min etc.).
The text contents can be changed by providing getBarText function.
Specifies whether effort values should display units or not.
Set to true if you want to display the maximum resource allocation line.
Content
CSS
Data
Dates
DOM
Float & align
Layout
Masking
misc
Misc
Parent histogram data collecting
Resources
Scale column
Scheduled events
State
Time axis
Tree
Zoom
Properties
209
Properties
209Common
Class hierarchy
CSS
Data
Dates
DOM
Infinite scroll
Layout
Misc
Other
Scale column
Scheduled events
Scrolling
Selection
State
Time axis
Tree
Widget hierarchy
Functions
178
Functions
178Other
The default method that returns the text to render inside a bar if no getBarText function was provided.
The method can be used in a getBarText function to invoke the default implementation:
new ResourceHistogram({
getBarText(datum) {
const resourceHistogram = this.owner;
// get default bar text
let result = resourceHistogram.getBarTextDefault();
// if the resource is overallocated in that tick display "Overallocated! " string
// before the allocation value
if (result && datum.maxEffort < datum.effort) {
result = 'Overallocated! ' + result;
}
return result;
},
})
The following parameters are passed:
| Parameter | Type | Description |
|---|---|---|
datum | ResourceAllocationInterval | The data of the bar being rendered |
index | Number | The index of the datum being rendered |
series | String | Identifier of the series (provided only if the histogram widget
singleTextForAllBars is |
renderData | ResourceHistogramRenderData | Current render data giving access to the record, row and cell being rendered. |
Text to render inside the bar
Returns unit to display effort values in when rendering the histogram bars. The method by default returns barTextEffortUnit value if provided and if not falls back to effortUnit value. But it also takes zooming into account and when the timeaxis ticks unit gets smaller than the default value the ticks unit is returned.
Time unit to display effort values in.
Formats effort value to display in the component bars and tooltips.
| Parameter | Type | Description |
|---|---|---|
effort | Number | Effort value |
unit | DurationUnit | Effort value unit |
showEffortUnit | Boolean | Provide |
Formatted effort value.
Returns the provided record's allocation data.
The process of allocation collecting is asynchronous so the method returns a Promise
that provides the data once resolved.
The method used as the default value of getRecordData config.
| Parameter | Type | Description |
|---|---|---|
record | ResourceModel | Resource record to collect allocation for. |
A Promise that provides the provided resource
allocation info when resolved.
Parent histogram data collecting
The default function used for aggregating a child record histogram data values to its parent entry.
The function sums up effort and maxEffort series values. It also propagates
isOverallocated and
isUnderallocated values so if there
is a child having the corresponding value as true it will be true on the parent level as well.
All children assignments are united on the parent level assignments property.
The method is used as aggregateDataEntry default value.
| Parameter | Type | Description |
|---|---|---|
aggregated | ResourceAllocationInterval | Target parent data entry to aggregate the entry into. |
entry | ResourceAllocationInterval | Current entry to aggregate into |
arrayIndex | Number | Index of the current record (among other records being aggregated). |
colIndex | Number |
|
Resulting parent data entry.
The default function that initializes a target group record entry.
The method is used as initAggregatedDataEntry default value.
Returns an empty allocation entry.
Scale column
Generates points for the scale column.
Override the method to customize the scale column points.
| Parameter | Type | Description |
|---|---|---|
scaleMax | Number | Maximum value for the scale. Uses current timeaxis increment if not provided. |
unit | DurationUnit | Time
unit |
Array of objects representing scale points. Each entry can have properties:
value- point valueunit- point value unittext- label text (if not provided the point will not have a label displayed)
Configuration
Data
Dates
Events
Getters
Misc
Rendering
Rows
Scrolling
Selection
Widget hierarchy
Zoom
Events
65
Events
65Fires when the component generates points for the scale column.
Use a listeners to override the generated scale points:
new ResourceHistogram({
...
listeners : {
generateScalePoints(params) {
// provide text for each scale point (if not provided already)
params.scalePoints.forEach(point => {
point.text = point.text || point.value;
});
}
}
})
// Adding a listener using the "on" method
resourceHistogram.on('generateScalePoints', ({ source, scalePoints }) => {
});| Parameter | Type | Description |
|---|---|---|
source | ResourceHistogram | The component instance |
scalePoints | ScalePoint[] | Array of objects representing scale points. Each entry can have properties:
|
Event handlers
65
Event handlers
65Called when the component generates points for the scale column.
Use a listeners to override the generated scale points:
new ResourceHistogram({
...
listeners : {
generateScalePoints(params) {
// provide text for each scale point (if not provided already)
params.scalePoints.forEach(point => {
point.text = point.text || point.value;
});
}
}
})
new ResourceHistogram({
onGenerateScalePoints({ source, scalePoints }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | ResourceHistogram | The component instance |
scalePoints | ScalePoint[] | Array of objects representing scale points. Each entry can have properties:
|
Typedefs
20
Typedefs
20ResourceHistogram renderer parameters.
| Parameter | Type | Description |
|---|---|---|
histogramData | Object | Histogram data |
histogramConfig | HistogramConfig | Configuration object for the histogram widget |
cellElement | HTMLElement | null | Cell element, for adding CSS classes, styling etc.
Can be |
record | ResourceModel | Record for the row |
column | TimeAxisColumn | Owning TimeAxisColumn column |
grid | ResourceHistogram | Owning ResourceHistogram instance |
row | Row | Row object. Can be null in case of export. Use the row's API to manipulate CSS class names. |
CSS variables
91
CSS variables
91| Name | Description |
|---|---|
--b-resource-histogram-bar-legend-font-size | Bar legend font size |
--b-resource-histogram-bar-color | Default bar color |
--b-resource-histogram-underallocated-bar-color | Under-allocated bar color |
--b-resource-histogram-overallocated-bar-color | Over-allocated bar color |
| Hovered | |
--b-resource-histogram-bar-hover-color | Default bar hover color |
--b-resource-histogram-underallocated-bar-hover-color | Under-allocated bar hover color |
--b-resource-histogram-overallocated-bar-hover-color | Over-allocated bar hover color |