Skip to content

Commit

Permalink
#7641 Java API for ImageFormat (#7657)
Browse files Browse the repository at this point in the history
* #7641 Java API for ImageFormat

* removed incorrect line from copyright banner

* #7641 Python API fro ImageFormat

* #7641 fix Image rendering initialized by kernel
  • Loading branch information
Mariusz Jurowicz authored and scottdraves committed Jul 5, 2018
1 parent 290f7ea commit b4393a3
Show file tree
Hide file tree
Showing 30 changed files with 124 additions and 33 deletions.
14 changes: 13 additions & 1 deletion beakerx/beakerx/tabledisplay/tableitems.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class TimeUnit(Enum):
HOURS = 7



class ColumnType(Enum):
String = "string"
Double = "double"
Expand Down Expand Up @@ -65,9 +64,15 @@ def __init__(self, min=4, max=4):
self.minDecimals = min
self.maxDecimals = max


class ImageFormat:
type = "image"


class HTMLFormat:
type = "html"


class HighlightStyle(Enum):
FULL_ROW = 1
SINGLE_COLUMN = 2
Expand All @@ -91,12 +96,19 @@ def getDataBarsRenderer(include_text=True):


class TableDisplayStringFormat:

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

@staticmethod
def getHTMLFormat():
return HTMLFormat()

@staticmethod
def getImageFormat():
return ImageFormat()

class TableDisplayCellHighlighter:
FULL_ROW = HighlightStyle.FULL_ROW
SINGLE_COLUMN = HighlightStyle.SINGLE_COLUMN
Expand Down
10 changes: 5 additions & 5 deletions js/notebook/src/tableDisplay/dataGrid/DataGridResize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ export class DataGridResize {
}
}

setSectionWidth(area, column: DataGridColumn, value: number): void {
this.dataGrid.resizeSection(area, column.getPosition().value, value);
column.setWidth(value);
}

private fillEmptySpaceResizeFn(region: ColumnRegion, value: number) {
return (section) => {
let column = this.dataGrid.columnManager.getColumnByPosition({
Expand Down Expand Up @@ -353,11 +358,6 @@ export class DataGridResize {
return result > MIN_COLUMN_WIDTH ? result : MIN_COLUMN_WIDTH;
}

private setSectionWidth(area, column: DataGridColumn, value: number): void {
this.dataGrid.resizeSection(area, column.getPosition().value, value);
column.setWidth(value);
}

private installMessageHook() {
MessageLoop.installMessageHook(this.dataGrid.viewport, this.viewportResizeMessageHook.bind(this));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export default class ImageCellRenderer extends CellRenderer {
}

if (selectColumnWidth(this.dataGrid.store.state, column) < width) {
column.setWidth(width);
column.dataGrid.dataGridResize.setSectionWidth("column", column, width);
column.dataGrid.dataGridResize.updateWidgetHeight();
column.dataGrid.dataGridResize.updateWidgetWidth();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default class DataGridColumn {

const position = this.getPosition();

this.setWidth(1);
this.dataGrid.dataGridResize.setSectionWidth("column", this, 1);
this.assignFormatFn();
this.recalculateLongestStringValue(displayType);
this.dataGrid.dataGridResize.setInitialSectionWidth({ index: position.value }, position.region);
Expand Down Expand Up @@ -229,7 +229,6 @@ export default class DataGridColumn {
));
this.columnManager.updateColumnFilterNodes();
this.columnManager.updateColumnMenuTriggers();
this.dataGrid.resize();
}

getState() {
Expand Down
4 changes: 4 additions & 0 deletions js/notebook/src/tableDisplay/dataGrid/dataTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export function getDisplayType(type: ALL_TYPES, stringFormatForType?: any, strin
return ALL_TYPES.string;
}

if (stringFormatForColumn && stringFormatForColumn.type === 'image') {
return ALL_TYPES.image;
}

if (type === ALL_TYPES.string && stringFormatForColumn && stringFormatForColumn.type) {
return ALL_TYPES[stringFormatForColumn.type] || ALL_TYPES.string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export function createInitialColumnsState(initialState: IDataModelState): IColum
keepTrigger: columnType === COLUMN_TYPES.index,
position: positions[columnType][index],
dataTypeName: types[columnType][index],
width: 20,
displayType: getDisplayType(
dataType,
selectStringFormatForType(state),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*import static org.assertj.core.api.Assertions.assertThat;
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*import static org.assertj.core.api.Assertions.assertThat;
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*import static org.assertj.core.api.Assertions.assertThat;
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*import static org.assertj.core.api.Assertions.assertThat;
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*import static org.assertj.core.api.Assertions.assertThat;
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*import static org.assertj.core.api.Assertions.assertThat;
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*import static org.assertj.core.api.Assertions.assertThat;
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*import static org.assertj.core.api.Assertions.assertThat;
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*import static org.assertj.core.api.Assertions.assertThat;
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*import static org.assertj.core.api.Assertions.assertThat;
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*import static org.assertj.core.api.Assertions.assertThat;
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*import static org.assertj.core.api.Assertions.assertThat;
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*import static org.assertj.core.api.Assertions.assertThat;
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*import static org.assertj.core.api.Assertions.assertThat;
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*import static org.assertj.core.api.Assertions.assertThat;
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 TWO SIGMA OPEN SOURCE, LLC
* Copyright 2018 TWO SIGMA OPEN SOURCE, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,7 @@
import com.twosigma.beakerx.jvm.serialization.DateSerializer;
import com.twosigma.beakerx.table.format.DecimalStringFormat;
import com.twosigma.beakerx.table.format.HTMLStringFormat;
import com.twosigma.beakerx.table.format.ImageStringFormat;
import com.twosigma.beakerx.table.format.TableDisplayStringFormat;
import com.twosigma.beakerx.table.format.TimeStringFormat;
import com.twosigma.beakerx.table.format.ValueStringFormat;
Expand All @@ -38,6 +39,7 @@
import com.twosigma.beakerx.table.serializer.DecimalStringFormatSerializer;
import com.twosigma.beakerx.table.serializer.HTMLStringFormatSerializer;
import com.twosigma.beakerx.table.serializer.HeatmapHighlighterSerializer;
import com.twosigma.beakerx.table.serializer.ImageStringFormatSerializer;
import com.twosigma.beakerx.table.serializer.TableDisplaySerializer;
import com.twosigma.beakerx.table.serializer.ThreeColorHeatmapHighlighterSerializer;
import com.twosigma.beakerx.table.serializer.TimeStringFormatSerializer;
Expand Down Expand Up @@ -94,6 +96,7 @@ public static SimpleModule tableDisplayModule() {
module.addSerializer(DecimalStringFormat.class, new DecimalStringFormatSerializer());
module.addSerializer(HTMLStringFormat.class, new HTMLStringFormatSerializer());
module.addSerializer(TimeStringFormat.class, new TimeStringFormatSerializer());
module.addSerializer(ImageStringFormat.class, new ImageStringFormatSerializer());
module.addSerializer(DataBarsRenderer.class, new DataBarsRendererSerializer());
module.addSerializer(HeatmapHighlighter.class, new HeatmapHighlighterSerializer());
module.addSerializer(ThreeColorHeatmapHighlighter.class, new ThreeColorHeatmapHighlighterSerializer());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2018 TWO SIGMA OPEN SOURCE, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.twosigma.beakerx.table.format;

public class ImageStringFormat extends TableDisplayStringFormat {

public ImageStringFormat() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,24 @@ public static TableDisplayStringFormat getTimeFormat() {
return new TimeStringFormat();
}

//Get a formatter that will show Date in a timestamp format with millisecond precision
// Get a formatter that will show Date in a timestamp format with millisecond precision
public static TableDisplayStringFormat getTimeFormat(boolean humanFriendly) {
return new TimeStringFormat(humanFriendly);
}

// Get a formatter that will show Date in a timestamp format with the specified precision
// Get a formatter that will show Date in a timestamp format with the specified precision
public static TableDisplayStringFormat getTimeFormat(TimeUnit unit) {
return new TimeStringFormat(unit);
}

//Get a formatter that will show Date in a timestamp format with the specified precision
// Get a formatter that will show Date in a timestamp format with the specified precision
public static TableDisplayStringFormat getTimeFormat(TimeUnit unit, boolean humanFriendly) {
return new TimeStringFormat(unit, humanFriendly);
}

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2018 TWO SIGMA OPEN SOURCE, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.twosigma.beakerx.table.serializer;

import com.twosigma.beakerx.table.format.ImageStringFormat;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

public class ImageStringFormatSerializer extends JsonSerializer<ImageStringFormat> {

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

@Override
public void serialize(ImageStringFormat value,
JsonGenerator jgen,
SerializerProvider provider)
throws IOException, JsonProcessingException {

synchronized (value) {
jgen.writeStartObject();
jgen.writeObjectField(TYPE, VALUE_IMAGE);
jgen.writeEndObject();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*import static org.assertj.core.api.Assertions.assertThat;
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*import static org.assertj.core.api.Assertions.assertThat;
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
Expand Down
Loading

0 comments on commit b4393a3

Please sign in to comment.