Skip to content

Commit

Permalink
Fixes pertaining to veg/hivtrace-secure#366
Browse files Browse the repository at this point in the history
  • Loading branch information
spond committed Jan 7, 2025
1 parent 747f4c2 commit 7c7f58e
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 39 deletions.
38 changes: 21 additions & 17 deletions src/clusternetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -2814,20 +2814,20 @@ var hivtrace_cluster_network_graph = function (
_.each(list, self._aux_process_category_values);
});

const colorStopsPath = [
/*const colorStopsPath = [
kGlobals.network.GraphAttrbuteID,
self.colorizer["category_id"],
"color_stops",
];

const color_stops = _.get(
graph_data,
colorStopsPath,
kGlobals.network.ContinuousColorStops
);
];*/

var valid_scales = _.filter(
_.map(graph_data[kGlobals.network.GraphAttrbuteID], (d, k) => {
let color_stops = _.get(
self.json,
[kGlobals.network.GraphAttrbuteID, k, "color_stops"],
kGlobals.network.ContinuousColorStops
);

function determine_scaling(d, values, scales) {
var low_var = Infinity;
_.each(scales, (scl, i) => {
Expand Down Expand Up @@ -2862,16 +2862,20 @@ var hivtrace_cluster_network_graph = function (
);
// automatically determine the scale and see what spaces the values most evenly
const range = d3.extent(values);

const scales_to_consider = [d3.scale.linear()];
if (range[0] > 0) {
scales_to_consider.push(d3.scale.log());
}
if (range[0] >= 0) {
scales_to_consider.push(d3.scale.pow().exponent(1 / 3));
scales_to_consider.push(d3.scale.pow().exponent(1 / 4));
scales_to_consider.push(d3.scale.pow().exponent(1 / 2));
scales_to_consider.push(d3.scale.pow().exponent(1 / 8));
scales_to_consider.push(d3.scale.pow().exponent(1 / 16));

if (!d.is_integer) {
if (range[0] > 0) {
scales_to_consider.push(d3.scale.log());
}
if (range[0] >= 0) {
scales_to_consider.push(d3.scale.pow().exponent(1 / 3));
scales_to_consider.push(d3.scale.pow().exponent(1 / 4));
scales_to_consider.push(d3.scale.pow().exponent(1 / 2));
scales_to_consider.push(d3.scale.pow().exponent(1 / 8));
scales_to_consider.push(d3.scale.pow().exponent(1 / 16));
}
}
determine_scaling(d, values, scales_to_consider);
} else if (d.type === "Date") {
Expand Down
75 changes: 53 additions & 22 deletions src/hiv_tx_network.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ class HIVTxNetwork {
*/

attribute_node_value_by_id(d, id, number) {
attribute_node_value_by_id(d, id, number, is_date) {
try {
if (kGlobals.network.NodeAttributeID in d && id) {
if (id in d[kGlobals.network.NodeAttributeID]) {
Expand All @@ -867,6 +867,8 @@ class HIVTxNetwork {
} else if (number) {
v = Number(v);
return _.isNaN(v) ? kGlobals.missing.label : v;
} else if (date) {
return v.getTime();
}
}
return v;
Expand Down Expand Up @@ -1764,8 +1766,8 @@ class HIVTxNetwork {
});

const pg_enum = [
"Yes (dx12 months)",
"Yes (12<dx 36 months)",
"Yes (dx12 months)",
"Yes (12<dx 36 months)",
"Yes (dx>36 months)",
"No",
];
Expand Down Expand Up @@ -2117,10 +2119,6 @@ class HIVTxNetwork {
_.has(this.json[kGlobals.network.GraphAttrbuteID], d)
)
) {
var extension = {};
extension[key] = computed;

_.extend(this.json[kGlobals.network.GraphAttrbuteID], extension);
this.inject_attribute_description(key, computed);
_.each(this.json.Nodes, (node) => {
HIVTxNetwork.inject_attribute_node_value_by_id(
Expand All @@ -2135,15 +2133,48 @@ class HIVTxNetwork {
this.uniqValues[key] = computed.enum;
} else {
var uniq_value_set = new Set();
_.each(this.json.Nodes, (n) =>
uniq_value_set.add(
this.attribute_node_value_by_id(n, key, computed.Type === "Number")
)
);

if (computed.type === "Date") {
_.each(this.json.Nodes, (n) =>
uniq_value_set.add(
this.attribute_node_value_by_id(n, key).getTime()
)
);
} else {
_.each(this.json.Nodes, (n) =>
uniq_value_set.add(
this.attribute_node_value_by_id(
n,
key,
computed.type === "Number"
)
)
);
}

this.uniqValues[key] = [...uniq_value_set];
if (computed.type === "Number" || computed.type == "Date") {
var color_stops =
computed["color_stops"] || kGlobals.network.ContinuousColorStops;

if (color_stops > this.uniqValues[key].length) {
computed["color_stops"] = this.uniqValues[key].length;
}

if (computed.type === "Number") {
computed.is_integer = _.every(this.uniqValues[key], (d) =>
Number.isInteger(d)
);
}
}
}
this.uniqs[key] = this.uniqValues[key].length;

var extension = {};
extension[key] = computed;

_.extend(this.json[kGlobals.network.GraphAttrbuteID], extension);

if (computed["overwrites"]) {
if (
_.has(
Expand Down Expand Up @@ -2196,13 +2227,13 @@ class HIVTxNetwork {

const subcluster_enum = [
"No, dx>36 months", // 0
"No, but dx12 months",
"Yes (dx12 months)",
"Yes (12<dx 36 months)",
"No, but dx12 months",
"Yes (dx12 months)",
"Yes (12<dx 36 months)",
"Future node", // 4
"Not a member of subcluster", // 5
"Not in a subcluster",
"No, but 12<dx 36 months",
"No, but 12<dx 36 months",
];

return {
Expand Down Expand Up @@ -2407,7 +2438,7 @@ class HIVTxNetwork {
depends: [timeDateUtil._networkCDCDateField],
label: label,
type: "Number",
label_format: d3.format(".2f"),
label_format: relative ? d3.format(".2f") : d3.format(".0f"),
map: (node) => {
try {
var value = this.parse_dates(
Expand Down Expand Up @@ -2526,7 +2557,7 @@ class HIVTxNetwork {
depends: ["age_dx"],
overwrites: "age_dx",
label: "Age at Diagnosis",
enum: ["<13", "13-19", "20-29", "30-39", "40-49", "50-59", "60"],
enum: ["<13", "13-19", "20-29", "30-39", "40-49", "50-59", "60"],
type: "String",
color_scale: function () {
return d3.scale
Expand All @@ -2538,7 +2569,7 @@ class HIVTxNetwork {
"30-39",
"40-49",
"50-59",
"60",
"60",
kGlobals.missing.label,
])
.range([
Expand All @@ -2555,13 +2586,13 @@ class HIVTxNetwork {
map: (node) => {
var vl_value = this.attribute_node_value_by_id(node, "age_dx");
if (vl_value === ">=60") {
return "60";
return "60";
}
if (vl_value === "\ufffd60") {
return "60";
return "60";
}
if (Number(vl_value) >= 60) {
return "60";
return "60";
}
return vl_value;
},
Expand Down
36 changes: 36 additions & 0 deletions src/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,42 @@ _.each(_.range(3, 20), (d) => {
]);
});

var hivtrace_generate_svg_ellipse = function () {
var self = this;

self.ellipse = function () {
var path =
"M " +
self.radius +
" 0 A " +
self.radius * 1 +
" " +
self.radius * 0.75 +
" 0 1 0 " +
self.radius +
" 0.00001";
return path;
};

self.ellipse.type = function () {
return self.ellipse;
};

self.ellipse.size = function (attr) {
if (_.isNumber(attr)) {
self.size = attr;
self.radius = Math.sqrt((1.25 * attr) / Math.PI);
return self.ellipse;
}

return self.size;
};

self.ellipse.size(64);

return self.ellipse;
};

/**
* Creates and returns an SVG polygon generator.
*
Expand Down

0 comments on commit 7c7f58e

Please sign in to comment.