Skip to content

Commit

Permalink
Add spec and size to counter and table tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
JCZuurmond committed Jun 13, 2024
1 parent 5d0a9fa commit f2aa048
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions src/databricks/labs/lsql/dashboards.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import abc
import argparse
import dataclasses
import json
Expand Down Expand Up @@ -85,16 +86,39 @@ def replace_from_arguments(self, arguments: list[str]) -> "WidgetMetadata":
)


class CounterTile:
pass
class Tile:
"""A dashboard tile."""

def __init__(self, fields: list[Field]) -> None:
self._fields = fields

class TableTile:
pass
@property
def size(self) -> tuple[int, int]:
"""The width and height."""
return 1, 3

@property
@abc.abstractmethod
def spec(self) -> WidgetSpec:
"""The widget spec"""

class MarkdownTile:
pass

class CounterTile(Tile):

def spec(self) -> WidgetSpec:
# Counters are expected to have one field
counter_encodings = CounterFieldEncoding(field_name=self._fields[0].name, display_name=self._fields[0].name)
spec = CounterSpec(CounterEncodingMap(value=counter_encodings))
return spec


class TableTile(Tile):

def spec(self) -> WidgetSpec:
field_encodings = [RenderFieldEncoding(field_name=field.name) for field in self._fields]
table_encodings = TableEncodingMap(field_encodings)
spec = TableV2Spec(encodings=table_encodings)
return spec


class Dashboards:
Expand Down

0 comments on commit f2aa048

Please sign in to comment.