Skip to content

Commit

Permalink
factors with null values for an attribute are not included when clust…
Browse files Browse the repository at this point in the history
…ering on that attribute, plus some fixes in table.js resulting from tabulator upgrade.
  • Loading branch information
micrology committed Nov 25, 2024
1 parent 6f83c83 commit 950c8b7
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 92 deletions.
27 changes: 13 additions & 14 deletions js/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ function clusterByAttribute(attribute) {
// collect all different values of the attribute that are in use
let attValues = new Set()
data.nodes.get().forEach((node) => {
if (!node.isCluster) attValues.add(node[attribute])
if (!node.isCluster && node[attribute]) attValues.add(node[attribute])
})
unSelect()
let nodesToUpdate = []
// for each cluster
for (let value of attValues) {
// collect relevant nodes that are not already in a cluster and are not cluster nodes
// and the attribute value is not blank
let nodesInCluster = data.nodes.get({
filter: (node) => node[attribute] === value && !node.clusteredIn && !node.isCluster,
})
Expand All @@ -68,19 +69,18 @@ function clusterByAttribute(attribute) {
let sumx = 0
let sumy = 0
let nInCluster = 0
if (!value) value = '[none]'
let clusterNode = data.nodes.get(`cluster-${attribute}-${value}`)
if (clusterNode === null) {
let color = makeColor()
clusterNode = deepMerge(styles.nodes['cluster'], {
id: `cluster-${attribute}-${value}`,
isCluster: true,
label: `${yNetMap.get('attributeTitles')[attribute]} ${value}`,
color: { background: color },
font: { color: lightOrDark(color) == 'light' ? 'rgba(0,0,0,1)' : 'rgb(255,255,255,1)' },
hidden: false,
font: { color: lightOrDark(color) == 'light' ? 'rgba(0,0,0,1)' : 'rgb(255,255,255,1)' }
})
} else clusterNode.hidden = false
}
clusterNode.label = `${yNetMap.get('attributeTitles')[attribute]} ${value}`
clusterNode.hidden = false
for (let node of nodesInCluster) {
// for each factor that should be in the cluster
node.clusteredIn = clusterNode.id
Expand Down Expand Up @@ -124,13 +124,13 @@ function clusterByColor() {
if (clusterNode === null) {
clusterNode = deepMerge(styles.nodes['cluster'], {
id: `cluster-color-${color}`,
isCluster: true,
label: `Cluster ${++clusterNumber}`,
color: { background: color },
font: { color: lightOrDark(color) == 'light' ? 'rgba(0,0,0,1)' : 'rgb(255,255,255,1)' },
hidden: false,
isCluster: true
})
} else clusterNode.hidden = false
}
clusterNode.hidden = false
clusterNode.label = `Cluster ${++clusterNumber}`
clusterNode.color = { background: color }
clusterNode.font = { color: lightOrDark(color) == 'light' ? 'rgba(0,0,0,1)' : 'rgb(255,255,255,1)' }
for (let node of nodesInCluster) {
// for each factor that should be in the cluster
node.clusteredIn = clusterNode.id
Expand Down Expand Up @@ -173,8 +173,7 @@ function clusterByStyle() {
if (clusterNode === null) {
clusterNode = deepMerge(styles.nodes['cluster'], {
id: `cluster-style-${style}`,
isCluster: true,
label: `${styles.nodes[style].groupLabel} cluster`,
isCluster: true
})
}
clusterNode.hidden = false
Expand Down
42 changes: 22 additions & 20 deletions js/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
setCurve,
setBackground,
setLegend,
setCluster,
sizing,
recreateClusteringMenu,
markMapSaved,
Expand Down Expand Up @@ -767,6 +768,24 @@ function loadExcelfile(contents) {
*/
export function savePRSMfile() {
network.storePositions()
let attributes = yNetMap.get('attributeTitles')
let nodeFields = [
'id',
'label',
'grp',
'x',
'y',
'color',
'font',
'borderWidth',
'shape',
'shapeProperties',
'margin',
'thumbUp',
'thumbDown',
'created',
'modified',
]
let json = JSON.stringify(
{
saved: new Date(Date.now()).toLocaleString(),
Expand All @@ -781,25 +800,7 @@ export function savePRSMfile() {
attributeTitles: yNetMap.get('attributeTitles'),
styles: styles,
nodes: data.nodes.get({
fields: [
'id',
'label',
'note',
'grp',
'x',
'y',
'arrows',
'color',
'font',
'borderWidth',
'shape',
'shapeProperties',
'margin',
'thumbUp',
'thumbDown',
'created',
'modified',
],
fields: [ ... nodeFields, ... Object.keys(attributes)],
filter: (n) => !n.isCluster,
}),
edges: data.edges.get({
Expand Down Expand Up @@ -852,7 +853,8 @@ function setButtonStatus(settings) {
yNetMap.set('radius', { radiusSetting: 'All', selected: [] })
yNetMap.set('stream', { streamSetting: 'All', selected: [] })
yNetMap.set('paths', { pathsSetting: 'All', selected: [] })
yNetMap.set('cluster', 'All')
yNetMap.set('cluster', 'none')
setCluster('none')
}

/**
Expand Down
2 changes: 1 addition & 1 deletion js/prsm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4704,7 +4704,7 @@ function selectClustering(e) {
fit()
yNetMap.set('cluster', option)
}
function setCluster(option) {
export function setCluster(option) {
elem('clustering').value = option
}
/**
Expand Down
2 changes: 1 addition & 1 deletion js/samples.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const styles = {
color: 'rgb(255, 255, 255)',
},
shape: 'database',
margin: {top: 40},
margin: { top: 40, right: 20, bottom: 20, left: 20 },
},
},
edges: {
Expand Down
Loading

0 comments on commit 950c8b7

Please sign in to comment.