Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement of gantt display #165

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 104 additions & 23 deletions dist/frappe-gantt.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ const month_names = {
'November',
'December'
],
es: [
'Enero',
'Febrero',
'Marzo',
'Abril',
'Mayo',
'Junio',
'Julio',
'Agosto',
'Septiembre',
'Octubre',
'Noviembre',
'Diciembre'
],
ru: [
'Январь',
'Февраль',
Expand All @@ -37,6 +51,48 @@ const month_names = {
'Октябрь',
'Ноябрь',
'Декабрь'
],
ptBr: [
'Janeiro',
'Fevereiro',
'Março',
'Abril',
'Maio',
'Junho',
'Julho',
'Agosto',
'Setembro',
'Outubro',
'Novembro',
'Dezembro'
],
fr: [
'Janvier',
'Février',
'Mars',
'Avril',
'Mai',
'Juin',
'Juillet',
'Août',
'Septembre',
'Octobre',
'Novembre',
'Décembre'
],
tr: [
'Ocak',
'Şubat',
'Mart',
'Nisan',
'Mayıs',
'Haziran',
'Temmuz',
'Ağustos',
'Eylül',
'Ekim',
'Kasım',
'Aralık'
]
};

Expand Down Expand Up @@ -585,18 +641,19 @@ class Bar {
show_popup() {
if (this.gantt.bar_being_dragged) return;

const start_date = date_utils.format(this.task._start, 'MMM D');
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'
'MMM D',
this.gantt.options.language
);
const subtitle = start_date + ' - ' + end_date;

this.gantt.show_popup({
target_element: this.$bar,
title: this.task.name,
subtitle: subtitle,
task: this.task
task: this.task,
});
}

Expand Down Expand Up @@ -1170,19 +1227,34 @@ class Gantt {
this.gantt_start = date_utils.start_of(this.gantt_start, 'day');
this.gantt_end = date_utils.start_of(this.gantt_end, 'day');

const padding_start = typeof this.options.padding_start === 'undefined' ? this.default_padding() : this.options.padding_start;
const padding_end = typeof this.options.padding_end === 'undefined' ? this.default_padding() : this.options.padding_end;

// add date padding on both sides
if (this.view_is(['Quarter Day', 'Half Day'])) {
this.gantt_start = date_utils.add(this.gantt_start, -7, 'day');
this.gantt_end = date_utils.add(this.gantt_end, 7, 'day');
if (this.view_is(['Quarter Day', 'Half Day', 'Day'])) {
this.gantt_start = date_utils.add(this.gantt_start, -padding_start, 'day');
this.gantt_end = date_utils.add(this.gantt_end, padding_end, 'day');
} else if (this.view_is('Week')) {
this.gantt_start = date_utils.add(this.gantt_start, -(padding_start * 7), 'day');
this.gantt_end = date_utils.add(this.gantt_end, (padding_end * 7), 'day');
} else if (this.view_is('Month')) {
this.gantt_start = date_utils.start_of(this.gantt_start, 'year');
this.gantt_end = date_utils.add(this.gantt_end, 1, 'year');
this.gantt_start = date_utils.add(this.gantt_start, -padding_start, 'month');
this.gantt_end = date_utils.add(this.gantt_end, padding_end, 'month');
} else if (this.view_is('Year')) {
this.gantt_start = date_utils.add(this.gantt_start, -2, 'year');
this.gantt_end = date_utils.add(this.gantt_end, 2, 'year');
} else {
this.gantt_start = date_utils.add(this.gantt_start, -1, 'month');
this.gantt_end = date_utils.add(this.gantt_end, 1, 'month');
this.gantt_start = date_utils.add(this.gantt_start, -padding_start, 'year');
this.gantt_end = date_utils.add(this.gantt_end, padding_end, 'year');
}
}

default_padding() {
if (this.view_is(['Quarter Day', 'Half Day', 'Day'])) {
return 7;
} else if (this.view_is('Week')) {
return 4;
} else if (this.view_is('Month')) {
return 6;
} else if (this.view_is('Year')) {
return 2;
}
}

Expand Down Expand Up @@ -1265,8 +1337,8 @@ class Gantt {
});

$.attr(this.$svg, {
height: grid_height + this.options.padding + 100,
width: '100%'
height: grid_height,
width: grid_width
});
}

Expand Down Expand Up @@ -1416,15 +1488,27 @@ class Gantt {

get_dates_to_draw() {
let last_date = null;
const monthPerYears = {};

if (this.options.view_mode === 'Month') {
this.dates.forEach(date => {
if (monthPerYears[date.getFullYear()]) {
monthPerYears[date.getFullYear()] += 1;
} else {
monthPerYears[date.getFullYear()] = 1;
}
});
}

const dates = this.dates.map((date, i) => {
const d = this.get_date_info(date, last_date, i);
const d = this.get_date_info(date, last_date, i, monthPerYears);
last_date = date;
return d;
});
return dates;
}

get_date_info(date, last_date, i) {
get_date_info(date, last_date, i, monthPerYears) {
if (!last_date) {
last_date = date_utils.add(date, 1, 'year');
}
Expand Down Expand Up @@ -1465,7 +1549,7 @@ class Gantt {
: '',
Week_upper:
date.getMonth() !== last_date.getMonth()
? date_utils.format(date, 'MMMM', this.options.language)
? date_utils.format(date, `MMMM${(i < 5 || date.getMonth() === 0) ? ' YYYY' : ''}`, this.options.language)
: '',
Month_upper:
date.getFullYear() !== last_date.getFullYear()
Expand Down Expand Up @@ -1493,7 +1577,7 @@ class Gantt {
Week_lower: 0,
Week_upper: this.options.column_width * 4 / 2,
Month_lower: this.options.column_width / 2,
Month_upper: this.options.column_width * 12 / 2,
Month_upper: this.options.column_width * (monthPerYears[date.getFullYear()]) / 2,
Year_lower: this.options.column_width / 2,
Year_upper: this.options.column_width * 30 / 2
};
Expand Down Expand Up @@ -1549,13 +1633,10 @@ class Gantt {
}

set_width() {
const cur_width = this.$svg.getBoundingClientRect().width;
const actual_width = this.$svg
.querySelector('.grid .grid-row')
.getAttribute('width');
if (cur_width < actual_width) {
this.$svg.setAttribute('width', actual_width);
}
this.$svg.setAttribute('width', actual_width);
}

set_scroll_position() {
Expand Down
2 changes: 1 addition & 1 deletion dist/frappe-gantt.min.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,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 @@ -207,7 +211,7 @@ export default class Bar {
target_element: this.$bar,
title: this.task.name,
subtitle: subtitle,
task: this.task,
task: this.task
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/date_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default {
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]]
Expand Down
Loading