Skip to content

Commit

Permalink
include image icon in label example
Browse files Browse the repository at this point in the history
  • Loading branch information
mggower committed Nov 2, 2023
1 parent a15449c commit c3a14ff
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 5 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+CiAgICA8ZGVmcz4KICAgICAgICA8cGF0aCBkPSJNOCwtNS4wMDAwMDAwNmUtMDggQzEwLjI5NzUwNDYsLTUuMDAwMDAwMDZlLTA4IDEyLjE2LDEuODYyNDk1NCAxMi4xNiw0LjE1OTk5OTk4IEMxMi4xNiw2LjQ1NzUwNDU1IDEwLjI5NzUwNDYsOC4zMiA4LDguMzIgQzUuNzAyNDk1NDMsOC4zMiAzLjgzOTk5OTk3LDYuNDU3NTA0NTUgMy44Mzk5OTk5Nyw0LjE1OTk5OTk4IEMzLjgzOTk5OTk3LDEuODYyNDk1NCA1LjcwMjQ5NTQzLC01LjAwMDAwMDA2ZS0wOCA4LC01LjAwMDAwMDA2ZS0wOCBaIE04LDAuOTk5OTk5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gZmlsbD0iI2ZmZiIgZmlsbC1ydWxlPSJub256ZXJvIiB4bGluazpocmVmPSIjcGF0aC0xIj48L3VzZT4KICAgICAgICAgICAgPGcgaWQ9ImNvbG9ycy9hYV9pY29uX2RhcmsiIG1hc2s9InVybCgjbWFzay0yKSIgZmlsbD0iI2ZmZiI+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: 8 additions & 1 deletion examples/native/src/labels/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
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',
fontFamily: 'sans-serif',
Expand All @@ -17,7 +24,7 @@ const TEXT_ICON: Graph.TextIcon = {

const NODE_STYLE: Graph.NodeStyle = {
color: GREEN,
icon: TEXT_ICON,
icon: IMAGE_ICON,
stroke: [{ width: 2, color: GREEN_LIGHT }],
label: {
position: 'right',
Expand Down
2 changes: 2 additions & 0 deletions src/renderers/webgl/objects/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export class Icon {
private create(style: TrellisIcon) {
const icon = style.type === 'textIcon' ? this.createTextIcon(style) : this.createImageIcon(style)
icon.anchor.set(0.5)
icon.x = this.x ?? 0
icon.y = this.y ?? 0
return icon
}

Expand Down
3 changes: 1 addition & 2 deletions src/renderers/webgl/objects/label/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ export class LabelBackground {
this.container = container
this._style = style

const bounds = this.label.getLocalBounds()
this.rect = { width: bounds.width, height: bounds.height }
this.rect = { ...this.label.getLocalBounds() }

const { width, height } = this.size

Expand Down
3 changes: 1 addition & 2 deletions src/renderers/webgl/objects/label/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ export class Label {
}

if (labelHasChanged || styleHasChanged) {
const { width, height } = this.text.getLocalBounds()
this.setBackground({ width, height }, this.text.anchor.clone(), style?.background)
this.setBackground({ ...this.text.getLocalBounds() }, this.text.anchor.clone(), style?.background)
}

return this
Expand Down

0 comments on commit c3a14ff

Please sign in to comment.