Frappe Gantt
repository·master·Indexed 27 days ago
https://github.com/frappe/ganttA modern, interactive, and configurable Gantt chart library for the web used by applications like ERPNext. It allows for the visualization of project tasks, schedules, and dependencies with support for custom view modes, multi-lingual localization, and the ability to exclude specific periods such as weekends or holidays. Version 1.2.2.
What's inside frappe-gantt
- Frappe Gantt is a modern, configurable Gantt library for the web designed to visually illustrate project tasks, schedules, and dependencies. It is used in production by ERPNext and supports highly customizable timelines, exclusion of specific periods (like weekends or holidays), and multi-lingual support.
Install and include Frappe Gantt
masterYou can install Frappe Gantt via npm or include it directly in your HTML using a script tag or CDN.
NPM Installation:
npm install frappe-ganttHTML Inclusion (Local):
<script src="frappe-gantt.umd.js"></script> <link rel="stylesheet" href="frappe-gantt.css" />HTML Inclusion (CDN):
<script src="https://cdn.jsdelivr.net/npm/frappe-gantt/dist/frappe-gantt.umd.js"></script> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/frappe-gantt/dist/frappe-gantt.css" />Set up a local development environment
masterTo contribute to Frappe Gantt, follow these steps to clone the repository, install dependencies, and build the project:
- Clone the repository.
- Navigate to the project directory.
- Install dependencies using
pnpm i. - Build the project using
pnpm run buildor usepnpm run build-devto build and watch for changes. - Open
index.htmlin your browser to view and test changes.
pnpm i pnpm run build # or for development with watching: pnpm run build-devCustomize popups with the `popup` option
masterThe
popupoption is a function used to customize the task popup. The function receives an object containing:task: The task object.chart: The Gantt chart instance.get_title,get_subtitle,get_details: Functions to retrieve HTML nodes for those sections.set_title,set_subtitle,set_details: Functions to set HTML for those sections.add_action: Function accepting(html, func)to add an action and its callback.
Return values of the
popupfunction:false: No popup is rendered.undefined: The popup is rendered based on manipulations made within the function.HTML string: The popup will be rendered using the provided string.
Configure view modes with `view_modes`
masterThe
view_modesoption allows you to define custom available view modes. It accepts an array of objects. Each object can include:name(string): The name of the view mode.padding(interval): Time padding.step: The interval of each column.lower_text(string|function): Format for text in the lower header. If a function, it receives(currentDate, previousDate, lang).upper_text(string|function): Format for text in the upper header. If a function, it receives(currentDate, previousDate, lang).upper_text_frequency(number): Frequency of upper text updates.thick_line(function): Returns boolean to determine if a date line should be thicker.
Additionally, you can override
date_format,column_width, andsnap_atspecifically for a view mode.Initialize and use a Gantt chart
masterTo start using Frappe Gantt, define an array of task objects and instantiate the
Ganttclass by passing a selector for the container element and the tasks array. You can update the chart by appending tasks to thetasksarray and calling.refresh()on the gantt instance.let tasks = [ { id: '1', name: 'Redesign website', start: '2016-12-28', end: '2016-12-31', progress: 20 }, // ... ] let gantt = new Gantt("#gantt", tasks); // Use .refresh to update the chart gantt.tasks.append({ id: '2', name: 'New Task', start: '2017-01-01', end: '2017-01-05', progress: 0 }); gantt.tasks.refresh();Use the Gantt API methods
masterInteract with an existing Gantt instance using the following methods:
.update_options(new_options): Re-renders the chart with the providednew_optionsobject..change_view_mode(view_mode, [maintain_pos]): Updates the view mode.view_modecan be a name (string) or a view mode object.maintain_pos(boolean, defaultfalse) determines if the scroll position is maintained..scroll_current(): Scrolls the chart to the current date..update_task(task_id, new_details): Re-renders a specific task bar using itstask_idand an object ofnew_details.
Configure ignored dates and holidays
masterYou can configure the Gantt chart to ignore specific dates or time periods (like weekends) using the
ignoreoption in the constructor.- String
'weekend': Automatically ignores Saturdays and Sundays. - Date strings: Pass a string like
'2023-12-25'to ignore a specific date. - Function: Pass a function
(date) => booleanto define custom logic for ignoring dates. - Holidays: Use the
holidaysoption to highlight specific dates with colors. You can pass an object where keys are colors and values are either'weekend'or a function/date object.
- String
Configure Gantt view modes
masterThe
view_modesoption allows you to define custom time scales. Each mode object typically includes:name: The identifier for the mode.step: The time increment (e.g.,'1 day').column_width: The width of each column in pixels.upper_text: A function or string to format the top header.lower_text: A function or string to format the bottom header.padding: Padding around the task range.
Configure Gantt chart options
masterFrappe Gantt provides a wide range of configuration options to customize the appearance and behavior of the chart. Common options include:
arrow_curve: Curve radius of arrows connecting dependencies (positive integer).bar_height: Height of task bars in pixels.container_height: Height of the container (autoor positive integer).date_format: Format for displaying dates (e.g.,YYYY-MM-DD).view_mode: Initial view mode (Day,Week,Month,Year).readonly: Disables all editing features.language: ISO 639-1 code for localization (e.g.,en,fr).holidays: Object mapping CSS colors to holiday types (e.g.,weekend).is_weekend: Function to determine if a day is a weekend.lines: Grid line display (none,vertical,horizontal,both).popup_on: Event to trigger popup (clickorhover).
Update tasks in the Gantt chart
masterUse the
update_task(id, new_details)method to modify an existing task. This method updates the task data and refreshes the corresponding bar in the chart.id: The unique ID of the task to update.new_details: An object containing the properties to update (e.g.,start,end,progress).
Get the oldest starting date
masterTheget_oldest_starting_date()method returns the earliest_startdate among all tasks in the Gantt chart. If no tasks exist, it returns a newDate()object.