@funnest/charts-ui 0.11.38 → 0.11.39

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.
@@ -1,4 +1,6 @@
1
1
  import type { WidgetContext } from '../context.js';
2
+ /** Any CSS color (incl. var(--x) already resolved by the browser) → #rrggbb for <input type=color>. */
3
+ export declare function toHex(color: string): string;
2
4
  /**
3
5
  * Chart settings ("차트 설정"), in tabs, with a live demo chart beside them (above them on a
4
6
  * phone) drawn with the settings as they are now. Changes apply to the chart immediately, like
@@ -0,0 +1,14 @@
1
+ import type { ComponentChildren, JSX } from 'preact';
2
+ import type { WidgetContext } from '../context.js';
3
+ /**
4
+ * 거래량 설정, from the volume pane's ⚙: its moving averages (a period and a color each, up to
5
+ * VOLUME_MA_MAX) and the bars' colors. Changes show on the chart at once; 취소 puts back what was.
6
+ */
7
+ export declare function VolumeSettings({ ctx, Dialog }: {
8
+ ctx: WidgetContext;
9
+ Dialog: (p: {
10
+ title: string;
11
+ onClose: () => void;
12
+ children: ComponentChildren;
13
+ }) => JSX.Element;
14
+ }): JSX.Element;
package/dist/context.d.ts CHANGED
@@ -39,6 +39,8 @@ export interface UiState {
39
39
  id: string;
40
40
  } | {
41
41
  kind: 'chartSettings';
42
+ } | {
43
+ kind: 'volumeSettings';
42
44
  } | {
43
45
  kind: 'goToDate';
44
46
  } | null;
package/dist/i18n.d.ts CHANGED
@@ -223,6 +223,10 @@ export declare const STRINGS: {
223
223
  moveIndicatorDown: string;
224
224
  textEditHint: string;
225
225
  hideVolume: string;
226
+ volumeSettings: string;
227
+ volumeMa: string;
228
+ volumeMaNone: string;
229
+ addVolumeMa: string;
226
230
  volumeDesc: string;
227
231
  apply: string;
228
232
  cancel: string;
@@ -594,6 +598,10 @@ export declare const STRINGS: {
594
598
  moveIndicatorDown: string;
595
599
  textEditHint: string;
596
600
  hideVolume: string;
601
+ volumeSettings: string;
602
+ volumeMa: string;
603
+ volumeMaNone: string;
604
+ addVolumeMa: string;
597
605
  volumeDesc: string;
598
606
  apply: string;
599
607
  cancel: string;
package/dist/index.js CHANGED
@@ -658,6 +658,10 @@ var STRINGS = {
658
658
  moveIndicatorDown: "\uC544\uB798\uB85C \uC62E\uAE30\uAE30",
659
659
  textEditHint: "Enter\uB85C \uC800\uC7A5 \xB7 Shift+Enter \uC904\uBC14\uAFC8 \xB7 Esc \uCDE8\uC18C",
660
660
  hideVolume: "\uAC70\uB798\uB7C9 \uC228\uAE30\uAE30",
661
+ volumeSettings: "\uAC70\uB798\uB7C9 \uC124\uC815",
662
+ volumeMa: "\uC774\uB3D9\uD3C9\uADE0\uC120",
663
+ volumeMaNone: "\uAC70\uB798\uB7C9 \uB9C9\uB300 \uC704\uC5D0 \uD3C9\uADE0 \uAC70\uB798\uB7C9 \uC120\uC744 \uADF8\uB824\uC694.",
664
+ addVolumeMa: "\uC774\uB3D9\uD3C9\uADE0\uC120 \uCD94\uAC00",
661
665
  volumeDesc: "\uBD09\uB9C8\uB2E4 \uAC70\uB798\uB41C \uC591 (\uAC00\uACA9 \uC544\uB798 \uC601\uC5ED)",
662
666
  apply: "\uC801\uC6A9",
663
667
  cancel: "\uCDE8\uC18C",
@@ -1031,6 +1035,10 @@ var STRINGS = {
1031
1035
  moveIndicatorDown: "Move down",
1032
1036
  textEditHint: "Enter to save \xB7 Shift+Enter for a new line \xB7 Esc to cancel",
1033
1037
  hideVolume: "Hide volume",
1038
+ volumeSettings: "Volume settings",
1039
+ volumeMa: "Moving average",
1040
+ volumeMaNone: "Draws the average volume as a line over the volume bars.",
1041
+ addVolumeMa: "Add moving average",
1034
1042
  volumeDesc: "How much traded in each bar (pane under the price)",
1035
1043
  apply: "Apply",
1036
1044
  cancel: "Cancel",
@@ -3729,6 +3737,8 @@ var CSS = (
3729
3737
  border-radius: 6px;
3730
3738
  }
3731
3739
  .fnc-ind-title { color: var(--fnc-text-2); }
3740
+ .fnc-volume-ma { color: var(--fnc-text-2); white-space: nowrap; }
3741
+ .fnc-volume-ma b { font-weight: 600; }
3732
3742
  .fnc-ind-hidden .fnc-ind-title { opacity: 0.5; text-decoration: line-through; }
3733
3743
  .fnc-ind-eye { margin-left: -4px; }
3734
3744
  .fnc-ind-hidden .fnc-ind-eye { color: var(--fnc-text-2); opacity: 0.7; }
@@ -5618,6 +5628,10 @@ function SettingsDialog({ ctx }) {
5618
5628
  CANDLE_COLORS.map(colorRow),
5619
5629
  /* @__PURE__ */ a3("div", { class: "fnc-section", children: t3.settingVolume }),
5620
5630
  VOLUME_COLORS.map(colorRow),
5631
+ /* @__PURE__ */ a3("div", { class: "fnc-row fnc-toggle-row", children: [
5632
+ /* @__PURE__ */ a3("span", { class: "fnc-toggle-label", children: t3.volumeMa }),
5633
+ /* @__PURE__ */ a3("button", { type: "button", class: "fnc-action fnc-app-link", onClick: () => ctx.store.set({ dialog: { kind: "volumeSettings" } }), children: settings.volumeMa.length ? settings.volumeMa.map((m3) => `MA${m3.period}`).join(" \xB7 ") : t3.addVolumeMa })
5634
+ ] }),
5621
5635
  /* @__PURE__ */ a3("div", { class: "fnc-section", children: t3.settingsGrid }),
5622
5636
  toggles(GRID)
5623
5637
  ] }),
@@ -5885,6 +5899,91 @@ function useSplitCount(ctx) {
5885
5899
  return m3 ? paneCount(LAYOUTS[m3.layout]) : 0;
5886
5900
  }
5887
5901
 
5902
+ // src/components/volume-settings.tsx
5903
+ import { VOLUME_MA_COLORS, VOLUME_MA_MAX, VOLUME_MA_PERIOD_MAX } from "@funnest/charts";
5904
+ var NEXT_PERIODS = [20, 5, 10, 60, 120];
5905
+ var hex62 = (c3) => /^#[0-9a-f]{6}/i.test(c3) ? c3.slice(0, 7) : toHex(c3);
5906
+ function VolumeSettings({ ctx, Dialog: Dialog2 }) {
5907
+ const t3 = stringsOf(ctx.store.get());
5908
+ const [before] = d2(() => {
5909
+ const s3 = ctx.chart.settings;
5910
+ return { volumeMa: s3.volumeMa, volumeUpColor: s3.volumeUpColor, volumeDownColor: s3.volumeDownColor };
5911
+ });
5912
+ const [settings, setSettings] = d2(ctx.chart.settings);
5913
+ A2(() => ctx.chart.on("settingsChange", setSettings), [ctx.chart]);
5914
+ const [typed, setTyped] = d2(() => settings.volumeMa.map((m3) => String(m3.period)));
5915
+ const lines = settings.volumeMa;
5916
+ const palette = ctx.chart.paletteInUse;
5917
+ const close = () => ctx.store.set({ dialog: null });
5918
+ const cancel = () => (ctx.chart.setSettings(before), close());
5919
+ const setLines = (next) => ctx.chart.setSettings({ volumeMa: next });
5920
+ const colorOf = (m3, i3) => m3.color ?? VOLUME_MA_COLORS[i3 % VOLUME_MA_COLORS.length];
5921
+ const add = () => {
5922
+ const used = new Set(lines.map((m3) => m3.period));
5923
+ const period = NEXT_PERIODS.find((p3) => !used.has(p3)) ?? Math.min(VOLUME_MA_PERIOD_MAX, (lines[lines.length - 1]?.period ?? 10) * 2);
5924
+ setLines([...lines, { period, color: null }]);
5925
+ setTyped([...typed.slice(0, lines.length), String(period)]);
5926
+ };
5927
+ const remove = (i3) => {
5928
+ setLines(lines.filter((_3, j2) => j2 !== i3));
5929
+ setTyped(typed.filter((_3, j2) => j2 !== i3));
5930
+ };
5931
+ const setPeriod = (i3, text) => {
5932
+ const digits = text.replace(/\D/g, "").slice(0, 3);
5933
+ setTyped(typed.map((x2, j2) => j2 === i3 ? digits : x2));
5934
+ const period = Number(digits);
5935
+ if (period >= 1) setLines(lines.map((m3, j2) => j2 === i3 ? { ...m3, period: Math.min(VOLUME_MA_PERIOD_MAX, period) } : m3));
5936
+ };
5937
+ return /* @__PURE__ */ a3(Dialog2, { title: t3.volumeSettings, onClose: cancel, children: /* @__PURE__ */ a3("form", { class: "fnc-form", onSubmit: (e3) => (e3.preventDefault(), close()), children: [
5938
+ /* @__PURE__ */ a3("div", { class: "fnc-section", children: t3.volumeMa }),
5939
+ /* @__PURE__ */ a3("div", { class: "fnc-rows", children: [
5940
+ lines.length === 0 && /* @__PURE__ */ a3("p", { class: "fnc-hint", children: t3.volumeMaNone }),
5941
+ lines.map((m3, i3) => /* @__PURE__ */ a3("div", { class: "fnc-row", children: [
5942
+ /* @__PURE__ */ a3("span", { class: "fnc-row-label", children: t3.period }),
5943
+ /* @__PURE__ */ a3(
5944
+ "input",
5945
+ {
5946
+ class: "fnc-input fnc-input-period",
5947
+ inputMode: "numeric",
5948
+ value: typed[i3] ?? String(m3.period),
5949
+ "aria-label": `${t3.volumeMa} ${i3 + 1} ${t3.period}`,
5950
+ onInput: (e3) => setPeriod(i3, e3.currentTarget.value),
5951
+ onBlur: () => setTyped(typed.map((x2, j2) => j2 === i3 ? String(lines[i3].period) : x2))
5952
+ }
5953
+ ),
5954
+ /* @__PURE__ */ a3(
5955
+ ColorPicker,
5956
+ {
5957
+ class: "fnc-color fnc-color-btn",
5958
+ style: { background: hex62(colorOf(m3, i3)) },
5959
+ value: hex62(colorOf(m3, i3)),
5960
+ label: `${t3.volumeMa} ${i3 + 1} ${t3.color}`,
5961
+ t: t3,
5962
+ onPick: (color) => setLines(lines.map((x2, j2) => j2 === i3 ? { ...x2, color } : x2))
5963
+ }
5964
+ ),
5965
+ /* @__PURE__ */ a3("button", { type: "button", class: "fnc-ind-btn", "aria-label": `${t3.volumeMa} ${i3 + 1} ${t3.removePeriod}`, "data-tip": t3.removePeriod, onClick: () => remove(i3), children: /* @__PURE__ */ a3(SmallCloseIcon, {}) })
5966
+ ] })),
5967
+ lines.length < VOLUME_MA_MAX && /* @__PURE__ */ a3("button", { type: "button", class: "fnc-add-row", onClick: add, children: [
5968
+ "+ ",
5969
+ t3.addVolumeMa
5970
+ ] })
5971
+ ] }),
5972
+ /* @__PURE__ */ a3("div", { class: "fnc-section", children: t3.color }),
5973
+ [
5974
+ ["volumeUpColor", t3.settingVolumeUp, palette.volumeUp],
5975
+ ["volumeDownColor", t3.settingVolumeDown, palette.volumeDown]
5976
+ ].map(([key, label, shown]) => /* @__PURE__ */ a3("div", { class: "fnc-row", children: [
5977
+ /* @__PURE__ */ a3("span", { class: "fnc-row-label fnc-row-label-wide", children: label }),
5978
+ /* @__PURE__ */ a3(ColorPicker, { class: "fnc-color fnc-color-btn", style: { background: hex62(shown) }, value: hex62(shown), label, t: t3, onPick: (c3) => ctx.chart.setSettings({ [key]: c3 }) })
5979
+ ] })),
5980
+ /* @__PURE__ */ a3("div", { class: "fnc-form-actions", children: [
5981
+ /* @__PURE__ */ a3("button", { type: "button", class: "fnc-action", onClick: cancel, children: t3.cancel }),
5982
+ /* @__PURE__ */ a3("button", { type: "submit", class: "fnc-action fnc-action-primary", children: t3.ok })
5983
+ ] })
5984
+ ] }) });
5985
+ }
5986
+
5888
5987
  // src/components/indicator-dialogs.tsx
5889
5988
  function Dialog({ title, onClose, children, wide }) {
5890
5989
  const ref = T2(null);
@@ -5998,6 +6097,7 @@ function Dialogs({ ctx }) {
5998
6097
  if (dialog?.kind === "indicators") return dialog.on ? /* @__PURE__ */ a3(IndicatorOnPicker, { ctx, on: dialog.on }) : /* @__PURE__ */ a3(IndicatorPicker, { ctx });
5999
6098
  if (dialog?.kind === "indicatorSettings") return /* @__PURE__ */ a3(IndicatorSettings, { ctx, id: dialog.id, Dialog }, dialog.id);
6000
6099
  if (dialog?.kind === "chartSettings") return /* @__PURE__ */ a3(SettingsDialog, { ctx });
6100
+ if (dialog?.kind === "volumeSettings") return /* @__PURE__ */ a3(VolumeSettings, { ctx, Dialog });
6001
6101
  if (dialog?.kind === "goToDate") return /* @__PURE__ */ a3(GoToDateDialog, { ctx });
6002
6102
  return null;
6003
6103
  }
@@ -7138,11 +7238,17 @@ function AppItem({ ctx, item }) {
7138
7238
  ] })
7139
7239
  ] });
7140
7240
  }
7141
- function VolumeItem({ ctx, value }) {
7241
+ function VolumeItem({ ctx, value, averages, locale }) {
7142
7242
  const t3 = stringsOf(ctx.store.get());
7143
7243
  return /* @__PURE__ */ a3("div", { class: "fnc-ind fnc-volume-item", children: [
7144
7244
  /* @__PURE__ */ a3("span", { class: "fnc-ind-title", children: t3.settingVolume }),
7145
7245
  value !== null && /* @__PURE__ */ a3("b", { class: "fnc-flat", children: value }),
7246
+ averages.map((a4) => /* @__PURE__ */ a3("span", { class: "fnc-volume-ma", children: [
7247
+ "MA",
7248
+ a4.period,
7249
+ " ",
7250
+ /* @__PURE__ */ a3("b", { style: { color: a4.color }, children: a4.value === null ? "\u2014" : formatCompact(a4.value, locale) })
7251
+ ] })),
7146
7252
  /* @__PURE__ */ a3("span", { class: "fnc-ind-actions", children: [
7147
7253
  ctx.chart.canMoveIndicator("volume", -1) && /* @__PURE__ */ a3("button", { class: "fnc-ind-btn", "data-tip": t3.moveIndicatorUp, "aria-label": `${t3.settingVolume} ${t3.moveIndicatorUp}`, onClick: () => ctx.chart.moveIndicator("volume", -1), children: /* @__PURE__ */ a3(ChevronUpIcon, {}) }),
7148
7254
  ctx.chart.canMoveIndicator("volume", 1) && /* @__PURE__ */ a3("button", { class: "fnc-ind-btn", "data-tip": t3.moveIndicatorDown, "aria-label": `${t3.settingVolume} ${t3.moveIndicatorDown}`, onClick: () => ctx.chart.moveIndicator("volume", 1), children: /* @__PURE__ */ a3(ChevronDownIcon, {}) }),
@@ -7150,9 +7256,9 @@ function VolumeItem({ ctx, value }) {
7150
7256
  "button",
7151
7257
  {
7152
7258
  class: "fnc-ind-btn",
7153
- "data-tip": t3.chartSettings,
7154
- "aria-label": `${t3.settingVolume} ${t3.chartSettings}`,
7155
- onClick: () => ctx.store.set({ dialog: { kind: "chartSettings" } }),
7259
+ "data-tip": t3.volumeSettings,
7260
+ "aria-label": t3.volumeSettings,
7261
+ onClick: () => ctx.store.set({ dialog: { kind: "volumeSettings" } }),
7156
7262
  children: /* @__PURE__ */ a3(GearIcon, {})
7157
7263
  }
7158
7264
  ),
@@ -7289,7 +7395,7 @@ function Legend({ ctx }) {
7289
7395
  !collapsed && s3.legendItems.map((item) => /* @__PURE__ */ a3(AppItem, { ctx, item })),
7290
7396
  overlayItems.length + s3.legendItems.length > 0 && (collapsed ? /* @__PURE__ */ a3("button", { class: "fnc-ind-handle", "aria-expanded": "false", "aria-label": t3.expand, "data-tip": t3.expand, onClick: () => setCollapsed(false), children: /* @__PURE__ */ a3("span", {}) }) : /* @__PURE__ */ a3("button", { class: "fnc-ind-collapse", "aria-expanded": "true", "aria-label": t3.collapse, "data-tip": t3.collapse, onClick: () => setCollapsed(true), children: /* @__PURE__ */ a3(ChevronUpIcon, {}) }))
7291
7397
  ] }),
7292
- volumePane && /* @__PURE__ */ a3("div", { class: "fnc-legend fnc-pane-legend", style: { top: `${volumePane.top + 4}px` }, children: /* @__PURE__ */ a3(VolumeItem, { ctx, value: bar?.volume !== void 0 ? formatCompact(bar.volume, s3.locale) : null }) }),
7398
+ volumePane && /* @__PURE__ */ a3("div", { class: "fnc-legend fnc-pane-legend", style: { top: `${volumePane.top + 4}px` }, children: /* @__PURE__ */ a3(VolumeItem, { ctx, value: bar?.volume !== void 0 ? formatCompact(bar.volume, s3.locale) : null, averages: ctx.chart.volumeAverages(hover?.index), locale: s3.locale }) }),
7293
7399
  paneLegends.map(
7294
7400
  ({ pane, item, kids }) => item && /* @__PURE__ */ a3("div", { class: tracking.current ? "fnc-legend fnc-pane-legend is-tracking" : "fnc-legend fnc-pane-legend", style: { top: `${pane.top + 4}px` }, children: [
7295
7401
  /* @__PURE__ */ a3(IndicatorItem, { ctx, item, values: showValues }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnest/charts-ui",
3
- "version": "0.11.38",
3
+ "version": "0.11.39",
4
4
  "description": "Pro trading UI (toolbar, drawing tools, sheets) for Funnest Charts. Framework-agnostic.",
5
5
  "keywords": [
6
6
  "chart",
@@ -42,7 +42,7 @@
42
42
  "NOTICE"
43
43
  ],
44
44
  "dependencies": {
45
- "@funnest/charts": "0.11.38"
45
+ "@funnest/charts": "0.11.39"
46
46
  },
47
47
  "devDependencies": {
48
48
  "preact": "^11.2.0"