feat: date highlight, handles out, improved font

This commit is contained in:
Safwan Samsudeen 2024-04-20 10:14:04 +05:30
parent 85c943b191
commit 769233a71a
2 changed files with 55 additions and 22 deletions

View File

@ -75,11 +75,11 @@ export default class Bar {
draw() { draw() {
this.draw_bar(); this.draw_bar();
this.draw_progress_bar();
if (this.gantt.options.show_expected_progress) { if (this.gantt.options.show_expected_progress) {
this.prepare_expected_progress_values(); this.prepare_expected_progress_values();
this.draw_expected_progress_bar(); this.draw_expected_progress_bar();
} }
this.draw_progress_bar();
this.draw_label(); this.draw_label();
this.draw_resize_handles(); this.draw_resize_handles();
@ -140,12 +140,27 @@ export default class Bar {
class: "bar-progress", class: "bar-progress",
append_to: this.bar_group, append_to: this.bar_group,
}); });
const x = (date_utils.diff(this.task._start, this.gantt.gantt_start, 'hour') /
this.gantt.options.step) *
this.gantt.options.column_width;
this.$date_highlight = createSVG("rect", {
x,
y: this.gantt.options.header_height - 17,
width: this.width,
height: this.height * 0.8,
rx: this.corner_radius * 2,
ry: this.corner_radius * 2,
class: "date-highlight",
append_to: this.bar_group,
});
animateSVG(this.$bar_progress, "width", 0, this.progress_width); animateSVG(this.$bar_progress, "width", 0, this.progress_width);
} }
draw_label() { draw_label() {
let x_coord = this.x + 5; let x_coord = this.x + this.$bar.getWidth() / 2;
if (this.task.thumbnail) { if (this.task.thumbnail) {
x_coord = this.x + this.image_size + 5; x_coord = this.x + this.image_size + 5;
@ -209,7 +224,7 @@ export default class Bar {
const handle_width = 8; const handle_width = 8;
createSVG("rect", { createSVG("rect", {
x: bar.getX() + bar.getWidth() - 9, x: bar.getX() + bar.getWidth() + handle_width - 4,
y: bar.getY() + 1, y: bar.getY() + 1,
width: handle_width, width: handle_width,
height: this.height - 2, height: this.height - 2,
@ -220,7 +235,7 @@ export default class Bar {
}); });
createSVG("rect", { createSVG("rect", {
x: bar.getX() + 1, x: bar.getX() - handle_width - 4,
y: bar.getY() + 1, y: bar.getY() + 1,
width: handle_width, width: handle_width,
height: this.height - 2, height: this.height - 2,
@ -240,12 +255,12 @@ export default class Bar {
get_progress_polygon_points() { get_progress_polygon_points() {
const bar_progress = this.$bar_progress; const bar_progress = this.$bar_progress;
return [ return [
bar_progress.getEndX() - 5, bar_progress.getEndX() - 6,
bar_progress.getY() + bar_progress.getHeight(), bar_progress.getY() + bar_progress.getHeight() + 8,
bar_progress.getEndX() + 5, bar_progress.getEndX() + 6,
bar_progress.getY() + bar_progress.getHeight(), bar_progress.getY() + bar_progress.getHeight() + 8,
bar_progress.getEndX(), bar_progress.getEndX(),
bar_progress.getY() + bar_progress.getHeight() - 8.66, bar_progress.getY() + bar_progress.getHeight() + 0.5,
]; ];
} }
@ -537,10 +552,12 @@ export default class Bar {
label = this.group.querySelector(".bar-label"), label = this.group.querySelector(".bar-label"),
img = this.group.querySelector('.bar-img'); img = this.group.querySelector('.bar-img');
let padding = 5; let padding = 5;
let x_offset_label_img = this.image_size + 10; let x_offset_label_img = this.image_size + 10;
const labelWidth = label.getBBox().width
if (label.getBBox().width > bar.getWidth()) { const barWidth = bar.getWidth()
if (labelWidth > barWidth) {
label.classList.add("big"); label.classList.add("big");
if (img) { if (img) {
img.setAttribute('x', bar.getX() + bar.getWidth() + padding); img.setAttribute('x', bar.getX() + bar.getWidth() + padding);
@ -554,9 +571,9 @@ export default class Bar {
if (img) { if (img) {
img.setAttribute('x', bar.getX() + padding); img.setAttribute('x', bar.getX() + padding);
img_mask.setAttribute('x', bar.getX() + padding); img_mask.setAttribute('x', bar.getX() + padding);
label.setAttribute('x', bar.getX() + x_offset_label_img); label.setAttribute('x', bar.getX() + barWidth / 2 + x_offset_label_img);
} else { } else {
label.setAttribute('x', bar.getX() + padding); label.setAttribute('x', bar.getX() + barWidth / 2 - labelWidth / 2);
} }
} }
} }
@ -566,10 +583,10 @@ export default class Bar {
const bar = this.$bar; const bar = this.$bar;
this.handle_group this.handle_group
.querySelector(".handle.left") .querySelector(".handle.left")
.setAttribute("x", bar.getX() + 1); .setAttribute("x", bar.getX() - 12);
this.handle_group this.handle_group
.querySelector(".handle.right") .querySelector(".handle.right")
.setAttribute("x", bar.getEndX() - 9); .setAttribute("x", bar.getEndX() + 4);
const handle = this.group.querySelector(".handle.progress"); const handle = this.group.querySelector(".handle.progress");
handle && handle.setAttribute("points", this.get_progress_polygon_points()); handle && handle.setAttribute("points", this.get_progress_polygon_points());
} }

View File

@ -81,17 +81,24 @@ $light-blue: #c4c4e9 !default;
stroke-width: 1.4; stroke-width: 1.4;
} }
.bar { .bar-wrapper .bar {
fill: $bar-color; fill: $bar-color;
stroke: $bar-stroke; stroke: $bar-stroke;
stroke-width: 0; stroke-width: 0;
transition: stroke-width 0.3s ease; transition: stroke-width 0.3s ease;
} }
.bar-progress { .bar-progress {
fill: $blue; fill: $blue;
} }
.date-highlight {
fill: darken(#f5f5f5, 5);
display: none;
}
.bar-expected-progress { .bar-expected-progress {
fill: $light-blue; fill: $light-blue;
} }
@ -111,8 +118,9 @@ $light-blue: #c4c4e9 !default;
fill: #fff; fill: #fff;
dominant-baseline: central; dominant-baseline: central;
// text-anchor: middle; // text-anchor: middle;
font-size: 12px; font-family: Helvetica;
font-weight: 500; font-size: 13px;
font-weight: 600;
&.big { &.big {
fill: $text-light; fill: $text-light;
@ -128,6 +136,13 @@ $light-blue: #c4c4e9 !default;
transition: opacity 0.3s ease; transition: opacity 0.3s ease;
} }
&:hover {
.handle {
visibility: visible;
opacity: 1;
}
}
.bar-wrapper { .bar-wrapper {
cursor: pointer; cursor: pointer;
outline: none; outline: none;
@ -141,9 +156,10 @@ $light-blue: #c4c4e9 !default;
fill: darken($blue, 5); fill: darken($blue, 5);
} }
.handle {
visibility: visible;
opacity: 1; .date-highlight {
display: block;
} }
} }
@ -160,7 +176,7 @@ $light-blue: #c4c4e9 !default;
.lower-text, .lower-text,
.upper-text { .upper-text {
font-size: 12px; font-size: 14px;
text-anchor: middle; text-anchor: middle;
} }