Spaces:
Running
Running
For string attributes use a categorical color scheme. (Instead of throwing an exception.)
Browse files
lynxkite-app/web/src/workspace/Workspace.tsx
CHANGED
|
@@ -30,7 +30,6 @@ import NodeWithParams from './nodes/NodeWithParams';
|
|
| 30 |
// import NodeWithTableView from './NodeWithTableView';
|
| 31 |
import EnvironmentSelector from './EnvironmentSelector';
|
| 32 |
import { LynxKiteState } from './LynxKiteState';
|
| 33 |
-
import '@xyflow/react/dist/style.css';
|
| 34 |
import { Workspace, WorkspaceNode } from "../apiTypes.ts";
|
| 35 |
import NodeSearch, { OpsOp, Catalog, Catalogs } from "./NodeSearch.tsx";
|
| 36 |
import NodeWithVisualization from "./nodes/NodeWithVisualization.tsx";
|
|
|
|
| 30 |
// import NodeWithTableView from './NodeWithTableView';
|
| 31 |
import EnvironmentSelector from './EnvironmentSelector';
|
| 32 |
import { LynxKiteState } from './LynxKiteState';
|
|
|
|
| 33 |
import { Workspace, WorkspaceNode } from "../apiTypes.ts";
|
| 34 |
import NodeSearch, { OpsOp, Catalog, Catalogs } from "./NodeSearch.tsx";
|
| 35 |
import NodeWithVisualization from "./nodes/NodeWithVisualization.tsx";
|
lynxkite-graph-analytics/src/lynxkite_plugins/graph_analytics/lynxkite_ops.py
CHANGED
|
@@ -249,13 +249,22 @@ def sample_graph(graph: nx.Graph, *, nodes: int = 100):
|
|
| 249 |
|
| 250 |
|
| 251 |
def _map_color(value):
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
|
| 260 |
|
| 261 |
@op("Visualize graph", view="visualization")
|
|
|
|
| 249 |
|
| 250 |
|
| 251 |
def _map_color(value):
|
| 252 |
+
if pd.api.types.is_numeric_dtype(value):
|
| 253 |
+
cmap = matplotlib.cm.get_cmap("viridis")
|
| 254 |
+
value = (value - value.min()) / (value.max() - value.min())
|
| 255 |
+
rgba = cmap(value)
|
| 256 |
+
return [
|
| 257 |
+
"#{:02x}{:02x}{:02x}".format(int(r * 255), int(g * 255), int(b * 255))
|
| 258 |
+
for r, g, b in rgba[:, :3]
|
| 259 |
+
]
|
| 260 |
+
else:
|
| 261 |
+
cmap = matplotlib.cm.get_cmap("Paired")
|
| 262 |
+
categories = pd.Index(value.unique())
|
| 263 |
+
colors = cmap.colors[: len(categories)]
|
| 264 |
+
return [
|
| 265 |
+
"#{:02x}{:02x}{:02x}".format(int(r * 255), int(g * 255), int(b * 255))
|
| 266 |
+
for r, g, b in [colors[categories.get_loc(v)] for v in value]
|
| 267 |
+
]
|
| 268 |
|
| 269 |
|
| 270 |
@op("Visualize graph", view="visualization")
|