mirror of https://github.com/MISP/MISP
chg: [eventGraph] Improved object coloring strategy
parent
349e2f2161
commit
3b4f61c884
|
@ -66,7 +66,11 @@ class ColourPaletteTool
|
||||||
// pass the element's id from the list along to get a colour for a single item
|
// pass the element's id from the list along to get a colour for a single item
|
||||||
public function generatePaletteFromString($string, $items, $onlySpecific = false)
|
public function generatePaletteFromString($string, $items, $onlySpecific = false)
|
||||||
{
|
{
|
||||||
$hue = $this->__stringToNumber($string);
|
if (Validation::uuid($string)) {
|
||||||
|
$hue = $this->__uuidToNumber($string);
|
||||||
|
} else {
|
||||||
|
$hue = $this->__stringToNumber($string);
|
||||||
|
}
|
||||||
$saturation = 1;
|
$saturation = 1;
|
||||||
$steps = 80 / $items;
|
$steps = 80 / $items;
|
||||||
$results = array();
|
$results = array();
|
||||||
|
@ -91,4 +95,12 @@ class ColourPaletteTool
|
||||||
}
|
}
|
||||||
return $number % 100 / 100;
|
return $number % 100 / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function __uuidToNumber($string)
|
||||||
|
{
|
||||||
|
$part = explode('-', $string)[4];
|
||||||
|
$number = hexdec($part);
|
||||||
|
$max = hexdec('ffffffffffff');
|
||||||
|
return round($number / $max, 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,9 @@
|
||||||
'distributionLevels' => $this->__eventModel->Attribute->distributionLevels
|
'distributionLevels' => $this->__eventModel->Attribute->distributionLevels
|
||||||
);
|
);
|
||||||
$this->__authorized_JSON_key = array('event_id', 'distribution', 'category', 'type', 'value', 'comment', 'uuid', 'to_ids', 'timestamp', 'id');
|
$this->__authorized_JSON_key = array('event_id', 'distribution', 'category', 'type', 'value', 'comment', 'uuid', 'to_ids', 'timestamp', 'id');
|
||||||
|
|
||||||
|
App::uses('ColourPaletteTool', 'Tools');
|
||||||
|
$this->__paletteTool = new ColourPaletteTool();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,6 +273,7 @@
|
||||||
$this->__extendedEventUUIDMapping[$toPush['event_id']] = '';
|
$this->__extendedEventUUIDMapping[$toPush['event_id']] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$templatesCount = [];
|
||||||
foreach ($object as $obj) {
|
foreach ($object as $obj) {
|
||||||
$toPush = array(
|
$toPush = array(
|
||||||
'id' => sprintf('o-%s', $obj['id']),
|
'id' => sprintf('o-%s', $obj['id']),
|
||||||
|
@ -290,6 +294,10 @@
|
||||||
$this->__json['existing_object_relation'][$attr['object_relation']] = 0; // set-alike
|
$this->__json['existing_object_relation'][$attr['object_relation']] = 0; // set-alike
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (empty($templatesCount[$obj['template_uuid']])) {
|
||||||
|
$templatesCount[$obj['template_uuid']] = 0;
|
||||||
|
}
|
||||||
|
$templatesCount[$obj['template_uuid']]++;
|
||||||
|
|
||||||
array_push($this->__json['items'], $toPush);
|
array_push($this->__json['items'], $toPush);
|
||||||
$this->__extendedEventUUIDMapping[$toPush['event_id']] = '';
|
$this->__extendedEventUUIDMapping[$toPush['event_id']] = '';
|
||||||
|
@ -307,6 +315,7 @@
|
||||||
array_push($this->__json['relations'], $toPush);
|
array_push($this->__json['relations'], $toPush);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$this->__json['items'] = $this->addObjectColors($this->__json['items'], $templatesCount);
|
||||||
|
|
||||||
if ($this->__extended_view) {
|
if ($this->__extended_view) {
|
||||||
$this->fetchEventUUIDFromId();
|
$this->fetchEventUUIDFromId();
|
||||||
|
@ -564,4 +573,18 @@
|
||||||
]);
|
]);
|
||||||
$this->__extendedEventUUIDMapping = $eventUUIDs;
|
$this->__extendedEventUUIDMapping = $eventUUIDs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function addObjectColors($items, $templatesCount)
|
||||||
|
{
|
||||||
|
$colours = [];
|
||||||
|
foreach ($templatesCount as $templateUUID => $count) {
|
||||||
|
$colours[$templateUUID] = $this->__paletteTool->generatePaletteFromString($templateUUID, $count);
|
||||||
|
}
|
||||||
|
foreach ($items as $i => $item) {
|
||||||
|
if ($item['node_type'] == 'object') {
|
||||||
|
$items[$i]['color'] = array_shift($colours[$item['template_uuid']]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,13 +86,13 @@ class EventGraph {
|
||||||
bind_listener() {
|
bind_listener() {
|
||||||
var that = this;
|
var that = this;
|
||||||
this.network.on("selectNode", function (params) {
|
this.network.on("selectNode", function (params) {
|
||||||
that.network.moveTo({
|
// that.network.moveTo({
|
||||||
position: {
|
// position: {
|
||||||
x: params.pointer.canvas.x,
|
// x: params.pointer.canvas.x,
|
||||||
y: params.pointer.canvas.y
|
// y: params.pointer.canvas.y
|
||||||
},
|
// },
|
||||||
animation: true,
|
// animation: true,
|
||||||
});
|
// });
|
||||||
});
|
});
|
||||||
|
|
||||||
this.network.on("dragStart", function (params) {
|
this.network.on("dragStart", function (params) {
|
||||||
|
@ -717,7 +717,7 @@ class EventGraph {
|
||||||
group: group,
|
group: group,
|
||||||
mass: 5,
|
mass: 5,
|
||||||
icon: {
|
icon: {
|
||||||
color: stringToRGB(label),
|
color: node.color,
|
||||||
face: '"Font Awesome 5 Free"',
|
face: '"Font Awesome 5 Free"',
|
||||||
code: that.get_FA_icon(node['meta-category']),
|
code: that.get_FA_icon(node['meta-category']),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue