Skip to content

Commit

Permalink
feat: fixed header in html
Browse files Browse the repository at this point in the history
  • Loading branch information
safwansamsudeen committed Apr 23, 2024
1 parent 35966f0 commit dd28b8e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 48 deletions.
43 changes: 25 additions & 18 deletions src/gantt.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,44 @@ $light-yellow: #f6e796 !default;
$holiday-color: #f3f4f7 !default;
$text-muted: #666 !default;
$text-light: #fff !default;
$text-dark: #333 !default;
$text-dark: #111 !default;
$progress-important: #2c94ec !default;
$progress: #dedfe0 !default;
$handle-color: #dcdce4 !default;
$handle-color-important: #94c4f4 !default;
$light-blue: #c4c4e9 !default;

.gantt-container {
.grid-header {
background-color: #ffffff;
position: sticky;
top: 0;
left: 0;
}

.lower-text,
.upper-text {
font-size: 14px;
text-anchor: middle;
color: $text-muted;
}

.lower-text {
position: absolute;
width: fit-content;
}
}

.gantt {
user-select: none;
-webkit-user-select: none;
position: absolute;

.grid-background {
fill: none;
}

.grid-header {
fill: #ffffff;
stroke: $border-color;
stroke-width: 1.4;
}


.grid-row {
fill: #ffffff;
Expand Down Expand Up @@ -171,7 +189,7 @@ $light-blue: #c4c4e9 !default;

.bar {
-webkit-filter: drop-shadow(3px 3px 2px rgba(0, 0, 0, .7));
filter: drop-shadow(0 0 5px rgba(17, 43, 66, .16));
filter: drop-shadow(0 0 2px rgba(17, 43, 66, .16));
border-radius: 3px;
}

Expand All @@ -189,17 +207,6 @@ $light-blue: #c4c4e9 !default;

}

.lower-text,
.upper-text {
font-size: 14px;
text-anchor: middle;
}


.lower-text,
.upper-text {
fill: $text-dark;
}

.hide {
display: none;
Expand Down
54 changes: 24 additions & 30 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export default class Gantt {

setup_layers() {
this.layers = {};
const layers = ["grid", "arrow", "progress", "bar", "details", "date"];
const layers = ["grid", "arrow", "progress", "bar", "details"];
// make group layers
for (let layer of layers) {
this.layers[layer] = createSVG("g", {
Expand Down Expand Up @@ -381,7 +381,7 @@ export default class Gantt {
width: grid_width,
height: grid_height,
class: "grid-background",
append_to: this.layers.date,
append_to: this.$svg,
});

$.attr(this.$svg, {
Expand Down Expand Up @@ -424,16 +424,13 @@ export default class Gantt {
}

make_grid_header() {
const header_width = this.dates.length * this.options.column_width;
const header_height = this.options.header_height + 10;
createSVG("rect", {
x: 0,
y: 0,
width: header_width,
height: header_height,
class: "grid-header",
append_to: this.layers.grid,
});
let header = document.createElement("div");

header.style.height = this.options.header_height + 10 + "px";
header.style.width = this.dates.length * this.options.column_width + "px";
header.classList.add('grid-header')
this.$header = header
this.$svg.parentElement.appendChild(header)
}

make_grid_ticks() {
Expand Down Expand Up @@ -578,25 +575,23 @@ export default class Gantt {

make_dates() {
for (let date of this.get_dates_to_draw()) {
createSVG("text", {
x: date.lower_x,
y: date.lower_y,
innerHTML: date.lower_text,
class: "lower-text",
append_to: this.layers.date,
});
let $lower_text = document.createElement('div');
$lower_text.classList.add('lower-text')
$lower_text.style.left = date.lower_x + 'px'
$lower_text.style.top = date.lower_y + 'px'
$lower_text.innerText = date.lower_text
this.$header.appendChild($lower_text)

if (date.upper_text) {
const $upper_text = createSVG("text", {
x: date.upper_x,
y: date.upper_y,
innerHTML: date.upper_text,
class: "upper-text",
append_to: this.layers.date,
});
let $upper_text = document.createElement('div');
$upper_text.classList.add('lower-text')
$upper_text.style.left = date.upper_x + 'px'
$upper_text.style.top = date.upper_y + 'px'
$upper_text.innerText = date.upper_text
this.$header.appendChild($upper_text)

// remove out-of-bound dates
if ($upper_text.getBBox().x2 > this.layers.grid.getBBox().width) {
if (date.upper_x > this.layers.grid.getBBox().width) {
$upper_text.remove();
}
}
Expand Down Expand Up @@ -666,8 +661,8 @@ export default class Gantt {
x: last_date_info
? last_date_info.base_pos_x + last_date_info.column_width
: 0,
lower_y: this.options.header_height,
upper_y: this.options.header_height - 25,
lower_y: this.options.header_height - 15,
upper_y: this.options.header_height - 35,
};

const x_pos = {
Expand Down Expand Up @@ -846,7 +841,6 @@ export default class Gantt {
const ids = [];
let dx;

this.layers.date.setAttribute('transform', 'translate(0,' + e.currentTarget.scrollTop + ')');
if (x_on_scroll_start) {
dx = e.currentTarget.scrollLeft - x_on_scroll_start;
}
Expand Down

0 comments on commit dd28b8e

Please sign in to comment.