Skip to content

Commit 7c7f58e

Browse files
committed
Fixes pertaining to veg/hivtrace-secure#366
1 parent 747f4c2 commit 7c7f58e

File tree

3 files changed

+110
-39
lines changed

3 files changed

+110
-39
lines changed

src/clusternetwork.js

+21-17
Original file line numberDiff line numberDiff line change
@@ -2814,20 +2814,20 @@ var hivtrace_cluster_network_graph = function (
28142814
_.each(list, self._aux_process_category_values);
28152815
});
28162816

2817-
const colorStopsPath = [
2817+
/*const colorStopsPath = [
28182818
kGlobals.network.GraphAttrbuteID,
28192819
self.colorizer["category_id"],
28202820
"color_stops",
2821-
];
2822-
2823-
const color_stops = _.get(
2824-
graph_data,
2825-
colorStopsPath,
2826-
kGlobals.network.ContinuousColorStops
2827-
);
2821+
];*/
28282822

28292823
var valid_scales = _.filter(
28302824
_.map(graph_data[kGlobals.network.GraphAttrbuteID], (d, k) => {
2825+
let color_stops = _.get(
2826+
self.json,
2827+
[kGlobals.network.GraphAttrbuteID, k, "color_stops"],
2828+
kGlobals.network.ContinuousColorStops
2829+
);
2830+
28312831
function determine_scaling(d, values, scales) {
28322832
var low_var = Infinity;
28332833
_.each(scales, (scl, i) => {
@@ -2862,16 +2862,20 @@ var hivtrace_cluster_network_graph = function (
28622862
);
28632863
// automatically determine the scale and see what spaces the values most evenly
28642864
const range = d3.extent(values);
2865+
28652866
const scales_to_consider = [d3.scale.linear()];
2866-
if (range[0] > 0) {
2867-
scales_to_consider.push(d3.scale.log());
2868-
}
2869-
if (range[0] >= 0) {
2870-
scales_to_consider.push(d3.scale.pow().exponent(1 / 3));
2871-
scales_to_consider.push(d3.scale.pow().exponent(1 / 4));
2872-
scales_to_consider.push(d3.scale.pow().exponent(1 / 2));
2873-
scales_to_consider.push(d3.scale.pow().exponent(1 / 8));
2874-
scales_to_consider.push(d3.scale.pow().exponent(1 / 16));
2867+
2868+
if (!d.is_integer) {
2869+
if (range[0] > 0) {
2870+
scales_to_consider.push(d3.scale.log());
2871+
}
2872+
if (range[0] >= 0) {
2873+
scales_to_consider.push(d3.scale.pow().exponent(1 / 3));
2874+
scales_to_consider.push(d3.scale.pow().exponent(1 / 4));
2875+
scales_to_consider.push(d3.scale.pow().exponent(1 / 2));
2876+
scales_to_consider.push(d3.scale.pow().exponent(1 / 8));
2877+
scales_to_consider.push(d3.scale.pow().exponent(1 / 16));
2878+
}
28752879
}
28762880
determine_scaling(d, values, scales_to_consider);
28772881
} else if (d.type === "Date") {

src/hiv_tx_network.js

+53-22
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ class HIVTxNetwork {
849849
850850
*/
851851

852-
attribute_node_value_by_id(d, id, number) {
852+
attribute_node_value_by_id(d, id, number, is_date) {
853853
try {
854854
if (kGlobals.network.NodeAttributeID in d && id) {
855855
if (id in d[kGlobals.network.NodeAttributeID]) {
@@ -867,6 +867,8 @@ class HIVTxNetwork {
867867
} else if (number) {
868868
v = Number(v);
869869
return _.isNaN(v) ? kGlobals.missing.label : v;
870+
} else if (date) {
871+
return v.getTime();
870872
}
871873
}
872874
return v;
@@ -1764,8 +1766,8 @@ class HIVTxNetwork {
17641766
});
17651767

17661768
const pg_enum = [
1767-
"Yes (dx12 months)",
1768-
"Yes (12<dx 36 months)",
1769+
"Yes (dx12 months)",
1770+
"Yes (12<dx 36 months)",
17691771
"Yes (dx>36 months)",
17701772
"No",
17711773
];
@@ -2117,10 +2119,6 @@ class HIVTxNetwork {
21172119
_.has(this.json[kGlobals.network.GraphAttrbuteID], d)
21182120
)
21192121
) {
2120-
var extension = {};
2121-
extension[key] = computed;
2122-
2123-
_.extend(this.json[kGlobals.network.GraphAttrbuteID], extension);
21242122
this.inject_attribute_description(key, computed);
21252123
_.each(this.json.Nodes, (node) => {
21262124
HIVTxNetwork.inject_attribute_node_value_by_id(
@@ -2135,15 +2133,48 @@ class HIVTxNetwork {
21352133
this.uniqValues[key] = computed.enum;
21362134
} else {
21372135
var uniq_value_set = new Set();
2138-
_.each(this.json.Nodes, (n) =>
2139-
uniq_value_set.add(
2140-
this.attribute_node_value_by_id(n, key, computed.Type === "Number")
2141-
)
2142-
);
2136+
2137+
if (computed.type === "Date") {
2138+
_.each(this.json.Nodes, (n) =>
2139+
uniq_value_set.add(
2140+
this.attribute_node_value_by_id(n, key).getTime()
2141+
)
2142+
);
2143+
} else {
2144+
_.each(this.json.Nodes, (n) =>
2145+
uniq_value_set.add(
2146+
this.attribute_node_value_by_id(
2147+
n,
2148+
key,
2149+
computed.type === "Number"
2150+
)
2151+
)
2152+
);
2153+
}
2154+
21432155
this.uniqValues[key] = [...uniq_value_set];
2156+
if (computed.type === "Number" || computed.type == "Date") {
2157+
var color_stops =
2158+
computed["color_stops"] || kGlobals.network.ContinuousColorStops;
2159+
2160+
if (color_stops > this.uniqValues[key].length) {
2161+
computed["color_stops"] = this.uniqValues[key].length;
2162+
}
2163+
2164+
if (computed.type === "Number") {
2165+
computed.is_integer = _.every(this.uniqValues[key], (d) =>
2166+
Number.isInteger(d)
2167+
);
2168+
}
2169+
}
21442170
}
21452171
this.uniqs[key] = this.uniqValues[key].length;
21462172

2173+
var extension = {};
2174+
extension[key] = computed;
2175+
2176+
_.extend(this.json[kGlobals.network.GraphAttrbuteID], extension);
2177+
21472178
if (computed["overwrites"]) {
21482179
if (
21492180
_.has(
@@ -2196,13 +2227,13 @@ class HIVTxNetwork {
21962227

21972228
const subcluster_enum = [
21982229
"No, dx>36 months", // 0
2199-
"No, but dx12 months",
2200-
"Yes (dx12 months)",
2201-
"Yes (12<dx 36 months)",
2230+
"No, but dx12 months",
2231+
"Yes (dx12 months)",
2232+
"Yes (12<dx 36 months)",
22022233
"Future node", // 4
22032234
"Not a member of subcluster", // 5
22042235
"Not in a subcluster",
2205-
"No, but 12<dx 36 months",
2236+
"No, but 12<dx 36 months",
22062237
];
22072238

22082239
return {
@@ -2407,7 +2438,7 @@ class HIVTxNetwork {
24072438
depends: [timeDateUtil._networkCDCDateField],
24082439
label: label,
24092440
type: "Number",
2410-
label_format: d3.format(".2f"),
2441+
label_format: relative ? d3.format(".2f") : d3.format(".0f"),
24112442
map: (node) => {
24122443
try {
24132444
var value = this.parse_dates(
@@ -2526,7 +2557,7 @@ class HIVTxNetwork {
25262557
depends: ["age_dx"],
25272558
overwrites: "age_dx",
25282559
label: "Age at Diagnosis",
2529-
enum: ["<13", "13-19", "20-29", "30-39", "40-49", "50-59", "60"],
2560+
enum: ["<13", "13-19", "20-29", "30-39", "40-49", "50-59", "60"],
25302561
type: "String",
25312562
color_scale: function () {
25322563
return d3.scale
@@ -2538,7 +2569,7 @@ class HIVTxNetwork {
25382569
"30-39",
25392570
"40-49",
25402571
"50-59",
2541-
"60",
2572+
"60",
25422573
kGlobals.missing.label,
25432574
])
25442575
.range([
@@ -2555,13 +2586,13 @@ class HIVTxNetwork {
25552586
map: (node) => {
25562587
var vl_value = this.attribute_node_value_by_id(node, "age_dx");
25572588
if (vl_value === ">=60") {
2558-
return "60";
2589+
return "60";
25592590
}
25602591
if (vl_value === "\ufffd60") {
2561-
return "60";
2592+
return "60";
25622593
}
25632594
if (Number(vl_value) >= 60) {
2564-
return "60";
2595+
return "60";
25652596
}
25662597
return vl_value;
25672598
},

src/misc.js

+36
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,42 @@ _.each(_.range(3, 20), (d) => {
1212
]);
1313
});
1414

15+
var hivtrace_generate_svg_ellipse = function () {
16+
var self = this;
17+
18+
self.ellipse = function () {
19+
var path =
20+
"M " +
21+
self.radius +
22+
" 0 A " +
23+
self.radius * 1 +
24+
" " +
25+
self.radius * 0.75 +
26+
" 0 1 0 " +
27+
self.radius +
28+
" 0.00001";
29+
return path;
30+
};
31+
32+
self.ellipse.type = function () {
33+
return self.ellipse;
34+
};
35+
36+
self.ellipse.size = function (attr) {
37+
if (_.isNumber(attr)) {
38+
self.size = attr;
39+
self.radius = Math.sqrt((1.25 * attr) / Math.PI);
40+
return self.ellipse;
41+
}
42+
43+
return self.size;
44+
};
45+
46+
self.ellipse.size(64);
47+
48+
return self.ellipse;
49+
};
50+
1551
/**
1652
* Creates and returns an SVG polygon generator.
1753
*

0 commit comments

Comments
 (0)