import { GanttView , GanttViewOptions , primaryDatePointTop , secondaryDatePointTop , GanttViewDate } from './view' ; import { GanttDate , differenceInCalendarQuarters , eachMonthOfInterval } from '../utils/date' ; import { GanttDatePoint } from '../class/date-point' ; const viewOptions = { start : new GanttDate ( ) . startOfQuarter ( ) . addQuarters ( - 1 ) , end : new GanttDate ( ) . endOfQuarter ( ) . addQuarters ( 2 ) , cellWidth : 280 , addAmount : 1 , addUnit : 'quarter' } ; export class GanttViewMonth extends GanttView { constructor ( start , end , options ? ) { super ( start , end , Object . assign ( { } , viewOptions , options ) ) ; } startOf ( date ) { return date . startOfQuarter ( ) ; } endOf ( date ) { return date . endOfQuarter ( ) ; } getPrimaryWidth ( ) { return this . getCellWidth ( ) * 3 ; } getDayOccupancyWidth ( date ) { return this . cellWidth / date . getDaysInMonth ( ) ; } getPrimaryDatePoints ( ) { const quarters = differenceInCalendarQuarters ( this . end . addSeconds ( 1 ) . value , this . start . value ) ; const points = [ ] ; for ( let i = 0 ; i < quarters ; i ++ ) { const start = this . start . addQuarters ( i ) ; const point = new GanttDatePoint ( start , start . format ( 'yyyy年QQQ' ) , ( this . getCellWidth ( ) * 3 ) / 2 + i * ( this . getCellWidth ( ) * 3 ) , primaryDatePointTop ) ; points . push ( point ) ; } return points ; } getSecondaryDatePoints ( ) { const months = eachMonthOfInterval ( { start : this . start . value , end : this . end . value } ) ; const points = [ ] ; for ( let i = 0 ; i < months . length ; i ++ ) { const start = new GanttDate ( months [ i ] ) ; const point = new GanttDatePoint ( start , `${ start . getMonth ( ) + 1 }月` , i * this . getCellWidth ( ) + this . getCellWidth ( ) / 2 , secondaryDatePointTop ) ; points . push ( point ) ; } return points ; } }