Skip to content

Commit

Permalink
fix: add template in range and change today style
Browse files Browse the repository at this point in the history
  • Loading branch information
HandsomeButterball authored and walkerkay committed Jul 28, 2020
1 parent 8aaaa1f commit a4391a5
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 28 deletions.
1 change: 0 additions & 1 deletion packages/gantt/src/components/bar/bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function linearGradient(sideOrCorner: string, color: string, stop: string) {
providers: [GanttBarDrag]
})
export class NgxGanttBarComponent extends GanttItemUpper implements OnInit, AfterViewInit, OnChanges, OnDestroy {
@Input() template: TemplateRef<any>;

@Output() barClick = new EventEmitter<GanttBarClickEvent>();

Expand Down
33 changes: 22 additions & 11 deletions packages/gantt/src/components/calendar/calendar.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<div class="gantt-calendar-today-overlay" *ngIf="ganttUpper.showTodayLine">
<svg [attr.width]="view.width" height="1">
<g>
<polygon class="today-line-angle" />
<line class="today-line"></line>
</g>
</svg>
Expand All @@ -11,16 +10,28 @@
<text class="primary-text" *ngFor="let point of view.primaryDatePoints; trackBy: trackBy" [attr.x]="point.x" [attr.y]="point.y">
{{ point.text }}
</text>
<text
*ngFor="let point of view.secondaryDatePoints; trackBy: trackBy"
class="secondary-text"
[class.secondary-text-weekend]="point.additions?.isWeekend"
[class.secondary-text-today]="point.additions?.isToday"
[attr.x]="point.x"
[attr.y]="point.y"
>
{{ point.text }}
</text>
<ng-container *ngFor="let point of view.secondaryDatePoints; trackBy: trackBy">
<rect
*ngIf="point.additions?.isToday"
class="today-rect"
[attr.x]="point.x - todayWidth / 2"
[attr.y]="point.y - todayWidth / 2"
[attr.rx]="todayBorderRadius"
[attr.ry]="todayBorderRadius"
[attr.width]="todayWidth"
[attr.height]="todayHeight"
></rect>
<text
class="secondary-text"
[class.secondary-text-weekend]="point.additions?.isWeekend"
[class.secondary-text-today]="point.additions?.isToday"
[attr.x]="point.x"
[attr.y]="point.y"
>
{{ point.text }}
</text>
</ng-container>

<g>
<line
*ngFor="let point of view.primaryDatePoints; let i = index; trackBy: trackBy"
Expand Down
10 changes: 5 additions & 5 deletions packages/gantt/src/components/calendar/calendar.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
fill: $gantt-date-secondary-weekend-color;
}
&-today {
fill: $gantt-date-today-color;
fill: $gantt-date-today-text-color;
}
}

Expand All @@ -66,12 +66,12 @@
fill: $gantt-date-week-backdrop-bg;
}

.today-line-angle {
fill: $gantt-date-today-color;
}

.today-line {
stroke: $gantt-date-today-color;
stroke-width: 2px;
}

.today-rect {
fill: $gantt-date-today-color;
}
}
12 changes: 8 additions & 4 deletions packages/gantt/src/components/calendar/calendar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { GanttDatePoint } from '../../class/date-point';
import { Subject, merge } from 'rxjs';
import { take, takeUntil } from 'rxjs/operators';
import { headerHeight } from '../../gantt.styles';
import { headerHeight, todayHeight, todayWidth, todayBorderRadius } from '../../gantt.styles';
import { isNumber } from '../../utils/helpers';
import { GanttDate } from '../../utils/date';
import { GanttDomService } from '../../gantt-dom.service';
Expand All @@ -37,6 +37,12 @@ export class GanttCalendarComponent implements OnInit, AfterViewInit, OnChanges,

mainHeight = mainHeight;

todayHeight = todayHeight;

todayWidth = todayWidth;

todayBorderRadius = todayBorderRadius;

@HostBinding('class.gantt-calendar-overlay') className = true;

constructor(
Expand All @@ -49,10 +55,8 @@ export class GanttCalendarComponent implements OnInit, AfterViewInit, OnChanges,

setTodayPoint() {
const x = this.view.getTodayXPoint();
const angle = this.elementRef.nativeElement.getElementsByClassName('today-line-angle')[0];
const line = this.elementRef.nativeElement.getElementsByClassName('today-line')[0];
if (angle && line && isNumber(x)) {
angle.setAttribute('points', [`${x - 6},${headerHeight}`, `${x + 6},${headerHeight}`, `${x},${headerHeight + 5}`].join(' '));
if (line && isNumber(x)) {
line.setAttribute('x1', x.toString());
line.setAttribute('x2', x.toString());
line.setAttribute('y1', headerHeight.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<ng-container *ngIf="item.type === ganttItemType.custom">
<ng-template [ngTemplateOutlet]="itemTemplate" [ngTemplateOutletContext]="{ item: item.origin, refs: item.refs }"></ng-template>
</ng-container>
<gantt-range *ngIf="item.type === ganttItemType.range" [item]="item"></gantt-range>
<gantt-range *ngIf="item.type === ganttItemType.range" [template]="rangeTemplate" [item]="item"></gantt-range>
<gantt-bar
*ngIf="item.type === ganttItemType.bar"
[item]="item"
Expand Down
2 changes: 2 additions & 0 deletions packages/gantt/src/components/main/gantt-main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export class GanttMainComponent implements OnInit {

@Input() barTemplate: TemplateRef<any>;

@Input() rangeTemplate: TemplateRef<any>;

@Output() barClick = new EventEmitter<GanttBarClickEvent>();

@Output() lineClick = new EventEmitter<GanttLineClickEvent>();
Expand Down
1 change: 1 addition & 0 deletions packages/gantt/src/components/range/range.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
</div>
<div class="gantt-range-triangle left"></div>
<div class="gantt-range-triangle right"></div>
<ng-template [ngTemplateOutlet]="template" [ngTemplateOutletContext]="{ item: item.origin, refs: item.refs }"></ng-template>
</ng-container>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.gantt-table {
display: block;
height: 100%;

.gantt-table-row {
display: flex;
Expand Down
4 changes: 3 additions & 1 deletion packages/gantt/src/gantt-item-upper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Input, ElementRef, Inject } from '@angular/core';
import { Input, ElementRef, Inject, TemplateRef } from '@angular/core';
import { GanttItemInternal, GanttItemType } from './class';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { rangeHeight } from './gantt.styles';
import { GANTT_UPPER_TOKEN, GanttUpper } from './gantt-upper';

export abstract class GanttItemUpper {
@Input() template: TemplateRef<any>;

@Input() item: GanttItemInternal;

public firstChange = true;
Expand Down
6 changes: 5 additions & 1 deletion packages/gantt/src/gantt-upper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export abstract class GanttUpper {

@ContentChild('bar', { static: true }) barTemplate: TemplateRef<any>;

@ContentChild('range', { static: true }) rangeTemplate: TemplateRef<any>;

@ContentChild('item', { static: true }) itemTemplate: TemplateRef<any>;

@ContentChild('group', { static: true }) groupTemplate: TemplateRef<any>;
Expand Down Expand Up @@ -120,7 +122,9 @@ export abstract class GanttUpper {
this.originItems = uniqBy(this.originItems, 'id');
// 根据上一次数据展开状态同步新的数据展开状态
this.originItems.forEach((item) => {
item.expanded = item.expanded || this.expandedItemIds.includes(item.id);
if (!this.firstChange) {
item.expanded = this.expandedItemIds.includes(item.id);
}
});
if (this.groups.length > 0) {
this.originItems.forEach((origin) => {
Expand Down
1 change: 1 addition & 0 deletions packages/gantt/src/gantt.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[items]="items"
[itemTemplate]="itemTemplate"
[barTemplate]="barTemplate"
[rangeTemplate]="rangeTemplate"
(barClick)="barClick.emit($event)"
(lineClick)="lineClick.emit($event)"
>
Expand Down
6 changes: 6 additions & 0 deletions packages/gantt/src/gantt.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ export const barBackground = '#348fe4';

export const rangeHeight = 17;

export const todayHeight = 25;

export const todayWidth = 35;

export const todayBorderRadius = 4;


12 changes: 9 additions & 3 deletions packages/gantt/src/styles/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ $gantt-bg-color: #fff !default;
$gantt-side-shadow: 12px 0 16px -10px rgba(0, 0, 0, 0.15) !default;
$gantt-container-background-color: #fafafa !default;
$gantt-item-height: 44px !default;
$gantt-group-background-color: rgba($color: #f3f3f3, $alpha: 0.5) !default;
$gantt-group-background-color: rgba(
$color: #f3f3f3,
$alpha: 0.5
) !default;
$gantt-group-height: 44px !default;
$gantt-table-td-padding: 0 15px !default;

Expand All @@ -20,8 +23,12 @@ $gantt-date-primary-border: #ddd !default;
$gantt-date-secondary-color: #333 !default;
$gantt-date-secondary-font-size: 14px !default;
$gantt-date-secondary-weekend-color: #aaa !default;
$gantt-date-week-backdrop-bg: rgba($color: #f3f3f3, $alpha: 0.5) !default;
$gantt-date-week-backdrop-bg: rgba(
$color: #f3f3f3,
$alpha: 0.5
) !default;
$gantt-date-today-color: #ff9f73 !default;
$gantt-date-today-text-color: #fff !default;

// bar
$gantt-bar-layer-bg: #fff !default;
Expand All @@ -35,4 +42,3 @@ $gantt-link-dragging-line-color: #348fe4 !default;

// link
$gantt-link-line-color: #348fe4 !default;

0 comments on commit a4391a5

Please sign in to comment.