Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Anonymization refactor #572

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions demo/data/graph.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"start": "2023-09-27T15:50:39.425118+00:00",
"end": "2023-09-27T15:51:11.922153+00:00",
"rootNodeIds": [
"ea9d7c12-7418-4ea9-b33d-189f22f737af",
"7d93e182-e17f-40a2-a0c3-784d1d0e7ff5"
],
"nodes": [
[
"ea9d7c12-7418-4ea9-b33d-189f22f737af",
{
"id": "ea9d7c12-7418-4ea9-b33d-189f22f737af",
"start": "2023-09-27T15:50:39.425118+00:00",
"end": "2023-09-27T15:51:05.922153+00:00",
"parents": [],
"children": [],
"attributes": {
"kind": "task-run",
"label": "random_number-1",
"state_name": "Completed",
"state_type": "COMPLETED"
}
}
],
[
"7d93e182-e17f-40a2-a0c3-784d1d0e7ff5",
{
"id": "7d93e182-e17f-40a2-a0c3-784d1d0e7ff5",
"start": "2023-09-27T15:50:39.425118+00:00",
"end": "2023-09-27T15:51:11.922153+00:00",
"parents": [],
"children": [],
"attributes": {
"kind": "task-run",
"label": "random_number-2",
"state_name": "Completed",
"state_type": "COMPLETED"
}
}
]
]
}
163 changes: 163 additions & 0 deletions demo/sections/components/GraphDemo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<template>
<p-layout-resizable placement="bottom" class="graph-demo">
<GraphRoot v-model:viewport="visibleDateRange" :data :config="config" class="graph-demo__graph p-background" />

<template #aside>
<p-layout-resizable class="graph-demo__data" placement="left">
<template #aside>
<div>View 1</div>
</template>

<div>
{{ visibleDateRange }}
</div>
</p-layout-resizable>
</template>
</p-layout-resizable>
</template>

<script lang="ts" setup>
import { useColorTheme } from '@prefecthq/prefect-design'
import { parseISO, isValid } from 'date-fns'
import { computed, ref } from 'vue'
import GraphRoot from '@/components/GraphRoot.vue'
import demograph from '@/demo/data/graph.json'
import { GraphConfig, GraphData } from '@/models/Graph'
import { ViewportDateRange } from '@/models/viewport'

const { value: colorThemeValue } = useColorTheme()

// quick and dirty way to convert the iso strings into actual dates.
function reviver(key: string, value: any): unknown {
if (typeof value === 'string') {
const date = parseISO(value)

if (isValid(date)) {
return date
}
}

if (key === 'nodes' || key === 'events') {
return new Map(value)
}

return value
}

function mapJsonToGraphData(json: unknown): GraphData {
return JSON.parse(JSON.stringify(json), reviver)
}

const data = computed(() => mapJsonToGraphData(demograph))
const visibleDateRange = ref<ViewportDateRange>()

const typeColors = {
COMPLETED: '#219D4B',
RUNNING: '#09439B',
SCHEDULED: '#E08504',
PENDING: '#554B58',
FAILED: '#DE0529',
CANCELLED: '#333333',
CANCELLING: '#333333',
CRASHED: '#EA580C',
PAUSED: '#554B58',
} satisfies Record<string, string>

const documentStyles = getComputedStyle(document.documentElement)

function getColorToken(cssVariable: string): string {
return documentStyles.getPropertyValue(cssVariable).trim()
}

const config = computed<GraphConfig>(() => ({
id: 'foo',
styles: {
colorMode: colorThemeValue.value,
textDefault: getColorToken('--p-color-text-default'),
textInverse: getColorToken('--p-color-text-inverse'),
nodeToggleBorderColor: getColorToken('--p-color-button-default-border'),
selectedBorderColor: getColorToken('--p-color-text-selected'),
edgeColor: getColorToken('--p-color-text-subdued'),
guideLineColor: getColorToken('--p-color-divider'),
guideTextColor: getColorToken('--p-color-text-subdued'),
// node: node => {
// // This could be a type guard downstream
// if ('type' in node.attributes && node.attributes.type && typeof node.attributes.type === 'string') {
// return {
// background: typeColors[node.attributes.type],
// }
// }
// },
},
}))
</script>

<style>
.graph-demo {
height: calc(100vh - 64px);
width: 100vw;
}

.graph-demo { @apply
rounded-lg
overflow-hidden
px-4
py-4
}

.graph-demo__data .p-layout-resizable__main,
.graph-demo__data .p-layout-resizable__aside { @apply
rounded-lg
p-4
border
}

.graph-demo.p-layout-resizable--top,
.graph-demo.p-layout-resizable--bottom {
--p-layout-resizable-aside-size: 40vh;
--p-layout-resizable-aside-max-size: 80vh;
--p-layout-resizable-aside-min-size: 350px;
}

.graph-demo .p-layout-resizable__handle--top,
.graph-demo .p-layout-resizable__handle--bottom { @apply
shadow-none
h-2
}

.graph-demo .p-layout-resizable__handle--left,
.graph-demo .p-layout-resizable__handle--right { @apply
shadow-none
w-2
}

.graph-demo__data.p-layout-resizable--left,
.graph-demo__data.p-layout-resizable--right {
--p-layout-resizable-aside-size: 30vw;
--p-layout-resizable-aside-max-size: 60vw;
--p-layout-resizable-aside-min-size: 350px;
}

.graph-demo__data .p-layout-resizable__aside,
.graph-demo__data .p-layout-resizable__main {
background-color: var(--p-color-bg-1);
}

.graph-demo__graph { @apply
rounded-lg
border
}


@screen lg {
.graph-demo {
height: 100vh;
width: 100vw;
}
}

.graph-demo__graph {
width: 100%;
height: 100%;
}
</style>
141 changes: 0 additions & 141 deletions demo/sections/components/RunGraphDemo.vue

This file was deleted.

2 changes: 1 addition & 1 deletion demo/sections/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { Section } from '@/demo/router/routeRecords'


export const components: Section = {
RunGraph: () => import('./RunGraphDemo.vue'),
Graph: () => import('./GraphDemo.vue'),
}
Loading