Skip to content

Commit 28c5d60

Browse files
committed
add logo to example graphic
1 parent c05e713 commit 28c5d60

File tree

2 files changed

+68
-10
lines changed

2 files changed

+68
-10
lines changed

v1-draft-0/examples/l3rd-name/graphic.mjs

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ class MyGraphic extends HTMLElement {
3939
this.appendChild(container);
4040

4141
container.style.position = "absolute";
42-
container.style.left = "10%";
42+
container.style.left = "calc(10% + 60px)";
4343
container.style.bottom = "calc(10% + 30px)";
44-
container.style.height = "50px";
44+
container.style.height = "32px";
4545

4646
container.style.padding = "6px 20px";
4747
container.style.backgroundColor = "#f00";
@@ -62,10 +62,10 @@ class MyGraphic extends HTMLElement {
6262
this.appendChild(container2);
6363

6464
container2.style.position = "absolute";
65-
container2.style.left = "10%";
65+
container2.style.left = "calc(10% + 60px)";
6666
container2.style.bottom = "10%";
67-
container2.style.height = "30px";
68-
container2.style.padding = "0px 20px";
67+
container2.style.height = "23px";
68+
container2.style.padding = "5px 20px 2px 20px";
6969
container2.style.backgroundColor = "#b00";
7070
container2.style.color = "#fff";
7171
container2.style.fontFamily = "Roboto, sans-serif";
@@ -79,11 +79,24 @@ class MyGraphic extends HTMLElement {
7979
nameText2.innerText = "";
8080
container2.appendChild(nameText2);
8181

82+
const logo = document.createElement("img");
83+
logo.src = await this._loadImage(import.meta.resolve("./lib/ograf-logo-app.svg"))
84+
logo.style.position = "absolute";
85+
logo.style.left = `calc(10%)`
86+
logo.style.bottom = `calc(10% + 10px)`
87+
logo.style.width = "50px";
88+
logo.style.boxShadow = "0 0 10px rgba(0,0,0,0.5)";
89+
logo.style.borderRadius = "5px";
90+
this.appendChild(logo);
91+
92+
93+
8294
this.elements = {
8395
container,
8496
nameText,
8597
container2,
8698
nameText2,
99+
logo
87100
};
88101

89102
// Initialize the GSAP timeline --------------------------------------------
@@ -128,13 +141,13 @@ class MyGraphic extends HTMLElement {
128141
// params.id
129142
// params.payload
130143

131-
await this._doAction('customAction', params.id, params.payload);
144+
await this._doAction('customAction', params);
132145
}
133-
async _doAction(type, payload) {
146+
async _doAction(type, params) {
134147
const timeline = this.g.gsap.timeline();
135148

136149
// Retrieve the tweens for the action:
137-
const tweens = this._getActionAnimation(type, payload);
150+
const tweens = this._getActionAnimation(type, params);
138151

139152
// Add the tweens to the timeline, so that they'll animate:
140153
for (const tween of tweens) {
@@ -205,7 +218,7 @@ class MyGraphic extends HTMLElement {
205218
gsap.set(this.elements.container, {
206219
x: -30,
207220
backgroundColor: "#f00",
208-
color: "#000",
221+
color: "#fff",
209222
opacity: 0,
210223
}),
211224
gsap.set(this.elements.nameText, {
@@ -218,6 +231,10 @@ class MyGraphic extends HTMLElement {
218231
gsap.set(this.elements.nameText2, {
219232
text: "",
220233
}),
234+
gsap.set(this.elements.logo, {
235+
scale: 0.5,
236+
opacity: 0
237+
}),
221238
];
222239

223240
// Add Tweens to the beginning of the timeline:
@@ -296,6 +313,16 @@ class MyGraphic extends HTMLElement {
296313
duration: 0.8,
297314
// text: this._currentData.name,
298315
}),
316+
gsap.to(this.elements.logo, {
317+
duration: 0.5,
318+
opacity: 1,
319+
}),
320+
gsap.to(this.elements.logo, {
321+
duration: 1.5,
322+
rotation: 360,
323+
scale: 1
324+
// text: this._currentData.name,
325+
}),
299326
];
300327
}
301328
_getStopAnimation(params) {
@@ -317,6 +344,12 @@ class MyGraphic extends HTMLElement {
317344
opacity: 0,
318345
ease: "power2.in",
319346
}),
347+
gsap.to(this.elements.logo, {
348+
duration: 0.8,
349+
rotation: 180,
350+
scale: 0.8,
351+
opacity: 0
352+
}),
320353
];
321354
}
322355
_getHighlightAnimation(params) {
@@ -338,10 +371,30 @@ class MyGraphic extends HTMLElement {
338371
color: "#fff",
339372

340373
ease: "power2.in",
341-
})
374+
}),
375+
gsap.to(this.elements.logo, {
376+
duration: 1,
377+
scale: 1.5,
378+
ease: "bounce.out",
379+
}),
380+
gsap.to(this.elements.logo, {
381+
delay: 1,
382+
duration: 1,
383+
scale: 1,
384+
}),
342385

343386
];
344387
}
388+
_loadImage(url) {
389+
return new Promise((resolve, reject) => {
390+
const newImg = new Image;
391+
newImg.onload = function() {
392+
resolve(this.src)
393+
}
394+
newImg.onerror = reject;
395+
newImg.src = url
396+
})
397+
}
345398
}
346399

347400
export default MyGraphic;
Lines changed: 5 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)