forked from mandiant/capa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
171 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<template> | ||
<div ref="chartRef" class="namespace-chart"></div> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, onMounted, watch } from 'vue' | ||
import Plotly from 'plotly.js-dist' | ||
const props = defineProps({ | ||
data: { | ||
type: Object, | ||
required: true | ||
} | ||
}) | ||
const chartRef = ref(null) | ||
const createSunburstData = (rules) => { | ||
const data = { | ||
ids: [], | ||
labels: [], | ||
parents: [], | ||
values: [] | ||
} | ||
const addNamespace = (namespace, value) => { | ||
const parts = namespace.split('/') | ||
let currentId = '' | ||
let parent = '' | ||
parts.forEach((part, index) => { | ||
currentId = currentId ? `${currentId}/${part}` : part | ||
if (!data.ids.includes(currentId)) { | ||
data.ids.push(currentId) | ||
data.labels.push(part) | ||
data.parents.push(parent) | ||
data.values.push(0) | ||
} | ||
const valueIndex = data.ids.indexOf(currentId) | ||
data.values[valueIndex] += value | ||
parent = currentId | ||
}) | ||
return parent | ||
} | ||
Object.entries(rules).forEach(([ruleName, rule]) => { | ||
if (rule.meta.lib) return // Skip library rules | ||
const namespace = rule.meta.namespace || 'root' | ||
const parent = addNamespace(namespace, rule.matches.length) | ||
// Add the rule itself | ||
data.ids.push(ruleName) | ||
data.labels.push(rule.meta.name) | ||
data.parents.push(parent) | ||
data.values.push(rule.matches.length) | ||
}) | ||
return data | ||
} | ||
const renderChart = () => { | ||
if (!chartRef.value) return | ||
const sunburstData = createSunburstData(props.data.rules) | ||
const layout = { | ||
margin: { l: 0, r: 0, b: 0, t: 0 }, | ||
sunburstcolorway: [ | ||
'#636efa', | ||
'#EF553B', | ||
'#00cc96', | ||
'#ab63fa', | ||
'#19d3f3', | ||
'#e763fa', | ||
'#FECB52', | ||
'#FFA15A', | ||
'#FF6692', | ||
'#B6E880' | ||
], | ||
extendsunburstcolorway: true | ||
} | ||
const config = { | ||
responsive: true | ||
} | ||
Plotly.newPlot( | ||
chartRef.value, | ||
[ | ||
{ | ||
type: 'sunburst', | ||
ids: sunburstData.ids, | ||
labels: sunburstData.labels, | ||
parents: sunburstData.parents, | ||
values: sunburstData.values, | ||
outsidetextfont: { size: 20, color: '#377eb8' }, | ||
leaf: { opacity: 0.5 }, | ||
marker: { line: { width: 2 } }, | ||
branchvalues: 'total' | ||
} | ||
], | ||
layout, | ||
config | ||
) | ||
return sunburstData | ||
} | ||
onMounted(() => { | ||
const data = renderChart() | ||
console.log(data) | ||
}) | ||
watch( | ||
() => props.data, | ||
() => { | ||
renderChart() | ||
}, | ||
{ deep: true } | ||
) | ||
</script> | ||
|
||
<style scoped> | ||
.namespace-chart { | ||
width: 100%; | ||
height: 600px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters