Skip to content

Commit

Permalink
#7338 width parameter for HTML and Image string format - backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasz Mitusinski committed Jul 6, 2018
1 parent d4c39f6 commit 33c8973
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 11 deletions.
29 changes: 18 additions & 11 deletions beakerx/beakerx/tabledisplay/tableitems.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,27 @@ def __init__(self, x):

class DecimalStringFormat:
type = "decimal"
minDecimals = 4
maxDecimals = 4

def __init__(self, min=4, max=4):
self.minDecimals = min
self.maxDecimals = max
def __init__(self, **kwargs):
self.minDecimals = kwargs.get('min', 4)
self.maxDecimals = kwargs.get('max', 4)


class ImageFormat:
type = "image"

def __init__(self, **kwargs):
if 'width' in kwargs:
self.width = kwargs.get('width')


class HTMLFormat:
type = "html"

def __init__(self, **kwargs):
if 'width' in kwargs:
self.width = kwargs.get('width')


class HighlightStyle(Enum):
FULL_ROW = 1
Expand All @@ -80,6 +86,7 @@ class HighlightStyle(Enum):

class HeatmapHighlighter:
type = "HeatmapHighlighter"

def __init__(self, colName, style, minVal, maxVal, minColor, maxColor):
self.colName = colName
self.style = style.name
Expand All @@ -98,16 +105,16 @@ def getDataBarsRenderer(include_text=True):
class TableDisplayStringFormat:

@staticmethod
def getDecimalFormat(min, max):
return DecimalStringFormat(min, max)
def getDecimalFormat(**kwargs):
return DecimalStringFormat(**kwargs)

@staticmethod
def getHTMLFormat():
return HTMLFormat()
def getHTMLFormat(**kwargs):
return HTMLFormat(**kwargs)

@staticmethod
def getImageFormat():
return ImageFormat()
def getImageFormat(**kwargs):
return ImageFormat(**kwargs)

class TableDisplayCellHighlighter:
FULL_ROW = HighlightStyle.FULL_ROW
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@

public class HTMLStringFormat extends TableDisplayStringFormat {

private Integer width;

public HTMLStringFormat() {
}

public HTMLStringFormat(Integer width) {
this.width = width;
}

public Integer getWidth() {
return width;
}

public void setWidth(Integer width) {
this.width = width;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@

public class ImageStringFormat extends TableDisplayStringFormat {

private Integer width;

public ImageStringFormat() {
}

public ImageStringFormat(Integer width) {
this.width = width;
}

public Integer getWidth() {
return width;
}

public void setWidth(Integer width) {
this.width = width;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public static TableDisplayStringFormat getHTMLFormat() {
return new HTMLStringFormat();
}

// Get a formatter that shows strings as formatted HTML with specified width
public static TableDisplayStringFormat getHTMLFormat(int width) {
return new HTMLStringFormat(width);
}

// Get a formatter that will show Date in a timestamp format with millisecond precision
public static TableDisplayStringFormat getTimeFormat() {
return new TimeStringFormat();
Expand All @@ -54,4 +59,9 @@ public static TableDisplayStringFormat getImageFormat() {
return new ImageStringFormat();
}

// Get a formatter that will show derived source as an image with specified width
public static TableDisplayStringFormat getImageFormat(int width) {
return new ImageStringFormat(width);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class HTMLStringFormatSerializer extends JsonSerializer<HTMLStringFormat>

public static final String TYPE = "type";
public static final String VALUE_HTML = "html";
public static final String WIDTH = "width";

@Override
public void serialize(HTMLStringFormat value,
Expand All @@ -37,6 +38,9 @@ public void serialize(HTMLStringFormat value,
synchronized (value) {
jgen.writeStartObject();
jgen.writeObjectField(TYPE, VALUE_HTML);
if (value.getWidth() != null) {
jgen.writeObjectField(WIDTH, value.getWidth());
}
jgen.writeEndObject();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class ImageStringFormatSerializer extends JsonSerializer<ImageStringForma

public static final String TYPE = "type";
public static final String VALUE_IMAGE = "image";
public static final String WIDTH = "width";

@Override
public void serialize(ImageStringFormat value,
Expand All @@ -37,6 +38,9 @@ public void serialize(ImageStringFormat value,
synchronized (value) {
jgen.writeStartObject();
jgen.writeObjectField(TYPE, VALUE_IMAGE);
if (value.getWidth() != null) {
jgen.writeObjectField(WIDTH, value.getWidth());
}
jgen.writeEndObject();
}
}
Expand Down

0 comments on commit 33c8973

Please sign in to comment.