Skip to content

Commit

Permalink
feat: add Node type renderConfig object
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-rietzke committed May 5, 2023
1 parent 4e702a2 commit 020cbaf
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

# Graphly D3

[![GitHub Repo stars](https://img.shields.io/github/stars/LiveReader/graphly-d3)](https://github.com/LiveReader/graphly-d3)
[![npm version](https://badge.fury.io/js/%40livereader%2Fgraphly-d3.svg)](https://www.npmjs.com/package/@livereader/graphly-d3)
[![npm](https://img.shields.io/npm/dm/@livereader/graphly-d3)](https://www.npmjs.com/package/@livereader/graphly-d3)
[![GitHub Workflow Status Release](https://img.shields.io/github/actions/workflow/status/livereader/graphly-d3/release.yml?branch=main)](https://www.npmjs.com/package/@livereader/graphly-d3)
[![GitHub Workflow Status Docs](https://img.shields.io/github/actions/workflow/status/livereader/graphly-d3/deploy-docs.yml?branch=main&label=docs)](https://docs.graphly.dev)
[![GitHub Repo stars](https://img.shields.io/github/stars/LiveReader/graphly-d3)](https://github.com/LiveReader/graphly-d3)
[![build](https://github.com/LiveReader/graphly-d3/actions/workflows/release.yml/badge.svg)](https://github.com/LiveReader/graphly-d3/actions/workflows/release.yml)

## Powerful Graph Visualization

Expand Down
1 change: 1 addition & 0 deletions lib/shape/utils/levelOfDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ function register(data: Node, threshold: number, styles: LODStyle[] = []) {
applyLODStyles(relativeScale, styles);
return true;
};
if (data.renderConfig) callback(data.renderConfig.scale);
if (data.simulation) data.simulation.registerOnZoom(id, globalThreshold, callback);
}
3 changes: 3 additions & 0 deletions lib/shape/utils/styleModifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ export function applyStyles(shape: d3.Selection<any, any, any, any>, styles: Sha
applyStyle(
shape,
style.key,
style.value.data.renderConfig?.theme ?? "light" == "light"
? style.value.lightValue
: style.value.darkValue,
style.condition
);
if (!style.value.data.simulation) return;
Expand Down
1 change: 1 addition & 0 deletions lib/shape/utils/themes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Node } from "../../types/Node";

export function OnThemeChange(data: Node, callback: (theme: "light" | "dark") => void) {
callback(data.renderConfig?.theme ?? "light");
if (!data.simulation) return;
data.simulation.eventStore.on("theme:change", callback);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/types/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ export type Satellite = {
distance: number;
};

export type RenderConfig = {
theme: "light" | "dark";
scale: number;
};

export type Node<T = any> = D3Node & {
shape: Shape;
renderConfig?: RenderConfig;
simulation?: ForceSimulation;
gravity?: number;
spawn?: Spawn;
Expand Down

0 comments on commit 020cbaf

Please sign in to comment.