Skip to content

Commit

Permalink
デフォルト色を工数集計対象から削除/グラフ作成機能を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
tsukuboshi committed Mar 11, 2024
1 parent 6dd5be4 commit 618934e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export CALENDER_ID_ARRAY="['xxxxxxxx','xxxxxxxx','xxxxxxxx']"
6. 環境変数として、Google Calenderの予定の色に対応したラベル名を指定(使用しない色については空文字を設定してください)

```bash
export DEFAULT_LABEL=""
export LAVENDER_LABEL=""
export SAGE_LABEL=""
export GRAPE_LABEL=""
Expand All @@ -110,7 +109,6 @@ function handler(): void {
main(
${CALENDER_ID_ARRAY},
{
デフォルト: '${DEFAULT_LABEL}',
ラベンダー: '${LAVENDER_LABEL}',
セージ: '${SAGE_LABEL}',
ブドウ: '${GRAPE_LABEL}',
Expand Down
32 changes: 31 additions & 1 deletion src/example-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ function calculateWorkHoursByColor(
status = 'ETC';
}
// ステータスがOWNER, YES, ETCの予定のみを対象とする
if (status === 'OWNER' || status === 'YES' || status === 'ETC') {
if (status === 'OWNER' || status === 'YES') {
// イベントの情報を取得
const eventContent = getEventContent(event);
let color = eventContent.color;
Expand Down Expand Up @@ -285,6 +285,9 @@ function writeWorkHoursToSheet(
colorMap: { [key: string]: string },
LabelMap: { [key: string]: string }
): void {
// デフォルトカラーの色番号('0')の工数をMapから削除する
workHoursMap.delete('0');

// ヘッダー行を考慮して2行目から開始
let row = 2;

Expand All @@ -301,6 +304,33 @@ function writeWorkHoursToSheet(
sheet.getRange('J' + row).setValue(hours);
row++;
});

// ラベル名一覧と工数合計が記載されている範囲を指定
const dataRange = sheet.getRange('I2:J' + (row - 1));

// シートから既存のチャートを取得
const charts = sheet.getCharts();

// 既存のチャートがあれば更新、なければ新しく作成
if (charts.length > 0) {
// 既存のチャートを更新
const chart = charts[0]; // ここでは最初のチャートを更新対象とします
const updatedChart = chart
.modify()
.addRange(dataRange) // データ範囲を更新
.setPosition(1, 12, 0, 0) // 必要に応じて位置を調整
.build();
sheet.updateChart(updatedChart);
} else {
// 新しいチャートを作成
const newChart = sheet
.newChart()
.setChartType(Charts.ChartType.BAR) // 帯グラフ(棒グラフ)を指定
.addRange(dataRange)
.setPosition(1, 12, 0, 0) // チャートをシート上のL列(12列目)の1行目に設定
.build();
sheet.insertChart(newChart);
}
}

// 現在の年と月を取得する関数
Expand Down

0 comments on commit 618934e

Please sign in to comment.