-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_test_data.sh
More file actions
executable file
·1704 lines (1479 loc) · 59.3 KB
/
setup_test_data.sh
File metadata and controls
executable file
·1704 lines (1479 loc) · 59.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
set -euo pipefail
# =============================================================================
# setup_test_data.sh — Generate comprehensive showcase for GGRS Plot Operator.
#
# Creates a Tercen project, uploads test data, configures multiple scenarios
# (scatter, line, bar, heatmap × color variants × themes × backends),
# renders all combinations, and produces an interactive showcase.html.
#
# Usage: ./setup_test_data.sh
#
# Environment:
# TERCEN_URI Tercen REST URI (default: http://127.0.0.1:5400)
# TERCEN_GRPC_URI gRPC URI (default: http://127.0.0.1:50051)
# TERCEN_USER Username (default: test)
# TERCEN_PASSWORD Password (default: test)
# =============================================================================
TERCEN_URI="${TERCEN_URI:-http://127.0.0.1:5400}"
TERCEN_GRPC_URI="${TERCEN_GRPC_URI:-http://127.0.0.1:50051}"
TERCEN_USER="${TERCEN_USER:-test}"
TERCEN_PASSWORD="${TERCEN_PASSWORD:-test}"
OPERATOR_ID="b1bd09be60002836389b3285f21d3bcd"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PREPARE_BIN="${SCRIPT_DIR}/target/dev-release/prepare"
DEV_BIN="${SCRIPT_DIR}/target/dev-release/dev"
OUTPUT_DIR="${SCRIPT_DIR}/showcase_output"
SHOWCASE_HTML="${SCRIPT_DIR}/showcase.html"
THEMES=(gray bw light dark minimal classic linedraw void publish)
HEATMAP_PALETTES=(Spectral Jet Viridis Hot Cool RdBu YlGnBu)
# Backends: override with SHOWCASE_BACKENDS env var (e.g., "cpu" for CI without GPU)
if [[ -n "${SHOWCASE_BACKENDS:-}" ]]; then
IFS=' ' read -ra BACKENDS <<< "$SHOWCASE_BACKENDS"
else
BACKENDS=(cpu gpu)
fi
# Axis transforms (currently only log, asinh, logicle are selectable in the Tercen UI)
TRANSFORMS=(none log asinh logicle)
# Toggle flags: text.disable, axis.lines.disable, grid.major.disable, grid.minor.disable
# Encoded as 4-digit binary suffix, e.g., _0000 = all shown, _1010 = text+major grid disabled
FLAGS_COMBOS=()
for t in 0 1; do for a in 0 1; do for gm in 0 1; do for gn in 0 1; do
FLAGS_COMBOS+=("${t}${a}${gm}${gn}")
done; done; done; done
# Associative array: scenario_name → step_id
declare -A SCENARIO_STEPS
# ============================================================================
# Helpers
# ============================================================================
json_field() {
grep "\"$1\"" | head -1 | sed 's/.*"'"$1"'"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/'
}
grpc_token() {
tercenctl user create-token --validity 1h -f json 2>/dev/null | tr -d '"'
}
# ============================================================================
# 1. Check / install tercenctl
# ============================================================================
check_tercenctl() {
if command -v tercenctl &>/dev/null; then
echo "[OK] tercenctl found"
return 0
fi
local candidates=(
"${SCRIPT_DIR}/../sci/sci_ctl/tercenctl"
"${SCRIPT_DIR}/../../sci/sci_ctl/tercenctl"
"${HOME}/.local/bin/tercenctl"
"/usr/local/bin/tercenctl"
)
local found=""
for candidate in "${candidates[@]}"; do
if [[ -x "$candidate" ]]; then
found="$(cd "$(dirname "$candidate")" && pwd)/$(basename "$candidate")"
break
fi
done
if [[ -z "$found" ]]; then
echo "[ERROR] tercenctl not found. Install it or add to PATH."
exit 1
fi
local INSTALL_DIR="${HOME}/.local/bin"
mkdir -p "$INSTALL_DIR"
ln -sf "$found" "${INSTALL_DIR}/tercenctl"
if command -v tercenctl &>/dev/null; then
echo "[OK] tercenctl linked from $found"
else
echo "[ERROR] ${INSTALL_DIR} is not in PATH"
exit 1
fi
}
# ============================================================================
# 2. Ensure tercenctl context
# ============================================================================
ensure_context() {
local current
current=$(tercenctl context current 2>&1 || true)
if echo "$current" | grep -q "No current context"; then
tercenctl context add -n local -u "$TERCEN_URI" \
--username "$TERCEN_USER" -p "$TERCEN_PASSWORD" --set-current
echo "[OK] Context 'local' created"
else
echo "[OK] Using existing context"
fi
if ! tercenctl user whoami &>/dev/null; then
echo "[ERROR] Authentication failed"
exit 1
fi
echo "[OK] Authenticated as $(tercenctl user whoami -f json 2>/dev/null | json_field 'name')"
}
# ============================================================================
# 3. Generate test CSV
# ============================================================================
generate_csv() {
local csv_path="$1"
awk 'BEGIN {
split("alpha,beta,gamma,delta", cat1, ",")
split("red,green,blue,yellow", cat2, ",")
split("small,medium,large,tiny,huge,normal", cat3, ",")
# Per-CAT1 Y offsets: separates scatter/line groups visually
y_off[1] = -6; y_off[2] = -2; y_off[3] = 2; y_off[4] = 6
# Per-CAT1 slopes: each category has a different trend
y_slope[1] = 0.3; y_slope[2] = 0.6; y_slope[3] = -0.2; y_slope[4] = 0.8
# Distinct base means for each CAT1 x CAT2 cell (4x4 = 16 cells)
# Spread across 0-100 range so heatmap shows clear structure
base[1,1]=15; base[1,2]=85; base[1,3]=40; base[1,4]=60
base[2,1]=70; base[2,2]=25; base[2,3]=90; base[2,4]=50
base[3,1]=45; base[3,2]=55; base[3,3]=10; base[3,4]=75
base[4,1]=80; base[4,2]=35; base[4,3]=65; base[4,4]=20
print "x,y,heatval,CAT1,CAT2,CAT3,x_log,y_log,x_asinh,y_asinh,x_logicle,y_logicle"
for (i = 1; i <= 5000; i++) {
srand(i * 7 + 3)
x = (rand() * 20) - 10
c1_idx = ((i - 1) % 4) + 1
c2_idx = (int((i - 1) / 4) % 4) + 1
c1 = cat1[c1_idx]
c2 = cat2[c2_idx]
c3 = cat3[(int((i - 1) / 16) % 6) + 1]
# y: category-dependent offset + slope + noise
srand(i * 13 + 7)
y = y_off[c1_idx] + (x * y_slope[c1_idx]) + (rand() * 4) - 2
# heatval: category-dependent mean + noise, clamped to [0, 100]
srand(i * 31 + 11)
hv = base[c1_idx, c2_idx] + (rand() * 16) - 8
if (hv < 0) hv = 0
if (hv > 100) hv = 100
# Pre-transformed columns for axis transform showcase
# Log: ln(value), non-positive values become NaN (skipped by GGRS)
x_log_s = (x > 0) ? sprintf("%.6f", log(x)) : ""
y_log_s = (y > 0) ? sprintf("%.6f", log(y)) : ""
# Asinh: handles negative values naturally
# asinh(v) = ln(v + sqrt(v^2 + 1))
x_asinh = log(x + sqrt(x*x + 1))
y_asinh = log(y + sqrt(y*y + 1))
# Logicle approximation: sign(v) * ln(1 + |v|)
# Similar to logicle: linear near zero, log-like for large |v|
ax = (x < 0) ? -x : x
ay = (y < 0) ? -y : y
sx = (x < 0) ? -1 : 1
sy = (y < 0) ? -1 : 1
x_logicle = sx * log(1 + ax)
y_logicle = sy * log(1 + ay)
printf "%.4f,%.4f,%.2f,%s,%s,%s,%s,%s,%.6f,%.6f,%.6f,%.6f\n", \
x, y, hv, c1, c2, c3, x_log_s, y_log_s, x_asinh, y_asinh, x_logicle, y_logicle
}
}' > "$csv_path"
echo "[OK] Generated 5000 rows"
}
# ============================================================================
# 4. Create project and upload data
# ============================================================================
create_project_and_upload() {
local DATE_TAG
DATE_TAG=$(date +%Y%m%d_%H%M%S)
PROJECT_NAME="showcase_${DATE_TAG}"
echo "[INFO] Creating project '${PROJECT_NAME}'..."
local proj_output
proj_output=$(tercenctl project create -n "$PROJECT_NAME" -f json 2>/dev/null)
PROJECT_ID=$(echo "$proj_output" | json_field "id")
if [[ -z "$PROJECT_ID" ]]; then
echo "[ERROR] Failed to create project"; exit 1
fi
echo "[OK] Project: $PROJECT_ID"
local csv_tmp
csv_tmp=$(mktemp /tmp/plot_data_XXXXXX.csv)
trap "rm -f '$csv_tmp'" EXIT
generate_csv "$csv_tmp"
echo "[INFO] Uploading CSV..."
local upload_output
upload_output=$(tercenctl data upload-csv -p "$PROJECT_ID" --filePath "$csv_tmp" -n "plot_data" -f json 2>/dev/null)
SCHEMA_ID=$(echo "$upload_output" | json_field "id")
if [[ -z "$SCHEMA_ID" ]]; then
echo "[ERROR] Failed to upload CSV"; exit 1
fi
echo "[OK] Schema: $SCHEMA_ID"
}
# ============================================================================
# 5. Create workflow with table step
# ============================================================================
add_table_step() {
local wf_id="$1" schema_id="$2"
local ts_id="ts-$(uuidgen)"
local patch
patch=$(cat <<EOF
{
"kind": "PatchRecords", "oI": "$wf_id",
"rs": [{"kind": "PatchRecord", "p": "/steps",
"recordType": {"kind": "PatchRecordListAdd",
"value": [{"kind": "TypedObject", "value": {
"kind": "TableStep", "id": "$ts_id", "groupId": "", "name": "data",
"inputs": [],
"outputs": [{"kind": "OutputPort", "id": "${ts_id}-o-0", "linkType": "relation", "name": "table"}],
"rectangle": {"kind": "Rectangle",
"extent": {"kind": "Point", "x": 100, "y": 55},
"topLeft": {"kind": "Point", "x": 250, "y": 120}},
"state": {"kind": "StepState", "taskId": "", "taskState": {"kind": "DoneState"}},
"description": "",
"model": {"kind": "TableStepModel",
"relation": {"kind": "SimpleRelation", "id": "$schema_id", "index": 0},
"filterSelector": ""}
}}]}}]
}
EOF
)
tercenctl object patch -p "$patch" &>/dev/null || { echo "[ERROR] Failed to add TableStep"; exit 1; }
echo "$ts_id"
}
create_workflow() {
echo "[INFO] Creating workflow..."
local wf_output
wf_output=$(tercenctl workflow create -p "$PROJECT_ID" -n "showcase" -f json 2>/dev/null)
WORKFLOW_ID=$(echo "$wf_output" | json_field "id")
if [[ -z "$WORKFLOW_ID" ]]; then
echo "[ERROR] Failed to create workflow"; exit 1
fi
echo "[OK] Workflow: $WORKFLOW_ID"
TABLE_STEP_ID=$(add_table_step "$WORKFLOW_ID" "$SCHEMA_ID")
echo "[OK] TableStep: $TABLE_STEP_ID"
}
# ============================================================================
# 6. Patching functions
# ============================================================================
patch_factor() {
local wf_id="$1" step_id="$2" path="$3" factor_name="$4" factor_type="$5"
local patch
patch=$(cat <<EOF
{"kind": "PatchRecords", "oI": "$wf_id",
"rs": [{"kind": "PatchRecord", "p": "/steps/@[id=$step_id]/$path",
"recordType": {"kind": "PatchRecordSet",
"value": {"kind": "TypedObject",
"value": {"kind": "Factor", "name": "$factor_name", "type": "$factor_type"}}}}]}
EOF
)
tercenctl object patch -p "$patch" &>/dev/null
}
add_color_factor() {
local wf_id="$1" step_id="$2" factor_name="$3" factor_type="$4"
local patch
patch=$(cat <<EOF
{"kind": "PatchRecords", "oI": "$wf_id",
"rs": [{"kind": "PatchRecord",
"p": "/steps/@[id=$step_id]/model/axis/xyAxis/@0/colors/factors",
"recordType": {"kind": "PatchRecordListAdd",
"value": [{"kind": "TypedObject",
"value": {"kind": "Factor", "name": "$factor_name", "type": "$factor_type"}}]}}]}
EOF
)
tercenctl object patch -p "$patch" &>/dev/null
}
patch_ramp_palette() {
local wf_id="$1" step_id="$2" palette_name="$3"
local patch
patch=$(cat <<EOF
{"kind": "PatchRecords", "oI": "$wf_id",
"rs": [{"kind": "PatchRecord",
"p": "/steps/@[id=$step_id]/model/axis/xyAxis/@0/colors/palette",
"recordType": {"kind": "PatchRecordSet",
"value": {"kind": "TypedObject",
"value": {"kind": "RampPalette",
"backcolor": -1,
"isUserDefined": false,
"properties": [{"kind": "PropertyValue", "name": "name", "value": "$palette_name"}],
"doubleColorElements": [
{"kind": "DoubleColorElement", "color": -16776961, "stringValue": "0"},
{"kind": "DoubleColorElement", "color": -65536, "stringValue": "100"}
]}}}}]}
EOF
)
tercenctl object patch -p "$patch" &>/dev/null
}
patch_chart_type() {
local wf_id="$1" step_id="$2" chart_kind="$3"
local chart_value
case "$chart_kind" in
point) chart_value='{"kind": "ChartPoint", "pointSize": 4}' ;;
line) chart_value='{"kind": "ChartLine", "pointSize": 4}' ;;
bar) chart_value='{"kind": "ChartBar"}' ;;
heatmap) chart_value='{"kind": "ChartHeatmap"}' ;;
*) echo "[ERROR] Unknown chart kind: $chart_kind"; return 1 ;;
esac
local patch
patch=$(cat <<EOF
{"kind": "PatchRecords", "oI": "$wf_id",
"rs": [{"kind": "PatchRecord",
"p": "/steps/@[id=$step_id]/model/axis/xyAxis/@0/chart",
"recordType": {"kind": "PatchRecordSet",
"value": {"kind": "TypedObject", "value": $chart_value}}}]}
EOF
)
tercenctl object patch -p "$patch" &>/dev/null
}
# ============================================================================
# 7. Create and configure a scenario step
# ============================================================================
# Usage: create_scenario_step NAME CHART_KIND Y_COL Y_TYPE [X_COL X_TYPE] [COLOR_COL COLOR_TYPE]
# For heatmap: create_heatmap_step NAME Y_COL Y_TYPE ROW_FACTOR COL_FACTOR
create_scenario_step() {
local name="$1" chart_kind="$2"
local y_col="$3" y_type="$4"
local x_col="${5:-}" x_type="${6:-}"
local color_col="${7:-}" color_type="${8:-}"
echo -n " $name: "
# Add data step
local ds_output
ds_output=$(tercenctl step add -w "$WORKFLOW_ID" -t data -n "$name" \
--inputStepId "$TABLE_STEP_ID" -f json 2>/dev/null)
local step_id
step_id=$(echo "$ds_output" | json_field "id")
if [[ -z "$step_id" ]]; then
echo "FAILED (step add)"
return 1
fi
# Set Y axis
patch_factor "$WORKFLOW_ID" "$step_id" "model/axis/xyAxis/@0/yAxis/graphicalFactor/factor" "$y_col" "$y_type"
# Set X axis (if provided)
if [[ -n "$x_col" ]]; then
patch_factor "$WORKFLOW_ID" "$step_id" "model/axis/xyAxis/@0/xAxis/graphicalFactor/factor" "$x_col" "$x_type"
fi
# Set color (if provided)
if [[ -n "$color_col" ]]; then
add_color_factor "$WORKFLOW_ID" "$step_id" "$color_col" "$color_type"
fi
# Set chart type (default is point, so skip if point)
if [[ "$chart_kind" != "point" ]]; then
patch_chart_type "$WORKFLOW_ID" "$step_id" "$chart_kind"
fi
# Set operator
tercenctl step set-operator -w "$WORKFLOW_ID" -s "$step_id" -o "$OPERATOR_ID" &>/dev/null
SCENARIO_STEPS["$name"]="$step_id"
echo "OK ($step_id)"
}
create_heatmap_step() {
local name="$1"
local y_col="$2" y_type="$3"
local row_factor="$4" col_factor="$5"
echo -n " $name: "
local ds_output
ds_output=$(tercenctl step add -w "$WORKFLOW_ID" -t data -n "$name" \
--inputStepId "$TABLE_STEP_ID" -f json 2>/dev/null)
local step_id
step_id=$(echo "$ds_output" | json_field "id")
if [[ -z "$step_id" ]]; then
echo "FAILED (step add)"
return 1
fi
# Set Y axis
patch_factor "$WORKFLOW_ID" "$step_id" "model/axis/xyAxis/@0/yAxis/graphicalFactor/factor" "$y_col" "$y_type"
# Set row factor (on crosstab row table)
patch_factor "$WORKFLOW_ID" "$step_id" "model/rowTable/graphicalFactors/@0/factor" "$row_factor" "string"
# Set column factor (on crosstab column table)
patch_factor "$WORKFLOW_ID" "$step_id" "model/columnTable/graphicalFactors/@0/factor" "$col_factor" "string"
# Set chart type to heatmap
patch_chart_type "$WORKFLOW_ID" "$step_id" "heatmap"
# Set color factor (Y values) and palette for heatmap coloring
add_color_factor "$WORKFLOW_ID" "$step_id" "$y_col" "$y_type"
patch_ramp_palette "$WORKFLOW_ID" "$step_id" "Spectral"
# Set operator
tercenctl step set-operator -w "$WORKFLOW_ID" -s "$step_id" -o "$OPERATOR_ID" &>/dev/null
SCENARIO_STEPS["$name"]="$step_id"
echo "OK ($step_id)"
}
# ============================================================================
# 8. Prepare step (create CubeQueryTask)
# ============================================================================
build_binaries() {
echo "[INFO] Building binaries..."
cargo build --bin prepare --bin dev --profile dev-release \
--manifest-path "${SCRIPT_DIR}/Cargo.toml" 2>&1 | tail -2
}
prepare_step() {
local name="$1"
local step_id="${SCENARIO_STEPS[$name]}"
local token
token=$(grpc_token)
echo -n " $name: "
local output
output=$(TERCEN_URI="$TERCEN_GRPC_URI" TERCEN_TOKEN="$token" \
"$PREPARE_BIN" --workflow-id "$WORKFLOW_ID" --step-id "$step_id" 2>&1)
if echo "$output" | grep -q "Done!"; then
echo "OK"
elif echo "$output" | grep -q "Nothing to do"; then
echo "OK (cached)"
else
echo "FAILED"
echo "$output" | tail -3
return 1
fi
}
# ============================================================================
# 9. Render a single plot
# ============================================================================
render_plot() {
local name="$1" backend="$2" theme="$3" flags="$4"
local extra_json="${5:-}" # Optional extra JSON properties (comma-separated key:value pairs)
local step_id="${SCENARIO_STEPS[$name]}"
local output_path="${OUTPUT_DIR}/${name}_${backend}_${theme}_${flags}.png"
# Decode flags: T=text, A=axis, M=major grid, G=minor grid (1=disabled)
local text_dis="${flags:0:1}" axis_dis="${flags:1:1}" gmaj_dis="${flags:2:1}" gmin_dis="${flags:3:1}"
local text_val="false" axis_val="false" gmaj_val="false" gmin_val="false"
[[ "$text_dis" == "1" ]] && text_val="true"
[[ "$axis_dis" == "1" ]] && axis_val="true"
[[ "$gmaj_dis" == "1" ]] && gmaj_val="true"
[[ "$gmin_dis" == "1" ]] && gmin_val="true"
# Build extra properties block
local extra_block=""
if [[ -n "$extra_json" ]]; then
extra_block=",
$extra_json"
fi
local token
token=$(grpc_token)
cat > "${SCRIPT_DIR}/operator_config.json" <<EOF
{
"backend": "$backend",
"theme": "$theme",
"output.format": "png",
"plot.width": "800",
"plot.height": "600",
"png.compression": "fast",
"legend.position": "right",
"point.size.multiplier": "1",
"opacity": "1",
"text.disable": "$text_val",
"axis.lines.disable": "$axis_val",
"grid.major.disable": "$gmaj_val",
"grid.minor.disable": "$gmin_val"${extra_block}
}
EOF
(
cd "$SCRIPT_DIR"
TERCEN_URI="$TERCEN_GRPC_URI" TERCEN_TOKEN="$token" \
WORKFLOW_ID="$WORKFLOW_ID" STEP_ID="$step_id" \
"$DEV_BIN" >/dev/null 2>&1
)
if [[ -f "${SCRIPT_DIR}/plot.png" ]]; then
mv "${SCRIPT_DIR}/plot.png" "$output_path"
return 0
else
echo "[WARN] No output for ${name}_${backend}_${theme}_${flags}"
return 1
fi
}
render_scenario() {
local name="$1"
local count=0 total=$(( ${#BACKENDS[@]} * ${#THEMES[@]} ))
for backend in "${BACKENDS[@]}"; do
for theme in "${THEMES[@]}"; do
count=$((count + 1))
printf "\r $name: %d/%d" "$count" "$total"
render_plot "$name" "$backend" "$theme" "0000" || true
done
done
printf "\r $name: %d/%d OK\n" "$total" "$total"
}
render_heatmap_scenario() {
local name="$1"
local step_id="${SCENARIO_STEPS[$name]}"
local count=0 total=$(( ${#BACKENDS[@]} * ${#THEMES[@]} * ${#HEATMAP_PALETTES[@]} ))
for palette in "${HEATMAP_PALETTES[@]}"; do
# Re-patch the palette on the step before rendering this batch
patch_ramp_palette "$WORKFLOW_ID" "$step_id" "$palette"
for backend in "${BACKENDS[@]}"; do
for theme in "${THEMES[@]}"; do
count=$((count + 1))
printf "\r $name: %d/%d" "$count" "$total"
local output_path="${OUTPUT_DIR}/${name}_${backend}_${theme}_${palette}_0000.png"
local token
token=$(grpc_token)
cat > "${SCRIPT_DIR}/operator_config.json" <<EOF
{
"backend": "$backend",
"theme": "$theme",
"output.format": "png",
"plot.width": "800",
"plot.height": "600",
"png.compression": "fast",
"legend.position": "right",
"point.size.multiplier": "1",
"opacity": "1"
}
EOF
(
cd "$SCRIPT_DIR"
TERCEN_URI="$TERCEN_GRPC_URI" TERCEN_TOKEN="$token" \
WORKFLOW_ID="$WORKFLOW_ID" STEP_ID="$step_id" \
"$DEV_BIN" >/dev/null 2>&1
)
if [[ -f "${SCRIPT_DIR}/plot.png" ]]; then
mv "${SCRIPT_DIR}/plot.png" "$output_path"
else
echo "[WARN] No output for ${name}_${backend}_${theme}_${palette}"
fi
done
done
done
printf "\r $name: %d/%d OK\n" "$total" "$total"
}
# Extra properties for toggle renders: axis labels + plot title
TOGGLE_EXTRA='"plot.title": "Plot Title", "axis.x.label": "X Label", "axis.y.label": "Y Label"'
# Render toggle combinations for a single scenario (bw theme, cpu backend)
render_toggle_combos() {
local name="$1" backend="cpu" theme="bw"
local step_id="${SCENARIO_STEPS[$name]}"
local count=0 total=${#FLAGS_COMBOS[@]}
for flags in "${FLAGS_COMBOS[@]}"; do
count=$((count + 1))
printf "\r toggle_$name: %d/%d" "$count" "$total"
render_plot "$name" "$backend" "$theme" "$flags" "$TOGGLE_EXTRA" || true
done
printf "\r toggle_$name: %d/%d OK\n" "$total" "$total"
}
render_faceted() {
local name="$1"
local width="${2:-800}" height="${3:-600}"
local step_id="${SCENARIO_STEPS[$name]}"
local output_path="${OUTPUT_DIR}/${name}_cpu_bw_0000.png"
local token
token=$(grpc_token)
cat > "${SCRIPT_DIR}/operator_config.json" <<EOF
{
"backend": "cpu",
"theme": "bw",
"output.format": "png",
"plot.width": "$width",
"plot.height": "$height",
"png.compression": "fast",
"legend.position": "right",
"point.size.multiplier": "1",
"opacity": "1",
"plot.title": "Plot Title",
"axis.x.label": "X Label",
"axis.y.label": "Y Label"
}
EOF
(
cd "$SCRIPT_DIR"
TERCEN_URI="$TERCEN_GRPC_URI" TERCEN_TOKEN="$token" \
WORKFLOW_ID="$WORKFLOW_ID" STEP_ID="$step_id" \
"$DEV_BIN" >/dev/null 2>&1
)
if [[ -f "${SCRIPT_DIR}/plot.png" ]]; then
mv "${SCRIPT_DIR}/plot.png" "$output_path"
echo " $name: OK"
else
echo " $name: FAILED"
fi
}
render_transform_combos() {
# Renders transform showcase: "none" uses scatter_cat (same clean bands as other sections),
# others use scatter_tf_<transform> (pre-transformed data) + transform override.
local count=0 total=${#TRANSFORMS[@]}
for tf in "${TRANSFORMS[@]}"; do
count=$((count + 1))
printf "\r transforms: %d/%d" "$count" "$total"
local step_name tf_block output_path
if [[ "$tf" == "none" ]]; then
step_name="scatter_cat"
tf_block=""
else
step_name="scatter_tf_${tf}"
tf_block="\"axis.y.transform\": \"$tf\",
\"axis.x.transform\": \"$tf\","
fi
local step_id="${SCENARIO_STEPS[$step_name]}"
output_path="${OUTPUT_DIR}/scatter_cat_cpu_bw_tf_${tf}.png"
local token
token=$(grpc_token)
cat > "${SCRIPT_DIR}/operator_config.json" <<EOF
{
"backend": "cpu",
"theme": "bw",
"output.format": "png",
"plot.width": "800",
"plot.height": "600",
"png.compression": "fast",
"legend.position": "right",
"point.size.multiplier": "1",
"opacity": "1",
${tf_block}
"plot.title": "Plot Title",
"axis.x.label": "X Label",
"axis.y.label": "Y Label"
}
EOF
(
cd "$SCRIPT_DIR"
TERCEN_URI="$TERCEN_GRPC_URI" TERCEN_TOKEN="$token" \
WORKFLOW_ID="$WORKFLOW_ID" STEP_ID="$step_id" \
"$DEV_BIN" >/dev/null 2>&1
)
if [[ -f "${SCRIPT_DIR}/plot.png" ]]; then
mv "${SCRIPT_DIR}/plot.png" "$output_path"
else
echo "[WARN] No output for transform ${tf}"
fi
done
printf "\r transforms: %d/%d OK\n" "$total" "$total"
}
render_marker_shapes() {
# Renders scatter_cat with each pch shape (0-25), bw theme, cpu backend
local count=0 total=26
for pch in $(seq 0 25); do
count=$((count + 1))
printf "\r markers: %d/%d" "$count" "$total"
local step_id="${SCENARIO_STEPS[scatter_cat]}"
local output_path="${OUTPUT_DIR}/scatter_cat_cpu_bw_pch_${pch}.png"
local token
token=$(grpc_token)
cat > "${SCRIPT_DIR}/operator_config.json" <<EOF
{
"backend": "cpu",
"theme": "bw",
"output.format": "png",
"plot.width": "800",
"plot.height": "600",
"png.compression": "fast",
"legend.position": "right",
"point.size.multiplier": "1",
"opacity": "1",
"point.shapes": "$pch",
"plot.title": "Plot Title",
"axis.x.label": "X Label",
"axis.y.label": "Y Label"
}
EOF
(
cd "$SCRIPT_DIR"
TERCEN_URI="$TERCEN_GRPC_URI" TERCEN_TOKEN="$token" \
WORKFLOW_ID="$WORKFLOW_ID" STEP_ID="$step_id" \
"$DEV_BIN" >/dev/null 2>&1
)
if [[ -f "${SCRIPT_DIR}/plot.png" ]]; then
mv "${SCRIPT_DIR}/plot.png" "$output_path"
else
echo "[WARN] No output for pch ${pch}"
fi
done
printf "\r markers: %d/%d OK\n" "$total" "$total"
}
OPACITIES=(0.25 0.5 0.75 1)
render_opacity_combos() {
# Renders scatter_cat with different opacity levels, bw theme, cpu backend
local count=0 total=${#OPACITIES[@]}
for op in "${OPACITIES[@]}"; do
count=$((count + 1))
printf "\r opacity: %d/%d" "$count" "$total"
local step_id="${SCENARIO_STEPS[scatter_cat]}"
local output_path="${OUTPUT_DIR}/scatter_cat_cpu_bw_opacity_${op}.png"
local token
token=$(grpc_token)
cat > "${SCRIPT_DIR}/operator_config.json" <<EOF
{
"backend": "cpu",
"theme": "bw",
"output.format": "png",
"plot.width": "800",
"plot.height": "600",
"png.compression": "fast",
"legend.position": "right",
"point.size.multiplier": "1",
"opacity": "$op",
"plot.title": "Plot Title",
"axis.x.label": "X Label",
"axis.y.label": "Y Label"
}
EOF
(
cd "$SCRIPT_DIR"
TERCEN_URI="$TERCEN_GRPC_URI" TERCEN_TOKEN="$token" \
WORKFLOW_ID="$WORKFLOW_ID" STEP_ID="$step_id" \
"$DEV_BIN" >/dev/null 2>&1
)
if [[ -f "${SCRIPT_DIR}/plot.png" ]]; then
mv "${SCRIPT_DIR}/plot.png" "$output_path"
else
echo "[WARN] No output for opacity ${op}"
fi
done
printf "\r opacity: %d/%d OK\n" "$total" "$total"
}
render_heatmap_toggle_combos() {
local name="$1" backend="cpu" theme="bw" palette="Jet"
local step_id="${SCENARIO_STEPS[$name]}"
local count=0 total=${#FLAGS_COMBOS[@]}
# Patch palette to Jet for toggle section
patch_ramp_palette "$WORKFLOW_ID" "$step_id" "$palette"
for flags in "${FLAGS_COMBOS[@]}"; do
count=$((count + 1))
printf "\r toggle_$name: %d/%d" "$count" "$total"
local output_path="${OUTPUT_DIR}/${name}_${backend}_${theme}_${palette}_${flags}.png"
# Decode flags
local text_dis="${flags:0:1}" axis_dis="${flags:1:1}" gmaj_dis="${flags:2:1}" gmin_dis="${flags:3:1}"
local text_val="false" axis_val="false" gmaj_val="false" gmin_val="false"
[[ "$text_dis" == "1" ]] && text_val="true"
[[ "$axis_dis" == "1" ]] && axis_val="true"
[[ "$gmaj_dis" == "1" ]] && gmaj_val="true"
[[ "$gmin_dis" == "1" ]] && gmin_val="true"
local token
token=$(grpc_token)
cat > "${SCRIPT_DIR}/operator_config.json" <<EOF
{
"backend": "$backend",
"theme": "$theme",
"output.format": "png",
"plot.width": "800",
"plot.height": "600",
"png.compression": "fast",
"legend.position": "right",
"point.size.multiplier": "1",
"opacity": "1",
"text.disable": "$text_val",
"axis.lines.disable": "$axis_val",
"grid.major.disable": "$gmaj_val",
"grid.minor.disable": "$gmin_val",
"plot.title": "Plot Title",
"axis.x.label": "X Label",
"axis.y.label": "Y Label"
}
EOF
(
cd "$SCRIPT_DIR"
TERCEN_URI="$TERCEN_GRPC_URI" TERCEN_TOKEN="$token" \
WORKFLOW_ID="$WORKFLOW_ID" STEP_ID="$step_id" \
"$DEV_BIN" >/dev/null 2>&1
)
if [[ -f "${SCRIPT_DIR}/plot.png" ]]; then
mv "${SCRIPT_DIR}/plot.png" "$output_path"
else
echo "[WARN] No output for toggle ${name}_${flags}"
fi
done
printf "\r toggle_$name: %d/%d OK\n" "$total" "$total"
}
# ============================================================================
# 10. Cleanup
# ============================================================================
delete_project() {
local project_id="$1"
local token
token=$(grpc_token)
TERCEN_URI="$TERCEN_GRPC_URI" TERCEN_TOKEN="$token" \
"$PREPARE_BIN" --delete-project "$project_id" 2>&1
}
# ============================================================================
# 11. Generate showcase.html
# ============================================================================
generate_html() {
# Build the scenarios JSON for JavaScript
# Format: { sectionName: { label, variants: [{name, label}] } }
cat > "$SHOWCASE_HTML" <<'HTMLEOF'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GGRS Plot Operator — Showcase</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; scroll-padding-top: 4rem; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
background: #f5f5f5; color: #333;
max-width: 1000px; margin: 0 auto; padding: 0 2rem 2rem;
}
/* --- Sticky nav --- */
nav {
position: sticky; top: 0; z-index: 100;
background: #fff; border-bottom: 1px solid #e0e0e0;
margin: 0 -2rem; padding: 0 2rem;
box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
nav .nav-inner {
display: flex; gap: 0; overflow-x: auto;
-webkit-overflow-scrolling: touch;
scrollbar-width: none;
}
nav .nav-inner::-webkit-scrollbar { display: none; }
nav .nav-group {
display: flex; gap: 0; align-items: stretch;
border-right: 1px solid #e8e8e8;
}
nav .nav-group:last-child { border-right: none; }
nav .nav-group-label {
font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em;
color: #999; padding: 0.25rem 0.6rem 0; white-space: nowrap;
align-self: flex-start;
}
nav a {
display: flex; align-items: center;
padding: 0.6rem 0.7rem; font-size: 0.8rem; color: #555;
text-decoration: none; white-space: nowrap;
border-bottom: 2px solid transparent;
transition: color 0.15s, border-color 0.15s;
}
nav a:hover { color: #111; }
nav a.active { color: #2563eb; border-bottom-color: #2563eb; font-weight: 600; }
/* --- Header --- */
.header { padding: 2rem 0 0.5rem; }
.header h1 { font-size: 1.8rem; margin-bottom: 0.3rem; }
.header .subtitle { color: #666; font-size: 0.95rem; margin-bottom: 0; }
.header .build-info {
font-size: 0.8rem; color: #999; margin-top: 0.3rem;
}
.header .build-info code {
background: #f0f0f0; padding: 0.1rem 0.4rem; border-radius: 3px;
font-family: "SF Mono", "Fira Code", monospace; font-size: 0.78rem;
}
/* --- Intro --- */
.intro {
background: #fff; border-radius: 8px; padding: 1.5rem;
margin: 1.5rem 0; box-shadow: 0 1px 3px rgba(0,0,0,0.1);
line-height: 1.6; font-size: 0.92rem; color: #444;
}
.intro h2 { font-size: 1.1rem; margin-bottom: 0.8rem; color: #333; }
.intro ul { margin: 0.5rem 0 0.5rem 1.5rem; }
.intro li { margin-bottom: 0.3rem; }
.intro strong { color: #333; }
.intro .tech-note { font-size: 0.82rem; color: #888; margin-top: 0.8rem; }
/* --- Category headers --- */
.category-header {
font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em;
color: #999; font-weight: 600; margin: 2rem 0 0.8rem;
padding-bottom: 0.3rem; border-bottom: 1px solid #e0e0e0;
}
/* --- Section cards --- */
section { background: #fff; border-radius: 8px; padding: 1.5rem;
margin-bottom: 1.5rem; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
section h2 { font-size: 1.3rem; margin-bottom: 1rem; }
.controls { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: flex-end; }
.control-group { display: flex; flex-direction: column; gap: 0.2rem; }