19
19
import numpy as np
20
20
import pandas as pd
21
21
22
+ from typing import TYPE_CHECKING
23
+
24
+ if TYPE_CHECKING :
25
+ from .conversion_edge import Graph
26
+
22
27
23
28
class _MatplotlibTransform (Protocol ):
24
29
def transform (self , verts ):
@@ -148,9 +153,8 @@ def compatible(a: dict[str, Desc], b: dict[str, Desc]) -> bool:
148
153
class DataContainer (Protocol ):
149
154
def query (
150
155
self ,
151
- # TODO 3D?!!
152
- coord_transform : _MatplotlibTransform ,
153
- size : Tuple [int , int ],
156
+ graph : Graph ,
157
+ parent_coordinates : str = "axes" ,
154
158
/ ,
155
159
) -> Tuple [Dict [str , Any ], Union [str , int ]]:
156
160
"""
@@ -208,8 +212,8 @@ def __init__(self, **data):
208
212
209
213
def query (
210
214
self ,
211
- coord_transform : _MatplotlibTransform ,
212
- size : Tuple [ int , int ] ,
215
+ graph : Graph ,
216
+ parent_coordinates : str = "axes" ,
213
217
) -> Tuple [Dict [str , Any ], Union [str , int ]]:
214
218
return dict (self ._data ), self ._cache_key
215
219
@@ -233,8 +237,8 @@ def __init__(self, **shapes):
233
237
234
238
def query (
235
239
self ,
236
- coord_transform : _MatplotlibTransform ,
237
- size : Tuple [ int , int ] ,
240
+ graph : Graph ,
241
+ parent_coordinates : str = "axes" ,
238
242
) -> Tuple [Dict [str , Any ], Union [str , int ]]:
239
243
return {k : np .random .randn (* d .shape ) for k , d in self ._desc .items ()}, str (
240
244
uuid .uuid4 ()
@@ -301,31 +305,101 @@ def _query_hash(self, coord_transform, size):
301
305
302
306
def query (
303
307
self ,
304
- coord_transform : _MatplotlibTransform ,
305
- size : Tuple [ int , int ] ,
308
+ graph : Graph ,
309
+ parent_coordinates : str = "axes" ,
306
310
) -> Tuple [Dict [str , Any ], Union [str , int ]]:
307
- hash_key = self ._query_hash (coord_transform , size )
308
- if hash_key in self ._cache :
309
- return self ._cache [hash_key ], hash_key
311
+ # hash_key = self._query_hash(coord_transform, size)
312
+ # if hash_key in self._cache:
313
+ # return self._cache[hash_key], hash_key
314
+
315
+ data_lim = graph .evaluator (
316
+ {
317
+ "x" : Desc (
318
+ ("N" ,),
319
+ np .dtype (
320
+ "f8" ,
321
+ ),
322
+ coordinates = "data" ,
323
+ ),
324
+ "y" : Desc (
325
+ ("N" ,),
326
+ np .dtype (
327
+ "f8" ,
328
+ ),
329
+ coordinates = "data" ,
330
+ ),
331
+ },
332
+ {
333
+ "x" : Desc (
334
+ ("N" ,),
335
+ np .dtype (
336
+ "f8" ,
337
+ ),
338
+ coordinates = parent_coordinates ,
339
+ ),
340
+ "y" : Desc (
341
+ ("N" ,),
342
+ np .dtype (
343
+ "f8" ,
344
+ ),
345
+ coordinates = parent_coordinates ,
346
+ ),
347
+ },
348
+ ).inverse
349
+ screen_size = graph .evaluator (
350
+ {
351
+ "x" : Desc (
352
+ ("N" ,),
353
+ np .dtype (
354
+ "f8" ,
355
+ ),
356
+ coordinates = parent_coordinates ,
357
+ ),
358
+ "y" : Desc (
359
+ ("N" ,),
360
+ np .dtype (
361
+ "f8" ,
362
+ ),
363
+ coordinates = parent_coordinates ,
364
+ ),
365
+ },
366
+ {
367
+ "x" : Desc (
368
+ ("N" ,),
369
+ np .dtype (
370
+ "f8" ,
371
+ ),
372
+ coordinates = "display" ,
373
+ ),
374
+ "y" : Desc (
375
+ ("N" ,),
376
+ np .dtype (
377
+ "f8" ,
378
+ ),
379
+ coordinates = "display" ,
380
+ ),
381
+ },
382
+ )
310
383
311
- xpix , ypix = size
312
- x_data , _ = coord_transform .transform (
313
- np .vstack (
314
- [
315
- np .linspace (0 , 1 , int (xpix ) * 2 ),
316
- np .zeros (int (xpix ) * 2 ),
317
- ]
318
- ).T
319
- ).T
320
- _ , y_data = coord_transform .transform (
321
- np .vstack (
322
- [
323
- np .zeros (int (ypix ) * 2 ),
324
- np .linspace (0 , 1 , int (ypix ) * 2 ),
325
- ]
326
- ).T
327
- ).T
384
+ screen_dims = screen_size .evaluate ({"x" : [0 , 1 ], "y" : [0 , 1 ]})
385
+ xpix , ypix = np .ceil (np .abs (np .diff (screen_dims ["x" ]))), np .ceil (
386
+ np .abs (np .diff (screen_dims ["y" ]))
387
+ )
328
388
389
+ x_data = data_lim .evaluate (
390
+ {
391
+ "x" : np .linspace (0 , 1 , int (xpix ) * 2 ),
392
+ "y" : np .zeros (int (xpix ) * 2 ),
393
+ }
394
+ )["x" ]
395
+ y_data = data_lim .evaluate (
396
+ {
397
+ "x" : np .zeros (int (ypix ) * 2 ),
398
+ "y" : np .linspace (0 , 1 , int (ypix ) * 2 ),
399
+ }
400
+ )["y" ]
401
+
402
+ hash_key = str (uuid .uuid4 ())
329
403
ret = self ._cache [hash_key ] = dict (
330
404
** {k : f (x_data ) for k , f in self ._xfuncs .items ()},
331
405
** {k : f (y_data ) for k , f in self ._yfuncs .items ()},
@@ -350,11 +424,49 @@ def __init__(self, raw_data, num_bins: int):
350
424
351
425
def query (
352
426
self ,
353
- coord_transform : _MatplotlibTransform ,
354
- size : Tuple [ int , int ] ,
427
+ graph : Graph ,
428
+ parent_coordinates : str = "axes" ,
355
429
) -> Tuple [Dict [str , Any ], Union [str , int ]]:
356
430
dmin , dmax = self ._full_range
357
- xmin , ymin , xmax , ymax = coord_transform .transform ([[0 , 0 ], [1 , 1 ]]).flatten ()
431
+
432
+ data_lim = graph .evaluator (
433
+ {
434
+ "x" : Desc (
435
+ ("N" ,),
436
+ np .dtype (
437
+ "f8" ,
438
+ ),
439
+ coordinates = "data" ,
440
+ ),
441
+ "y" : Desc (
442
+ ("N" ,),
443
+ np .dtype (
444
+ "f8" ,
445
+ ),
446
+ coordinates = "data" ,
447
+ ),
448
+ },
449
+ {
450
+ "x" : Desc (
451
+ ("N" ,),
452
+ np .dtype (
453
+ "f8" ,
454
+ ),
455
+ coordinates = parent_coordinates ,
456
+ ),
457
+ "y" : Desc (
458
+ ("N" ,),
459
+ np .dtype (
460
+ "f8" ,
461
+ ),
462
+ coordinates = parent_coordinates ,
463
+ ),
464
+ },
465
+ ).inverse
466
+
467
+ pts = data_lim .evaluate ({"x" : (0 , 1 ), "y" : (0 , 1 )})
468
+ xmin , xmax = pts ["x" ]
469
+ ymin , ymax = pts ["y" ]
358
470
359
471
xmin , xmax = np .clip ([xmin , xmax ], dmin , dmax )
360
472
hash_key = hash ((xmin , xmax ))
@@ -398,8 +510,8 @@ def __init__(self, series: pd.Series, *, index_name: str, col_name: str):
398
510
399
511
def query (
400
512
self ,
401
- coord_transform : _MatplotlibTransform ,
402
- size : Tuple [ int , int ] ,
513
+ graph : Graph ,
514
+ parent_coordinates : str = "axes" ,
403
515
) -> Tuple [Dict [str , Any ], Union [str , int ]]:
404
516
return {
405
517
self ._index_name : self ._data .index .values ,
@@ -440,8 +552,8 @@ def __init__(
440
552
441
553
def query (
442
554
self ,
443
- coord_transform : _MatplotlibTransform ,
444
- size : Tuple [ int , int ] ,
555
+ graph : Graph ,
556
+ parent_coordinates : str = "axes" ,
445
557
) -> Tuple [Dict [str , Any ], Union [str , int ]]:
446
558
ret = {}
447
559
if self ._index_name is not None :
@@ -463,10 +575,10 @@ def __init__(self, data: DataContainer, mapping: Dict[str, str]):
463
575
464
576
def query (
465
577
self ,
466
- coord_transform : _MatplotlibTransform ,
467
- size : Tuple [ int , int ] ,
578
+ graph : Graph ,
579
+ parent_coordinates : str = "axes" ,
468
580
) -> Tuple [Dict [str , Any ], Union [str , int ]]:
469
- base , cache_key = self ._data .query (coord_transform , size )
581
+ base , cache_key = self ._data .query (graph , parent_coordinates )
470
582
return {v : base [k ] for k , v in self ._mapping .items ()}, cache_key
471
583
472
584
def describe (self ):
@@ -481,13 +593,13 @@ def __init__(self, *data: DataContainer):
481
593
482
594
def query (
483
595
self ,
484
- coord_transform : _MatplotlibTransform ,
485
- size : Tuple [ int , int ] ,
596
+ graph : Graph ,
597
+ parent_coordinates : str = "axes" ,
486
598
) -> Tuple [Dict [str , Any ], Union [str , int ]]:
487
599
cache_keys = []
488
600
ret = {}
489
601
for data in self ._datas :
490
- base , cache_key = data .query (coord_transform , size )
602
+ base , cache_key = data .query (graph , parent_coordinates )
491
603
ret .update (base )
492
604
cache_keys .append (cache_key )
493
605
return ret , hash (tuple (cache_keys ))
@@ -499,8 +611,8 @@ def describe(self):
499
611
class WebServiceContainer :
500
612
def query (
501
613
self ,
502
- coord_transform : _MatplotlibTransform ,
503
- size : Tuple [ int , int ] ,
614
+ graph : Graph ,
615
+ parent_coordinates : str = "axes" ,
504
616
) -> Tuple [Dict [str , Any ], Union [str , int ]]:
505
617
def hit_some_database ():
506
618
{}, "1"
0 commit comments