Skip to content

Commit

Permalink
Merge pull request #80 from sayari-analytics/feature/assets
Browse files Browse the repository at this point in the history
reimplement Image Icon's in v7 & FontBook class
  • Loading branch information
mggower authored Feb 26, 2024
2 parents 8645fef + 86576a6 commit a9b2475
Show file tree
Hide file tree
Showing 53 changed files with 2,132 additions and 1,543 deletions.
2 changes: 2 additions & 0 deletions examples/assets/icons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const person = `data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB3aWR0aD0iMTZweCIgaGVpZ2h0PSIxNnB4IiB2aWV3Qm94PSIwIDAgMTYgMTYiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgICA8IS0tIEdlbmVyYXRvcjogc2tldGNodG9vbCA2My4xICgxMDEwMTApIC0gaHR0cHM6Ly9za2V0Y2guY29tIC0tPgogICAgPHRpdGxlPkNDNEQ2NkYzLTg3QTktNEIxQy1CRjNBLUMwQUY0RjQ5OTM1MTwvdGl0bGU+CiAgICA8ZGVzYz5DcmVhdGVkIHdpdGggc2tldGNodG9vbC48L2Rlc2M+CiAgICA8ZGVmcz4KICAgICAgICA8cGF0aCBkPSJNOCwtNS4wMDAwMDAwNmUtMDggQzEwLjI5NzUwNDYsLTUuMDAwMDAwMDZlLTA4IDEyLjE2LDEuODYyNDk1NCAxMi4xNiw0LjE1OTk5OTk4IEMxMi4xNiw2LjQ1NzUwNDU1IDEwLjI5NzUwNDYsOC4zMiA4LDguMzIgQzUuNzAyNDk1NDMsOC4zMiAzLjgzOTk5OTk3LDYuNDU3NTA0NTUgMy44Mzk5OTk5Nyw0LjE1OTk5OTk4IEMzLjgzOTk5OTk3LDEuODYyNDk1NCA1LjcwMjQ5NTQzLC01LjAwMDAwMDA2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XNrPgogICAgICAgICAgICA8dXNlIGlkPSJDb21iaW5lZC1TaGFwZSIgZmlsbD0iI2ZmZiIgZmlsbC1ydWxlPSJub256ZXJvIiB4bGluazpocmVmPSIjcGF0aC0xIj48L3VzZT4KICAgICAgICAgICAgPGcgaWQ9ImNvbG9ycy9hYV9pY29uX2RhcmsiIG1hc2s9InVybCgjbWFzay0yKSIgZmlsbD0iI2ZmZiI+CiAgICAgICAgICAgICAgICA8cmVjdCBpZD0iaWNvbl9kYXJrIiB4PSIwIiB5PSIwIiB3aWR0aD0iMTYiIGhlaWdodD0iMTYiPjwvcmVjdD4KICAgICAgICAgICAgPC9nPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+`
Binary file added examples/assets/person.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions examples/native/src/index.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
@import '../../reset';
@import url("https://fonts.googleapis.com/css?family=Roboto:400,500,700&display=swap");

@font-face {
font-family: Roboto;
font-weight: 400;
font-style: normal;
font-stretch: normal;
font-display: swap;
}

#examples {
display: flex;
Expand Down
56 changes: 41 additions & 15 deletions examples/native/src/labels/index.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,50 @@
import * as Renderer from '@trellis/renderers/webgl'
import * as Graph from '@trellis/index'
import * as Collide from '@trellis/layout/collide'
import { person } from '../../../assets/icons'

const GREEN = '#91AD49'
const GREEN_LIGHT = '#C6D336'
const DARK_GREEN = '#607330'

const IMAGE_ICON: Graph.ImageIcon = {
type: 'imageIcon',
url: person,
scale: 0.66
}

const TEXT_ICON: Graph.TextIcon = {
type: 'textIcon',
family: 'sans-serif',
color: '#fff',
weight: '400',
text: '!',
size: 14
content: '!',
style: {
fontSize: 14,
fontWeight: '400',
color: '#fff'
}
}

const NODE_STYLE: Graph.NodeStyle = {
color: GREEN,
icon: TEXT_ICON,
stroke: [{ width: 2, color: GREEN_LIGHT }],
label: {
position: 'right',
position: 'bottom',
fontName: 'NodeLabel',
fontFamily: 'Arial, sans-serif',
background: { color: GREEN_LIGHT },
fontFamily: 'Roboto',
highlight: { color: GREEN_LIGHT },
margin: 4
}
}

const NODE_HOVER_STYLE: Graph.NodeStyle = {
color: DARK_GREEN,
icon: TEXT_ICON,
icon: IMAGE_ICON,
stroke: [{ width: 2, color: GREEN_LIGHT }],
label: {
position: 'right',
position: 'bottom',
fontName: 'NodeLabelHover',
fontFamily: 'Arial, sans-serif',
background: { color: DARK_GREEN },
fontFamily: 'Roboto',
highlight: { color: DARK_GREEN },
color: '#FFF',
margin: 4
}
Expand All @@ -59,11 +67,29 @@ const data = [

const collide = Collide.Layout()

const edges: Graph.Edge[] = []
const edges: Graph.Edge[] = [
{
id: '0::1',
source: '0',
target: '1',
label: '0 <- EDGE LABEL -> 1',
style: {
arrow: 'both',
label: {
fontName: 'EdgeLabel',
fontFamily: 'Roboto',
fontSize: 10,
color: DARK_GREEN,
margin: 4
}
}
}
]

let nodes = data.map<Graph.Node>((label, index) => ({
radius: 10,
label: index % 2 === 0 ? label + ' 北京' : label,
id: `${index}-${label}`,
label: `${label}${index % 2 === 0 ? ' 北京' : ''}`,
id: `${index}`,
style: NODE_STYLE
}))

Expand Down
23 changes: 14 additions & 9 deletions examples/native/src/perf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,33 @@ const sampleCoordinatePlane = function* (count: number, step: number, sample: nu
const PURPLE = '#7A5DC5'
const LIGHT_PURPLE = '#CAD'
const ARIAL_PINK = 'ArialPink'
const TEXT_ICON: Graph.TextIcon = {
type: 'textIcon',
content: 'T',
style: {
fontSize: 14,
color: '#fff',
fontWeight: '400'
}
}

const NODE_STYLE: Graph.NodeStyle = {
color: PURPLE,
stroke: [{ width: 2, color: LIGHT_PURPLE }],
icon: { type: 'textIcon', text: 'T', family: 'sans-serif', size: 14, color: '#fff', weight: '400' },
icon: TEXT_ICON,
label: {
position: 'top',
position: 'bottom',
fontName: ARIAL_PINK,
fontFamily: ['Arial', 'sans-serif'],
margin: 2,
background: {
color: '#f66',
opacity: 0.5
}
fontFamily: 'Roboto',
margin: 2
}
}

const NODE_HOVER_STYLE: Graph.NodeStyle = {
color: '#f66',
stroke: [{ width: 2, color: '#fcc' }],
label: { position: 'bottom', color: '#fcc' },
icon: { type: 'textIcon', text: 'L', family: 'sans-serif', size: 14, color: '#fff', weight: '400' }
icon: TEXT_ICON
}

const EDGE_STYLE: Graph.EdgeStyle = {
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"d3-force": "^3.0.0",
"d3-hierarchy": "^3.1.2",
"d3-interpolate": "^3.0.1",
"fontfaceobserver": "^2.3.0",
"pixi.js": "^7.3.2",
"stats.js": "^0.17.0"
},
Expand All @@ -54,6 +55,7 @@
"@types/d3-interpolate": "^3.0.3",
"@types/d3-scale": "^4.0.6",
"@types/d3-scale-chromatic": "^3.0.1",
"@types/fontfaceobserver": "^2.1.3",
"@types/react": "^18.2.33",
"@types/react-dom": "^18.2.14",
"@types/stats.js": "^0.17.2",
Expand All @@ -75,13 +77,23 @@
"vite": "^4.5.0",
"vitest": "^0.34.6"
},
"keywords": ["graph", "network", "infovis", "visualization", "react", "webgl"],
"keywords": [
"graph",
"network",
"infovis",
"visualization",
"react",
"webgl"
],
"peerDependencies": {
"react": ">=16.0"
},
"repository": {
"type": "git",
"url": "https://github.com/sayari-analytics/trellis.git"
},
"workspaces": ["examples/native", "examples/react"]
"workspaces": [
"examples/native",
"examples/react"
]
}
2 changes: 1 addition & 1 deletion src/bindings/react/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createElement, useRef, useEffect } from 'react'
import { Renderer as WebGLRenderer, Options } from '../../renderers/webgl'
import { Node, Edge, Annotation } from '../..'
import { Node, Edge, Annotation } from '../../types/api'

export type Props<N extends Node = Node, E extends Edge = Edge> = Options & {
nodes: N[]
Expand Down
26 changes: 15 additions & 11 deletions src/bindings/react/selection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReactNode, useCallback, useEffect, useRef, useState } from 'react'
import { ViewportDragDecelerateEvent, ViewportDragEvent } from '../../renderers/webgl'
import { Annotation, Node } from '../..'
import { Annotation, Node } from '../../types/api'

export type SelectionChangeEvent = {
type: 'selectionChange'
Expand Down Expand Up @@ -209,11 +209,13 @@ export const Selection = <N extends Node>(props: Props<N>) => {
y: state.annotation.y,
radius: state.annotation.radius,
style: {
backgroundColor: props.color ?? '#eee',
stroke: {
color: props.strokeColor ?? '#ccc',
width: props.strokeWidth ?? 2
}
color: props.color ?? '#eee',
stroke: [
{
color: props.strokeColor ?? '#ccc',
width: props.strokeWidth ?? 2
}
]
}
}
: state.annotation?.type === 'rectangle'
Expand All @@ -225,11 +227,13 @@ export const Selection = <N extends Node>(props: Props<N>) => {
width: state.annotation.width,
height: state.annotation.height,
style: {
backgroundColor: props.color ?? '#eee',
stroke: {
color: props.strokeColor ?? '#ccc',
width: props.strokeWidth ?? 2
}
color: props.color ?? '#eee',
stroke: [
{
color: props.strokeColor ?? '#ccc',
width: props.strokeWidth ?? 2
}
]
}
}
: undefined
Expand Down
Loading

0 comments on commit a9b2475

Please sign in to comment.