@leviosa-ai/detail-page-editor 0.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.
- package/components/cardnews/color-input.tsx +380 -0
- package/components/detail-page/ai-generate-panel.tsx +763 -0
- package/components/detail-page/annotation-canvas.tsx +860 -0
- package/components/detail-page/annotation-dialog.tsx +397 -0
- package/components/detail-page/bubble-tail-overlay.tsx +209 -0
- package/components/detail-page/canvas-context-menu.tsx +234 -0
- package/components/detail-page/canvas-observer.tsx +68 -0
- package/components/detail-page/canvas-overlay-host.tsx +44 -0
- package/components/detail-page/canvas-store-facade.ts +51 -0
- package/components/detail-page/chart-inspector.tsx +531 -0
- package/components/detail-page/design-reference-picker.tsx +383 -0
- package/components/detail-page/detail-page-basic-shapes.tsx +180 -0
- package/components/detail-page/detail-page-brand-gifs-panel.tsx +261 -0
- package/components/detail-page/detail-page-brand-kit-panel.tsx +77 -0
- package/components/detail-page/detail-page-brand-panel-header.tsx +44 -0
- package/components/detail-page/detail-page-charts-panel.tsx +104 -0
- package/components/detail-page/detail-page-decorations-panel.tsx +125 -0
- package/components/detail-page/detail-page-download-dialog.tsx +524 -0
- package/components/detail-page/detail-page-editor.tsx +974 -0
- package/components/detail-page/detail-page-elements-panel.tsx +117 -0
- package/components/detail-page/detail-page-font-picker.tsx +231 -0
- package/components/detail-page/detail-page-history-buttons.tsx +87 -0
- package/components/detail-page/detail-page-host-context.tsx +465 -0
- package/components/detail-page/detail-page-icons-panel.tsx +251 -0
- package/components/detail-page/detail-page-konva-json-preview.tsx +474 -0
- package/components/detail-page/detail-page-layers-panel.tsx +618 -0
- package/components/detail-page/detail-page-my-images-panel.tsx +179 -0
- package/components/detail-page/detail-page-my-shapes-panel.tsx +174 -0
- package/components/detail-page/detail-page-page-toolbar.tsx +171 -0
- package/components/detail-page/detail-page-pages-panel.tsx +299 -0
- package/components/detail-page/detail-page-pages-timeline.tsx +79 -0
- package/components/detail-page/detail-page-photos-panel.tsx +257 -0
- package/components/detail-page/detail-page-properties-panel.tsx +2680 -0
- package/components/detail-page/detail-page-qr-panel.tsx +137 -0
- package/components/detail-page/detail-page-references-panel.tsx +166 -0
- package/components/detail-page/detail-page-selection.ts +44 -0
- package/components/detail-page/detail-page-shapes-panel.tsx +16 -0
- package/components/detail-page/detail-page-sidebar-sections.tsx +324 -0
- package/components/detail-page/detail-page-tables-panel.tsx +106 -0
- package/components/detail-page/detail-page-text-panel.tsx +179 -0
- package/components/detail-page/detail-page-thumbnail-bus.ts +42 -0
- package/components/detail-page/edit-quota-ui.tsx +150 -0
- package/components/detail-page/editor-history.ts +56 -0
- package/components/detail-page/editor-hotkeys.tsx +165 -0
- package/components/detail-page/element-recents-strip.tsx +105 -0
- package/components/detail-page/element-rects.ts +82 -0
- package/components/detail-page/fill-control.tsx +261 -0
- package/components/detail-page/find-replace-panel.tsx +252 -0
- package/components/detail-page/generation-progress-fill.tsx +57 -0
- package/components/detail-page/gif-animator.tsx +184 -0
- package/components/detail-page/gif-effect-picker.tsx +136 -0
- package/components/detail-page/group-drill-in.tsx +219 -0
- package/components/detail-page/group-prompt-edit-panel.tsx +154 -0
- package/components/detail-page/hover-highlight-overlay.tsx +111 -0
- package/components/detail-page/hovered-layer.ts +34 -0
- package/components/detail-page/inspector-controls.tsx +175 -0
- package/components/detail-page/leviosa-canvas-workspace.tsx +313 -0
- package/components/detail-page/nested-selection-overlay.tsx +364 -0
- package/components/detail-page/panel-search-input.tsx +49 -0
- package/components/detail-page/prompt-edit-panel.tsx +146 -0
- package/components/detail-page/section-height-handle.tsx +276 -0
- package/components/detail-page/section-reauthor-controller.tsx +210 -0
- package/components/detail-page/spec-prompt-edit-panel.tsx +178 -0
- package/components/detail-page/spec-resize-absorber.tsx +149 -0
- package/components/detail-page/svg-prompt-edit-panel.tsx +139 -0
- package/components/detail-page/table-canvas-overlay.tsx +707 -0
- package/components/detail-page/table-inspector.tsx +586 -0
- package/components/ui/button.tsx +64 -0
- package/components/ui/command.tsx +175 -0
- package/components/ui/dialog.tsx +167 -0
- package/components/ui/label.tsx +24 -0
- package/components/ui/select.tsx +190 -0
- package/components/ui/slider.tsx +63 -0
- package/components/ui/switch.tsx +35 -0
- package/components/ui/tooltip.tsx +57 -0
- package/config/detail-page-bundle-font-tags.json +39 -0
- package/config/detail-page-fonts.json +373 -0
- package/index.ts +24 -0
- package/lib/cardnews/font-loader.ts +306 -0
- package/lib/detail-page/animation-sniff.ts +101 -0
- package/lib/detail-page/asset-bytes-url.ts +70 -0
- package/lib/detail-page/basic-shapes.ts +603 -0
- package/lib/detail-page/canvas-menu.ts +182 -0
- package/lib/detail-page/chart/defaults.ts +283 -0
- package/lib/detail-page/chart/format.ts +66 -0
- package/lib/detail-page/chart/normalize.ts +149 -0
- package/lib/detail-page/chart/palette.ts +85 -0
- package/lib/detail-page/chart/paste.ts +82 -0
- package/lib/detail-page/chart/preview.ts +78 -0
- package/lib/detail-page/chart/render.ts +188 -0
- package/lib/detail-page/chart/renderers/bar-h.ts +103 -0
- package/lib/detail-page/chart/renderers/bar-v.ts +213 -0
- package/lib/detail-page/chart/renderers/donut.ts +186 -0
- package/lib/detail-page/chart/renderers/gauge.ts +96 -0
- package/lib/detail-page/chart/renderers/line.ts +143 -0
- package/lib/detail-page/chart/renderers/shared.ts +263 -0
- package/lib/detail-page/chart/renderers/stack.ts +121 -0
- package/lib/detail-page/chart/sync.ts +92 -0
- package/lib/detail-page/chart/types.ts +145 -0
- package/lib/detail-page/css-color.ts +34 -0
- package/lib/detail-page/data-gif-payload.ts +167 -0
- package/lib/detail-page/design-reference.ts +244 -0
- package/lib/detail-page/distribute.ts +89 -0
- package/lib/detail-page/editor-routes.ts +10 -0
- package/lib/detail-page/element-recents.ts +167 -0
- package/lib/detail-page/find-replace.ts +120 -0
- package/lib/detail-page/format-painter.ts +159 -0
- package/lib/detail-page/gif-frames.ts +216 -0
- package/lib/detail-page/gif-timeline.ts +65 -0
- package/lib/detail-page/group-action.ts +62 -0
- package/lib/detail-page/hangul-roman.ts +58 -0
- package/lib/detail-page/icon-curated.ts +290 -0
- package/lib/detail-page/icon-fuzzy.ts +250 -0
- package/lib/detail-page/icon-keywords.generated.ts +3766 -0
- package/lib/detail-page/icon-keywords.ko.ts +524 -0
- package/lib/detail-page/icon-search.ts +257 -0
- package/lib/detail-page/icons.ts +67 -0
- package/lib/detail-page/image-credit.ts +121 -0
- package/lib/detail-page/image-data-uri.ts +29 -0
- package/lib/detail-page/insert-image.ts +75 -0
- package/lib/detail-page/insert-shape.ts +49 -0
- package/lib/detail-page/korean-dictionary.ts +187 -0
- package/lib/detail-page/layer-move.ts +257 -0
- package/lib/detail-page/new-product-draft-store.ts +105 -0
- package/lib/detail-page/new-product-draft.ts +283 -0
- package/lib/detail-page/personal-images-refresh.ts +30 -0
- package/lib/detail-page/product-source.ts +587 -0
- package/lib/detail-page/qr-code.ts +214 -0
- package/lib/detail-page/reference-image.ts +103 -0
- package/lib/detail-page/reference-upload.ts +181 -0
- package/lib/detail-page/replace-page.ts +35 -0
- package/lib/detail-page/replace-with-gif.ts +251 -0
- package/lib/detail-page/section-height.ts +131 -0
- package/lib/detail-page/section-reauthor-bus.ts +61 -0
- package/lib/detail-page/shape-to-image.ts +219 -0
- package/lib/detail-page/spec-group/clipboard.ts +35 -0
- package/lib/detail-page/spec-group/sync.ts +377 -0
- package/lib/detail-page/spec-group/text-metrics.ts +48 -0
- package/lib/detail-page/stock-photos.ts +88 -0
- package/lib/detail-page/svg-colors.ts +74 -0
- package/lib/detail-page/table/defaults.ts +344 -0
- package/lib/detail-page/table/edit.ts +312 -0
- package/lib/detail-page/table/harvest.ts +103 -0
- package/lib/detail-page/table/normalize.ts +125 -0
- package/lib/detail-page/table/paste.ts +49 -0
- package/lib/detail-page/table/preview.ts +66 -0
- package/lib/detail-page/table/render.ts +388 -0
- package/lib/detail-page/table/sync.ts +107 -0
- package/lib/detail-page/table/types.ts +102 -0
- package/lib/detail-page/text-gif-layout.ts +245 -0
- package/lib/detail-page/text-gif-payload.ts +67 -0
- package/lib/detail-page/text-presets.ts +230 -0
- package/lib/detail-page/use-fake-progress.ts +67 -0
- package/lib/detail-page/z-order.ts +82 -0
- package/lib/detail-page-canvas/bubble-path.ts +190 -0
- package/lib/detail-page-canvas/canvas-key.ts +22 -0
- package/lib/detail-page-canvas/clip-rect.ts +65 -0
- package/lib/detail-page-canvas/custom-props-adapter.ts +219 -0
- package/lib/detail-page-canvas/editor-fonts.ts +161 -0
- package/lib/detail-page-canvas/export/ai.ts +413 -0
- package/lib/detail-page-canvas/export/color.ts +35 -0
- package/lib/detail-page-canvas/export/document-model.ts +78 -0
- package/lib/detail-page-canvas/export/export-files.ts +290 -0
- package/lib/detail-page-canvas/export/font-subset.ts +264 -0
- package/lib/detail-page-canvas/export/gif-export.ts +310 -0
- package/lib/detail-page-canvas/export/gif-plan.ts +95 -0
- package/lib/detail-page-canvas/export/mp4-encode.ts +158 -0
- package/lib/detail-page-canvas/export/mp4-support.ts +22 -0
- package/lib/detail-page-canvas/export/pdf/geometry.ts +309 -0
- package/lib/detail-page-canvas/export/pdf/inline-svg.ts +399 -0
- package/lib/detail-page-canvas/export/pdf/resources.ts +443 -0
- package/lib/detail-page-canvas/export/pdf/text-ops.ts +81 -0
- package/lib/detail-page-canvas/export/pdf/writer.ts +109 -0
- package/lib/detail-page-canvas/export/psd.ts +354 -0
- package/lib/detail-page-canvas/export/raster.ts +255 -0
- package/lib/detail-page-canvas/export/svg.ts +479 -0
- package/lib/detail-page-canvas/export/text-layout.ts +142 -0
- package/lib/detail-page-canvas/font-catalog.ts +177 -0
- package/lib/detail-page-canvas/font-tags.ts +47 -0
- package/lib/detail-page-canvas/gif-web-fonts.ts +90 -0
- package/lib/detail-page-canvas/konva-fallback.ts +477 -0
- package/lib/detail-page-canvas/text-background-plan.ts +124 -0
- package/lib/detail-page-canvas/text-highlight-bands.ts +127 -0
- package/lib/utils.ts +10 -0
- package/package.json +68 -0
- package/types/commerce.ts +171 -0
- package/types/detail-page-api.ts +200 -0
- package/types/detail-page-canvas.ts +20 -0
- package/types/fontkit.d.ts +42 -0
- package/types/gifenc.d.ts +51 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 세로 막대 — 항목 수가 적고 라벨이 짧을 때(연차 비교, 3~5개 스펙 대비).
|
|
3
|
+
*
|
|
4
|
+
* 값은 막대 **바로 위**에 앉힌다. 위쪽에 값 한 줄 높이를 미리 비워 두므로, 막대가
|
|
5
|
+
* 플롯을 꽉 채워도 값이 프레임 밖으로 나가지 않는다.
|
|
6
|
+
*
|
|
7
|
+
* ``style.plot``이 있으면 판 크롬(기둥 밴드·눈금선·축선·눈금 라벨)을 함께 그린다.
|
|
8
|
+
* 브랜드 상세페이지의 막대그래프가 그 모양이고, 지금은 그 좌표를 손으로 계산해 통짜
|
|
9
|
+
* SVG로 굽고 있다. 여기서는 ``resolved.max`` 하나에서 전부 나오므로 **수치를 고치면
|
|
10
|
+
* 막대·눈금선·눈금 라벨이 같이 따라간다** — 축이 거짓말을 할 수가 없다.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { formatChartValue } from "../format";
|
|
14
|
+
import { itemColor, ratioOf, type ResolvedChart } from "../normalize";
|
|
15
|
+
import type { ChartNode, ChartRender, ChartSpec } from "../types";
|
|
16
|
+
import {
|
|
17
|
+
barRadius,
|
|
18
|
+
estimateTextWidth,
|
|
19
|
+
rectNode,
|
|
20
|
+
textHeight,
|
|
21
|
+
textNode,
|
|
22
|
+
visibleLength,
|
|
23
|
+
} from "./shared";
|
|
24
|
+
|
|
25
|
+
export function renderBarV(spec: ChartSpec, resolved: ResolvedChart): ChartRender {
|
|
26
|
+
const { style, options } = spec;
|
|
27
|
+
const values = resolved.series[0]?.values ?? [];
|
|
28
|
+
const count = Math.max(1, resolved.labels.length);
|
|
29
|
+
const chrome = style.plot;
|
|
30
|
+
const ticks = chrome?.ticks ?? null;
|
|
31
|
+
|
|
32
|
+
// 눈금 라벨은 플롯 **왼쪽 바깥**에 앉으므로 그만큼 판을 오른쪽으로 민다.
|
|
33
|
+
const gutter = ticks ? Math.max(0, ticks.gutter) : 0;
|
|
34
|
+
const width = spec.frame.width;
|
|
35
|
+
const plotWidth = Math.max(1, width - gutter);
|
|
36
|
+
|
|
37
|
+
const labelH = textHeight(style.labelSize);
|
|
38
|
+
const valueH = textHeight(style.valueSize);
|
|
39
|
+
// 단위 캡("(%)")은 눈금 맨 위보다 더 위에 앉는다.
|
|
40
|
+
const capH = ticks && ticks.unitCap ? textHeight(ticks.size) + 4 : 0;
|
|
41
|
+
const headH = options.showValue ? valueH + style.labelGap : 0;
|
|
42
|
+
const plotTop = Math.max(headH, capH);
|
|
43
|
+
const plotBottom = plotTop + style.plotSize;
|
|
44
|
+
|
|
45
|
+
const colWidth = (plotWidth - style.gap * (count - 1)) / count;
|
|
46
|
+
// 가로형의 ``barSize``(막대 두께)를 세로형에 그대로 쓰면 젓가락처럼 얇아진다.
|
|
47
|
+
// 칸 폭의 60%를 바닥으로 깔되, 더 두꺼운 값을 명시하면 그쪽을 따른다.
|
|
48
|
+
const barWidth = Math.min(colWidth, Math.max(style.barSize, colWidth * 0.6));
|
|
49
|
+
const radius = barRadius(style, barWidth);
|
|
50
|
+
|
|
51
|
+
const chromeNodes: ChartNode[] = [];
|
|
52
|
+
const nodes: ChartNode[] = [];
|
|
53
|
+
|
|
54
|
+
// ── 판 크롬 ───────────────────────────────────────────────────────────────
|
|
55
|
+
if (chrome?.bands) {
|
|
56
|
+
resolved.labels.forEach((_label, i) => {
|
|
57
|
+
const colX = gutter + i * (colWidth + style.gap);
|
|
58
|
+
chromeNodes.push(
|
|
59
|
+
rectNode(
|
|
60
|
+
`band:${i}`,
|
|
61
|
+
{ x: colX, y: plotTop, width: colWidth, height: style.plotSize },
|
|
62
|
+
chrome.bands as string,
|
|
63
|
+
),
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (chrome?.grid && chrome.grid.count > 0) {
|
|
69
|
+
const steps = chrome.grid.count;
|
|
70
|
+
// 0선은 축선이 대신 그으므로 위쪽 눈금만 긋는다.
|
|
71
|
+
for (let i = 0; i < steps; i += 1) {
|
|
72
|
+
const y = plotTop + (style.plotSize * i) / steps;
|
|
73
|
+
chromeNodes.push(
|
|
74
|
+
rectNode(
|
|
75
|
+
`grid:${i}`,
|
|
76
|
+
{ x: gutter, y, width: plotWidth, height: 1 },
|
|
77
|
+
chrome.grid.color,
|
|
78
|
+
),
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (chrome?.axis) {
|
|
84
|
+
const thickness = Math.max(1, chrome.axis.width);
|
|
85
|
+
chromeNodes.push(
|
|
86
|
+
rectNode(
|
|
87
|
+
"axis:y",
|
|
88
|
+
{ x: gutter, y: plotTop, width: thickness, height: style.plotSize },
|
|
89
|
+
chrome.axis.color,
|
|
90
|
+
),
|
|
91
|
+
rectNode(
|
|
92
|
+
"axis:x",
|
|
93
|
+
{ x: gutter, y: plotBottom, width: plotWidth, height: thickness },
|
|
94
|
+
chrome.axis.color,
|
|
95
|
+
),
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (ticks) {
|
|
100
|
+
const steps = chrome?.grid?.count ?? 4;
|
|
101
|
+
const labelWidth = Math.max(16, gutter - 8);
|
|
102
|
+
for (let i = 0; i <= steps; i += 1) {
|
|
103
|
+
const value = (resolved.max * i) / steps;
|
|
104
|
+
const y = plotBottom - (style.plotSize * i) / steps;
|
|
105
|
+
chromeNodes.push(
|
|
106
|
+
textNode(
|
|
107
|
+
`tick:${i}`,
|
|
108
|
+
{ x: 0, y: y - textHeight(ticks.size) / 2, width: labelWidth },
|
|
109
|
+
formatChartValue(value, { decimals: options.decimals }),
|
|
110
|
+
{
|
|
111
|
+
style,
|
|
112
|
+
fontSize: ticks.size,
|
|
113
|
+
fill: ticks.color,
|
|
114
|
+
align: "right",
|
|
115
|
+
fontWeight: "400",
|
|
116
|
+
},
|
|
117
|
+
),
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
if (ticks.unitCap) {
|
|
121
|
+
chromeNodes.push(
|
|
122
|
+
textNode(
|
|
123
|
+
"tick:cap",
|
|
124
|
+
{
|
|
125
|
+
x: 0,
|
|
126
|
+
y: plotTop - textHeight(ticks.size) - 4,
|
|
127
|
+
width: Math.max(labelWidth, estimateTextWidth(ticks.unitCap, ticks.size)),
|
|
128
|
+
},
|
|
129
|
+
ticks.unitCap,
|
|
130
|
+
{
|
|
131
|
+
style,
|
|
132
|
+
fontSize: ticks.size,
|
|
133
|
+
fill: ticks.color,
|
|
134
|
+
align: "right",
|
|
135
|
+
fontWeight: "400",
|
|
136
|
+
},
|
|
137
|
+
),
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// ── 막대 ─────────────────────────────────────────────────────────────────
|
|
143
|
+
resolved.labels.forEach((label, i) => {
|
|
144
|
+
const colX = gutter + i * (colWidth + style.gap);
|
|
145
|
+
const barX = colX + (colWidth - barWidth) / 2;
|
|
146
|
+
const value = values[i] ?? null;
|
|
147
|
+
const ratio = ratioOf(value, resolved.max);
|
|
148
|
+
const barH = visibleLength(style.plotSize * ratio, ratio);
|
|
149
|
+
const barTop = plotBottom - barH;
|
|
150
|
+
const color = itemColor(spec, i, resolved.highlightIndex);
|
|
151
|
+
|
|
152
|
+
if (style.showTrack) {
|
|
153
|
+
nodes.push(
|
|
154
|
+
rectNode(
|
|
155
|
+
`track:${i}`,
|
|
156
|
+
{ x: barX, y: plotTop, width: barWidth, height: style.plotSize },
|
|
157
|
+
style.trackColor,
|
|
158
|
+
radius,
|
|
159
|
+
),
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
nodes.push(
|
|
163
|
+
rectNode(
|
|
164
|
+
`bar:${i}`,
|
|
165
|
+
{ x: barX, y: barTop, width: barWidth, height: barH },
|
|
166
|
+
color,
|
|
167
|
+
radius,
|
|
168
|
+
),
|
|
169
|
+
);
|
|
170
|
+
if (options.showValue) {
|
|
171
|
+
nodes.push(
|
|
172
|
+
textNode(
|
|
173
|
+
`value:${i}`,
|
|
174
|
+
{ x: colX, y: barTop - style.labelGap - valueH, width: colWidth },
|
|
175
|
+
formatChartValue(value, {
|
|
176
|
+
decimals: options.decimals,
|
|
177
|
+
unit: options.unit,
|
|
178
|
+
}),
|
|
179
|
+
{
|
|
180
|
+
style,
|
|
181
|
+
fontSize: style.valueSize,
|
|
182
|
+
fill: style.valueColor,
|
|
183
|
+
align: "center",
|
|
184
|
+
fontWeight: "700",
|
|
185
|
+
},
|
|
186
|
+
),
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
nodes.push(
|
|
190
|
+
textNode(
|
|
191
|
+
`label:${i}`,
|
|
192
|
+
{ x: colX, y: plotBottom + style.labelGap, width: colWidth },
|
|
193
|
+
label,
|
|
194
|
+
{
|
|
195
|
+
style,
|
|
196
|
+
fontSize: style.labelSize,
|
|
197
|
+
fill: style.labelColor,
|
|
198
|
+
align: "center",
|
|
199
|
+
fontWeight: "500",
|
|
200
|
+
},
|
|
201
|
+
),
|
|
202
|
+
);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
return {
|
|
206
|
+
// 크롬이 먼저 = 막대 뒤에 깔린다.
|
|
207
|
+
nodes: [...chromeNodes, ...nodes],
|
|
208
|
+
size: {
|
|
209
|
+
width,
|
|
210
|
+
height: Math.round(plotBottom + style.labelGap + labelH),
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 도넛 — 구성비(성분, 만족도 비중)에 쓴다.
|
|
3
|
+
*
|
|
4
|
+
* 고리만 ``svg`` 하나로 그리고, 가운데 수치와 아래 범례는 전부 네이티브 텍스트다.
|
|
5
|
+
* 글자를 SVG 안에 넣으면 폰트가 시스템 폰트로 떨어진다.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { formatChartValue } from "../format";
|
|
9
|
+
import { itemColor, type ResolvedChart } from "../normalize";
|
|
10
|
+
import type { ChartNode, ChartRender, ChartSpec } from "../types";
|
|
11
|
+
import {
|
|
12
|
+
rectNode,
|
|
13
|
+
ringSlicePath,
|
|
14
|
+
svgNode,
|
|
15
|
+
textHeight,
|
|
16
|
+
textNode,
|
|
17
|
+
} from "./shared";
|
|
18
|
+
|
|
19
|
+
/** 범례 색 칩의 한 변. */
|
|
20
|
+
const CHIP = 12;
|
|
21
|
+
|
|
22
|
+
export function renderDonut(spec: ChartSpec, resolved: ResolvedChart): ChartRender {
|
|
23
|
+
const { style, options } = spec;
|
|
24
|
+
const width = spec.frame.width;
|
|
25
|
+
const values = resolved.series[0]?.values ?? [];
|
|
26
|
+
const nodes: ChartNode[] = [];
|
|
27
|
+
|
|
28
|
+
const diameter = Math.max(60, Math.min(width, style.plotSize));
|
|
29
|
+
const thickness = Math.max(style.barSize, Math.round(diameter * 0.08));
|
|
30
|
+
const cx = diameter / 2;
|
|
31
|
+
const cy = diameter / 2;
|
|
32
|
+
const outer = diameter / 2;
|
|
33
|
+
const inner = Math.max(4, outer - thickness);
|
|
34
|
+
|
|
35
|
+
const total = values.reduce<number>(
|
|
36
|
+
(sum, value) => sum + Math.max(0, value ?? 0),
|
|
37
|
+
0,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
// 고리: 값이 하나도 없으면 트랙만 남겨 "빈 차트"로 보이게 한다.
|
|
41
|
+
const pieces: string[] = [];
|
|
42
|
+
if (style.showTrack || total <= 0) {
|
|
43
|
+
pieces.push(
|
|
44
|
+
`<path d="${ringSlicePath(cx, cy, outer, inner, -90, 270)}" fill="${style.trackColor}"/>`,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
if (total > 0) {
|
|
48
|
+
let cursor = -90;
|
|
49
|
+
values.forEach((value, i) => {
|
|
50
|
+
const share = Math.max(0, value ?? 0) / total;
|
|
51
|
+
if (share <= 0) return;
|
|
52
|
+
const end = cursor + share * 360;
|
|
53
|
+
pieces.push(
|
|
54
|
+
`<path d="${ringSlicePath(cx, cy, outer, inner, cursor, end)}" fill="${itemColor(
|
|
55
|
+
spec,
|
|
56
|
+
i,
|
|
57
|
+
resolved.highlightIndex,
|
|
58
|
+
)}"/>`,
|
|
59
|
+
);
|
|
60
|
+
cursor = end;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
nodes.push(
|
|
64
|
+
svgNode(
|
|
65
|
+
"ring",
|
|
66
|
+
{ x: (width - diameter) / 2, y: 0, width: diameter, height: diameter },
|
|
67
|
+
pieces.join(""),
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// 가운데: 주목할 항목 하나의 값과 이름. 강조가 없으면 첫 항목.
|
|
72
|
+
const focus = resolved.highlightIndex ?? 0;
|
|
73
|
+
const centerSize = Math.round(style.valueSize * 1.6);
|
|
74
|
+
const centerH = textHeight(centerSize);
|
|
75
|
+
const labelH = textHeight(style.labelSize);
|
|
76
|
+
if (resolved.labels.length > 0) {
|
|
77
|
+
const block = centerH + labelH;
|
|
78
|
+
nodes.push(
|
|
79
|
+
textNode(
|
|
80
|
+
"center:value",
|
|
81
|
+
{
|
|
82
|
+
x: (width - diameter) / 2,
|
|
83
|
+
y: cy - block / 2,
|
|
84
|
+
width: diameter,
|
|
85
|
+
},
|
|
86
|
+
formatChartValue(values[focus] ?? null, {
|
|
87
|
+
decimals: options.decimals,
|
|
88
|
+
unit: options.unit,
|
|
89
|
+
}),
|
|
90
|
+
{
|
|
91
|
+
style,
|
|
92
|
+
fontSize: centerSize,
|
|
93
|
+
fill: style.valueColor,
|
|
94
|
+
align: "center",
|
|
95
|
+
fontWeight: "700",
|
|
96
|
+
},
|
|
97
|
+
),
|
|
98
|
+
);
|
|
99
|
+
nodes.push(
|
|
100
|
+
textNode(
|
|
101
|
+
"center:label",
|
|
102
|
+
{
|
|
103
|
+
x: (width - diameter) / 2,
|
|
104
|
+
y: cy - block / 2 + centerH,
|
|
105
|
+
width: diameter,
|
|
106
|
+
},
|
|
107
|
+
resolved.labels[focus] ?? "",
|
|
108
|
+
{
|
|
109
|
+
style,
|
|
110
|
+
fontSize: style.labelSize,
|
|
111
|
+
fill: style.labelColor,
|
|
112
|
+
align: "center",
|
|
113
|
+
fontWeight: "400",
|
|
114
|
+
},
|
|
115
|
+
),
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// 범례: 칩 · 이름 · 값. 도넛은 조각 위에 글자를 얹으면 금세 읽기 어려워진다.
|
|
120
|
+
const rowH = Math.max(labelH, textHeight(style.valueSize));
|
|
121
|
+
const rowGap = Math.round(style.gap / 2);
|
|
122
|
+
const legendTop = diameter + style.gap;
|
|
123
|
+
resolved.labels.forEach((label, i) => {
|
|
124
|
+
const top = legendTop + i * (rowH + rowGap);
|
|
125
|
+
nodes.push(
|
|
126
|
+
rectNode(
|
|
127
|
+
`chip:${i}`,
|
|
128
|
+
{
|
|
129
|
+
x: 0,
|
|
130
|
+
y: top + (rowH - CHIP) / 2,
|
|
131
|
+
width: CHIP,
|
|
132
|
+
height: CHIP,
|
|
133
|
+
},
|
|
134
|
+
itemColor(spec, i, resolved.highlightIndex),
|
|
135
|
+
3,
|
|
136
|
+
),
|
|
137
|
+
);
|
|
138
|
+
nodes.push(
|
|
139
|
+
textNode(
|
|
140
|
+
`label:${i}`,
|
|
141
|
+
{ x: CHIP + 8, y: top + (rowH - labelH) / 2, width: width * 0.6 },
|
|
142
|
+
label,
|
|
143
|
+
{
|
|
144
|
+
style,
|
|
145
|
+
fontSize: style.labelSize,
|
|
146
|
+
fill: style.labelColor,
|
|
147
|
+
align: "left",
|
|
148
|
+
fontWeight: "400",
|
|
149
|
+
},
|
|
150
|
+
),
|
|
151
|
+
);
|
|
152
|
+
if (options.showValue) {
|
|
153
|
+
nodes.push(
|
|
154
|
+
textNode(
|
|
155
|
+
`value:${i}`,
|
|
156
|
+
{
|
|
157
|
+
x: width * 0.6 + CHIP + 8,
|
|
158
|
+
y: top + (rowH - textHeight(style.valueSize)) / 2,
|
|
159
|
+
width: width * 0.4 - CHIP - 8,
|
|
160
|
+
},
|
|
161
|
+
formatChartValue(values[i] ?? null, {
|
|
162
|
+
decimals: options.decimals,
|
|
163
|
+
unit: options.unit,
|
|
164
|
+
}),
|
|
165
|
+
{
|
|
166
|
+
style,
|
|
167
|
+
fontSize: style.valueSize,
|
|
168
|
+
fill: style.valueColor,
|
|
169
|
+
align: "right",
|
|
170
|
+
fontWeight: "700",
|
|
171
|
+
},
|
|
172
|
+
),
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
const rows = resolved.labels.length;
|
|
178
|
+
const legendHeight = rows > 0 ? rows * rowH + (rows - 1) * rowGap : 0;
|
|
179
|
+
return {
|
|
180
|
+
nodes,
|
|
181
|
+
size: {
|
|
182
|
+
width,
|
|
183
|
+
height: Math.round(diameter + (rows > 0 ? style.gap + legendHeight : 0)),
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 게이지 — 값 하나를 최댓값 대비로 보여준다(만족도, 달성률, 개선율).
|
|
3
|
+
*
|
|
4
|
+
* 항목이 여러 개면 강조 항목(없으면 첫 항목) 하나만 그린다. 나머지 데이터는 스펙에
|
|
5
|
+
* 그대로 남아 있어서 종류를 되돌리면 살아난다.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { formatChartValue } from "../format";
|
|
9
|
+
import { itemColor, ratioOf, type ResolvedChart } from "../normalize";
|
|
10
|
+
import type { ChartNode, ChartRender, ChartSpec } from "../types";
|
|
11
|
+
import { ringSlicePath, svgNode, textHeight, textNode } from "./shared";
|
|
12
|
+
|
|
13
|
+
export function renderGauge(spec: ChartSpec, resolved: ResolvedChart): ChartRender {
|
|
14
|
+
const { style, options } = spec;
|
|
15
|
+
const width = spec.frame.width;
|
|
16
|
+
const values = resolved.series[0]?.values ?? [];
|
|
17
|
+
const index = resolved.highlightIndex ?? 0;
|
|
18
|
+
const value = values[index] ?? null;
|
|
19
|
+
const ratio = ratioOf(value, resolved.max);
|
|
20
|
+
const nodes: ChartNode[] = [];
|
|
21
|
+
|
|
22
|
+
// 반원이라 지름은 프레임 폭에, 높이는 그 절반에 맞춘다.
|
|
23
|
+
const diameter = Math.max(80, Math.min(width, style.plotSize * 1.6));
|
|
24
|
+
const thickness = Math.max(style.barSize, Math.round(diameter * 0.09));
|
|
25
|
+
const cx = diameter / 2;
|
|
26
|
+
const cy = diameter / 2;
|
|
27
|
+
const outer = diameter / 2;
|
|
28
|
+
const inner = Math.max(4, outer - thickness);
|
|
29
|
+
const left = (width - diameter) / 2;
|
|
30
|
+
|
|
31
|
+
const pieces: string[] = [];
|
|
32
|
+
if (style.showTrack) {
|
|
33
|
+
pieces.push(
|
|
34
|
+
`<path d="${ringSlicePath(cx, cy, outer, inner, 180, 360)}" fill="${style.trackColor}"/>`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
if (ratio > 0) {
|
|
38
|
+
pieces.push(
|
|
39
|
+
`<path d="${ringSlicePath(cx, cy, outer, inner, 180, 180 + ratio * 180)}" fill="${itemColor(
|
|
40
|
+
spec,
|
|
41
|
+
index,
|
|
42
|
+
resolved.highlightIndex,
|
|
43
|
+
)}"/>`,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
// 반원만 쓰므로 SVG 상자도 위 절반만 잡는다(아래 빈 공간이 레이아웃을 밀지 않게).
|
|
47
|
+
nodes.push(
|
|
48
|
+
svgNode(
|
|
49
|
+
"arc",
|
|
50
|
+
{ x: left, y: 0, width: diameter, height: Math.ceil(diameter / 2) },
|
|
51
|
+
pieces.join(""),
|
|
52
|
+
),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const valueSize = Math.round(style.valueSize * 1.6);
|
|
56
|
+
const valueH = textHeight(valueSize);
|
|
57
|
+
const labelH = textHeight(style.labelSize);
|
|
58
|
+
const arcHeight = Math.ceil(diameter / 2);
|
|
59
|
+
|
|
60
|
+
nodes.push(
|
|
61
|
+
textNode(
|
|
62
|
+
"center:value",
|
|
63
|
+
{ x: left, y: arcHeight - valueH, width: diameter },
|
|
64
|
+
formatChartValue(value, {
|
|
65
|
+
decimals: options.decimals,
|
|
66
|
+
unit: options.unit,
|
|
67
|
+
}),
|
|
68
|
+
{
|
|
69
|
+
style,
|
|
70
|
+
fontSize: valueSize,
|
|
71
|
+
fill: style.valueColor,
|
|
72
|
+
align: "center",
|
|
73
|
+
fontWeight: "700",
|
|
74
|
+
},
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
nodes.push(
|
|
78
|
+
textNode(
|
|
79
|
+
"center:label",
|
|
80
|
+
{ x: left, y: arcHeight + style.labelGap, width: diameter },
|
|
81
|
+
resolved.labels[index] ?? "",
|
|
82
|
+
{
|
|
83
|
+
style,
|
|
84
|
+
fontSize: style.labelSize,
|
|
85
|
+
fill: style.labelColor,
|
|
86
|
+
align: "center",
|
|
87
|
+
fontWeight: "400",
|
|
88
|
+
},
|
|
89
|
+
),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
nodes,
|
|
94
|
+
size: { width, height: Math.round(arcHeight + style.labelGap + labelH) },
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 꺾은선 — 시간에 따른 변화(사용 주차별 개선, 월별 판매).
|
|
3
|
+
*
|
|
4
|
+
* 선만 ``svg`` 하나로 그리고 점은 네이티브 원(figure), 글자는 네이티브 텍스트다.
|
|
5
|
+
* 시리즈가 여럿이면 위에 범례가 붙고, 값 라벨은 한 시리즈일 때만 붙인다 — 여러 줄의
|
|
6
|
+
* 값이 점 위에 겹치면 아무것도 안 읽힌다.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { formatChartValue } from "../format";
|
|
10
|
+
import { itemColor, ratioOf, type ResolvedChart } from "../normalize";
|
|
11
|
+
import type { ChartNode, ChartRender, ChartSpec } from "../types";
|
|
12
|
+
import {
|
|
13
|
+
circleNode,
|
|
14
|
+
polylinePath,
|
|
15
|
+
seriesLegend,
|
|
16
|
+
svgNode,
|
|
17
|
+
textHeight,
|
|
18
|
+
textNode,
|
|
19
|
+
} from "./shared";
|
|
20
|
+
|
|
21
|
+
export function renderLine(spec: ChartSpec, resolved: ResolvedChart): ChartRender {
|
|
22
|
+
const { style, options } = spec;
|
|
23
|
+
const width = spec.frame.width;
|
|
24
|
+
const nodes: ChartNode[] = [];
|
|
25
|
+
const count = resolved.labels.length;
|
|
26
|
+
const single = resolved.series.length <= 1;
|
|
27
|
+
|
|
28
|
+
const seriesColors = resolved.series.map((_, i) =>
|
|
29
|
+
single
|
|
30
|
+
? (style.palette[0] ?? style.mutedColor)
|
|
31
|
+
: (style.palette[i % Math.max(1, style.palette.length)] ?? style.mutedColor),
|
|
32
|
+
);
|
|
33
|
+
const legend = seriesLegend({
|
|
34
|
+
names: resolved.series.map((s) => s.name),
|
|
35
|
+
colors: seriesColors,
|
|
36
|
+
style,
|
|
37
|
+
top: 0,
|
|
38
|
+
});
|
|
39
|
+
nodes.push(...legend.nodes);
|
|
40
|
+
|
|
41
|
+
const valueH = textHeight(style.valueSize);
|
|
42
|
+
const labelH = textHeight(style.labelSize);
|
|
43
|
+
const showValues = single && options.showValue;
|
|
44
|
+
const headH =
|
|
45
|
+
(legend.height > 0 ? legend.height + style.labelGap : 0) +
|
|
46
|
+
(showValues ? valueH + style.labelGap : 0);
|
|
47
|
+
const plotTop = headH;
|
|
48
|
+
const plotBottom = plotTop + style.plotSize;
|
|
49
|
+
|
|
50
|
+
// 점이 프레임 모서리에서 반쪽으로 잘리지 않게 양쪽을 조금 비운다.
|
|
51
|
+
const dot = Math.max(3, Math.round(style.barSize / 3));
|
|
52
|
+
const pad = dot + 4;
|
|
53
|
+
const span = Math.max(1, width - pad * 2);
|
|
54
|
+
const xAt = (i: number) =>
|
|
55
|
+
count <= 1 ? width / 2 : pad + (span * i) / (count - 1);
|
|
56
|
+
const yAt = (value: number | null) =>
|
|
57
|
+
plotBottom - style.plotSize * ratioOf(value, resolved.max);
|
|
58
|
+
|
|
59
|
+
const paths = resolved.series
|
|
60
|
+
.map((series, s) => {
|
|
61
|
+
const points = series.values
|
|
62
|
+
.map((value, i) => ({ value, point: { x: xAt(i), y: yAt(value) } }))
|
|
63
|
+
.filter((entry) => entry.value !== null)
|
|
64
|
+
.map((entry) => entry.point);
|
|
65
|
+
if (points.length < 2) return "";
|
|
66
|
+
return `<path d="${polylinePath(points)}" fill="none" stroke="${
|
|
67
|
+
seriesColors[s]
|
|
68
|
+
}" stroke-width="${Math.max(2, Math.round(style.barSize / 4))}" stroke-linecap="round" stroke-linejoin="round"/>`;
|
|
69
|
+
})
|
|
70
|
+
.join("");
|
|
71
|
+
nodes.push(
|
|
72
|
+
svgNode(
|
|
73
|
+
"line",
|
|
74
|
+
{ x: 0, y: plotTop, width, height: style.plotSize },
|
|
75
|
+
// path 좌표는 플롯 상단 기준이라 svg 안에서 다시 0으로 내린다.
|
|
76
|
+
`<g transform="translate(0 ${-plotTop})">${paths}</g>`,
|
|
77
|
+
),
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
resolved.series.forEach((series, s) => {
|
|
81
|
+
series.values.forEach((value, i) => {
|
|
82
|
+
if (value === null) return;
|
|
83
|
+
nodes.push(
|
|
84
|
+
circleNode(`dot:${s}:${i}`, { x: xAt(i), y: yAt(value) }, dot, seriesColors[s]),
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
if (showValues) {
|
|
90
|
+
const values = resolved.series[0]?.values ?? [];
|
|
91
|
+
values.forEach((value, i) => {
|
|
92
|
+
const slot = count <= 1 ? width : span / Math.max(1, count - 1);
|
|
93
|
+
nodes.push(
|
|
94
|
+
textNode(
|
|
95
|
+
`value:${i}`,
|
|
96
|
+
{
|
|
97
|
+
x: xAt(i) - slot / 2,
|
|
98
|
+
y: yAt(value) - style.labelGap - valueH,
|
|
99
|
+
width: slot,
|
|
100
|
+
},
|
|
101
|
+
formatChartValue(value, {
|
|
102
|
+
decimals: options.decimals,
|
|
103
|
+
unit: options.unit,
|
|
104
|
+
}),
|
|
105
|
+
{
|
|
106
|
+
style,
|
|
107
|
+
fontSize: style.valueSize,
|
|
108
|
+
fill: style.valueColor,
|
|
109
|
+
align: "center",
|
|
110
|
+
fontWeight: "700",
|
|
111
|
+
},
|
|
112
|
+
),
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
resolved.labels.forEach((label, i) => {
|
|
118
|
+
const slot = count <= 1 ? width : span / Math.max(1, count - 1);
|
|
119
|
+
nodes.push(
|
|
120
|
+
textNode(
|
|
121
|
+
`label:${i}`,
|
|
122
|
+
{
|
|
123
|
+
x: xAt(i) - slot / 2,
|
|
124
|
+
y: plotBottom + style.labelGap,
|
|
125
|
+
width: slot,
|
|
126
|
+
},
|
|
127
|
+
label,
|
|
128
|
+
{
|
|
129
|
+
style,
|
|
130
|
+
fontSize: style.labelSize,
|
|
131
|
+
fill: style.labelColor,
|
|
132
|
+
align: "center",
|
|
133
|
+
fontWeight: "400",
|
|
134
|
+
},
|
|
135
|
+
),
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
nodes,
|
|
141
|
+
size: { width, height: Math.round(plotBottom + style.labelGap + labelH) },
|
|
142
|
+
};
|
|
143
|
+
}
|