darabos commited on
Commit
33299ee
·
1 Parent(s): 27dd7b2

Allow images in tables.

Browse files
examples/Image table.lynxkite.json ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "edges": [
3
+ {
4
+ "id": "Example image table 1 View tables 1",
5
+ "source": "Example image table 1",
6
+ "sourceHandle": "output",
7
+ "target": "View tables 1",
8
+ "targetHandle": "bundle"
9
+ }
10
+ ],
11
+ "env": "LynxKite Graph Analytics",
12
+ "nodes": [
13
+ {
14
+ "data": {
15
+ "display": null,
16
+ "error": null,
17
+ "input_metadata": [],
18
+ "meta": {
19
+ "color": "orange",
20
+ "inputs": [],
21
+ "name": "Example image table",
22
+ "outputs": [
23
+ {
24
+ "name": "output",
25
+ "position": "right",
26
+ "type": {
27
+ "type": "None"
28
+ }
29
+ }
30
+ ],
31
+ "params": [],
32
+ "type": "basic"
33
+ },
34
+ "params": {},
35
+ "status": "done",
36
+ "title": "Example image table"
37
+ },
38
+ "dragHandle": ".bg-primary",
39
+ "height": 200.0,
40
+ "id": "Example image table 1",
41
+ "position": {
42
+ "x": 450.0,
43
+ "y": 165.0
44
+ },
45
+ "type": "basic",
46
+ "width": 200.0
47
+ },
48
+ {
49
+ "data": {
50
+ "display": {
51
+ "dataframes": {
52
+ "df": {
53
+ "columns": [
54
+ "names",
55
+ "images"
56
+ ],
57
+ "data": [
58
+ [
59
+ "svg",
60
+ "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 64 64\" enable-background=\"new 0 0 64 64\"><path d=\"M56 2 18.8 42.909 8 34.729 2 34.729 18.8 62 62 2z\"/></svg>"
61
+ ],
62
+ [
63
+ "data",
64
+ "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2NCA2NCIgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgNjQgNjQiPjxwYXRoIGQ9Ik01NiAyIDE4LjggNDIuOTA5IDggMzQuNzI5IDIgMzQuNzI5IDE4LjggNjIgNjIgMnoiLz48L3N2Zz4="
65
+ ],
66
+ [
67
+ "http",
68
+ "https://upload.wikimedia.org/wikipedia/commons/2/2e/Emojione_BW_2714.svg"
69
+ ]
70
+ ]
71
+ }
72
+ },
73
+ "other": {},
74
+ "relations": []
75
+ },
76
+ "error": null,
77
+ "input_metadata": [
78
+ {
79
+ "dataframes": {
80
+ "df": {
81
+ "columns": [
82
+ "images",
83
+ "names"
84
+ ]
85
+ }
86
+ },
87
+ "other": {},
88
+ "relations": []
89
+ }
90
+ ],
91
+ "meta": {
92
+ "color": "orange",
93
+ "inputs": [
94
+ {
95
+ "name": "bundle",
96
+ "position": "left",
97
+ "type": {
98
+ "type": "<class 'lynxkite_graph_analytics.core.Bundle'>"
99
+ }
100
+ }
101
+ ],
102
+ "name": "View tables",
103
+ "outputs": [],
104
+ "params": [
105
+ {
106
+ "default": 100,
107
+ "name": "limit",
108
+ "type": {
109
+ "type": "<class 'int'>"
110
+ }
111
+ }
112
+ ],
113
+ "type": "table_view"
114
+ },
115
+ "params": {
116
+ "limit": 100.0
117
+ },
118
+ "status": "done",
119
+ "title": "View tables"
120
+ },
121
+ "dragHandle": ".bg-primary",
122
+ "height": 200.0,
123
+ "id": "View tables 1",
124
+ "position": {
125
+ "x": 840.0,
126
+ "y": 135.0
127
+ },
128
+ "type": "table_view",
129
+ "width": 200.0
130
+ }
131
+ ]
132
+ }
examples/make_image_table.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from lynxkite.core.ops import op
2
+ import pandas as pd
3
+ import base64
4
+
5
+
6
+ @op("LynxKite Graph Analytics", "Example image table")
7
+ def make_image_table():
8
+ svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" enable-background="new 0 0 64 64"><path d="M56 2 18.8 42.909 8 34.729 2 34.729 18.8 62 62 2z"/></svg>'
9
+ data = "data:image/svg+xml;base64," + base64.b64encode(svg.encode("utf-8")).decode("utf-8")
10
+ http = "https://upload.wikimedia.org/wikipedia/commons/2/2e/Emojione_BW_2714.svg"
11
+ return pd.DataFrame({"names": ["svg", "data", "http"], "images": [svg, data, http]})
lynxkite-app/web/src/index.css CHANGED
@@ -274,6 +274,16 @@ body {
274
  padding: 5px 10px;
275
  width: 100%;
276
  }
 
 
 
 
 
 
 
 
 
 
277
  }
278
 
279
  .params-expander {
 
274
  padding: 5px 10px;
275
  width: 100%;
276
  }
277
+
278
+ .table-viewer {
279
+ td {
280
+ padding: 5px 10px;
281
+ }
282
+
283
+ .image-in-table {
284
+ max-height: 50px;
285
+ }
286
+ }
287
  }
288
 
289
  .params-expander {
lynxkite-app/web/src/workspace/nodes/Table.tsx CHANGED
@@ -1,6 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  export default function Table(props: any) {
2
  return (
3
- <table id={props.name || "table"}>
4
  <thead>
5
  <tr>
6
  {props.columns.map((column: string) => (
@@ -12,7 +27,9 @@ export default function Table(props: any) {
12
  {props.data.map((row: { [column: string]: any }, i: number) => (
13
  <tr key={`row-${i}`}>
14
  {props.columns.map((_column: string, j: number) => (
15
- <td key={`cell ${i}, ${j}`}>{JSON.stringify(row[j])}</td>
 
 
16
  ))}
17
  </tr>
18
  ))}
 
1
+ function Cell({ value }: { value: any }) {
2
+ if (typeof value === "string") {
3
+ if (value.startsWith("https://") || value.startsWith("data:")) {
4
+ return <img className="image-in-table" src={value} alt={value} />;
5
+ }
6
+ if (value.startsWith("<svg")) {
7
+ // A data URL is safer than just dropping it in the DOM.
8
+ const data = `data:image/svg+xml;base64,${btoa(value)}`;
9
+ return <img className="image-in-table" src={data} alt={value} />;
10
+ }
11
+ return <>{value}</>;
12
+ }
13
+ return <>{JSON.stringify(value)}</>;
14
+ }
15
+
16
  export default function Table(props: any) {
17
  return (
18
+ <table className="table-viewer">
19
  <thead>
20
  <tr>
21
  {props.columns.map((column: string) => (
 
27
  {props.data.map((row: { [column: string]: any }, i: number) => (
28
  <tr key={`row-${i}`}>
29
  {props.columns.map((_column: string, j: number) => (
30
+ <td key={`cell ${i}, ${j}`}>
31
+ <Cell value={row[j]} />
32
+ </td>
33
  ))}
34
  </tr>
35
  ))}