1use super::*;
2
3fn owned_labels(labels: &[&str]) -> Vec<String> {
13 labels.iter().map(|s: &&str| (*s).to_string()).collect()
14}
15
16fn build_line_option() -> EuvChartOption {
22 EuvChartOption::new()
23 .title(EuvChartTitle::new(TITLE_LINE_CHART).subtext(SUB_LINE_CHART))
24 .legend(EuvChartLegend::at(EuvChartPosition::Top))
25 .tooltip(EuvChartTooltip::axis(EuvChartAxisPointerType::Cross))
26 .toolbox(EuvChartToolbox::full())
27 .data_zoom(EuvChartDataZoom::inside())
28 .data_zoom(EuvChartDataZoom::slider().range(10.0, 85.0))
29 .x_axis(EuvChartAxis::category(owned_labels(&DAYS_EIGHT)))
30 .y_axis(EuvChartAxis::value().unit_suffix("k"))
31 .add_series(EuvChartSeries::new(
32 SER_DIRECT,
33 EuvChartSeriesData::Line(
34 EuvChartLineSeries::from_values(vec![
35 120.0, 165.0, 148.0, 224.0, 286.0, 260.0, 318.0, 342.0,
36 ])
37 .smooth(true)
38 .area(0.28)
39 .stack(STACK_TRAFFIC)
40 .mark_point(EuvChartMarkPoint::new(
41 EuvChartMarkPointKind::Max,
42 MARK_PEAK,
43 ))
44 .mark_line(EuvChartMarkLine::new(
45 EuvChartMarkLineKind::Average,
46 MARK_AVG,
47 ))
48 .mark_area(EuvChartMarkArea::x_range(3.0, 5.0, MARK_PROMO)),
49 ),
50 ))
51 .add_series(EuvChartSeries::new(
52 SER_ORGANIC,
53 EuvChartSeriesData::Line(
54 EuvChartLineSeries::from_values(vec![
55 64.0, 82.0, 96.0, 112.0, 128.0, 118.0, 146.0, 160.0,
56 ])
57 .smooth(true)
58 .area(0.22)
59 .stack(STACK_TRAFFIC),
60 ),
61 ))
62 .add_series(EuvChartSeries::new(
63 SER_SEARCH,
64 EuvChartSeriesData::Line(
65 EuvChartLineSeries::from_values(vec![
66 90.0, 110.0, 104.0, 152.0, 178.0, 162.0, 205.0, 226.0,
67 ])
68 .step(EuvChartStepMode::Middle)
69 .dashed(true)
70 .symbol(EuvChartSymbol::Diamond, 4.0),
71 ),
72 ))
73}
74
75fn build_bar_dataset_option() -> EuvChartOption {
81 let rev_vals: [f32; 6] = [120.0, 152.0, 188.0, 174.0, 232.0, 276.0];
82 let prof_vals: [f32; 6] = [34.0, 44.0, 58.0, 52.0, 76.0, 94.0];
83 let margin_vals: [f32; 6] = [28.0, 29.0, 31.0, 30.0, 33.0, 34.0];
84 let mut rows: Vec<Vec<EuvChartCell>> = Vec::with_capacity(6);
85 for idx in 0..6usize {
86 rows.push(vec![
87 EuvChartCell::Text(MONTHS_SIX[idx].to_string()),
88 EuvChartCell::Number(rev_vals[idx]),
89 EuvChartCell::Number(prof_vals[idx]),
90 EuvChartCell::Number(margin_vals[idx]),
91 ]);
92 }
93 let ds: EuvChartDataset = EuvChartDataset::new(
94 vec![
95 DIM_MONTH.to_string(),
96 DIM_REVENUE.to_string(),
97 DIM_PROFIT.to_string(),
98 DIM_MARGIN.to_string(),
99 ],
100 rows,
101 );
102 EuvChartOption::new()
103 .title(EuvChartTitle::new(TITLE_BAR_CHART))
104 .legend(EuvChartLegend::at(EuvChartPosition::Top))
105 .tooltip(EuvChartTooltip::axis(EuvChartAxisPointerType::Shadow))
106 .toolbox(EuvChartToolbox::full())
107 .dataset(ds)
108 .y_axis(EuvChartAxis::value().name(DIM_REVENUE).unit_suffix("k"))
109 .y_axis(
110 EuvChartAxis::value()
111 .name(DIM_MARGIN)
112 .unit_suffix("%")
113 .position(EuvChartPosition::Right),
114 )
115 .add_series(EuvChartSeries::new(
116 DIM_REVENUE,
117 EuvChartSeriesData::Bar(
118 EuvChartBarSeries::default()
119 .axes(0, 0)
120 .stack(STACK_REV)
121 .show_background(true)
122 .encode(EuvChartEncode::default().x(DIM_MONTH).y(DIM_REVENUE)),
123 ),
124 ))
125 .add_series(EuvChartSeries::new(
126 DIM_PROFIT,
127 EuvChartSeriesData::Bar(
128 EuvChartBarSeries::default()
129 .axes(0, 0)
130 .stack(STACK_REV)
131 .encode(EuvChartEncode::default().x(DIM_MONTH).y(DIM_PROFIT)),
132 ),
133 ))
134 .add_series(EuvChartSeries::new(
135 DIM_MARGIN,
136 EuvChartSeriesData::Line(
137 EuvChartLineSeries::default()
138 .axes(0, 1)
139 .smooth(true)
140 .encode(EuvChartEncode::default().x(DIM_MONTH).y(DIM_MARGIN)),
141 ),
142 ))
143}
144
145fn build_horizontal_bar_option() -> EuvChartOption {
151 EuvChartOption::new()
152 .title(EuvChartTitle::new(TITLE_HBAR_CHART))
153 .tooltip(EuvChartTooltip::item())
154 .toolbox(EuvChartToolbox::full().magic_type(false))
155 .x_axis(EuvChartAxis::value().max(100.0).unit_suffix("%"))
156 .y_axis(EuvChartAxis::category(owned_labels(&PLATFORMS_FIVE)))
157 .add_series(EuvChartSeries::new(
158 SER_SHARE,
159 EuvChartSeriesData::Bar(
160 EuvChartBarSeries::from_values(vec![94.0, 91.0, 88.0, 85.0, 79.0])
161 .show_background(true)
162 .show_labels(true),
163 ),
164 ))
165}
166
167fn build_scatter_option() -> EuvChartOption {
173 EuvChartOption::new()
174 .title(EuvChartTitle::new(TITLE_SCATTER_CHART))
175 .legend(EuvChartLegend::at(EuvChartPosition::Top))
176 .tooltip(EuvChartTooltip::item())
177 .toolbox(EuvChartToolbox::full().magic_type(false))
178 .visual_map(EuvChartVisualMap::continuous(10.0, 100.0))
179 .x_axis(EuvChartAxis::value().min(0.0).max(100.0))
180 .y_axis(EuvChartAxis::value().min(0.0).max(100.0))
181 .add_series(EuvChartSeries::new(
182 SER_CLUSTERS,
183 EuvChartSeriesData::Scatter(
184 EuvChartScatterSeries::new(vec![
185 EuvChartScatterPoint::new(14.0, 26.0)
186 .size(7.0)
187 .label(PT_EDGE_A),
188 EuvChartScatterPoint::new(28.0, 44.0).size(9.5),
189 EuvChartScatterPoint::new(42.0, 58.0)
190 .size(11.0)
191 .label(PT_EDGE_B),
192 EuvChartScatterPoint::new(56.0, 49.0).size(8.5),
193 EuvChartScatterPoint::new(70.0, 74.0)
194 .size(12.0)
195 .label(PT_CORE_C),
196 ])
197 .symbol(EuvChartSymbol::Circle, 7.0)
198 .show_labels(true),
199 ),
200 ))
201 .add_series(EuvChartSeries::new(
202 SER_HOTSPOTS,
203 EuvChartSeriesData::EffectScatter(
204 EuvChartScatterSeries::new(vec![
205 EuvChartScatterPoint::new(82.0, 88.0)
206 .size(10.0)
207 .label(PT_BURST_D),
208 EuvChartScatterPoint::new(34.0, 76.0).size(8.0),
209 ])
210 .show_labels(true),
211 ),
212 ))
213}
214
215fn build_candlestick_option() -> EuvChartOption {
221 EuvChartOption::new()
222 .title(EuvChartTitle::new(TITLE_CANDLE_CHART))
223 .legend(EuvChartLegend::at(EuvChartPosition::Top))
224 .tooltip(EuvChartTooltip::axis(EuvChartAxisPointerType::Cross))
225 .toolbox(EuvChartToolbox::full().magic_type(false))
226 .data_zoom(EuvChartDataZoom::inside())
227 .data_zoom(EuvChartDataZoom::slider().range(10.0, 85.0))
228 .x_axis(EuvChartAxis::category(owned_labels(&DAYS_EIGHT)))
229 .y_axis(EuvChartAxis::value())
230 .add_series(EuvChartSeries::new(
231 SER_KLINE,
232 EuvChartSeriesData::Candlestick(EuvChartCandlestickSeries::new(vec![
233 EuvChartOhlcPoint::new(102.0, 114.0, 98.0, 119.0),
234 EuvChartOhlcPoint::new(114.0, 108.0, 103.0, 117.0),
235 EuvChartOhlcPoint::new(108.0, 124.0, 106.0, 129.0),
236 EuvChartOhlcPoint::new(124.0, 119.0, 115.0, 128.0),
237 EuvChartOhlcPoint::new(119.0, 134.0, 117.0, 139.0),
238 EuvChartOhlcPoint::new(134.0, 142.0, 130.0, 147.0),
239 EuvChartOhlcPoint::new(142.0, 136.0, 131.0, 145.0),
240 EuvChartOhlcPoint::new(136.0, 149.0, 134.0, 154.0),
241 ])),
242 ))
243 .add_series(EuvChartSeries::new(
244 SER_MA5,
245 EuvChartSeriesData::Line(
246 EuvChartLineSeries::from_values(vec![
247 108.0, 110.0, 114.0, 117.0, 122.0, 129.0, 134.0, 140.0,
248 ])
249 .smooth(true),
250 ),
251 ))
252}
253
254fn build_boxplot_option() -> EuvChartOption {
260 EuvChartOption::new()
261 .title(EuvChartTitle::new(TITLE_BOXPLOT_CHART))
262 .tooltip(EuvChartTooltip::item())
263 .toolbox(EuvChartToolbox::full().magic_type(false))
264 .x_axis(EuvChartAxis::category(owned_labels(&BACKENDS_THREE)))
265 .y_axis(EuvChartAxis::value().unit_suffix("ms"))
266 .add_series(EuvChartSeries::new(
267 SER_LATENCY,
268 EuvChartSeriesData::Boxplot(EuvChartBoxplotSeries::new(vec![
269 EuvChartBoxplotItem::new(3.6, 5.4, 7.2, 9.8, 12.4).outliers(vec![15.6]),
270 EuvChartBoxplotItem::new(1.8, 2.9, 3.8, 5.1, 6.9).outliers(vec![9.2]),
271 EuvChartBoxplotItem::new(0.8, 1.4, 2.1, 3.0, 4.2),
272 ])),
273 ))
274}
275
276fn build_heatmap_option() -> EuvChartOption {
282 let vals: [[f32; 6]; 4] = [
283 [14.0, 26.0, 52.0, 74.0, 66.0, 38.0],
284 [18.0, 34.0, 68.0, 88.0, 79.0, 46.0],
285 [12.0, 28.0, 62.0, 95.0, 84.0, 52.0],
286 [20.0, 40.0, 72.0, 91.0, 76.0, 44.0],
287 ];
288 let mut cells: Vec<EuvChartHeatmapCell> = Vec::with_capacity(24);
289 for (y_i, row) in vals.iter().enumerate() {
290 for (x_i, &v) in row.iter().enumerate() {
291 cells.push(EuvChartHeatmapCell::new(x_i, y_i, v));
292 }
293 }
294 EuvChartOption::new()
295 .title(EuvChartTitle::new(TITLE_HEATMAP_CHART))
296 .tooltip(EuvChartTooltip::item())
297 .toolbox(EuvChartToolbox::full().magic_type(false))
298 .x_axis(EuvChartAxis::category(owned_labels(&HOURS_SIX)))
299 .y_axis(EuvChartAxis::category(owned_labels(&WEEKDAYS_FOUR)))
300 .visual_map(EuvChartVisualMap::continuous(0.0, 100.0))
301 .add_series(EuvChartSeries::new(
302 SER_LOAD,
303 EuvChartSeriesData::Heatmap(EuvChartHeatmapSeries::new(cells)),
304 ))
305}
306
307fn build_calendar_heatmap_option() -> EuvChartOption {
313 let mut cells: Vec<EuvChartHeatmapCell> = Vec::with_capacity(96);
314 for w in 0..16usize {
315 for d in 0..7usize {
316 let v: f32 = (((w * 7 + d * 5 + 3) % 21) + 1) as f32;
317 cells.push(EuvChartHeatmapCell::new(w, d, v));
318 }
319 }
320 let piece_vm: EuvChartVisualMap = EuvChartVisualMap::piecewise(vec![
321 EuvChartVisualPiece::new(None, Some(7.0), VM_QUIET, Color::hex(0x93C5FD)),
322 EuvChartVisualPiece::new(Some(7.0), Some(14.0), VM_ACTIVE, Color::hex(0x3B82F6)),
323 EuvChartVisualPiece::new(Some(14.0), None, VM_PEAK, Color::hex(0x1D4ED8)),
324 ]);
325 EuvChartOption::new()
326 .title(EuvChartTitle::new(TITLE_CALENDAR_CHART))
327 .tooltip(EuvChartTooltip::item())
328 .toolbox(EuvChartToolbox::full().magic_type(false))
329 .calendar(EuvChartCalendar::new(2026, 16))
330 .visual_map(piece_vm)
331 .add_series(EuvChartSeries::new(
332 SER_COMMITS,
333 EuvChartSeriesData::Heatmap(
334 EuvChartHeatmapSeries::new(cells)
335 .coordinate_system(EuvChartCoordinateSystem::Calendar),
336 ),
337 ))
338}
339
340fn build_pie_option() -> EuvChartOption {
346 EuvChartOption::new()
347 .title(EuvChartTitle::new(TITLE_PIE_CHART))
348 .legend(EuvChartLegend::at(EuvChartPosition::Bottom))
349 .tooltip(EuvChartTooltip::item())
350 .toolbox(EuvChartToolbox::full().magic_type(false))
351 .add_series(EuvChartSeries::new(
352 SER_TRAFFIC,
353 EuvChartSeriesData::Pie(
354 EuvChartPieSeries::new(vec![
355 EuvChartPieSlice::new(SLICE_SEARCH, 420.0).selected(true),
356 EuvChartPieSlice::new(SER_DIRECT, 310.0),
357 EuvChartPieSlice::new(SLICE_REFERRAL, 230.0),
358 EuvChartPieSlice::new(SLICE_SOCIAL, 175.0),
359 EuvChartPieSlice::new(SLICE_EMAIL, 120.0),
360 ])
361 .donut(0.32)
362 .rose(EuvChartRoseType::Radius)
363 .pad_angle(2.0),
364 ),
365 ))
366}
367
368fn build_radar_option() -> EuvChartOption {
374 EuvChartOption::new()
375 .title(EuvChartTitle::new(TITLE_RADAR_CHART))
376 .legend(EuvChartLegend::at(EuvChartPosition::Top))
377 .tooltip(EuvChartTooltip::item())
378 .toolbox(EuvChartToolbox::full().magic_type(false))
379 .radar(
380 EuvChartRadar::new(vec![
381 EuvChartRadarIndicator::new(IND_FPS.to_string(), 0.0, 120.0),
382 EuvChartRadarIndicator::new(IND_MEM.to_string(), 0.0, 100.0),
383 EuvChartRadarIndicator::new(IND_STARTUP.to_string(), 0.0, 100.0),
384 EuvChartRadarIndicator::new(IND_BINARY.to_string(), 0.0, 100.0),
385 EuvChartRadarIndicator::new(IND_BATTERY.to_string(), 0.0, 100.0),
386 ])
387 .shape(EuvChartRadarShape::Polygon),
388 )
389 .add_series(EuvChartSeries::new(
390 SER_PROFILE,
391 EuvChartSeriesData::Radar(EuvChartRadarSeries::new(vec![
392 EuvChartRadarItem::new(ITEM_EUV_NATIVE, vec![120.0, 94.0, 97.0, 93.0, 92.0]),
393 EuvChartRadarItem::new(ITEM_WEBVIEW, vec![60.0, 48.0, 44.0, 38.0, 52.0]),
394 ])),
395 ))
396}
397
398fn build_gauge_option() -> EuvChartOption {
404 EuvChartOption::new()
405 .title(EuvChartTitle::new(TITLE_GAUGE_CHART))
406 .tooltip(EuvChartTooltip::item())
407 .toolbox(EuvChartToolbox::full().magic_type(false))
408 .add_series(EuvChartSeries::new(
409 SER_BUDGET,
410 EuvChartSeriesData::Gauge(
411 EuvChartGaugeSeries::new(84.5, 0.0, 100.0)
412 .unit("%")
413 .title(GAUGE_EFFICIENCY),
414 ),
415 ))
416}
417
418fn build_treemap_option() -> EuvChartOption {
424 EuvChartOption::new()
425 .title(EuvChartTitle::new(TITLE_TREEMAP_CHART))
426 .tooltip(EuvChartTooltip::item())
427 .toolbox(EuvChartToolbox::full().magic_type(false))
428 .add_series(EuvChartSeries::new(
429 SER_FOOTPRINT,
430 EuvChartSeriesData::Treemap(EuvChartTreemapSeries::new(vec![
431 EuvChartHierarchyNode::branch(
432 H_CORE,
433 vec![
434 EuvChartHierarchyNode::leaf(H_LAYOUT, 145.0),
435 EuvChartHierarchyNode::leaf(H_RENDER, 240.0),
436 EuvChartHierarchyNode::leaf(H_SIGNALS, 88.0),
437 ],
438 ),
439 EuvChartHierarchyNode::branch(
440 H_UI_SUITE,
441 vec![
442 EuvChartHierarchyNode::leaf(H_CHARTS, 175.0),
443 EuvChartHierarchyNode::leaf(H_MARKDOWN, 110.0),
444 EuvChartHierarchyNode::leaf(H_ROUTER, 72.0),
445 ],
446 ),
447 ])),
448 ))
449}
450
451fn build_sunburst_option() -> EuvChartOption {
457 EuvChartOption::new()
458 .title(EuvChartTitle::new(TITLE_SUNBURST_CHART))
459 .tooltip(EuvChartTooltip::item())
460 .toolbox(EuvChartToolbox::full().magic_type(false))
461 .add_series(EuvChartSeries::new(
462 SER_TAXONOMY,
463 EuvChartSeriesData::Sunburst(EuvChartSunburstSeries::new(vec![
464 EuvChartHierarchyNode::branch(
465 H_NATIVE,
466 vec![
467 EuvChartHierarchyNode::leaf(H_METAL, 48.0),
468 EuvChartHierarchyNode::leaf(H_VULKAN, 42.0),
469 EuvChartHierarchyNode::leaf(H_DX12, 26.0),
470 ],
471 ),
472 EuvChartHierarchyNode::branch(
473 H_BROWSER,
474 vec![
475 EuvChartHierarchyNode::leaf(PLATFORMS_FIVE[0], 34.0),
476 EuvChartHierarchyNode::leaf(H_CANVAS2D, 22.0),
477 ],
478 ),
479 ])),
480 ))
481}
482
483fn build_sankey_option() -> EuvChartOption {
489 EuvChartOption::new()
490 .title(EuvChartTitle::new(TITLE_SANKEY_CHART))
491 .tooltip(EuvChartTooltip::item())
492 .toolbox(EuvChartToolbox::full().magic_type(false))
493 .add_series(EuvChartSeries::new(
494 SER_FLOW,
495 EuvChartSeriesData::Sankey(EuvChartSankeySeries::new(
496 vec![
497 EuvChartSankeyNode::new(SER_ORGANIC),
498 EuvChartSankeyNode::new(SK_PAID_ADS),
499 EuvChartSankeyNode::new(SK_LANDING),
500 EuvChartSankeyNode::new(SK_TRIAL),
501 EuvChartSankeyNode::new(SK_SIGNUP),
502 EuvChartSankeyNode::new(SK_ENTERPRISE),
503 ],
504 vec![
505 EuvChartSankeyLink::new(SER_ORGANIC.to_string(), SK_LANDING.to_string(), 64.0),
506 EuvChartSankeyLink::new(SK_PAID_ADS.to_string(), SK_LANDING.to_string(), 36.0),
507 EuvChartSankeyLink::new(SK_LANDING.to_string(), SK_TRIAL.to_string(), 58.0),
508 EuvChartSankeyLink::new(SK_LANDING.to_string(), SK_SIGNUP.to_string(), 32.0),
509 EuvChartSankeyLink::new(SK_TRIAL.to_string(), SK_ENTERPRISE.to_string(), 28.0),
510 EuvChartSankeyLink::new(SK_SIGNUP.to_string(), SK_ENTERPRISE.to_string(), 18.0),
511 ],
512 )),
513 ))
514}
515
516fn build_funnel_option() -> EuvChartOption {
522 EuvChartOption::new()
523 .title(EuvChartTitle::new(TITLE_FUNNEL_CHART))
524 .tooltip(EuvChartTooltip::item())
525 .toolbox(EuvChartToolbox::full().magic_type(false))
526 .add_series(EuvChartSeries::new(
527 SER_CONVERSION,
528 EuvChartSeriesData::Funnel(
529 EuvChartFunnelSeries::new(vec![
530 EuvChartFunnelStage::new(FN_VISIT, 100.0),
531 EuvChartFunnelStage::new(FN_EXPLORE, 74.0),
532 EuvChartFunnelStage::new(FN_EVAL, 48.0),
533 EuvChartFunnelStage::new(FN_ADOPT, 26.0),
534 ])
535 .sort(EuvChartFunnelSort::Descending),
536 ),
537 ))
538}
539
540fn build_graph_option(layout: EuvChartGraphLayout) -> EuvChartOption {
550 EuvChartOption::new()
551 .title(EuvChartTitle::new(TITLE_GRAPH_CHART))
552 .tooltip(EuvChartTooltip::item())
553 .toolbox(EuvChartToolbox::full().magic_type(false))
554 .add_series(EuvChartSeries::new(
555 SER_CLUSTER,
556 EuvChartSeriesData::Graph(
557 EuvChartGraphSeries::new(
558 vec![
559 EuvChartGraphNode::new("gw", GR_GATEWAY, 13.0, 0),
560 EuvChartGraphNode::new("au", GR_AUTH, 10.0, 1),
561 EuvChartGraphNode::new("ca", GR_CACHE, 10.0, 1),
562 EuvChartGraphNode::new("wk", GR_WORKER, 11.0, 2),
563 EuvChartGraphNode::new("db", GR_STORAGE, 12.0, 2),
564 EuvChartGraphNode::new("mt", GR_METRICS, 9.0, 3),
565 ],
566 vec![
567 EuvChartGraphEdge::new("gw", "au"),
568 EuvChartGraphEdge::new("gw", "ca"),
569 EuvChartGraphEdge::new("gw", "wk"),
570 EuvChartGraphEdge::new("au", "db"),
571 EuvChartGraphEdge::new("wk", "db"),
572 EuvChartGraphEdge::new("wk", "mt").curveness(0.15),
573 EuvChartGraphEdge::new("ca", "mt").curveness(0.0),
574 ],
575 )
576 .layout(layout),
577 ),
578 ))
579}
580
581fn build_tree_option(layout: EuvChartTreeLayout) -> EuvChartOption {
591 EuvChartOption::new()
592 .title(EuvChartTitle::new(TITLE_TREE_CHART))
593 .tooltip(EuvChartTooltip::item())
594 .toolbox(EuvChartToolbox::full().magic_type(false))
595 .add_series(EuvChartSeries::new(
596 SER_SCENE_TREE,
597 EuvChartSeriesData::Tree(
598 EuvChartTreeSeries::new(EuvChartHierarchyNode::branch(
599 TR_ROOT,
600 vec![
601 EuvChartHierarchyNode::branch(
602 TR_SHELL,
603 vec![
604 EuvChartHierarchyNode::leaf(TR_SIDEBAR, 1.0),
605 EuvChartHierarchyNode::leaf(TR_OUTLET, 1.0),
606 ],
607 ),
608 EuvChartHierarchyNode::branch(
609 TR_PORTAL,
610 vec![
611 EuvChartHierarchyNode::leaf(TR_FULLSCREEN, 1.0),
612 EuvChartHierarchyNode::leaf(TR_TOOLTIP, 1.0),
613 ],
614 ),
615 ],
616 ))
617 .layout(layout),
618 ),
619 ))
620}
621
622fn build_geo_lines_option() -> EuvChartOption {
628 EuvChartOption::new()
629 .title(EuvChartTitle::new(TITLE_GEO_CHART))
630 .tooltip(EuvChartTooltip::item())
631 .toolbox(EuvChartToolbox::full().magic_type(false))
632 .geo(EuvChartGeo::world())
633 .visual_map(EuvChartVisualMap::continuous(0.0, 100.0))
634 .add_series(EuvChartSeries::new(
635 SER_USERS,
636 EuvChartSeriesData::GeoMap(EuvChartGeoMapSeries::new(vec![
637 EuvChartGeoDatum::new(GEO_CHINA, 96.0),
638 EuvChartGeoDatum::new(GEO_USA, 90.0),
639 EuvChartGeoDatum::new(GEO_EUROPE, 82.0),
640 EuvChartGeoDatum::new(GEO_INDIA, 74.0),
641 EuvChartGeoDatum::new(GEO_BRAZIL, 58.0),
642 EuvChartGeoDatum::new(GEO_AUSTRALIA, 64.0),
643 ])),
644 ))
645 .add_series(EuvChartSeries::new(
646 SER_EDGE_ROUTES,
647 EuvChartSeriesData::Lines(
648 EuvChartLinesSeries::new(vec![
649 EuvChartFlowArc::new("SFO", "SHA", (-122.4, 37.7), (121.4, 31.2), 92.0),
650 EuvChartFlowArc::new("FRA", "SHA", (8.6, 50.1), (121.4, 31.2), 78.0),
651 EuvChartFlowArc::new("SFO", "FRA", (-122.4, 37.7), (8.6, 50.1), 84.0),
652 EuvChartFlowArc::new("SHA", "SYD", (121.4, 31.2), (151.2, -33.8), 64.0),
653 ])
654 .coordinate_system(EuvChartCoordinateSystem::Geo),
655 ),
656 ))
657 .add_series(EuvChartSeries::new(
658 SER_EDGE_HUBS,
659 EuvChartSeriesData::EffectScatter(
660 EuvChartScatterSeries::new(vec![
661 EuvChartScatterPoint::new(121.4, 31.2)
662 .size(6.0)
663 .label("SHA"),
664 EuvChartScatterPoint::new(-122.4, 37.7)
665 .size(6.0)
666 .label("SFO"),
667 EuvChartScatterPoint::new(8.6, 50.1).size(5.5).label("FRA"),
668 EuvChartScatterPoint::new(151.2, -33.8)
669 .size(5.5)
670 .label("SYD"),
671 ])
672 .coordinate_system(EuvChartCoordinateSystem::Geo)
673 .show_labels(true),
674 ),
675 ))
676}
677
678fn build_parallel_option() -> EuvChartOption {
684 EuvChartOption::new()
685 .title(EuvChartTitle::new(TITLE_PARALLEL_CHART))
686 .tooltip(EuvChartTooltip::item())
687 .toolbox(EuvChartToolbox::full().magic_type(false))
688 .add_series(EuvChartSeries::new(
689 SER_BENCHMARKS,
690 EuvChartSeriesData::Parallel(EuvChartParallelSeries::new(
691 vec![
692 EuvChartParallelAxis::new(AX_TTFF).range(0.0, 120.0),
693 EuvChartParallelAxis::new(IND_FPS).range(0.0, 120.0),
694 EuvChartParallelAxis::new(AX_RAM).range(0.0, 256.0),
695 EuvChartParallelAxis::new(AX_SCORE).range(0.0, 100.0),
696 ],
697 vec![
698 EuvChartParallelRow::new(ITEM_EUV_NATIVE, vec![12.0, 120.0, 24.0, 97.0], 0),
699 EuvChartParallelRow::new(ITEM_FLUTTER, vec![38.0, 90.0, 92.0, 78.0], 1),
700 EuvChartParallelRow::new(ITEM_WEBVIEW, vec![94.0, 58.0, 210.0, 48.0], 2),
701 ],
702 )),
703 ))
704}
705
706fn build_themeriver_option() -> EuvChartOption {
712 EuvChartOption::new()
713 .title(EuvChartTitle::new(TITLE_RIVER_CHART))
714 .tooltip(EuvChartTooltip::item())
715 .toolbox(EuvChartToolbox::full().magic_type(false))
716 .add_series(EuvChartSeries::new(
717 SER_STREAMS,
718 EuvChartSeriesData::ThemeRiver(EuvChartThemeRiverSeries::new(vec![
719 EuvChartThemeRiverPoint::new(1.0, 14.0, STREAM_RUST.to_string()),
720 EuvChartThemeRiverPoint::new(2.0, 22.0, STREAM_RUST.to_string()),
721 EuvChartThemeRiverPoint::new(3.0, 32.0, STREAM_RUST.to_string()),
722 EuvChartThemeRiverPoint::new(4.0, 40.0, STREAM_RUST.to_string()),
723 EuvChartThemeRiverPoint::new(1.0, 18.0, STREAM_WASM.to_string()),
724 EuvChartThemeRiverPoint::new(2.0, 24.0, STREAM_WASM.to_string()),
725 EuvChartThemeRiverPoint::new(3.0, 20.0, STREAM_WASM.to_string()),
726 EuvChartThemeRiverPoint::new(4.0, 28.0, STREAM_WASM.to_string()),
727 EuvChartThemeRiverPoint::new(1.0, 12.0, STREAM_MOBILE.to_string()),
728 EuvChartThemeRiverPoint::new(2.0, 19.0, STREAM_MOBILE.to_string()),
729 EuvChartThemeRiverPoint::new(3.0, 29.0, STREAM_MOBILE.to_string()),
730 EuvChartThemeRiverPoint::new(4.0, 36.0, STREAM_MOBILE.to_string()),
731 ])),
732 ))
733}
734
735fn build_pictorial_custom_option() -> EuvChartOption {
741 let paint_target = move |rect: Rect, ctx: &EuvChartCustomDrawContext, dl: &mut DisplayList| {
742 let cx: f32 = rect.get_x() + rect.get_width() * 0.5;
743 let cy: f32 = rect.get_y() + 6.0;
744 let col: Color = ctx
745 .get_palette()
746 .get(1)
747 .copied()
748 .unwrap_or_else(|| ctx.get_tokens().get_palette().get_primary());
749 dl.push(DrawCommand::Line {
750 from: Point::new(cx - 12.0, cy),
751 to: Point::new(cx + 12.0, cy),
752 color: col,
753 width: 2.0,
754 });
755 dl.push(DrawCommand::Circle {
756 center: Point::new(cx, cy),
757 radius: 4.5,
758 color: col,
759 });
760 };
761 EuvChartOption::new()
762 .title(EuvChartTitle::new(TITLE_PIC_CUSTOM_CHART))
763 .legend(EuvChartLegend::at(EuvChartPosition::Top))
764 .tooltip(EuvChartTooltip::axis(EuvChartAxisPointerType::Line))
765 .toolbox(EuvChartToolbox::full().magic_type(false))
766 .x_axis(EuvChartAxis::category(owned_labels(&TIERS_FOUR)))
767 .y_axis(EuvChartAxis::value().max(100.0))
768 .add_series(EuvChartSeries::new(
769 SER_CAPSULES,
770 EuvChartSeriesData::PictorialBar(EuvChartPictorialBarSeries::new(
771 vec![46.0, 78.0, 64.0, 92.0],
772 EuvChartSymbol::RoundRect,
773 )),
774 ))
775 .add_series(EuvChartSeries::new(
776 SER_CUSTOM_TARGET,
777 EuvChartSeriesData::Custom(EuvChartCustomSeries::new(
778 vec![55.0, 82.0, 74.0, 95.0],
779 paint_target,
780 )),
781 ))
782}
783
784fn build_static_chart_card(
799 title: &'static str,
800 subtitle: &'static str,
801 option: EuvChartOption,
802 height: f32,
803 tokens: ThemeTokens,
804 event_log: Signal<String>,
805) -> NodeId {
806 let hit_log: Signal<String> = event_log;
807 let on_hit: EuvChartHitCallback = Rc::new(move |hit: &EuvChartDatumHit| {
808 let msg: String = format!(
809 "Clicked {} [{}] = {:.1}",
810 hit.get_series_name(),
811 hit.get_category_label(),
812 hit.get_value()
813 );
814 let _: bool = hit_log.set_if_changed(msg);
815 });
816 let leg_log: Signal<String> = event_log;
817 let on_legend: EuvChartLegendCallback = Rc::new(move |name: &str, visible: bool| {
818 let msg: String = format!("Legend {name}: visible={visible}");
819 let _: bool = leg_log.set_if_changed(msg);
820 });
821 let zoom_log: Signal<String> = event_log;
822 let on_zoom: Rc<dyn Fn(f32, f32)> = Rc::new(move |start_pct: f32, end_pct: f32| {
823 let msg: String = format!("DataZoom range: {start_pct:.0}% .. {end_pct:.0}%");
824 let _: bool = zoom_log.set_if_changed(msg);
825 });
826 view! {
827 EuvCard {
828 title: title.to_string()
829 tokens: tokens
830 subtitle: subtitle
831 EuvEChart {
832 option: option
833 tokens: tokens
834 style: {
835 width: Length::Percent(100.0)
836 height: Length::Px(height)
837 }
838 on_point_click: on_hit
839 on_legend_change: on_legend
840 on_zoom_change: on_zoom
841 }
842 }
843 }
844}
845
846fn build_graph_card(tokens: ThemeTokens, event_log: Signal<String>) -> NodeId {
857 let opt_sig: Signal<EuvChartOption> =
858 Signal::new(build_graph_option(EuvChartGraphLayout::Force));
859 let active_idx: Signal<usize> = Signal::new(0);
860 let hit_log: Signal<String> = event_log;
861 let on_hit: EuvChartHitCallback = Rc::new(move |hit: &EuvChartDatumHit| {
862 let msg: String = format!(
863 "Clicked {} [{}] = {:.1}",
864 hit.get_series_name(),
865 hit.get_category_label(),
866 hit.get_value()
867 );
868 let _: bool = hit_log.set_if_changed(msg);
869 });
870 let build_toggle_bar = move || -> Vec<NodeId> {
871 let cur: usize = active_idx.get();
872 let on_force = move |_: &UiEvent| {
873 let _: bool = active_idx.set_if_changed(0);
874 let _: bool = opt_sig.set(build_graph_option(EuvChartGraphLayout::Force));
875 let _: bool = event_log.set_if_changed(BTN_GRAPH_FORCE.to_string());
876 };
877 let on_circular = move |_: &UiEvent| {
878 let _: bool = active_idx.set_if_changed(1);
879 let _: bool = opt_sig.set(build_graph_option(EuvChartGraphLayout::Circular));
880 let _: bool = event_log.set_if_changed(BTN_GRAPH_CIRCULAR.to_string());
881 };
882 let v_force: EuvButtonVariant = if cur == 0 {
883 EuvButtonVariant::Primary
884 } else {
885 EuvButtonVariant::Outline
886 };
887 let v_circ: EuvButtonVariant = if cur == 1 {
888 EuvButtonVariant::Primary
889 } else {
890 EuvButtonVariant::Outline
891 };
892 vec![view! {
893 EuvActionRow {
894 EuvButton {
895 label: BTN_GRAPH_FORCE.to_string()
896 variant: v_force
897 tokens: tokens
898 sm()
899 on_click: on_force
900 }
901 EuvButton {
902 label: BTN_GRAPH_CIRCULAR.to_string()
903 variant: v_circ
904 tokens: tokens
905 sm()
906 on_click: on_circular
907 }
908 }
909 }]
910 };
911 view! {
912 EuvCard {
913 title: CARD_GRAPH_TITLE.to_string()
914 tokens: tokens
915 subtitle: CARD_GRAPH_SUB
916 column {
917 style: {
918 width: Length::Percent(100.0)
919 }
920 bind_children: build_toggle_bar
921 }
922 EuvEChart {
923 option_signal: opt_sig
924 tokens: tokens
925 style: {
926 width: Length::Percent(100.0)
927 height: Length::Px(CHART_CARD_TALL_HEIGHT)
928 }
929 on_point_click: on_hit
930 }
931 }
932 }
933}
934
935fn build_tree_card(tokens: ThemeTokens, event_log: Signal<String>) -> NodeId {
946 let opt_sig: Signal<EuvChartOption> =
947 Signal::new(build_tree_option(EuvChartTreeLayout::OrthogonalLeftRight));
948 let active_idx: Signal<usize> = Signal::new(0);
949 let hit_log: Signal<String> = event_log;
950 let on_hit: EuvChartHitCallback = Rc::new(move |hit: &EuvChartDatumHit| {
951 let msg: String = format!(
952 "Clicked {} [{}] = {:.1}",
953 hit.get_series_name(),
954 hit.get_category_label(),
955 hit.get_value()
956 );
957 let _: bool = hit_log.set_if_changed(msg);
958 });
959 let build_toggle_bar = move || -> Vec<NodeId> {
960 let cur: usize = active_idx.get();
961 let on_ortho = move |_: &UiEvent| {
962 let _: bool = active_idx.set_if_changed(0);
963 let _: bool = opt_sig.set(build_tree_option(EuvChartTreeLayout::OrthogonalLeftRight));
964 let _: bool = event_log.set_if_changed(BTN_TREE_ORTHO.to_string());
965 };
966 let on_radial = move |_: &UiEvent| {
967 let _: bool = active_idx.set_if_changed(1);
968 let _: bool = opt_sig.set(build_tree_option(EuvChartTreeLayout::Radial));
969 let _: bool = event_log.set_if_changed(BTN_TREE_RADIAL.to_string());
970 };
971 let v_ortho: EuvButtonVariant = if cur == 0 {
972 EuvButtonVariant::Primary
973 } else {
974 EuvButtonVariant::Outline
975 };
976 let v_radial: EuvButtonVariant = if cur == 1 {
977 EuvButtonVariant::Primary
978 } else {
979 EuvButtonVariant::Outline
980 };
981 vec![view! {
982 EuvActionRow {
983 EuvButton {
984 label: BTN_TREE_ORTHO.to_string()
985 variant: v_ortho
986 tokens: tokens
987 sm()
988 on_click: on_ortho
989 }
990 EuvButton {
991 label: BTN_TREE_RADIAL.to_string()
992 variant: v_radial
993 tokens: tokens
994 sm()
995 on_click: on_radial
996 }
997 }
998 }]
999 };
1000 view! {
1001 EuvCard {
1002 title: CARD_TREE_TITLE.to_string()
1003 tokens: tokens
1004 subtitle: CARD_TREE_SUB
1005 column {
1006 style: {
1007 width: Length::Percent(100.0)
1008 }
1009 bind_children: build_toggle_bar
1010 }
1011 EuvEChart {
1012 option_signal: opt_sig
1013 tokens: tokens
1014 style: {
1015 width: Length::Percent(100.0)
1016 height: Length::Px(CHART_CARD_TALL_HEIGHT)
1017 }
1018 on_point_click: on_hit
1019 }
1020 }
1021 }
1022}
1023
1024fn build_category_filter_row(cat_sig: Signal<usize>, tokens: ThemeTokens) -> NodeId {
1035 let active_idx: usize = cat_sig.get();
1036 let cats: [(usize, &'static str); 6] = [
1037 (0, CHARTS_CAT_ALL),
1038 (1, CHARTS_CAT_CARTESIAN),
1039 (2, CHARTS_CAT_FINANCIAL),
1040 (3, CHARTS_CAT_RADIAL),
1041 (4, CHARTS_CAT_HIERARCHY),
1042 (5, CHARTS_CAT_GEO_FLOW),
1043 ];
1044 let mut row: EuvActionRow = EuvActionRow::default();
1045 for (idx, label) in cats.into_iter() {
1046 let on_pick = move |_: &UiEvent| {
1047 let _: bool = cat_sig.set_if_changed(idx);
1048 };
1049 let btn: NodeId = if active_idx == idx {
1050 view! {
1051 EuvButton {
1052 label: label.to_string()
1053 tokens: tokens
1054 sm()
1055 on_click: on_pick
1056 }
1057 }
1058 } else {
1059 view! {
1060 EuvButton {
1061 label: label.to_string()
1062 tokens: tokens
1063 outline()
1064 sm()
1065 on_click: on_pick
1066 }
1067 }
1068 };
1069 row = row.child(btn);
1070 }
1071 row.mount()
1072}
1073
1074fn build_filtered_chart_cards(
1086 cat_idx: usize,
1087 tokens: ThemeTokens,
1088 event_log: Signal<String>,
1089) -> Vec<NodeId> {
1090 let mut cards: Vec<NodeId> = Vec::with_capacity(21);
1091 if cat_idx == 0 || cat_idx == 1 {
1092 cards.push(build_static_chart_card(
1093 CARD_LINE_TITLE,
1094 CARD_LINE_SUB,
1095 build_line_option(),
1096 CHART_CARD_TALL_HEIGHT,
1097 tokens,
1098 event_log,
1099 ));
1100 cards.push(build_static_chart_card(
1101 CARD_BAR_TITLE,
1102 CARD_BAR_SUB,
1103 build_bar_dataset_option(),
1104 CHART_CARD_HEIGHT,
1105 tokens,
1106 event_log,
1107 ));
1108 cards.push(build_static_chart_card(
1109 CARD_HBAR_TITLE,
1110 CARD_HBAR_SUB,
1111 build_horizontal_bar_option(),
1112 CHART_CARD_HEIGHT,
1113 tokens,
1114 event_log,
1115 ));
1116 cards.push(build_static_chart_card(
1117 CARD_SCATTER_TITLE,
1118 CARD_SCATTER_SUB,
1119 build_scatter_option(),
1120 CHART_CARD_HEIGHT,
1121 tokens,
1122 event_log,
1123 ));
1124 }
1125 if cat_idx == 0 || cat_idx == 2 {
1126 cards.push(build_static_chart_card(
1127 CARD_CANDLE_TITLE,
1128 CARD_CANDLE_SUB,
1129 build_candlestick_option(),
1130 CHART_CARD_TALL_HEIGHT,
1131 tokens,
1132 event_log,
1133 ));
1134 cards.push(build_static_chart_card(
1135 CARD_BOXPLOT_TITLE,
1136 CARD_BOXPLOT_SUB,
1137 build_boxplot_option(),
1138 CHART_CARD_HEIGHT,
1139 tokens,
1140 event_log,
1141 ));
1142 cards.push(build_static_chart_card(
1143 CARD_HEATMAP_TITLE,
1144 CARD_HEATMAP_SUB,
1145 build_heatmap_option(),
1146 CHART_CARD_HEIGHT,
1147 tokens,
1148 event_log,
1149 ));
1150 cards.push(build_static_chart_card(
1151 CARD_CALENDAR_TITLE,
1152 CARD_CALENDAR_SUB,
1153 build_calendar_heatmap_option(),
1154 CHART_CARD_HEIGHT,
1155 tokens,
1156 event_log,
1157 ));
1158 }
1159 if cat_idx == 0 || cat_idx == 3 {
1160 cards.push(build_static_chart_card(
1161 CARD_PIE_TITLE,
1162 CARD_PIE_SUB,
1163 build_pie_option(),
1164 CHART_CARD_TALL_HEIGHT,
1165 tokens,
1166 event_log,
1167 ));
1168 cards.push(build_static_chart_card(
1169 CARD_RADAR_TITLE,
1170 CARD_RADAR_SUB,
1171 build_radar_option(),
1172 CHART_CARD_HEIGHT,
1173 tokens,
1174 event_log,
1175 ));
1176 cards.push(build_static_chart_card(
1177 CARD_GAUGE_TITLE,
1178 CARD_GAUGE_SUB,
1179 build_gauge_option(),
1180 CHART_CARD_HEIGHT,
1181 tokens,
1182 event_log,
1183 ));
1184 }
1185 if cat_idx == 0 || cat_idx == 4 {
1186 cards.push(build_static_chart_card(
1187 CARD_TREEMAP_TITLE,
1188 CARD_TREEMAP_SUB,
1189 build_treemap_option(),
1190 CHART_CARD_HEIGHT,
1191 tokens,
1192 event_log,
1193 ));
1194 cards.push(build_static_chart_card(
1195 CARD_SUNBURST_TITLE,
1196 CARD_SUNBURST_SUB,
1197 build_sunburst_option(),
1198 CHART_CARD_TALL_HEIGHT,
1199 tokens,
1200 event_log,
1201 ));
1202 cards.push(build_static_chart_card(
1203 CARD_SANKEY_TITLE,
1204 CARD_SANKEY_SUB,
1205 build_sankey_option(),
1206 CHART_CARD_HEIGHT,
1207 tokens,
1208 event_log,
1209 ));
1210 cards.push(build_static_chart_card(
1211 CARD_FUNNEL_TITLE,
1212 CARD_FUNNEL_SUB,
1213 build_funnel_option(),
1214 CHART_CARD_HEIGHT,
1215 tokens,
1216 event_log,
1217 ));
1218 cards.push(build_graph_card(tokens, event_log));
1219 cards.push(build_tree_card(tokens, event_log));
1220 }
1221 if cat_idx == 0 || cat_idx == 5 {
1222 cards.push(build_static_chart_card(
1223 CARD_GEO_TITLE,
1224 CARD_GEO_SUB,
1225 build_geo_lines_option(),
1226 CHART_CARD_TALL_HEIGHT,
1227 tokens,
1228 event_log,
1229 ));
1230 cards.push(build_static_chart_card(
1231 CARD_PARALLEL_TITLE,
1232 CARD_PARALLEL_SUB,
1233 build_parallel_option(),
1234 CHART_CARD_HEIGHT,
1235 tokens,
1236 event_log,
1237 ));
1238 cards.push(build_static_chart_card(
1239 CARD_RIVER_TITLE,
1240 CARD_RIVER_SUB,
1241 build_themeriver_option(),
1242 CHART_CARD_HEIGHT,
1243 tokens,
1244 event_log,
1245 ));
1246 cards.push(build_static_chart_card(
1247 CARD_PIC_CUSTOM_TITLE,
1248 CARD_PIC_CUSTOM_SUB,
1249 build_pictorial_custom_option(),
1250 CHART_CARD_HEIGHT,
1251 tokens,
1252 event_log,
1253 ));
1254 }
1255 cards
1256}
1257
1258pub fn mount_charts_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
1269 state.ensure_charts_loaded();
1270 let cat_sig: Signal<usize> = state.get_charts_category_idx();
1271 let event_log: Signal<String> = state.get_charts_event_log();
1272 let build_filter_bar = move || -> Vec<NodeId> {
1273 let live_tok: ThemeTokens = live_tokens_untracked(tokens);
1274 vec![build_category_filter_row(cat_sig, live_tok)]
1275 };
1276 let status_text = move || -> String { event_log.get() };
1277 let status_style = move || -> Style {
1278 let live: ThemeTokens = use_live_tokens(tokens);
1279 Style::default()
1280 .width(Length::Percent(100.0))
1281 .font_size(12.5)
1282 .font_weight(FontWeight::Medium)
1283 .color(live.get_palette().get_primary())
1284 };
1285 let build_gallery = move || -> Vec<NodeId> {
1286 let cat_idx: usize = cat_sig.get();
1287 let live_tok: ThemeTokens = live_tokens_untracked(tokens);
1288 let cards: Vec<NodeId> = build_filtered_chart_cards(cat_idx, live_tok, event_log);
1289 vec![mount_responsive_grid(cards, CHARTS_GRID_MAX_COLS)]
1290 };
1291 view! {
1292 EuvPage {
1293 title: CHARTS_PAGE_TITLE.to_string()
1294 subtitle: CHARTS_PAGE_SUBTITLE.to_string()
1295 tokens: tokens
1296 EuvCard {
1297 title: CHARTS_FILTER_TITLE.to_string()
1298 tokens: tokens
1299 subtitle: CHARTS_FILTER_SUBTITLE
1300 column {
1301 style: {
1302 width: Length::Percent(100.0)
1303 }
1304 bind_children: build_filter_bar
1305 }
1306 text {
1307 bind_style: status_style
1308 { status_text }
1309 }
1310 }
1311 column {
1312 style: {
1313 width: Length::Percent(100.0)
1314 gap: SPACE_MD
1315 }
1316 bind_children: build_gallery
1317 }
1318 }
1319 }
1320}