1+ import { AwsClient } from 'aws4fetch' ;
12import * as d3 from 'd3' ;
23
34import { ini_deck_sst } from '../deck-gl/core/deck_sst' ;
@@ -19,6 +20,7 @@ import {
1920 set_tile_name_to_index_map ,
2021} from '../global_variables/tile_names_array' ;
2122import { set_tile_scatter_data } from '../global_variables/tile_scatter_data' ;
23+ import { create_obs_store } from '../obs_store/obs_store' ;
2224import { get_arrow_table } from '../read_parquet/get_arrow_table' ;
2325import { get_scatter_data } from '../read_parquet/get_scatter_data' ;
2426import { make_sst_ui_container } from '../ui/ui_containers' ;
@@ -36,17 +38,22 @@ export const landscape_sst = async (
3638 square_tile_size = 1.4 ,
3739 _dataset_name = '' ,
3840 width = 0 ,
39- height = 800
41+ height = 800 ,
42+ creds = { }
4043) => {
4144 if ( width === 0 ) {
4245 width = '100%' ;
4346 }
4447
4548 // Create and append the visualization container
4649 const root = document . createElement ( 'div' ) ;
47- root . style . height = '800px' ;
50+ root . style . height = `${ height } px` ;
51+ root . style . width = typeof width === 'number' ? `${ width } px` : width ;
4852
4953 const viz_state = { } ;
54+
55+ viz_state . obs_store = create_obs_store ( ) ;
56+
5057 set_options ( token ) ;
5158 set_global_base_url ( viz_state , base_url ) ;
5259
@@ -58,8 +65,55 @@ export const landscape_sst = async (
5865
5966 await set_landscape_parameters ( viz_state . img , base_url ) ;
6067
68+ // AWS credentials setup
69+
70+ if ( 'accessKeyId' in creds ) {
71+ viz_state . aws = new AwsClient ( {
72+ accessKeyId : creds . accessKeyId ,
73+ secretAccessKey : creds . secretAccessKey ,
74+ sessionToken : creds . sessionToken ,
75+ region : 'us-east-1' ,
76+ service : 's3' ,
77+ } ) ;
78+
79+ // fetch after initialization of aws client is apparently required?
80+ const response = await viz_state . aws . fetch (
81+ `${ base_url } /landscape_parameters.json`
82+ ) ;
83+
84+ if ( ! response . ok ) {
85+ throw new Error ( `Fetch failed: ${ response . statusText } ` ) ;
86+ }
87+ } else {
88+ viz_state . aws = null ;
89+ }
90+
6191 await set_dimensions ( viz_state , base_url , 'cells' ) ;
6292
93+ const parseDim = ( val , ref ) => {
94+ if ( typeof val === 'string' && val . includes ( '%' ) ) {
95+ const ratio = parseFloat ( val ) / 100 ;
96+ return ref * ratio ;
97+ }
98+ return parseFloat ( val ) || ref ;
99+ } ;
100+
101+ const imgWidth = viz_state . dimensions . width ;
102+ const imgHeight = viz_state . dimensions . height ;
103+ const containerWidth = parseDim ( width , el . clientWidth || imgWidth ) ;
104+ const containerHeight = parseDim ( height , el . clientHeight || imgHeight ) ;
105+ const scale = Math . min (
106+ containerWidth / imgWidth ,
107+ containerHeight / imgHeight
108+ ) ;
109+ const autoZoom = Math . log2 ( scale ) ;
110+
111+ if ( ini_x === 0 && ini_y === 0 && ini_zoom === 0 ) {
112+ ini_x = imgWidth / 2 ;
113+ ini_y = imgHeight / 2 ;
114+ ini_zoom = autoZoom ;
115+ }
116+
63117 viz_state . buttons = { } ;
64118 viz_state . buttons . blue = '#8797ff' ;
65119 viz_state . buttons . gray = 'gray' ;
@@ -95,7 +149,7 @@ export const landscape_sst = async (
95149
96150 viz_state . cats . square_tile_size = square_tile_size ;
97151
98- await set_meta_gene ( viz_state . genes , base_url ) ;
152+ await set_meta_gene ( viz_state . genes , base_url , 'default' , viz_state . aws ) ;
99153
100154 // move this to landscape_parameters
101155 const _info = {
@@ -105,7 +159,11 @@ export const landscape_sst = async (
105159
106160 const tile_url = `${ base_url } /tile_geometries.parquet` ;
107161
108- const tile_arrow_table = await get_arrow_table ( tile_url , options . fetch ) ;
162+ const tile_arrow_table = await get_arrow_table (
163+ tile_url ,
164+ options . fetch ,
165+ viz_state . aws
166+ ) ;
109167
110168 viz_state . cats . tile_cats_array = tile_arrow_table
111169 . getChild ( 'cluster' )
@@ -122,7 +180,10 @@ export const landscape_sst = async (
122180 ) ;
123181 set_tile_name_to_index_map ( viz_state . cats ) ;
124182
125- viz_state . cats . tile_color_dict = await set_tile_color_dict ( base_url ) ;
183+ viz_state . cats . tile_color_dict = await set_tile_color_dict (
184+ viz_state ,
185+ base_url
186+ ) ;
126187
127188 const simple_image_layer = await make_simple_image_layer ( viz_state , _info ) ;
128189 const square_scatter_layer = ini_square_scatter_layer ( viz_state . cats ) ;
0 commit comments