From 4ee9c5e05066e37280bd72300c50a657e7570f1f Mon Sep 17 00:00:00 2001 From: mioupa <79833278+mioupa@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:42:07 +0900 Subject: [PATCH 01/16] Design Phase 5e: subplot panels (G9) Co-Authored-By: Claude Opus 5.5 --- docs/PHASE5_DESIGN.md | 182 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 181 insertions(+), 1 deletion(-) diff --git a/docs/PHASE5_DESIGN.md b/docs/PHASE5_DESIGN.md index 9b695ac..380d4df 100644 --- a/docs/PHASE5_DESIGN.md +++ b/docs/PHASE5_DESIGN.md @@ -687,7 +687,7 @@ ax.plot(x_fit, fit(x_fit), color="#FF4B00", linewidth=2.0, linestyle="dashed", l - 生成コードは、`fig, axs = plt.subplots(行, 列, squeeze=False)` の後、パネルごとの節で `ax = axs[0, 1]` と置き直す。系列・注釈・軸・グリッドと凡例は、今の書き方をそのまま使う(第2Y軸もパネルごとに `ax2 = ax.twinx()`)。1×1 のときは、今のコードと1文字も変えない。 - 軸の設定(スケール・範囲・目盛)は全パネル共通。タイトルと軸ラベルは、パネルごとに上書きできる。グラフの種類も全パネル共通。 - (a)(b) のラベルは各パネルの左上に置く(`ax.set_title("(a)", loc="left")`。注釈の数え方を変えないため)。 -- 詳しい設計(系列の無いパネル、色分け散布図のカラーバー、ヒストグラムの区間をパネルで共有するか、など)は、5d のマージ後に相談する。 +- 詳しい設計(系列の無いパネル、色分け散布図のカラーバー、ヒストグラムの区間をパネルで共有するか、など)は、5d のマージ後に相談する。→ §8 に書いた(2026-11-13)。 ### 7.6 性能の見込み @@ -721,3 +721,183 @@ ax.plot(x_fit, fit(x_fit), color="#FF4B00", linewidth=2.0, linestyle="dashed", l 2. **ヒートマップのデータの形**: 案 H2(X・Y・値の3列の縦長の表から格子を作る。推奨)か、案 H1(系列の Y 列を並べて行列にする)か(§7.3)。 3. **箱ひげ図・バイオリン図の見た目**: 箱・胴の塗りは系列の色。ひげは 1.5×IQR。外れ値は表示・平均は非表示が既定。向きは縦だけで、凡例は出さない。これでよいか。 4. **任意の式**: パラメータは `a`〜`e` の5つまで、初期値の既定は 1、表示は「y = 式(a = …, b = …、R² = …)」。開発用の依存に scipy を足す。これでよいか。 + +--- + +## 8. 5e の詳細(G9 サブプロット) + +作成: 2026-11-13。§7.5 の方針を具体化したもの。 + +### 8.0 準備 + +- PR #9(5d)は main にマージ済み(`28617ba`)。最新の main から `phase5e-panels` を作った。 +- スキーマは v4 のまま、項目を足す(§2.1)。新しい項目の既定値(1行×1列)では、生成コードは Phase 4 と1文字も変わらない(ゴールデンテスト)。 +- 今のコードで「軸は1組」を前提にしているところ(調べた結果): + - codegen: 系列・注釈・軸・グリッドと凡例の各節が `ax` / `ax2` を直接書く。`fig.colorbar(..., ax=ax)`、`ax.hist`、`ax.boxplot` なども同じ。節の順は「全系列 → 全注釈 → 軸 → グリッドと凡例」で、棒グラフの `positions` / `x_labels` やヒートマップの `x_cats` は、系列の節で作って軸の節で使う。 + - dataprep: `PlotPlan` の項目(軸の計画、自動の軸ラベル、第2Y軸を使うか、注釈、近似曲線、ヒストグラムの区間、カラーバー)がすべて図に1つ。近似曲線の「図の中」の並び順も図全体で数えている。 + - runner: `figure_summary` は Axes ごとの一覧。カラーバーは、図の最初のカラーバーを一覧の先頭の項目に付けている。 + - 画面: 軸の種類(`xAxisKind` / `yAxisKind`)と第2Y軸の有無(`hasSecondaryAxis`)は図全体で1つ。 +- matplotlib で確かめたこと(CPython): + - 軸を共有したパネル(`sharex=True`)は目盛の設定も共有する。各パネルで `invert_xaxis()` を呼ぶと、反転が2回かかって元に戻る。 + - `sharex=True` は、内側のパネルの目盛の数字を消すが、あとから付けた軸ラベルは消さない。 + - `fig.suptitle` とパネルごとのカラーバー(`fig.colorbar(..., ax=ax)`)は、どちらも `tight_layout` で正しく配置される(警告も出ない)。 +- CPython での実測(10,000 行、線、凡例の位置 best、`tight_layout`、PNG まで、中央値): 1行×1列・5系列 55 ms、2×2 に 5 系列 101 ms、4×4 に 5 系列 124 ms、4×4 の各パネルに1系列(16 系列)326 ms。 + +### 8.1 方針: パネル1つを、今の図1枚と同じ規則で描く + +- 今の図で「系列どうしで共有しているもの」は、パネルの中で共有する。ヒストグラムの区間、色分け散布図の色の範囲とカラーバー、箱ひげ図・バイオリン図の並び、棒グラフの位置、凡例、第2Y軸、近似曲線の「図の中」の並び順が、これに当たる。 + - パネルどうしでは共有しない。たとえばカラーバーはパネルごとに付き、色の範囲もパネルごとに決まる。 + - ヒートマップは「パネルごとに系列1つ」になる。複数のヒートマップを並べられる。 +- 次の設定は、全パネルで共通にする(今の設定をそのまま全パネルに使う)。 + - グラフの種類と、種類ごとの設定。 + - 軸の設定(スケール・範囲・目盛・書式・反転)、枠線、グリッド、凡例の位置。 + - フォント、パレット、カラーマップ、カラーバーのラベル。 + - 図のサイズ、余白。 +- 図全体での検査は今のまま残す(すべての系列が対象)。 + - 棒グラフでは、すべての系列のデータ元が同じであること。 + - 日時の X とそれ以外の X を混ぜないこと。 +- 新しい検査を1つ足す。X・Y の種類(数値・日時・文字列)は全パネルでそろえる。軸の設定が全パネル共通なので、パネルごとに種類が違うと、目盛の間隔の意味(数か「何個おき」か)が決まらないため。 + - エラー: 「パネルによって X の種類(数値・文字列)が違います。X軸の目盛の設定は全パネル共通なので、X列の種類をそろえてください。」(`field` は「X列」。Y も同じ形)。 +- 系列・注釈・近似曲線の番号(系列N・注釈N・近似曲線N)は、今までどおり図全体で数える。エラーの文と `field` も今と同じ。 + +### 8.2 追加する設定項目(v4 に足す) + +| キー | 既定値 | 受け付ける値・検証 | +|---|---|---| +| `plot.layout.rows` / `cols` | `1` / `1` | 1〜4 の整数。常に検証する(「パネルの行数」「パネルの列数」) | +| `plot.layout.shareX` / `shareY` | `false` | X軸・Y軸をパネルで共有するか(真偽)。パネルが2つ以上のときだけ使う(§8.4) | +| `plot.layout.labelStyle` | `"(a)"` | パネルの記号の書式。`(a)` / `a` / `A` / `(A)` / `none`。パネルが2つ以上のときだけ使う | +| `plot.layout.labelBold` | `false` | パネルの記号を太字にするか | +| `plot.panels` | `[]` | `[{title, xLabel, yLabel, y2Label}]`。配列の位置がパネルの位置(左上から右へ、行ごと)。足りない分は空として扱う。16 個まで | +| `series[].panel` | `0` | 系列を描くパネルの位置(0 始まり)。パネルが2つ以上のときだけ検証して使う | +| `annotations[].panel` | `0` | 注釈を置くパネルの位置。同上 | + +- 1行×1列のときは、`plot.layout` の行数・列数以外の新しい項目を検証せず、使わない(値は残す。§2.2)。2×2 → 1×1 → 2×2 と戻しても、系列のパネルの割り当ては残る。 +- パネルが2つ以上のとき、配置にないパネル(2×2 で 5 番目など)を指す系列・注釈は、日本語のエラーにする。例: 「系列3のパネル(パネル5)は今の配置(2行×2列)にありません。パネルを選び直してください。」(`field` は「系列3のパネル」)。画面では、配置を小さくしたときに JS が自動で付け替えるので(§8.6)、手で書いた設定 JSON のときだけ出る。 +- パネルのタイトルと軸ラベルは文字列(`literal()` を通してコードに入る)。数式(mathtext)の誤りは、今のタイトルと同じく「数式」のエラーになる。 +- 近似曲線には項目を足さない。近似する系列のパネルに描く。 + +### 8.3 生成コード + +1行×1列のときは今と1文字も変えない。パネルが2つ以上のとき(例: 2×2、X を共有): + +```python +# ==== 3. 図と軸 ==== +# 2行 × 2列のパネル(axs[行, 列]。左上が axs[0, 0]) +fig, axs = plt.subplots(2, 2, figsize=(8, 6), dpi=100, squeeze=False, sharex=True) # 幅 8 × 高さ 6インチ +fig.suptitle("図のタイトル", fontsize=FONT_SIZE + 2) + +# ==== 4. パネル1 (a)(1行目・1列目) ==== +ax = axs[0, 0] +# --- 系列 --- +# 系列1: …(今と同じ。第2Y軸を使う系列があれば、このパネルで ax2 = ax.twinx()) +# --- 注釈 --- +# --- 軸(ラベル・スケール・範囲・目盛) --- +ax.set_title("(a)", loc="left", fontsize=FONT_SIZE + 2) +ax.set_title("パネルのタイトル", fontsize=FONT_SIZE + 2) +ax.set_ylabel("温度 [1]", fontsize=FONT_SIZE) +# --- グリッドと凡例 --- +ax.legend(loc="best", fontsize=FONT_SIZE, edgecolor="black") + +# ==== 5. パネル2 (b)(1行目・2列目) ==== +ax = axs[0, 1] +… + +# ==== 7. 使わないパネル ==== +axs[1, 1].axis("off") # パネル4: 系列が無い + +# ==== 8. 余白 ==== +fig.tight_layout() + +# ==== 9. 保存と表示 ==== +``` + +- パネルごとの節では、`ax`(と第2Y軸を使うパネルでは `ax2`)を置き直し、その中で今の「系列」「注釈」「軸」「グリッドと凡例」を、そのパネルの分だけ書く。小見出しは `# --- 系列 ---` の形にする(節の番号は振らない)。棒グラフの `positions` やヒートマップの `x_cats` は、同じパネルの節の中で作って使う。変数名はパネルごとに書き直すので、パネルをまたいで使う変数は無い。 +- 系列の無いパネルは描かない(「使わないパネル」の節で `axs[i, j].axis("off")`。記号も付けない)。注釈だけのパネルも描かず、警告を出す(「注釈2: パネル4に系列が無いため、描きません。」)。 +- パネルに系列があっても、どの系列にも描ける点が無いときは、今の「描ける数値データがありません」と同じエラーに「パネルN: 」を付ける。 +- タイトル: + - `plot.title` は図全体の上に出す(`fig.suptitle`。`tight_layout` が場所を空ける)。 + - パネルのタイトル(`plot.panels[i].title`)は、各パネルの上に出す(`ax.set_title`)。 + - パネルの記号は、パネルの左上(タイトルと同じ高さの左端)に出す(`ax.set_title("(a)", loc="left")`)。記号はパネルの位置で決まる(パネル3 は常に (c))。使わないパネルの記号は飛ぶ。 +- 軸ラベル: パネルの欄 → 全体の欄(`axes.x.label` など)→ 自動(そのパネルの系列から、今と同じ規則で決める)の順に、最初に空でないものを使う。 +- 余白: パネルが2つ以上のときは、余白を4辺とも指定していても、先に `fig.tight_layout()` でパネルの間隔を決めてから `fig.subplots_adjust(...)` で外側の余白を指定する。4辺とも指定したときに matplotlib の既定の間隔のままだと、隣のパネルの目盛の数字と重なるため。 +- 冒頭の import と定義(`mdates`、`ticker`、`draw_error_bars`、`poly_text`、`curve_fit`)は、全パネルのどれかで使うときに1回だけ書く。 +- 自動描画用の変種と手順(`Step`)は、今の仕組みのまま使う(行番号は表示中のスクリプトと同じ)。 + +### 8.4 軸の共有(`shareX` / `shareY`) + +- `plt.subplots(..., sharex=True)` / `sharey=True` を使う。範囲・目盛が全パネルでそろい、内側のパネルの目盛の数字が消える。 +- 使えるのは、その軸が数値・対数・日時のときだけ。文字列の X、棒グラフ・積み上げ棒・箱ひげ図・バイオリン図の X、横棒の Y、文字列の列を使うヒートマップの X・Y では、カテゴリの並びがパネルごとに違うので使えない。画面ではチェックを無効にして補足を出し、Python も使わない(隠れた設定。§2.2)。第2Y軸は共有しない。 +- 共有した軸のラベルは、外側のパネルだけに付ける(X は各列の一番下の描くパネル、Y は各行の一番左の描くパネル)。一番下のパネルを使わないときは、その上のパネルに目盛の数字を出し直す(`ax.tick_params(axis="x", labelbottom=True)`)。 +- 軸の反転は、パネルが2つ以上のときは `ax.xaxis.set_inverted(True)` と書く(何度呼んでも同じ結果になる)。1×1 は今の `ax.invert_xaxis()` のまま。 + +### 8.5 dataprep・runner + +- `PlotPlan` に `panels`(`PanelPlan` の配列)と `layout` を足す。`PanelPlan` は、今 `PlotPlan` が図に1つずつ持っている項目(系列・軸の計画・自動の軸ラベル・第2Y軸を使うか・注釈・近似曲線・ヒストグラム・カラーバー・ヒートマップ・棒の位置など)を、パネルの分だけ持つ。1×1 のときは、`PlotPlan` の今の項目がそのままパネル1になる(codegen の 1×1 の経路は変えない)。 +- 手順: + 1. 図全体の処理と検査(データ元の解決、`skipRows`、Y 列の自動割り当て、計算した列、棒グラフのデータ元、日時の混在)。 + 2. パネルごとに、今の種類ごとの計画(`_plan_xy` など)を、そのパネルの系列・注釈・近似曲線だけで作る。 + 3. X・Y の種類が全パネルでそろっているかを確かめる。 +- 近似曲線の「図の中」の並び順は、パネルごとに数え直す(どのパネルでも左上から並ぶ)。 +- 主目盛の本数の検査(100 本まで)は、パネルごとのデータの範囲で行う。 +- `figure_summary`(Axes ごとの一覧)に項目を足す。既存の項目の意味は変えない。 + - `panel`: その Axes のパネルの位置 `[行, 列]`。 + - `axison`: 軸を表示しているか。使わないパネルは `false`。 + - `titleleft`: 左のタイトル(パネルの記号)。 + - `suptitle`: 図のタイトル。一覧の先頭の項目にだけ付ける。 + - `colorbar` は、カラーバーを付けた Axes の項目に出す(今は図の最初のカラーバーを先頭に付けている)。1×1 では今と同じ結果になる。 + +### 8.6 画面 + +- 「系列」区分の「グラフの種類」の下に「パネルの配置」を置く。 + - 行数 `#layoutRows`、列数 `#layoutCols`(1〜4 のセレクト)。 + - パネルが2つ以上のときだけ、次を出す: X軸を共有 `#layoutShareX`、Y軸を共有 `#layoutShareY`(使えないときは無効にし、補足 `#layoutShareHelp`)、記号 `#panelLabelStyle`、太字 `#panelLabelBold`。 +- 系列カードに、パネルの選択 `series--panel` を足す(パネルが2つ以上のときだけ表示)。選択肢は「パネル1(1行目・1列目)」の形。 + - 新しい系列は、一覧の最後の系列と同じパネルに入れる。複製は同じパネルに入れる。 +- 注釈カードに、パネルの選択 `annotation--panel` を足す(同上)。新しい注釈はパネル1。 +- 「軸・目盛」区分の軸ラベルの下に、折りたたみ「パネルごとのタイトル・軸ラベル」`#panelLabelsGroup` を置く(パネルが2つ以上のときだけ表示)。 + - 入力欄はパネルごとに `panel--title` / `-xlabel` / `-ylabel` / `-y2label`。N は 1 始まり。第2Y軸の欄は、そのパネルに第2Y軸の系列があるときだけ出す。 + - 空欄の placeholder に、代わりに使う値を出す(全体の欄の値、または「自動」)。 + - パネルが2つ以上のときは、`#title` の下に「パネルが2つ以上のときは、図全体の上に出します」と補足する。 +- 配置を小さくしたとき(2×2 → 2×1 など。1×1 にしたときは除く)は、無くなったパネルにあった系列・注釈を最後のパネルに移し、注意を添える(`addNote`。「系列3: パネル4が無くなったため、パネル2に移しました。」)。 +- 新しい JS: `js/ui/panels.js`(配置の欄の出し分け、パネルごとの入力欄、付け替え)。`state.js` に `updatePanel(index, patch)`(通知の `kind` は `panel-field`)。共有できる軸の判定は `js/chart-types.js` に足す(Python と同じ規則)。どの変更も今の「通常の変更」の経路で 250 ms 後に再描画する。 + +### 8.7 性能の見込みと計測 + +- パネルを分けると、凡例の位置の探索が軸ごとに小さくなる。一方で、軸の数だけ目盛と `tight_layout` の処理が増える(§8.0 の実測で、2×2 は 1×1 より +46 ms)。10,000 行 × 5 系列なら、1 秒以内に収まる見込み。 +- 計測(`--only p5e`): + - 2×2 に 10,000 行 × 5 系列(線。1つのパネルに第2Y軸、1つに「図の中」の近似曲線)の設定変更 → 再描画。要件の確認に使う。 + - 4×4 の各パネルに1系列(10,000 行 × 16 系列、X を共有)の設定変更 → 再描画。上限の参考値。 + - 2×2 の色分け散布図(パネルごとのカラーバー)の設定変更 → 再描画。 + +### 8.8 テスト + +- 単体: + - `test_panels.py`(新規): + - 設定: 既定値、1×1 で隠れた項目を検証しないこと、範囲外のパネルのエラー。 + - 計画: パネルごとの計画、X・Y の種類がそろわないときのエラー、ヒートマップはパネルごとに1系列、注釈だけのパネルの警告、近似曲線の並び順がパネルごとであること、描ける点の無いパネルのエラー。 + - 生成コードを実行して確かめること: Axes の数と位置、系列が選んだパネルに描かれること、第2Y軸はそのパネルだけにあること、凡例・カラーバー・ヒストグラムの区間・箱の並びがパネルごとであること、使わないパネルを消すこと、記号の書式と太字、図のタイトル、軸ラベルの優先順。 + - 共有: 反転が1回だけ効くこと、外側のパネルだけにラベルが付くこと、一番下のパネルを使わないときの目盛の数字。 + - 4辺を指定した余白。 + - 「全体を実行した図」と「自動描画用の図」の要約の一致。 + - コード注入(パネルのタイトル・軸ラベル)。 + - 既存の単体テスト: 1×1 の生成コードはゴールデンテストで変わらないことを確かめる。`test_defaults_parity.py`(新しい既定値)、`test_runner.py`(`figure_summary` の新しい項目と、1×1 で既存の項目が変わらないこと)、`test_js_modules.py`(付け替えと新しい系列のパネル)。 +- E2E(`test_panels.py` を新規): + - 配置の欄と、系列・注釈カードのパネルの選択の出し分け。 + - 系列をパネルに振り分けたときの `data-summary`。 + - パネルごとのタイトル・軸ラベル。 + - 配置を小さくしたときの付け替えと注意。 + - 共有の欄がカテゴリの軸で無効になること。 + - 種類がそろわないときのエラーと復帰。 + - 編集モードで配置を変えても、図もコードも変わらないこと。 + - 狭い画面で横スクロールが出ないこと。 +- 一致確認(`test_codegen_consistency.py`)に4つ足す: 2×2 の線(第2Y軸・注釈・「図の中」の近似曲線・使わないパネル)、X を共有した日時の線(反転あり)、色分け散布図のパネルごとのカラーバー、箱ひげ図の 1×2。比べる要約に `panel` / `axison` / `titleleft` / `suptitle` を加える。 + +### 8.9 確認したいこと + +1. **方針(§8.1)**: パネル1つを今の図1枚と同じ規則で描く。ヒストグラムの区間、色の範囲とカラーバー、凡例、第2Y軸はパネルごとになる。これでよいか。 + - 代わりの案: 図全体で共有する。たとえばヒートマップの色の範囲をそろえて比べられる。ただし、カラーバーの置き方と `tight_layout` の扱いが難しくなる。 +2. **軸の共有(§8.4)**: X・Y の共有を入れるか。推奨は「入れる」(既定は共有しない。カテゴリの軸では使えない)。 +3. **パネルの記号(§8.3)**: 書式の選択肢(`(a)` / `a` / `A` / `(A)` / なし)、太字の切り替え、置き場所(パネルの左上の上)、既定 `(a)`。記号はパネルの位置で決め、使わないパネルの分は飛ぶ。これでよいか。 +4. **タイトルと軸ラベル(§8.3)**: 図のタイトルは図全体の上に出す。パネルのタイトルは各パネルの上に出す。軸ラベルは「パネルの欄 → 全体の欄 → 自動」の順で決める。これでよいか。 +5. **使わないパネルと種類の検査(§8.1・§8.3)**: 系列の無いパネルは枠ごと消す。X・Y の種類(数値・日時・文字列)がパネルによって違うときはエラーにする。配置は 4×4 まで。これでよいか。 From 87d63c48360b359027b52203524759efc9166743 Mon Sep 17 00:00:00 2001 From: mioupa <79833278+mioupa@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:43:21 +0900 Subject: [PATCH 02/16] Record the Phase 5e (subplot panels) decisions Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 1 + docs/PHASE5_DESIGN.md | 2 +- docs/REQUIREMENTS.md | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index 0238520..e19d372 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -442,3 +442,4 @@ uv run pytest tests/e2e # E2E(Chromium とローカルの静的サー - 5c(2026-11-12): ヒストグラムの複数系列は区間ごとに横に並べる(区間は全系列で共通)。計算した列の式から、ほかの計算した列は参照できない(読み直しで列の数が変わると式の列番号を直せないため。複数の処理は1つの式に書く)。計算した列は「描画から除外する先頭行」を除いた行で計算し(集計もその行だけ)、データ確認タブには出さない。色分け散布図は、凡例の点を灰色にし、第2Y軸は使えず、色の範囲は全系列共通で自動(指定なし)。重さは普通の散布図と同じ見た目で作って計測し、1 秒を超えたら見直す。→ 計測で約 1.21 秒になったため、点の縁を描かず、縁の太さ(1.5 pt)の分だけ点の面積を大きくすることにした(約 0.94 秒。点の形が x / + のときは縁を描く。2026-11-12 にユーザーが決定)。 - 5d・5e(2026-11-12): 5d を2本に分ける(5d: G8・G10、5e: G9。G9 は軸が1組という前提を全体で変え、G8 の種類もパネルに載せるため後にする。5e の詳しい設計は 5d のマージ後に相談)。ヒートマップは X・Y・値の3列から格子を作る(同じ組は平均、系列は1つ)。箱ひげ図・バイオリン図は系列ごとに左から並べ、塗りは系列の色、ひげは 1.5×IQR、外れ値は表示・平均は非表示が既定、縦向きだけ、凡例なし。任意関数のフィッティングは変数 `x` とパラメータ `a`〜`e`、初期値の既定 1、表示は「y = 式(a = …、R² = …)」。dev の依存に scipy を足す。 - 5d の実装での決定(2026-11-12): バイオリン図の中央値・平均の線は黒にした(系列の色では、塗りつぶした胴(既定の不透明度 1)の上で見えないため。箱ひげ図の中央値の線と同じ。端の線は系列の色)。ヒートマップは系列が2つ以上のとき、系列ごとの検証(値の列が未選択など)より先に「ヒートマップは系列1つで描きます。系列を1つにしてください。」を返す(先に値の列のエラーが出ると、系列を足した直後に利用者が混乱するため)。任意の式の近似曲線は、`curve_fit` が収束しても、初期値のところで式が有限でない値になると初期値のまま黙って返すことがあるので、生成コードで当てはめた曲線の値が有限か確かめ、有限でなければ ValueError にする(手順で「式を当てはめられませんでした」に置き換わる)。 +- 5e(2026-11-13): G9(サブプロット)は、パネル1つを今の図1枚と同じ規則で描く(区間・色の範囲とカラーバー・凡例・第2Y軸・近似曲線の並び順はパネルごと。ヒートマップはパネルごとに系列1つ)。グラフの種類と軸の設定は全パネル共通で、X・Y の種類は全パネルでそろえる。行数・列数は 1〜4。X軸・Y軸の共有(数値・対数・日時の軸だけ)、パネルの記号((a)・a・A・(A)・なし、太字の切替。位置で決まり、使わないパネルの分は飛ぶ)、図のタイトルは図全体の上、軸ラベルは「パネルの欄 → 全体の欄 → 自動」。系列の無いパネルは枠ごと消す。詳しくは docs/PHASE5_DESIGN.md §8。 diff --git a/docs/PHASE5_DESIGN.md b/docs/PHASE5_DESIGN.md index 380d4df..913ab2e 100644 --- a/docs/PHASE5_DESIGN.md +++ b/docs/PHASE5_DESIGN.md @@ -726,7 +726,7 @@ ax.plot(x_fit, fit(x_fit), color="#FF4B00", linewidth=2.0, linestyle="dashed", l ## 8. 5e の詳細(G9 サブプロット) -作成: 2026-11-13。§7.5 の方針を具体化したもの。 +作成: 2026-11-13。§7.5 の方針を具体化したもの。2026-11-13 にユーザーが承認(§8.9 はすべて提案どおり)。 ### 8.0 準備 diff --git a/docs/REQUIREMENTS.md b/docs/REQUIREMENTS.md index 36d43cf..a3c2e4e 100644 --- a/docs/REQUIREMENTS.md +++ b/docs/REQUIREMENTS.md @@ -96,6 +96,14 @@ - ヒートマップは、X・Y・値の3列(縦長の表)から格子を作る(色分け散布図と同じ3列)。同じ X・Y の組は平均を描き、値の無いマスは塗らない。系列は1つだけ。 - 箱ひげ図・バイオリン図は、系列ごとに1つずつ左から並べる。箱・胴の塗りは系列の色、ひげは箱の端から 1.5×IQR まで、外れ値は表示・平均は非表示が既定。向きは縦だけで、凡例は出さない(名前は目盛に出す)。 - 任意関数のフィッティングの式は、変数 `x` とパラメータ `a`〜`e`(5つまで)で書く。初期値の既定は 1。表示は「y = 式(a = …, b = …、R² = …)」。開発用の依存(単体テスト用)に scipy を足す(ブラウザと同じ版。実行時は U5 のとおり使うときだけ読み込む)。 +- 5e(G9 サブプロット、2026-11-13): + - パネルは、行数・列数(それぞれ 1〜4)で並べる。系列と注釈は、描くパネルを選ぶ。近似曲線は、近似する系列のパネルに描く。1行×1列のときは今と同じ図・同じ生成コードにする。 + - パネル1つを、今の図1枚と同じ規則で描く。ヒストグラムの区間、色分け散布図・ヒートマップの色の範囲とカラーバー、凡例、第2Y軸、近似曲線の「図の中」の並び順は、パネルごとに決める(パネルどうしでは共有しない)。ヒートマップは、パネルごとに系列1つ。 + - グラフの種類、軸の設定(スケール・範囲・目盛・書式・反転)、枠線、グリッド、凡例の位置、フォント、カラーマップは全パネル共通。X・Y の種類(数値・日時・文字列)は全パネルでそろえる(違えば日本語のエラー)。 + - X軸・Y軸をパネルで共有できる(既定は共有しない)。共有できるのは、数値・対数・日時の軸だけ(カテゴリの軸では使えない)。共有した軸のラベルは、外側のパネルだけに付ける。 + - パネルの記号は、書式((a)・a・A・(A)・なし)と太字を選べる(既定は (a)、太字なし)。パネルの左上(タイトルと同じ高さの左端)に出す。記号はパネルの位置で決め、使わないパネルの分は飛ぶ。 + - 図のタイトルは図全体の上に出し、パネルごとのタイトルは各パネルの上に出す。軸ラベルは「パネルの欄 → 全体の欄 → 自動(そのパネルの系列から)」の順に決める。 + - 系列の無いパネルは、枠ごと消す(注釈だけのパネルも描かず、警告する)。 --- From 0e0b514854f020e241ee198f91b59392d0fb9a28 Mon Sep 17 00:00:00 2001 From: mioupa <79833278+mioupa@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:44:26 +0900 Subject: [PATCH 03/16] Add Phase 5e setting defaults (layout, panels, series/annotation panel) Co-Authored-By: Claude Opus 5.5 --- js/defaults.js | 5 +++++ py/mplgui/settings.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/js/defaults.js b/js/defaults.js index c2c7f49..526ec6e 100644 --- a/js/defaults.js +++ b/js/defaults.js @@ -40,6 +40,7 @@ export const DEFAULT_SERIES = { alpha: 1, fill: { lower: "", upper: "", alpha: 0.25 }, colorColumn: "", + panel: 0, // Phase 5e: 描くパネルの位置(0 始まり。パネルが2つ以上のときだけ使う) }; // 注釈(annotations[])1つの既定値。id は追加するときに a1, a2, ... を振る(削除しても再利用しない) @@ -59,6 +60,7 @@ export const DEFAULT_ANNOTATION = { alpha: null, fontSize: null, label: "", + panel: 0, // Phase 5e: 置くパネルの位置(0 始まり) }; // 近似曲線(fits[])1つの既定値。id は f1, f2, ...。series は追加するときに系列1の id にする @@ -98,6 +100,9 @@ export const DEFAULT_SETTINGS = { colorbarLabel: "", box: { fliers: true, means: false }, violin: { medians: true, means: false }, + // Phase 5e: パネルの配置(1行×1列は今と同じ図)と、パネルごとのタイトル・軸ラベル(配列の位置 = パネルの位置) + layout: { rows: 1, cols: 1, shareX: false, shareY: false, labelStyle: "(a)", labelBold: false }, + panels: [], }, axes: { x: { label: "", scale: "linear", min: null, max: null, dateFormat: "", ...defaultTicks(), majorStepUnit: "day", dateMin: "", dateMax: "" }, diff --git a/py/mplgui/settings.py b/py/mplgui/settings.py index c5972bf..40e2d94 100644 --- a/py/mplgui/settings.py +++ b/py/mplgui/settings.py @@ -112,6 +112,7 @@ "alpha": None, "fontSize": None, "label": "", + "panel": 0, } _DEFAULT_COMPUTED = {"id": "", "source": "", "name": "", "expr": ""} _DEFAULT_FIT = { @@ -135,6 +136,7 @@ "alpha": 1, "fill": copy.deepcopy(_DEFAULT_FILL), "colorColumn": "", + "panel": 0, } @@ -186,6 +188,8 @@ def default_settings() -> dict: "colorbarLabel": "", "box": {"fliers": True, "means": False}, "violin": {"medians": True, "means": False}, + "layout": {"rows": 1, "cols": 1, "shareX": False, "shareY": False, "labelStyle": "(a)", "labelBold": False}, + "panels": [], }, "axes": { "x": { From 0cb70634ad81f3673cab8599ae5be2b0cda8d117 Mon Sep 17 00:00:00 2001 From: mioupa <79833278+mioupa@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:50:17 +0900 Subject: [PATCH 04/16] Add Phase 5e panel UI: layout, per-series/annotation panel, per-panel labels Co-Authored-By: Claude Opus 5.5 --- css/style.css | 16 ++++ index.html | 49 ++++++++++ js/chart-types.js | 16 ++++ js/main.js | 3 + js/state.js | 21 +++++ js/ui/annotations.js | 7 ++ js/ui/forms.js | 4 + js/ui/panels.js | 162 ++++++++++++++++++++++++++++++++++ js/ui/series.js | 5 ++ tests/unit/test_js_modules.py | 66 ++++++++++++++ 10 files changed, 349 insertions(+) create mode 100644 js/ui/panels.js diff --git a/css/style.css b/css/style.css index da1b26f..b3db806 100644 --- a/css/style.css +++ b/css/style.css @@ -1258,3 +1258,19 @@ button.series-color-chip.active { flex: 1 1 64px; min-width: 64px; } + +/* Phase 5e: パネル */ +#panelLabelsGroup > summary { + cursor: pointer; + font-weight: 600; +} +.panel-label-row { + margin-top: 10px; + padding-top: 8px; + border-top: 1px solid #ddd; +} +.panel-label-row input { + width: 100%; + min-width: 0; + box-sizing: border-box; +} diff --git a/index.html b/index.html index a9bd4f9..f050afb 100644 --- a/index.html +++ b/index.html @@ -209,6 +209,49 @@

Matplotlib GUI

+
+
+
+ + +
+
+ + +
+
+
行×列が2以上のとき、系列と注釈ごとに描くパネルを選べます。
+ +
+
@@ -241,6 +284,7 @@

Matplotlib GUI

+
@@ -259,6 +303,11 @@

Matplotlib GUI

+ +
タイトル・軸ラベル・凡例名では、$ で囲んだ部分が数式になります。例: m$^2$(上付き)、H$_2$O(下付き)、$\alpha$(ギリシャ文字)。$ を文字として書くときは \$ とします。 書き方の詳細(matplotlib) diff --git a/js/chart-types.js b/js/chart-types.js index 402c8ee..69b1abd 100644 --- a/js/chart-types.js +++ b/js/chart-types.js @@ -37,3 +37,19 @@ export const isHeatmap = (type) => type === "heatmap"; export const usesColor = (type) => type !== "heatmap"; export const usesLineWidth = (type) => type !== "heatmap"; export const usesLineStyle = (type) => type !== "heatmap" && !BOX_TYPES.includes(type); + +// ---- Phase 5e: サブプロットのパネル(純粋な関数。DOM にも state にも触れない) ---- +export const panelCount = (layout) => Math.max(1, (Number(layout && layout.rows) || 1) * (Number(layout && layout.cols) || 1)); + +// パネルの位置 panel(0 始まり)を、パネルが n 個に減ったときの位置にする(範囲外は最後のパネル)。n が 1 以下なら変えない +export const remapPanelIndex = (panel, n) => (n > 1 && Number(panel) >= n ? n - 1 : panel); + +// 系列・注釈のパネルの付け替え計画。{series: [{id, index, from, to}], annotations: [...]}(index は一覧の位置、0 始まり) +export const planPanelRemap = (series, annotations, n) => { + const plan = (items) => + items.flatMap((item, index) => { + const to = remapPanelIndex(item.panel, n); + return to === item.panel ? [] : [{ id: item.id, index, from: item.panel, to }]; + }); + return { series: plan(series), annotations: plan(annotations) }; +}; diff --git a/js/main.js b/js/main.js index 91a1fef..35afae2 100644 --- a/js/main.js +++ b/js/main.js @@ -15,6 +15,7 @@ import { addVisibilityHook, bindSeriesEvents, refreshSources, renderSeriesList, import { bindAnnotations, renderAnnotationList, syncAnnotations } from "./ui/annotations.js"; import { bindComputed, renderComputedList, syncComputed } from "./ui/computed.js"; import { bindFits, renderFitList, syncFits } from "./ui/fits.js"; +import { bindPanels, syncPanels } from "./ui/panels.js"; import { bindStyleSection } from "./ui/styleSection.js"; import { initPanelSections } from "./ui/panelSections.js"; import { bindTabs } from "./ui/tabs.js"; @@ -42,9 +43,11 @@ bindSeriesEvents(); addVisibilityHook(syncAnnotations); addVisibilityHook(syncFits); addVisibilityHook(syncComputed); +addVisibilityHook(syncPanels); bindComputed(); bindAnnotations(); bindFits(); +bindPanels(); bindSaveFormatEvents(); bindLoadSection(); bindDropPaste(); diff --git a/js/state.js b/js/state.js index 2ba50e2..0c4afa3 100644 --- a/js/state.js +++ b/js/state.js @@ -96,6 +96,9 @@ export const addSeries = (overrides = {}) => { ...overrides, id: `s${seriesCounter}`, }; + // Phase 5e: 新しい系列は、一覧の最後の系列と同じパネルに置く + const last = settings.series[settings.series.length - 1]; + if (last && !("panel" in overrides)) series.panel = last.panel ?? 0; settings.series.push(series); notify({ kind: "series-list", origin: "user" }); return series; @@ -194,6 +197,24 @@ export const removeFit = (id) => { notify({ kind: "fit-list", origin: "user" }); }; +// ---- パネル(Phase 5e)。plot.panels[index] = {title, xLabel, yLabel, y2Label}。足りない要素は空文字として補う ---- +const emptyPanel = () => ({ title: "", xLabel: "", yLabel: "", y2Label: "" }); + +export const updatePanel = (index, patch, origin = "user") => { + if (!Number.isInteger(index) || index < 0) return; + const panels = settings.plot.panels; + while (panels.length <= index) panels.push(emptyPanel()); + const item = panels[index]; + let changed = false; + for (const [key, value] of Object.entries(patch)) { + if (item[key] !== value) { + item[key] = value; + changed = true; + } + } + if (changed) notify({ kind: "panel-field", index, fields: Object.keys(patch), origin }); +}; + // ---- 計算した列(G6)。id は c1, c2, ...(削除しても再利用しない) ---- export const MAX_COMPUTED = 20; let computedCounter = 0; diff --git a/js/ui/annotations.js b/js/ui/annotations.js index 2055bb2..b6c411a 100644 --- a/js/ui/annotations.js +++ b/js/ui/annotations.js @@ -4,6 +4,7 @@ import { addAnnotation, getSettings, hasSecondaryAxis, removeAnnotation, updateA import { bindSeriesColorControls, colorPickerHtml } from "./colorPicker.js"; import { readNumber } from "./forms.js"; import { xAxisKind, yAxisKind } from "./series.js"; +import { syncPanelSelects } from "./panels.js"; const esc = (text) => String(text ?? "").replace(/&/g, "&").replace(//g, ">").replace(/"/g, """); @@ -31,6 +32,7 @@ const FIELD_KEYS = { alpha: ["alpha", "number"], "font-size": ["fontSize", "number"], label: ["label", "text"], + panel: ["panel", "number"], }; const X_EXAMPLE = { @@ -85,6 +87,10 @@ const cardHtml = (a, index) => {
+
@@ -204,6 +210,7 @@ export const syncAnnotations = () => { const a = annotations.find((x) => x.id === item.dataset.annId); if (a) syncCard(item, a, xKind, yKind, hasY2); } + syncPanelSelects(); }; export const renderAnnotationList = () => { diff --git a/js/ui/forms.js b/js/ui/forms.js index 8df985d..c5f1cb1 100644 --- a/js/ui/forms.js +++ b/js/ui/forms.js @@ -18,6 +18,10 @@ export const FIELDS = [ ["boxMeans", "plot.box.means", "checkbox"], ["violinMedians", "plot.violin.medians", "checkbox"], ["violinMeans", "plot.violin.means", "checkbox"], + ["layoutShareX", "plot.layout.shareX", "checkbox"], + ["layoutShareY", "plot.layout.shareY", "checkbox"], + ["panelLabelStyle", "plot.layout.labelStyle", "select"], + ["panelLabelBold", "plot.layout.labelBold", "checkbox"], ["colorMap", "plot.colormap", "select"], ["colorbarLabel", "plot.colorbarLabel", "text"], ["skipRows", "plot.skipRows", "number"], diff --git a/js/ui/panels.js b/js/ui/panels.js new file mode 100644 index 0000000..84fecc6 --- /dev/null +++ b/js/ui/panels.js @@ -0,0 +1,162 @@ +// サブプロットのパネル(Phase 5e, G9): 配置(行・列)、系列・注釈のパネルの選択、パネルごとのタイトル・軸ラベル。 +// 表示の同期(syncPanels)は入力中の欄を作り直さない(computed.js の syncComputed と同じ考え方)。 +import { getSettings, setPath, updateAnnotation, updatePanel, updateSeries } from "../state.js"; +import { addNote } from "../bridge.js"; +import { panelCount, planPanelRemap, usesY2 } from "../chart-types.js"; +import { xAxisKind, yAxisKind } from "./series.js"; + +const esc = (text) => + String(text ?? "").replace(/&/g, "&").replace(//g, ">").replace(/"/g, """); + +// 画面の表示は 1 始まり: 「パネル1(1行目・1列目)」 +export const panelName = (index, cols) => `パネル${index + 1}(${Math.floor(index / cols) + 1}行目・${(index % cols) + 1}列目)`; + +const layoutKey = (layout) => `${layout.rows}x${layout.cols}`; + +// 系列・注釈カードのパネルの選択(.series-panel / .annotation-panel)の選択肢と値、表示の有無を合わせる +export const syncPanelSelects = () => { + const { plot, series, annotations } = getSettings(); + const n = panelCount(plot.layout); + const key = layoutKey(plot.layout); + const sync = (select, panel) => { + const wrap = select.closest(".series-panel-wrap, .ann-panel-wrap"); + if (wrap) wrap.hidden = n < 2; + if (select.dataset.layout !== key) { + select.replaceChildren( + ...Array.from({ length: n }, (_, i) => { + const o = document.createElement("option"); + o.value = String(i); + o.textContent = panelName(i, plot.layout.cols); + return o; + }), + ); + select.dataset.layout = key; + } + if (document.activeElement !== select) select.value = String(panel ?? 0); + }; + for (const item of document.querySelectorAll("#seriesList .series-item")) { + const s = series.find((x) => x.id === item.dataset.seriesId); + const select = item.querySelector(".series-panel"); + if (s && select) sync(select, s.panel); + } + for (const item of document.querySelectorAll("#annotationList .annotation-item")) { + const a = annotations.find((x) => x.id === item.dataset.annId); + const select = item.querySelector(".annotation-panel"); + if (a && select) sync(select, a.panel); + } +}; + +const rowHtml = (i, cols, hasY2) => { + const id = (name) => `panel-${i + 1}-${name}`; + return ` +
+
${esc(panelName(i, cols))}
+
+ + +
+
+
+ + +
+
+ + +
+
+ ${ + hasY2 + ? `
` + : "" + } +
`; +}; + +const syncPanelLabels = (multi) => { + const { plot, axes, series } = getSettings(); + const group = document.getElementById("panelLabelsGroup"); + if (!group) return; + group.hidden = !multi; + if (!multi) return; + const n = panelCount(plot.layout); + const y2 = Array.from({ length: n }, (_, i) => usesY2(plot.type) && series.some((s) => s.secondaryAxis && (s.panel ?? 0) === i)); + const key = `${layoutKey(plot.layout)}|${y2.map(Number).join("")}`; + const list = document.getElementById("panelLabelsList"); + if (list.dataset.key !== key) { + list.innerHTML = Array.from({ length: n }, (_, i) => rowHtml(i, plot.layout.cols, y2[i])).join(""); + list.dataset.key = key; + } + const holders = { title: "なし", xLabel: axes.x.label || "自動", yLabel: axes.y.label || "自動", y2Label: axes.y2.label || "自動" }; + for (const input of list.querySelectorAll("[data-panel-field]")) { + const i = Number(input.closest(".panel-label-row").dataset.panelIndex); + const field = input.dataset.panelField; + input.placeholder = holders[field]; + if (document.activeElement !== input) input.value = (plot.panels[i] && plot.panels[i][field]) || ""; + } +}; + +export const syncPanels = () => { + const { plot } = getSettings(); + const multi = panelCount(plot.layout) > 1; + for (const [id, value] of [["layoutRows", plot.layout.rows], ["layoutCols", plot.layout.cols]]) { + const el = document.getElementById(id); + if (el && document.activeElement !== el) el.value = String(value); + } + const hide = (id, hidden) => { + const el = document.getElementById(id); + if (el) el.hidden = hidden; + }; + hide("layoutOptionsGroup", !multi); + hide("titlePanelHelp", !multi); + // カテゴリの軸は共有できない(値は残す) + const catX = xAxisKind() === "category"; + const catY = yAxisKind() === "category"; + const shareX = document.getElementById("layoutShareX"); + const shareY = document.getElementById("layoutShareY"); + if (shareX) shareX.disabled = catX; + if (shareY) shareY.disabled = catY; + hide("layoutShareHelp", !(multi && (catX || catY))); + const help = document.getElementById("layoutShareHelp"); + if (help) help.textContent = `${[catX ? "X" : "", catY ? "Y" : ""].filter(Boolean).join("・")}軸はカテゴリなので共有できません(設定は残ります)。`; + syncPanelLabels(multi); + syncPanelSelects(); +}; + +// パネルが減ったとき、範囲外のパネルを最後のパネルへ移し、画面の注意を添える(n が 1 のときは何も変えない) +export const applyPanelRemap = () => { + const { plot, series, annotations } = getSettings(); + const n = panelCount(plot.layout); + if (n < 2) return; + const plan = planPanelRemap(series, annotations, n); + for (const m of plan.series) { + updateSeries(m.id, { panel: m.to }, "reconcile"); + addNote(`系列${m.index + 1}: パネル${m.from + 1}が無くなったため、パネル${m.to + 1}に移しました。`); + } + for (const m of plan.annotations) { + updateAnnotation(m.id, { panel: m.to }, "reconcile"); + addNote(`注釈${m.index + 1}: パネル${m.from + 1}が無くなったため、パネル${m.to + 1}に移しました。`); + } +}; + +export const bindPanels = () => { + for (const [id, key] of [["layoutRows", "rows"], ["layoutCols", "cols"]]) { + const el = document.getElementById(id); + if (!el) continue; + el.addEventListener("change", () => { + setPath(`plot.layout.${key}`, Number(el.value)); + applyPanelRemap(); + }); + } + const list = document.getElementById("panelLabelsList"); + if (list) { + const onInput = (event) => { + const target = event.target; + if (!target || !target.dataset || !target.dataset.panelField) return; + updatePanel(Number(target.closest(".panel-label-row").dataset.panelIndex), { [target.dataset.panelField]: target.value }); + }; + list.addEventListener("input", onInput); + list.addEventListener("change", onInput); + } + syncPanels(); +}; diff --git a/js/ui/series.js b/js/ui/series.js index 9790e01..a66d670 100644 --- a/js/ui/series.js +++ b/js/ui/series.js @@ -282,6 +282,10 @@ const cardHtml = (series, plotType) => {
+