Define bar corner radius on initialization (#43)
* Merge defaults and config deeply in set_defaults
The Object.assign method performs a shallow merge, thus it can lose
properties in nested objects. For example, if config.bar = { foo: bar }
then it would entirely replace defaults.bar and self.config.bar.height
would be undefined. The deepmerge library is a lightweight module that
merges enumerable attributes deeply. In the above example,
self.config.bar would then be {foo: bar, height: 20}.
I think this commit also retroactively applies some previous changes to
dist/frappe-gantt.js and dist/frappe-gantt.js.map from commits: 241c65db697475a3a17324f4c613d28353f89a8c,
1926ddbd48f1ff0bd7a0d49cadf14fcd415c3bfd, and be45a9656ffd482e1611198158b6032c965e1309.
* Define bar corner radius on initialization
Allows this property to be set without changing source code. Requires
deep merge of default and config objects added in commit f32e76af7733515f10a9adc004100e57f794f804
* Fix bug causing TypeError when config parameter is undefined
Fixes issue when optional config parameter is unspecified since
Deepmerge throws error "Cannot convert undefined or null to object"
in such cases.
This commit is contained in:
parent
c8bfc1d679
commit
2abbb1dce5
736
dist/frappe-gantt.js
vendored
736
dist/frappe-gantt.js
vendored
File diff suppressed because one or more lines are too long
2
dist/frappe-gantt.js.map
vendored
2
dist/frappe-gantt.js.map
vendored
File diff suppressed because one or more lines are too long
6
dist/frappe-gantt.min.js
vendored
6
dist/frappe-gantt.min.js
vendored
File diff suppressed because one or more lines are too long
6
dist/frappe-gantt.min.js.map
vendored
6
dist/frappe-gantt.min.js.map
vendored
File diff suppressed because one or more lines are too long
@ -45,6 +45,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/frappe/gantt",
|
||||
"dependencies": {
|
||||
"deepmerge": "^2.0.1",
|
||||
"moment": "^2.17.1",
|
||||
"snapsvg": "^0.4.0"
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ export default function Bar(gt, task) {
|
||||
self.height = gt.config.bar.height;
|
||||
self.x = compute_x();
|
||||
self.y = compute_y();
|
||||
self.corner_radius = 3;
|
||||
self.corner_radius = gt.config.bar.corner_radius;
|
||||
self.duration = (self.task._end.diff(self.task._start, 'hours') + 24) / gt.config.step;
|
||||
self.width = gt.config.column_width * self.duration;
|
||||
self.progress_width = gt.config.column_width * self.duration * (self.task.progress / 100) || 0;
|
||||
|
||||
@ -11,7 +11,7 @@ import './gantt.scss';
|
||||
import Bar from './Bar';
|
||||
import Arrow from './Arrow';
|
||||
|
||||
export default function Gantt(element, tasks, config) {
|
||||
export default function Gantt(element, tasks, config = {}) {
|
||||
|
||||
const self = {};
|
||||
|
||||
@ -32,6 +32,8 @@ export default function Gantt(element, tasks, config) {
|
||||
|
||||
function set_defaults() {
|
||||
|
||||
const merge = require('deepmerge');
|
||||
|
||||
const defaults = {
|
||||
header_height: 50,
|
||||
column_width: 30,
|
||||
@ -44,7 +46,8 @@ export default function Gantt(element, tasks, config) {
|
||||
'Month'
|
||||
],
|
||||
bar: {
|
||||
height: 20
|
||||
height: 20,
|
||||
corner_radius: 3
|
||||
},
|
||||
arrow: {
|
||||
curve: 5
|
||||
@ -54,7 +57,7 @@ export default function Gantt(element, tasks, config) {
|
||||
date_format: 'YYYY-MM-DD',
|
||||
custom_popup_html: null
|
||||
};
|
||||
self.config = Object.assign({}, defaults, config);
|
||||
self.config = merge(defaults, config);
|
||||
|
||||
reset_variables(tasks);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user