Skip to content

Phase 5c: 計算した列とグラフの種類(段・横棒・積み上げ棒・ヒストグラム・色分け散布図) - #8

Merged
mioupa merged 10 commits into
mainfrom
phase5c-data
Nov 12, 2026
Merged

mioupa merged 10 commits into
mainfrom
phase5c-data

Conversation

@mioupa

@mioupa mioupa commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

要件定義書9章の Phase 5 のうち、5c(G6 式で新しい列を作る「計算した列」、G7 グラフの種類 第1弾)を実装しました。Phase 5 の4本のうち3本目です。

#7(5b を main に入れる PR)の上に積んで作り、#7 のマージ後に向き先を main に替えました。差分は 5c の分だけです。

変更内容

グラフの種類(G7)

  • 「グラフの種類」に5つ足した(既存の選択肢の表示は変えていない)。
    • step(段グラフ): 段の付き方(前・中央・後)を選べる。点の形・帯・エラーバー・第2Y軸・近似曲線は line と同じように使える(帯も段に合わせて塗る)。
    • barh(横棒): 縦軸がカテゴリ。軸の設定は画面の軸のまま(X軸 = 横軸 = 値、Y軸 = 縦軸 = カテゴリ)で、自動の軸ラベルだけ入れ替える。縦軸の目盛は「何個おき」、注釈の Y は「何番目のカテゴリか」(0 始まり)。Y 方向のエラーバーは横向きに描く。
    • bar(積み上げ): 正の値は上へ、負の値は下へ積む。欠けた値は 0 として積む。
    • hist(ヒストグラム): 区間の数(空欄 = 自動)と確率密度を選べる。複数系列は、全系列で共通の区間に横に並べる。X列は使わない。自動の区間が 1,000 個を超えるときは、区間の数を指定するよう日本語のエラーで案内する。
    • scatter(色分け): 系列ごとに色分けの列を選ぶ。カラーマップ(8種)とカラーバーのラベルを選べる。色の範囲は全系列で共通。凡例の点は灰色。
  • 種類ごとに使わない設定は、画面で隠し、図に使わない(値は残る)。規則は js/chart-types.js と settings.py の定数(BAR_LIKE_TYPES / NO_Y2_TYPES / NO_Y_ERROR_TYPES)に持ち、両方を揃えている。
  • 棒グラフ・横棒・積み上げ・ヒストグラムでは、系列カードの「点サイズ」の欄も隠すようにした(今まで棒グラフで出ていたが、図には使っていなかった)。近似曲線の補足は「棒グラフ・ヒストグラムでは近似曲線を使えません。」に改めた。

計算した列(G6)

  • 「注釈・解析」の区分に「計算した列」を足した(20 個まで)。名前と式で新しい列を作る(例: [1] / max([1])、B - first(B)、rolling_mean([2], 5)。正規化・オフセット・移動平均の雛形ボタンあり)。
  • 式で使えるもの: 列([N] か Excel の列記号 A = [0])、+ - * /、**(^ も)、括弧、要素ごとの関数(abs sqrt exp log log10 sin cos tan)、集計(min max mean median std first last)、系列の処理(rolling_mean / diff / cumsum)。
  • 式は新しいモジュール py/mplgui/expr.py が自前で解釈する(eval / exec / compile / ast を使わない)。誤りは「5文字目: …」のように位置付きの日本語のエラーにする。
  • 作った列は、そのデータ元のファイルの列の後ろの番号(ファイルの列が 5 個なら [5])として、系列の X・Y・エラーバー・帯・色分けの列に選べる。データ確認タブには出さない。
  • 生成コードには、計算した列があるときだけ「計算した列」の節が入る。式は、解釈した結果から決まった形の pandas / numpy のコードで書く。利用者が書いた式の文字列は、comment_text() を通してコメントにだけ入る。
  • 計算は「描画から除外する先頭行」を除いた行で行う(集計もその行だけ)。数値にできない値と、0 での割り算などで計算できなかった値は警告にする。
  • 計算した列の削除・データ元の変更、読み直しによるファイルの列数の変化、ファイルの削除では、列を参照している設定の番号を付け替える。使えなくなった参照は空に戻し、警告で知らせる。

そのほか

  • 設定スキーマは v4 のまま、項目を足した。既定の設定で生成するコードは、Phase 4 と1文字も変わらない。
  • 新しい Python モジュール py/mplgui/expr.py を pyscript.toml の [files] に足した。CDN と CI の変更は無い。
  • figure_summary に drawstyles / bars / colorbar を足した(既存のキーの値は変えていない)。

計測値(docs/PERFORMANCE.md「Phase 5c 後」)

項目(ms、中央値) Phase 5b 後 Phase 5c 後 比較
初回ファイル読込 → 最初のプロット 186 187 同等
設定変更 → プロット更新(デバウンス込み) 476 470 同等
保存(PNG、300 dpi) 417 414 同等
編集モードでの実行 598 599 同等
帯・近似曲線・注釈を付けた設定変更 → プロット更新 718 707 同等
色分け散布図(系列5本)の設定変更 → プロット更新 – 941 –
ヒストグラム(系列5本)の設定変更 → プロット更新 – 416 –
計算した列(正規化5つ)を Y にした line の設定変更 → プロット更新 – 482 –
  • 10,000 行 × 5 系列で設定変更から 1 秒以内という要件は、新しい種類でも満たしている。
  • 色分け散布図は、最初の形(点の縁あり)では 1,209 ms で 1 秒を超えた。点ごとに色が違うと、matplotlib が縁を1点ずつ描くため。オーナーと相談し、縁を描かず、縁の太さ(1.5 pt)の分だけ点を大きくする形にした(941 ms)。点の形が x / + のときは、線だけの点なので縁を描く。
  • 1回通しの計測で、コールド起動・ウォーム起動・120 dpi の保存が 5% を超えて遅く見えた。5b のコードと続けて測り直すと差は無く(例: コールド起動 3,733 → 3,742 ms)、ネットワークとマシンの状態によるぶれだった。

オーナーが決めたこと(2026-11-12。AGENTS.md §13.4、要件定義書 §2.5 に記録)

  • ヒストグラムの複数系列は、区間ごとに横に並べる(区間は全系列で共通)。
  • 計算した列の式から、ほかの計算した列は参照できない(読み直しで列の数が変わると、式の中の列番号を直せないため。複数の処理は1つの式に書く)。
  • 計算した列は「描画から除外する先頭行」を除いた行で計算し、データ確認タブには出さない。
  • 色分け散布図は、凡例の点を灰色にし、第2Y軸は使えず、色の範囲は全系列で共通の自動。
  • 色分け散布図の点は縁を描かず、縁の太さの分だけ大きくする(上記)。

テスト

  • 単体テスト: 1208 passed(uv run pytest)
  • E2E: 232 passed(uv run pytest tests/e2e、18 分 19 秒)
  • 既定の設定で生成するコードが Phase 4 と1文字も変わらないことを、ゴールデンテスト(test_codegen_compat.py)で確認した
  • 生成コードの一致確認に7ケースを追加した: step、横棒とエラーバー、積み上げ棒、ヒストグラム、色分け散布図、計算した列(1ファイル・2ファイル)
  • 式の解釈: evaluate の値と、to_code で書いた式を実行した値の一致、優先順位、上限(200 文字・入れ子 30)、有限でない定数の拒否
  • コード注入のテストを追加した(計算した列の名前と式、色分けの列名、カラーバーのラベル)
  • 新しい欄を狭い画面(375 px)で表示し、横スクロールが出ないことを E2E で確認した

注意点

  • 実フォントを jsDelivr から取得する E2E があり、インターネット接続が必要。E2E の全体は、ローカルで約 18 分、CI では 30 分を超える(時間制限は 60 分)。
  • Safari と Firefox の実機では確かめていない(自動テストは Chromium のみ)。

🤖 Generated with Claude Code

mioupa and others added 10 commits November 12, 2026 08:38
…ecisions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A hand-written tokenizer and recursive-descent parser (no eval, exec or
ast). evaluate() and to_code() share one semantics; constant subtrees are
folded so the generated code never does Python-float-only arithmetic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ettings and generated code (Phase 5c, G7)

Hidden settings for each type are neither validated nor used. Default
settings still generate byte-identical code (golden tests).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hase 5c, G6)

Each source's computed columns are appended after its file columns, after
skipRows, and are written as a 「計算した列」 section only when present.
Auto-render injects a copy of a source that gets computed columns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lumn to the UI (Phase 5c, G7)

js/chart-types.js holds the per-type rules shared by every show/hide
decision (same rules as settings.py). barh treats the vertical axis as the
category axis in ticks and annotations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…5c, G6)

Computed columns appear in every per-source column select as 「名前 [k](計算)」.
js/computed-refs.js re-points column references when a computed column is
deleted, changes source, or the file's column count changes on reload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ile; word the source-change note

When a reload removes file columns, references to them were shifted into
the computed-column range and kept silently. Move them out of range so
reconcileColumns resets them (with the band note).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… width

Per-point colours make matplotlib stroke every edge separately; the
10,000 x 5 redraw took 1.21 s in the browser. Without edges and with the
area grown by the 1.5 pt edge (same apparent size) it takes 0.94 s.
x / + markers are line-only, so they keep their edges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mputed columns

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ADME

Also record the decision to draw colour-mapped scatter points without
edges (REQUIREMENTS §2.5, AGENTS §13.4, design §6.6).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mioupa
mioupa deleted the branch phase5b-annotations November 12, 2026 05:53
@mioupa mioupa closed this Nov 12, 2026
@mioupa mioupa reopened this Nov 12, 2026
@mioupa
mioupa changed the base branch from phase5b-annotations to main November 12, 2026 05:53
@mioupa
mioupa merged commit 60c20cb into main Nov 12, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant