@mogura/moguchart-core 0.12.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,8 @@ import { LitElement, type PropertyValues } from 'lit';
3
3
  import './gantt-calendar';
4
4
  import './gantt-row';
5
5
  import './gantt-minimap';
6
- import { type ExportImageOptions } from './gantt-chart-export';
6
+ import { PluginManager, type GanttPlugin } from '../core/plugin';
7
+ import type { ExportImageOptions } from '../core/types';
7
8
  export declare class GanttChartElement extends LitElement {
8
9
  rows: GanttRow[];
9
10
  option: GanttChartOption;
@@ -39,6 +40,7 @@ export declare class GanttChartElement extends LitElement {
39
40
  private cursorLineX;
40
41
  private connectorDrag;
41
42
  private _systemThemeMediaQuery;
43
+ private _pluginManager;
42
44
  private isExporting;
43
45
  private focusedTaskId;
44
46
  private focusedRowId;
@@ -59,6 +61,9 @@ export declare class GanttChartElement extends LitElement {
59
61
  private _lastZoomPxPerDay;
60
62
  private _lastZoomPxPerMonth;
61
63
  private _scrollContainer;
64
+ private _collapsedRowIds;
65
+ private _prevExternalCollapsed;
66
+ private _draggingRowId;
62
67
  private get displayRows();
63
68
  /**
64
69
  * 現在有効な pxPerDay(ズームオーバーライドがあればそちらを優先)
@@ -72,6 +77,7 @@ export declare class GanttChartElement extends LitElement {
72
77
  protected firstUpdated(): void;
73
78
  connectedCallback(): void;
74
79
  disconnectedCallback(): void;
80
+ private _handleGlobalDragEnd;
75
81
  private handleSystemThemeChange;
76
82
  protected willUpdate(changedProperties: PropertyValues): void;
77
83
  protected updated(changedProperties: PropertyValues): void;
@@ -107,6 +113,8 @@ export declare class GanttChartElement extends LitElement {
107
113
  private handleBarMouseLeave;
108
114
  private reorderRows;
109
115
  private handleContainerDragOver;
116
+ private handleRowDragStart;
117
+ private handleRowDragEnd;
110
118
  private handleContainerDragLeave;
111
119
  private handleContainerDrop;
112
120
  private handleExternalTaskDrop;
@@ -137,12 +145,26 @@ export declare class GanttChartElement extends LitElement {
137
145
  bottom: number;
138
146
  }[];
139
147
  /**
140
- * html2canvas を使用してガントチャートを画像としてエクスポートする。
141
- * (Shadow DOMネイティブ対応版 html2canvas-pro を使用)
148
+ * プラグインを登録してインストールする。
149
+ * @param plugin 登録するプラグイン
150
+ * @param config プラグインの設定オプション(任意)
151
+ */
152
+ use<TConfig = any>(plugin: GanttPlugin<TConfig>, config?: TConfig): this;
153
+ /**
154
+ * 内部のプラグインマネージャーを取得する。
155
+ */
156
+ get pluginManager(): PluginManager;
157
+ /**
158
+ * ガントチャートを画像またはPDFとしてエクスポートする。
159
+ * ※ エクスポート機能を使用するには、`@mogura/moguchart-plugin-export` プラグインの登録が必要です。
160
+ * 例:
161
+ * import { exportPlugin } from '@mogura/moguchart-plugin-export'
162
+ * chart.use(exportPlugin())
142
163
  *
143
- * @param options エクスポートオプション。
164
+ * @param format 'png' または 'pdf'
165
+ * @param options エクスポートオプション
144
166
  */
145
- exportImage(format?: 'png' | 'pdf', options?: ExportImageOptions): Promise<string | Blob>;
167
+ exportImage(_format?: 'png' | 'pdf', _options?: ExportImageOptions): Promise<string | Blob>;
146
168
  /**
147
169
  * Ctrl/Cmd + マウスホイールによるズーム処理
148
170
  */
@@ -217,6 +239,35 @@ export declare class GanttChartElement extends LitElement {
217
239
  * @returns タスクが見つかり選択できた場合はtrue、見つからなかった場合はfalse
218
240
  */
219
241
  selectTask(taskId: string): boolean;
242
+ private handleRowToggleCollapse;
243
+ /**
244
+ * 指定した行の折りたたみ状態を切り替えます。
245
+ *
246
+ * @param rowId 対象の行ID
247
+ * @param collapsed 設定する折りたたみ状態(省略時は現在の状態を反転)
248
+ * @returns 切り替えに成功した場合はtrue、行が見つからない場合はfalse
249
+ */
250
+ toggleRowCollapse(rowId: string, collapsed?: boolean): boolean;
251
+ /**
252
+ * 子行を持つすべての親行を折りたたみます。
253
+ */
254
+ collapseAll(): void;
255
+ /**
256
+ * すべての行を展開(折りたたみ解除)します。
257
+ */
258
+ expandAll(): void;
259
+ /**
260
+ * スクロール位置を左上(0, 0)にリセットします。
261
+ */
262
+ resetScroll(): void;
263
+ /**
264
+ * 指定したスクロール位置に移動します。
265
+ */
266
+ scrollToPosition(options: {
267
+ left?: number;
268
+ top?: number;
269
+ behavior?: ScrollBehavior;
270
+ }): void;
220
271
  /**
221
272
  * 指定タスクが表示範囲外の場合にスクロールして表示する
222
273
  */
@@ -5,6 +5,9 @@ import './gantt-row-background';
5
5
  export declare class GanttRowElement extends LitElement {
6
6
  row: GanttRow;
7
7
  option: GanttChartOption;
8
+ level: number;
9
+ hasChildren: boolean;
10
+ wbsCode: string;
8
11
  isDragTarget: boolean;
9
12
  draggingTask: {
10
13
  id: string;
@@ -59,6 +62,7 @@ export declare class GanttRowElement extends LitElement {
59
62
  private calculateMarkerLanes;
60
63
  static styles: import("lit").CSSResult;
61
64
  private handleDragStart;
65
+ private handleDragEnd;
62
66
  private handleHeaderClick;
63
67
  private handleHeaderContextMenu;
64
68
  private handleHeaderDblClick;
@@ -66,6 +70,10 @@ export declare class GanttRowElement extends LitElement {
66
70
  private _rowHeaderTooltipTimer;
67
71
  private handleHeaderMouseEnter;
68
72
  private handleHeaderMouseLeave;
73
+ private handleToggleMouseEnter;
74
+ private handleToggleMouseLeave;
75
+ private handleToggleCollapse;
76
+ private handleToggleDblClick;
69
77
  protected updated(changedProperties: PropertyValues): void;
70
78
  render(): import("lit").TemplateResult<1>;
71
79
  }
@@ -0,0 +1,60 @@
1
+ import type { GanttChartElement } from '../components/gantt-chart';
2
+ import type { TaskUpdateEventDetail } from './types';
3
+ /**
4
+ * ガントチャート拡張プラグインの共通インターフェース
5
+ */
6
+ export interface GanttPlugin<TConfig = any, TChart = any> {
7
+ /** プラグインの一意な識別名 (例: 'export', 'auto-schedule') */
8
+ name: string;
9
+ /** プラグインのバージョン (任意) */
10
+ version?: string;
11
+ /** チャートインスタンス初期化時またはuse()呼び出し時のインストール処理 */
12
+ install?: (chart: TChart, config?: TConfig) => void;
13
+ /** チャート破棄時(disconnectedCallback)のクリーンアップ処理 */
14
+ destroy?: (chart: TChart) => void;
15
+ /** ライフサイクルフック */
16
+ hooks?: {
17
+ /** タスク更新直前のフック(false を返すと更新処理をキャンセル) */
18
+ beforeTaskUpdate?: (detail: TaskUpdateEventDetail) => boolean | void | Promise<boolean | void>;
19
+ /** タスク更新直後のフック */
20
+ afterTaskUpdate?: (detail: TaskUpdateEventDetail) => void;
21
+ /** レンダリング後のフック */
22
+ afterRender?: (chart: TChart) => void;
23
+ };
24
+ }
25
+ /**
26
+ * プラグイン管理マネージャークラス
27
+ */
28
+ export declare class PluginManager {
29
+ private plugins;
30
+ private chart;
31
+ constructor(chart: GanttChartElement);
32
+ /**
33
+ * プラグインを登録・インストールする
34
+ */
35
+ use<TConfig = any>(plugin: GanttPlugin<TConfig>, config?: TConfig): void;
36
+ /**
37
+ * 登録済みプラグインの一覧を取得する
38
+ */
39
+ getPlugin(name: string): GanttPlugin | undefined;
40
+ /**
41
+ * プラグインが登録されているかどうかを確認する
42
+ */
43
+ hasPlugin(name: string): boolean;
44
+ /**
45
+ * beforeTaskUpdate フックを一括実行する
46
+ */
47
+ executeBeforeTaskUpdate(detail: TaskUpdateEventDetail): Promise<boolean>;
48
+ /**
49
+ * afterTaskUpdate フックを一括実行する
50
+ */
51
+ executeAfterTaskUpdate(detail: TaskUpdateEventDetail): void;
52
+ /**
53
+ * afterRender フックを一括実行する
54
+ */
55
+ executeAfterRender(): void;
56
+ /**
57
+ * 全プラグインを破棄・クリーンアップする
58
+ */
59
+ destroy(): void;
60
+ }
@@ -1,4 +1,5 @@
1
1
  import type { MoguchartLocale } from './i18n';
2
+ import type { GanttPlugin } from './plugin';
2
3
  /**
3
4
  * ガントチャートのバーに適用できるパターンの種類
4
5
  */
@@ -83,6 +84,8 @@ export interface GanttTask {
83
84
  progressStyle?: string;
84
85
  /** 進捗バーのドラッグ編集可否 (指定がない場合はoption.progress.editableに準ずる) */
85
86
  progressResizable?: boolean;
87
+ /** タスクの種別 ('task': 通常, 'summary': 親サマリー集計バー, 'milestone': マイルストーン) */
88
+ type?: 'task' | 'summary' | 'milestone';
86
89
  }
87
90
  /**
88
91
  * ガントチャートの行を表すインターフェース
@@ -100,6 +103,16 @@ export interface GanttRow {
100
103
  selectedMarkerId?: string;
101
104
  /** 行を表示するかどうか (デフォルト: true) */
102
105
  visible?: boolean;
106
+ /** 親行のID (ルート階層の場合は null または undefined) */
107
+ parentId?: string | null;
108
+ /** 折りたたみ状態 (trueの場合、配下の子孫行を非表示にする) */
109
+ collapsed?: boolean;
110
+ /** サマリー行(グループ行)かどうか */
111
+ isSummary?: boolean;
112
+ /** サマリータスクバーのカスタム色 (CSSカラー文字列)。指定がない場合はoption.tree.summaryColorまたは既定色 */
113
+ summaryColor?: string;
114
+ /** WBSコード (例: "1.2.1") */
115
+ wbsCode?: string;
103
116
  }
104
117
  /**
105
118
  * 内部計算用: レーン情報が付与されたタスク
@@ -369,6 +382,8 @@ export interface GanttChartOption {
369
382
  snapDuration?: number;
370
383
  /** 非表示に設定された行を表示するかどうか (デフォルト: false) */
371
384
  showHiddenRows?: boolean;
385
+ /** チャート全体のフォントサイズ倍率 (デフォルト: 1) */
386
+ fontScale?: number;
372
387
  /** カスタムレンダリング設定 */
373
388
  customRendering?: GanttChartOptionCustomRendering;
374
389
  /** ロケール設定 (デフォルト: 日本語) */
@@ -399,6 +414,27 @@ export interface GanttChartOption {
399
414
  progress?: GanttChartOptionProgress;
400
415
  /** タスク選択に関する設定 */
401
416
  selection?: GanttChartOptionSelection;
417
+ /** WBS・階層ツリーに関する設定 */
418
+ tree?: GanttChartOptionTree;
419
+ /** 拡張プラグインの配列 */
420
+ plugins?: GanttPlugin[];
421
+ }
422
+ /**
423
+ * WBS・階層ツリーに関するオプション
424
+ */
425
+ export interface GanttChartOptionTree {
426
+ /** ツリー表示を有効にするかどうか (デフォルト: true) */
427
+ enabled?: boolean;
428
+ /** 階層レベルあたりのインデント幅 (px、デフォルト: 16) */
429
+ indentWidth?: number;
430
+ /** 折りたたみトグルアイコン(▶/▼)を表示するかどうか (デフォルト: true) */
431
+ showToggleIcon?: boolean;
432
+ /** WBSコード(1, 1.1など)を行ヘッダーに自動表示するかどうか (デフォルト: false) */
433
+ showWbsCode?: boolean;
434
+ /** 子タスクの変更時に親サマリータスクを自動計算するかどうか (デフォルト: true) */
435
+ autoSummary?: boolean;
436
+ /** サマリータスクバーの既定色 (CSSカラー文字列、デフォルト: '#334155') */
437
+ summaryColor?: string;
402
438
  }
403
439
  /**
404
440
  * タスク選択・矩形範囲選択に関するオプション
@@ -423,6 +459,8 @@ export interface GanttChartOptionProgress {
423
459
  color?: string;
424
460
  /** 進捗ラベル (例: '50%') を表示するかどうか (デフォルト: false) */
425
461
  showLabel?: boolean;
462
+ /** サマリータスクにも進捗ラベルを表示するかどうか (デフォルト: false) */
463
+ showSummaryLabel?: boolean;
426
464
  /** 進捗ラベルの表示位置 ('inside' | 'right' | 'left' | 'center') (デフォルト: 'inside') */
427
465
  labelPosition?: 'inside' | 'right' | 'left' | 'center';
428
466
  /** 進捗ラベルのカスタムフォーマット関数 */
@@ -648,6 +686,17 @@ export interface RowHeaderContextMenuEventDetail {
648
686
  /** 右クリックされたヘッダー要素 */
649
687
  target: HTMLElement;
650
688
  }
689
+ /**
690
+ * 行の折りたたみ/展開切り替えイベントの詳細
691
+ */
692
+ export interface RowToggleCollapseEventDetail {
693
+ /** 対象の行ID */
694
+ rowId: string;
695
+ /** 新しい折りたたみ状態 (true: 折りたたみ, false: 展開) */
696
+ collapsed: boolean;
697
+ /** 対象の行データ */
698
+ row: GanttRow;
699
+ }
651
700
  /**
652
701
  * テーマカラーパレット定義
653
702
  */
@@ -827,3 +876,16 @@ export interface TaskProgressChangeEventDetail {
827
876
  /** キャンセルされたかどうか */
828
877
  cancelled?: boolean;
829
878
  }
879
+ /**
880
+ * 画像・PDFエクスポートのオプション
881
+ */
882
+ export interface ExportImageOptions {
883
+ /** ダウンロード時のファイル名(拡張子なし)。省略時は 'gantt-chart' */
884
+ filename?: string;
885
+ /** true の場合、自動的にファイルダウンロードを開始する。デフォルト: false */
886
+ download?: boolean;
887
+ /** PNG 出力時のスケール倍率(高解像度化)。デフォルト: 2 */
888
+ scale?: number;
889
+ /** 画像を指定したピクセル数で縦に分割し、分割位置にカレンダー(ヘッダー)を挿入する。未指定時は分割しない */
890
+ splitHeight?: number;
891
+ }
@@ -0,0 +1,58 @@
1
+ import type { GanttRow, GanttTask } from './types';
2
+ /**
3
+ * 各行の階層レベル(深さ: ルートは0, その子は1, 孫は2...)を計算します。
4
+ * 循環参照や存在しない親IDがある場合でも安全にフォールバックします。
5
+ *
6
+ * @param rows ガント行の配列
7
+ * @returns 行ID -> 階層レベルのMap
8
+ */
9
+ export declare function computeRowLevels(rows: GanttRow[]): Map<string, number>;
10
+ /**
11
+ * 各行のWBSコード(例: "1", "1.1", "1.2", "2", "2.1"...)を行の順序に基づいて自動採番します。
12
+ *
13
+ * @param rows ガント行の配列
14
+ * @returns 行ID -> WBSコードのMap
15
+ */
16
+ export declare function computeRowWbsCodes(rows: GanttRow[]): Map<string, string>;
17
+ /**
18
+ * 指定された親行の直下、または再帰的なすべての子孫行IDを取得します。
19
+ *
20
+ * @param rows ガント行の配列
21
+ * @param parentId 親行のID
22
+ * @param recursive 再帰的に孫以降も取得するかどうか (デフォルト: true)
23
+ * @returns 子行IDの配列
24
+ */
25
+ export declare function computeChildRowIds(rows: GanttRow[], parentId: string, recursive?: boolean): string[];
26
+ /**
27
+ * 折りたたまれた親行を持つ子孫行を除外した、実際に画面に表示されるべき可視行リストを返します。
28
+ *
29
+ * @param rows ガント行の配列
30
+ * @param includeHidden `row.visible === false` の行も含めるか (showHiddenRows 用、デフォルト: false)
31
+ * @returns 表示対象の行配列
32
+ */
33
+ export declare function computeVisibleTreeRows(rows: GanttRow[], includeHidden?: boolean): GanttRow[];
34
+ /**
35
+ * 子タスクの配列から、親サマリータスク(最小開始日〜最大終了日、加重平均進捗率)を計算します。
36
+ *
37
+ * @param childTasks 子タスクの配列
38
+ * @param template サマリータスクの基本プロパティ(id, name 等)
39
+ * @returns 計算されたサマリータスク。子タスクがない場合は null
40
+ */
41
+ export declare function computeSummaryTask(childTasks: GanttTask[], template?: Partial<GanttTask>): GanttTask | null;
42
+ /**
43
+ * 行ドラッグ&ドロップ時に、移動先が安全かつWBSの階層構造(親子関係)を維持できるかを判定します。
44
+ *
45
+ * - 循環参照ガード: 移動対象自身または自身の子孫へのドロップ、および自身の親を自身(または自身の子孫)にするドロップは禁止
46
+ * - 展開中親行の直下ガード: 展開中の親行の bottom は最初の子行の前への割り込みになるため禁止(親自身の子行の先頭移動を除く)
47
+ * - ドロップ先に応じた階層(parentId)の変化:
48
+ * - ルート行へのドロップ: ルート行(parentId = null)に移動
49
+ * - 子行へのドロップ: その子行の兄弟行(同じ parentId)に移動
50
+ * - 親行へのドロップ: bottom なら先頭子行に移動、top なら親行の前(親行の兄弟)に移動
51
+ *
52
+ * @param rows ガント行の配列
53
+ * @param movingRowIds 移動しようとしている行ID(単一または複数)
54
+ * @param targetRowId ドロップ先の行ID
55
+ * @param position ドロップ位置 ('top' または 'bottom'、省略時は行へのドロップ可否全般)
56
+ * @returns ドロップ可能なら true, 不正な移動なら false
57
+ */
58
+ export declare function canDropRow(rows: GanttRow[], movingRowIds: string | string[], targetRowId: string, position?: 'top' | 'bottom'): boolean;
package/dist/index.d.ts CHANGED
@@ -6,5 +6,7 @@ export * from './components/gantt-minimap';
6
6
  export * from './core/types';
7
7
  export * from './core/patterns';
8
8
  export * from './core/i18n';
9
- export { clampProgress, calculateRowProgress, calculateWeightedRowProgress, calculateProjectProgress, } from './core/utils';
9
+ export * from './core/plugin';
10
+ export { clampProgress, calculateRowProgress, calculateWeightedRowProgress, calculateProjectProgress, getThemeColors, } from './core/utils';
10
11
  export { computeCriticalPath } from './core/critical-path';
12
+ export { computeRowLevels, computeRowWbsCodes, computeChildRowIds, computeVisibleTreeRows, computeSummaryTask, canDropRow, } from './core/wbs';