Skip to content

Commit

Permalink
style: prettier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
netchampfaris committed Apr 28, 2022
1 parent 9d01fa8 commit aba84bd
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 116 deletions.
2 changes: 1 addition & 1 deletion src/arrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default class Arrow {
this.element = createSVG('path', {
d: this.path,
'data-from': this.from_task.task.id,
'data-to': this.to_task.task.id
'data-to': this.to_task.task.id,
});
}

Expand Down
50 changes: 27 additions & 23 deletions src/bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,32 @@ export default class Bar {
(this.task.progress / 100) || 0;
this.group = createSVG('g', {
class: 'bar-wrapper ' + (this.task.custom_class || ''),
'data-id': this.task.id
'data-id': this.task.id,
});
this.bar_group = createSVG('g', {
class: 'bar-group',
append_to: this.group
append_to: this.group,
});
this.handle_group = createSVG('g', {
class: 'handle-group',
append_to: this.group
append_to: this.group,
});
}

prepare_helpers() {
SVGElement.prototype.getX = function() {
SVGElement.prototype.getX = function () {
return +this.getAttribute('x');
};
SVGElement.prototype.getY = function() {
SVGElement.prototype.getY = function () {
return +this.getAttribute('y');
};
SVGElement.prototype.getWidth = function() {
SVGElement.prototype.getWidth = function () {
return +this.getAttribute('width');
};
SVGElement.prototype.getHeight = function() {
SVGElement.prototype.getHeight = function () {
return +this.getAttribute('height');
};
SVGElement.prototype.getEndX = function() {
SVGElement.prototype.getEndX = function () {
return this.getX() + this.getWidth();
};
}
Expand All @@ -82,7 +82,7 @@ export default class Bar {
rx: this.corner_radius,
ry: this.corner_radius,
class: 'bar',
append_to: this.bar_group
append_to: this.bar_group,
});

animateSVG(this.$bar, 'width', 0, this.width);
Expand All @@ -102,7 +102,7 @@ export default class Bar {
rx: this.corner_radius,
ry: this.corner_radius,
class: 'bar-progress',
append_to: this.bar_group
append_to: this.bar_group,
});

animateSVG(this.$bar_progress, 'width', 0, this.progress_width);
Expand All @@ -114,7 +114,7 @@ export default class Bar {
y: this.y + this.height / 2,
innerHTML: this.task.name,
class: 'bar-label',
append_to: this.bar_group
append_to: this.bar_group,
});
// labels get BBox in the next tick
requestAnimationFrame(() => this.update_label_position());
Expand All @@ -134,7 +134,7 @@ export default class Bar {
rx: this.corner_radius,
ry: this.corner_radius,
class: 'handle right',
append_to: this.handle_group
append_to: this.handle_group,
});

createSVG('rect', {
Expand All @@ -145,14 +145,14 @@ export default class Bar {
rx: this.corner_radius,
ry: this.corner_radius,
class: 'handle left',
append_to: this.handle_group
append_to: this.handle_group,
});

if (this.task.progress && this.task.progress < 100) {
this.$handle_progress = createSVG('polygon', {
points: this.get_progress_polygon_points().join(','),
class: 'handle progress',
append_to: this.handle_group
append_to: this.handle_group,
});
}
}
Expand All @@ -165,7 +165,7 @@ export default class Bar {
bar_progress.getEndX() + 5,
bar_progress.getY() + bar_progress.getHeight(),
bar_progress.getEndX(),
bar_progress.getY() + bar_progress.getHeight() - 8.66
bar_progress.getY() + bar_progress.getHeight() - 8.66,
];
}

Expand All @@ -175,7 +175,7 @@ export default class Bar {
}

setup_click_event() {
$.on(this.group, 'focus ' + this.gantt.options.popup_trigger, e => {
$.on(this.group, 'focus ' + this.gantt.options.popup_trigger, (e) => {
if (this.action_completed) {
// just finished a move action, wait for a few seconds
return;
Expand All @@ -186,7 +186,7 @@ export default class Bar {
this.group.classList.add('active');
});

$.on(this.group, 'dblclick', e => {
$.on(this.group, 'dblclick', (e) => {
if (this.action_completed) {
// just finished a move action, wait for a few seconds
return;
Expand All @@ -199,7 +199,11 @@ export default class Bar {
show_popup() {
if (this.gantt.bar_being_dragged) return;

const start_date = date_utils.format(this.task._start, 'MMM D', this.gantt.options.language);
const start_date = date_utils.format(
this.task._start,
'MMM D',
this.gantt.options.language
);
const end_date = date_utils.format(
date_utils.add(this.task._end, -1, 'second'),
'MMM D',
Expand All @@ -219,7 +223,7 @@ export default class Bar {
const bar = this.$bar;
if (x) {
// get all x values of parent task
const xs = this.task.dependencies.map(dep => {
const xs = this.task.dependencies.map((dep) => {
return this.gantt.get_bar(dep).$bar.getX();
});
// child task must not go before parent
Expand Down Expand Up @@ -260,7 +264,7 @@ export default class Bar {
this.gantt.trigger_event('date_change', [
this.task,
new_start_date,
date_utils.add(new_end_date, -1, 'second')
date_utils.add(new_end_date, -1, 'second'),
]);
}

Expand Down Expand Up @@ -295,7 +299,7 @@ export default class Bar {

compute_progress() {
const progress =
this.$bar_progress.getWidth() / this.$bar.getWidth() * 100;
(this.$bar_progress.getWidth() / this.$bar.getWidth()) * 100;
return parseInt(progress, 10);
}

Expand All @@ -305,11 +309,11 @@ export default class Bar {
const gantt_start = this.gantt.gantt_start;

const diff = date_utils.diff(task_start, gantt_start, 'hour');
let x = diff / step * column_width;
let x = (diff / step) * column_width;

if (this.gantt.view_is('Month')) {
const diff = date_utils.diff(task_start, gantt_start, 'day');
x = diff * column_width / 30;
x = (diff * column_width) / 30;
}
return x;
}
Expand Down
38 changes: 19 additions & 19 deletions src/date_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const month_names = {
'September',
'October',
'November',
'December'
'December',
],
es: [
'Enero',
Expand All @@ -33,7 +33,7 @@ const month_names = {
'Septiembre',
'Octubre',
'Noviembre',
'Diciembre'
'Diciembre',
],
ru: [
'Январь',
Expand All @@ -47,7 +47,7 @@ const month_names = {
'Сентябрь',
'Октябрь',
'Ноябрь',
'Декабрь'
'Декабрь',
],
ptBr: [
'Janeiro',
Expand All @@ -61,7 +61,7 @@ const month_names = {
'Setembro',
'Outubro',
'Novembro',
'Dezembro'
'Dezembro',
],
fr: [
'Janvier',
Expand All @@ -75,7 +75,7 @@ const month_names = {
'Septembre',
'Octobre',
'Novembre',
'Décembre'
'Décembre',
],
tr: [
'Ocak',
Expand All @@ -89,7 +89,7 @@ const month_names = {
'Eylül',
'Ekim',
'Kasım',
'Aralık'
'Aralık',
],
zh: [
'一月',
Expand All @@ -103,8 +103,8 @@ const month_names = {
'九月',
'十月',
'十一月',
'十二月'
]
'十二月',
],
};

export default {
Expand All @@ -118,7 +118,7 @@ export default {

date_parts = parts[0]
.split(date_separator)
.map(val => parseInt(val, 10));
.map((val) => parseInt(val, 10));
time_parts = parts[1] && parts[1].split(time_separator);

// month is 0 indexed
Expand Down Expand Up @@ -161,26 +161,26 @@ export default {
},

format(date, format_string = 'YYYY-MM-DD HH:mm:ss.SSS', lang = 'en') {
const values = this.get_date_values(date).map(d => padStart(d, 2, 0));
const values = this.get_date_values(date).map((d) => padStart(d, 2, 0));
const format_map = {
YYYY: values[0],
MM: padStart(+values[1] + 1, 2, 0),
DD: values[2],
HH: values[3],
mm: values[4],
ss: values[5],
SSS:values[6],
SSS: values[6],
D: values[2],
MMMM: month_names[lang][+values[1]],
MMM: month_names[lang][+values[1]]
MMM: month_names[lang][+values[1]],
};

let str = format_string;
const formatted_values = [];

Object.keys(format_map)
.sort((a, b) => b.length - a.length) // big string first
.forEach(key => {
.forEach((key) => {
if (str.includes(key)) {
str = str.replace(key, `$${formatted_values.length}`);
formatted_values.push(format_map[key]);
Expand Down Expand Up @@ -217,7 +217,7 @@ export default {
hours,
days,
months,
years
years,
}[scale]
);
},
Expand All @@ -240,7 +240,7 @@ export default {
date.getHours() + (scale === HOUR ? qty : 0),
date.getMinutes() + (scale === MINUTE ? qty : 0),
date.getSeconds() + (scale === SECOND ? qty : 0),
date.getMilliseconds() + (scale === MILLISECOND ? qty : 0)
date.getMilliseconds() + (scale === MILLISECOND ? qty : 0),
];
return new Date(...vals);
},
Expand All @@ -253,7 +253,7 @@ export default {
[HOUR]: 3,
[MINUTE]: 2,
[SECOND]: 1,
[MILLISECOND]: 0
[MILLISECOND]: 0,
};

function should_reset(_scale) {
Expand All @@ -268,7 +268,7 @@ export default {
should_reset(DAY) ? 0 : date.getHours(),
should_reset(HOUR) ? 0 : date.getMinutes(),
should_reset(MINUTE) ? 0 : date.getSeconds(),
should_reset(SECOND) ? 0 : date.getMilliseconds()
should_reset(SECOND) ? 0 : date.getMilliseconds(),
];

return new Date(...vals);
Expand All @@ -286,7 +286,7 @@ export default {
date.getHours(),
date.getMinutes(),
date.getSeconds(),
date.getMilliseconds()
date.getMilliseconds(),
];
},

Expand All @@ -305,7 +305,7 @@ export default {
return 29;
}
return 28;
}
},
};

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart
Expand Down
Loading

0 comments on commit aba84bd

Please sign in to comment.