parent 18620fcd50
commit 749399cb9a
  1. 1
      Previously_Executed_Analyses_Files/Bank_Projection.txt
  2. 1
      Previously_Executed_Analyses_Files/Breast_Cancer_Projection.txt
  3. 2
      Previously_Executed_Analyses_Files/Diabetes_Projection.txt
  4. 2
      css/style.css
  5. 1538
      data/diabetes.csv
  6. 11
      index.html
  7. 5
      js/tsne.js
  8. 294
      js/tsne_vis.js
  9. 2
      modules/d3-star/.gitignore
  10. 273
      modules/d3-star/d3-starPlot.js
  11. 1
      modules/pcp/d3v3.parcoords.js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -411,7 +411,7 @@ rect {
padding: 5px 5px 5px 5px;
}
#starPlot{
#PCP{
margin-left:-15px;
margin-top:0px;
width: 23.2vw;

File diff suppressed because it is too large Load Diff

@ -12,8 +12,7 @@
<script src='./modules/d3v3/d3.min.js'></script>
<script src='./modules/d3/d3.min.js'></script>
<!-- Importing additional modules such as starPlot, annotator, tip, legend, lasso, papaParse, and Jquery. -->
<script src='./modules/d3-star/d3-starPlot.js'></script>
<!-- Importing additional modules such as PCP, annotator, tip, legend, lasso, papaParse, and Jquery. -->
<script src='./modules/d3-annotations/d3-annotator.js'></script>
<script src="./modules/d3-tip/tip.js"></script>
<script src="./modules/d3-legend/d3-legend.min.js"></script>
@ -97,7 +96,7 @@
</label>
<label style="margin-top: 15px">
<input id="downloadDists" checked type="checkbox">
Distances cache (Save Exec)
Distances cache (Save Exec.)
</label>
</div>
</div>
@ -165,7 +164,7 @@
</div>
<div class="param">
<label for="param-learningrate">Learning rate</label>
<input id="param-learningrate" type="range" min="5" max="150" value="10", step="1">
<input id="param-learningrate" type="range" min="1" max="150" value="10", step="1">
<output for="param-learningrate" id="param-learningrate-value">10</output>
</div>
<div class="param">
@ -200,10 +199,10 @@
<div class="col-md-3 col-md-offset-6">
<div class="panel panel-default right-side-star">
<div class="panel-heading">
<h2 class="panel-title">Starplot with PCA Calculation</h2>
<h2 class="panel-title">Parallel Coordinates Plot with Local PCA Calculation</h2>
</div>
<div class="panel-body">
<div id="starPlot" class="parcoords"></div>
<div id="PCP" class="parcoords"></div>
</div>
</div>
</div>

@ -197,7 +197,7 @@ var tsnejs = tsnejs || { REVISION: 'ALPHA' };
// generate random solution to t-SNE
this.Y = randn2d(this.N, this.dim); // the solution
this.gains = randn2d(this.N, this.dim, 1.0); // step gains to accelerate progress in unchanging directions
this.ystep = randn2d(this.N, this.dim, 0.0); // momentum accumulator
this.ystep = randn2d(this.N, this.dim, 0.0); // momentum accumulator
this.iter = 0;
},
@ -229,10 +229,9 @@ var tsnejs = tsnejs || { REVISION: 'ALPHA' };
this.gains[i][d] = newgain; // store for next turn
// compute momentum step direction
var momval = this.iter < 250 ? 0.5 : 0.8;
var momval = this.iter < 250 ? 0.5 : 0.8;
var newsid = momval * sid - this.epsilon * newgain * grad[i][d];
this.ystep[i][d] = newsid; // remember the step we took
// step!
this.Y[i][d] += newsid;

@ -19,7 +19,7 @@ var dim = document.getElementById('overviewRect').offsetWidth-2; var dimensions
// Category = the name of the category if it exists. The user has to add an asterisk ("*") mark in order to let the program identify this feature as a label/category name.
// ColorsCategorical = the categorical colors (maximum value = 10).
var Category; var ColorsCategorical;
var Category; var ColorsCategorical; var valCategExists = 0;
// This is for the removal of the distances cache.
var returnVal = false;
@ -29,7 +29,9 @@ var ArrayWithCosts = []; var Iterations = [];
var VisiblePoints = [];
// This variable is for the kNN Bar Chart in order to store the first execution.
var inside = 0;
var inside = 0;
var format;
// Schema Investigation
// svgClick = Click a left mouse click in order to add a point.
@ -87,7 +89,6 @@ function fetchVal(callback) {
var getData = function() {
PreComputFlagCorrelation = true;
let format;
let value;
if (typeof window.FileReader !== 'function') {
alert("The file API is not supported on this browser yet.");
@ -212,7 +213,7 @@ function setReset(){ // Reset only the filters which were applied into the data
d3.selectAll("#correlation > *").remove();
d3.selectAll("#modtSNEcanvas_svg > *").remove();
d3.selectAll("#modtSNEcanvas_svg_Schema > *").remove();
d3.select("#starPlot").selectAll('g').remove();
d3.select("#PCP").selectAll('g').remove();
// Enable lasso interaction
lassoEnable();
// Disable Schema Investigation
@ -230,12 +231,12 @@ function setReset(){ // Reset only the filters which were applied into the data
ArrayContainsDataFeaturesLimit = [];
prevRightClick = false;
//StarplotInitialize();
//pcpInitialize();
// Reset the points into their initial state
for (var i=0; i < InitialStatePoints.length; i++){
InitialStatePoints[i].selected = true;
InitialStatePoints[i].starplot = false;
InitialStatePoints[i].pcp = false;
InitialStatePoints[i].schemaInv = false;
InitialStatePoints[i].DimON = null;
}
@ -285,14 +286,14 @@ function setReInitialize(flag){
// Reset the points into their initial state
for (var i=0; i < InitialStatePoints.length; i++){
InitialStatePoints[i].selected = true;
InitialStatePoints[i].starplot = false;
InitialStatePoints[i].pcp = false;
}
redraw(InitialStatePoints);
}
function setLayerProj(){ // The main Layer becomes the projection
VisiblePoints = [];
d3.select("#modtSNEcanvas").style("z-index", 2);
d3.select("#modtSNEcanvas_svg").style("z-index", 1);
d3.select("#modtSNEcanvas_svg_Schema").style("z-index", 1);
@ -300,8 +301,8 @@ function setLayerProj(){ // The main Layer becomes the projection
}
function setLayerComp(){ // The main Layer becomes the comparison (starplot)
function setLayerComp(){ // The main Layer becomes the comparison (pcp)
VisiblePoints = [];
d3.selectAll("#modtSNEcanvas_svg > *").remove();
d3.select("#modtSNEcanvas_svg").style("z-index", 2);
d3.select("#modtSNEcanvas_svg_Schema").style("z-index", 1);
@ -317,22 +318,18 @@ function setLayerComp(){ // The main Layer becomes the comparison (starplot)
}
function setLayerSche(){ // The main Layer becomes the correlation (barchart)
VisiblePoints = [];
d3.select("#modtSNEcanvas_svg_Schema").style("z-index", 2);
d3.select("#modtSNEcanvas").style("z-index", 1);
d3.select("#modtSNEcanvas_svg").style("z-index", 1);
d3.select("#SvgAnnotator").style("z-index", 1);
let c = 0;
for (var i=0; i < points.length; i++){
points[i].selected = true;
if (points[i].starplot == true){
c = c + 1;
if (c == 1){
alert("The starplot visualization will be lost!"); // Alert the user that the starplot will be lost!
}
points[i].starplot = false;
if (points[i].pcp == true){
points[i].pcp = false;
}
}
emptyPCP();
redraw(points);
click();
if (prevRightClick == true){
@ -481,6 +478,7 @@ function MainVisual(){
// data variable is all the columns except strings, undefined values, or "Version" plus beta and cost values."
// fields variable is all the features (columns) plus beta and cost strings.
function init(data, results_all, fields) {
ArrayWithCosts = [];
Iterations = [];
VisiblePoints = [];
@ -494,9 +492,9 @@ function init(data, results_all, fields) {
d3.selectAll("#overviewRect > *").remove();
d3.selectAll("#knnBarChart > *").remove();
d3.selectAll("#costHist > *").remove();
d3.select("#starPlot").selectAll('g').remove();
d3.select("#PCP").selectAll('g').remove();
MainVisual();
//StarplotInitialize();
//pcpInitialize();
d3.select("#hider").style("z-index", 2);
d3.select("#knnBarChart").style("z-index", 1);
@ -518,6 +516,10 @@ function init(data, results_all, fields) {
d3.selectAll("#legend2 > *").remove();
d3.selectAll("#legend3 > *").remove();
$("#datasetDetails").html('(Unknown number of features and instances.)');
$("#CategoryName").html('No Classification');
$("#knnBarChartDetails").html('(Number of Selected Points: 0/0)');
// Enable again the lasso interaction.
lassoEnable();
emptyPCP();
@ -593,24 +595,24 @@ function init(data, results_all, fields) {
ArrayContainsDataFeaturesClearedwithoutNull.push(object2);
ArrayContainsDataFeaturesClearedwithoutNullKeys.push(object3);
}
var valCategExists = 0;
valCategExists = 0;
for (var i=0; i<Object.keys(dataFeatures[0]).length; i++){
if (Object.keys(dataFeatures[0])[i] == Category){
valCategExists = valCategExists + 1;
}
}
$("#datasetDetails").html("(Number of Features: " + (Object.keys(dataFeatures[0]).length - valCategExists) + ", Number of Instances: " + final_dataset.length + ")"); // Print on the screen the number of features and instances of the data set, which is being analyzed.
if (Category == undefined){
$("#CategoryName").html("Classification label: No category"); // Print on the screen the classification label.
} else {
$("#CategoryName").html("Classification label: "+Category.replace('*','')); // Print on the screen the classification label.
}
for(var i = 0; i < dataFeatures.length; i++) {
if (dataFeatures[i][Category] != "" || dataFeatures[i][Category] != "undefined"){ // If a categorization label exist then add it into all_labels variable.
all_labels[i] = dataFeatures[i][Category];
if (format[0] == "diabetes"){
if (dataFeatures[i][Category] == 1){
all_labels[i] = "Positive";
} else{
all_labels[i] = "Negative";
}
} else{
all_labels[i] = dataFeatures[i][Category];
}
}
}
@ -837,8 +839,8 @@ function updateEmbedding(AnalysisResults) {
for(var i = 0; i < final_dataset.length; i++) {
x_position[i] = x(Y[i][0]); // x points position
y_position[i] = y(Y[i][1]); // y points position
points[i] = {id: i, x: x_position[i], y: y_position[i], beta: final_dataset[i].beta, cost: final_dataset[i].cost, selected: true, schemaInv: false, DimON: null, starplot: false}; // Create the points and points2D (2 dimensions)
points2d[i] = {x: x_position[i], y: y_position[i]}; // and add everything that we know about the points (e.g., selected = true, starplot = false in the beginning and so on)
points[i] = {id: i, x: x_position[i], y: y_position[i], beta: final_dataset[i].beta, cost: final_dataset[i].cost, selected: true, schemaInv: false, DimON: null, pcp: false}; // Create the points and points2D (2 dimensions)
points2d[i] = {x: x_position[i], y: y_position[i]}; // and add everything that we know about the points (e.g., selected = true, pcp = false in the beginning and so on)
points[i] = extend(points[i], ArrayContainsDataFeaturesCleared[i]);
points[i] = extend(points[i], dataFeatures[i]);
}
@ -1075,7 +1077,7 @@ function ShepardHeatMap () {
var legend = d3.legendColor() // Legend color and title!
.labelFormat(d3.format(",.0f"))
.cells(7)
.cells(9)
.title("Number of Points")
.scale(colorScale);
@ -1120,9 +1122,32 @@ function resize(canvas) { // This is being used in the WebGL t-SNE for the overv
function OverviewtSNE(points){ // The overview t-SNE function
if (format[0] == "diabetes"){
for(var i = 0; i < dataFeatures.length; i++) {
if (dataFeatures[i][Category] != "" || dataFeatures[i][Category] != "undefined"){ // If a categorization label exist then add it into all_labels variable.
if (dataFeatures[i][Category] == 1){
all_labels[i] = "Positive";
} else{
all_labels[i] = "Negative";
}
}
}
}
$("#datasetDetails").html("(Number of Features: " + (Object.keys(dataFeatures[0]).length - valCategExists) + ", Number of Instances: " + final_dataset.length + ")"); // Print on the screen the number of features and instances of the data set, which is being analyzed.
if (Category == undefined){
$("#CategoryName").html("Classification label: No category"); // Print on the screen the classification label.
} else {
$("#CategoryName").html("Classification label: "+Category.replace('*','')); // Print on the screen the classification label.
}
//Make an SVG Container
d3.selectAll("#overviewRect > *").remove();
ColorsCategorical = ['#a6cee3','#fb9a99','#b2df8a','#33a02c','#1f78b4','#e31a1c','#fdbf6f','#ff7f00','#cab2d6','#6a3d9a']; // Colors for the labels/categories if there are some!
if (format[0] == "diabetes"){
ColorsCategorical = ['#fb9a99','#a6cee3','#b2df8a','#33a02c','#1f78b4','#e31a1c','#fdbf6f','#ff7f00','#cab2d6','#6a3d9a']; // Colors for the labels/categories if there are some!
} else{
ColorsCategorical = ['#a6cee3','#fb9a99','#b2df8a','#33a02c','#1f78b4','#e31a1c','#fdbf6f','#ff7f00','#cab2d6','#6a3d9a']; // Colors for the labels/categories if there are some!
}
if (all_labels[0] == undefined){
var colorScale = d3.scaleOrdinal().domain(["No Category"]).range(["#00000"]); // If no category then grascale.
@ -1203,7 +1228,15 @@ var theRect = theGroup.append('rect')
return "#D3D3D3";
} else{
if (all_labels[0] != undefined){
return colorScale(d[Category]); // Normal color for the points that are selected
if (format[0] == "diabetes"){
if (d[Category] == 1){
return colorScale("Positive");
} else{
return colorScale("Negative");
}
} else{
return colorScale(d[Category]); // Normal color for the points that are selected
}
} else {
return "#00000";
}
@ -1338,12 +1371,12 @@ function handleLassoEnd(lassoPolygon) { // This is for the lasso interaction
if (points.length - countLassoFalse <= 10 && points.length - countLassoFalse != 0){
for (var i = 0 ; i < points.length ; i ++) {
if (points[i].selected == true){
points[i].starplot = true;
points[i].pcp = true;
}
}
} else{
for (var i = 0 ; i < points.length ; i ++) {
points[i].starplot = false;
points[i].pcp = false;
}
}
redraw(points);
@ -1355,16 +1388,15 @@ function emptyPCP(){
//////////////////////////////////////////////////////////////
//////////////////// Draw the Chart //////////////////////////
//////////////////////////////////////////////////////////////
var colors = ['#a6cee3','#1f78b4','#b2df8a','#33a02c','#fb9a99','#e31a1c','#fdbf6f','#ff7f00','#cab2d6','#6a3d9a']; // Colorscale for the starplot
var colors = ['#a6cee3','#1f78b4','#b2df8a','#33a02c','#fb9a99','#e31a1c','#fdbf6f','#ff7f00','#cab2d6','#6a3d9a']; // Colorscale for the pcp
var colorScl = d3v3.scale.ordinal()
.domain(IDS)
.range(colors);
var color = function(d) { return colors(d.group); };
var parcoords = d3v3.parcoords()("#starPlot")
var parcoords = d3v3.parcoords()("#PCP")
.data(wrapData)
.alpha(0.75)
.composite("darken")
.margin({ top: 20, left: 0, bottom: 5, right: 0 })
.mode("queue")
@ -1382,7 +1414,7 @@ function handleLassoStart(lassoPolygon) { // Empty we do not need to reset anyth
KNNEnabled = false;
for (var i = 0 ; i < points.length ; i ++) {
points[i].selected = true;
points[i].starplot = false;
points[i].pcp = false;
}
redraw(points);
@ -1638,7 +1670,7 @@ function CalculateCorrel(flagForSchema){ // Calculate the correlation is a funct
for (var i=0; i < InitialStatePoints.length; i++){
InitialStatePoints[i].selected = true;
InitialStatePoints[i].starplot = false;
InitialStatePoints[i].pcp = false;
}
redraw(InitialStatePoints);
@ -2237,14 +2269,14 @@ function clearThree(obj){ // Clear three.js object!
var viewport3 = getViewport(); // Get the width and height of the main visualization
var vw3 = viewport3[0] * 0.2;
var margin = {top: 40, right: 100, bottom: 40, left: 190}, // Set the margins for the starplot
var margin = {top: 40, right: 100, bottom: 40, left: 190}, // Set the margins for the pcp
width = Math.min(vw3, window.innerWidth - 10) - margin.left - margin.right,
height = Math.min(width, window.innerHeight - margin.top - margin.bottom);
/*function StarplotInitialize() {
/*function pcpInitialize() {
var wrapData = [];
var radarChartOptions = { // starplot options
var radarChartOptions = { // pcp options
w: width,
h: height,
margin: margin,
@ -2258,11 +2290,11 @@ height = Math.min(width, window.innerHeight - margin.top - margin.bottom);
//////////////////// Draw the Chart //////////////////////////
//////////////////////////////////////////////////////////////
//Call function to draw the Radar chart (starplot)
RadarChart("#starPlot", wrapData, colors, IDS, radarChartOptions);
//Call function to draw the Radar chart (pcp)
RadarChart("#PCP", wrapData, colors, IDS, radarChartOptions);
}*/
//StarplotInitialize();
//pcpInitialize();
function BetatSNE(points){ // Run the main visualization
inside = inside + 1;
@ -2432,17 +2464,16 @@ if (points.length) { // If points exist (at least 1 point)
Plotly.newPlot('knnBarChart', data, layout, {displayModeBar:false}, {staticPlot: true});
// Here we have the code for the starplot
d3.select("#starPlot").selectAll('g').remove(); // Remove the starplot if there was one before
// Here we have the code for the pcp
d3.select("#PCP").selectAll('g').remove(); // Remove the pcp if there was one before
var coun = 0;
for (var i=0; i < selectedPoints.length; i++){
if (selectedPoints[i].starplot == true){ // Count the selected points
if (selectedPoints[i].pcp == true){ // Count the selected points
coun = coun + 1;
}
}
if(selectedPoints.length <= 10 && coun > 0){ // If points > 10 then do not draw! If points = 0 then do not draw!
var FeatureWise = [];
for (var j=0; j<Object.values(dataFeatures[0]).length; j++){ // Get the features of the data set.
@ -2484,10 +2515,14 @@ if (points.length) { // If points exist (at least 1 point)
var indices = new Array(len);
for (var i = 0; i < len; ++i) indices[i] = i;
indices = indices.sort(function (a, b) { return PCASelVec[a] < PCASelVec[b] ? -1 : PCASelVec[a] > PCASelVec[b] ? 1 : 0; }); // Get the most important features first! Clockwise ordering
if (len > 10){
indices = indices.slice(0,9);
if (len > 8){
indices = indices.slice(0,8);
}
emptyPCP();
var parcoords = d3v3.parcoords()("#PCP");
if(selectedPoints.length <= 10 && coun > 0){ // If points > 10 then do not draw! If points = 0 then do not draw!
var wrapData = [];
var IDS = [];
for (var i=0; i<selectedPoints.length; i++){
@ -2495,50 +2530,138 @@ if (points.length) { // If points exist (at least 1 point)
for (var j=0; j< ArrayContainsDataFeaturesClearedwithoutNull[selectedPoints[i].id].length; j++){
for (m=0; m < len; m++){
if (indices[m] == j){
Object.assign(data,{[ArrayContainsDataFeaturesClearedwithoutNullKeys[selectedPoints[i].id][m]]:parseFloat(ArrayContainsDataFeaturesClearedwithoutNull[selectedPoints[i].id][m]).toFixed(1)}); // Push the values into the starplot
Object.assign(data,{[ArrayContainsDataFeaturesClearedwithoutNullKeys[selectedPoints[i].id][m]]:parseFloat(ArrayContainsDataFeaturesClearedwithoutNull[selectedPoints[i].id][m]).toFixed(1)}); // Push the values into the pcp
}
}
}
wrapData.push(data); // Wrap everything together
Object.assign(data,{"ID":selectedPoints[i].id});
wrapData.push(data);
IDS.push(selectedPoints[i].id); // Push all the IDs of the selected points
}
var AllPointsWrapData = [];
for (var i=0; i<points.length; i++){
var data = [];
for (var j=0; j< ArrayContainsDataFeaturesClearedwithoutNull[points[i].id].length; j++){
for (m=0; m < len; m++){
if (indices[m] == j){
Object.assign(data,{[ArrayContainsDataFeaturesClearedwithoutNullKeys[points[i].id][m]]:parseFloat(ArrayContainsDataFeaturesClearedwithoutNull[points[i].id][m]).toFixed(1)}); // Push the values into the pcp
}
}
}
Object.assign(data,{"ID":points[i].id});
AllPointsWrapData.push(data);
}
//////////////////////////////////////////////////////////////
//////////////////// Draw the Chart //////////////////////////
//////////////////////////////////////////////////////////////
var colors = ['#a6cee3','#1f78b4','#b2df8a','#33a02c','#fb9a99','#e31a1c','#fdbf6f','#ff7f00','#cab2d6','#6a3d9a']; // Colorscale for the starplot
var colors = ['#a6cee3','#1f78b4','#b2df8a','#33a02c','#fb9a99','#e31a1c','#fdbf6f','#ff7f00','#cab2d6','#6a3d9a']; // Colorscale for the pcp
var colorScl = d3v3.scale.ordinal()
.domain(IDS)
.range(colors);
var color = function(d) { return colors(d.group); };
var color = function(d) {
return colorScl(d.ID);
};
var parcoords = d3v3.parcoords()("#starPlot")
.data(wrapData)
.alpha(0.75)
parcoords
.data(AllPointsWrapData)
.alpha(0.1)
.hideAxis(["ID"])
.composite("darken")
.margin({ top: 20, left: 0, bottom: 5, right: 0 })
.mode("queue")
.color(function(d, i) { return colorScl(IDS[i]); })
.margin({ top: 20, left: 0, bottom: 5, right: -5 })
.mode("default")
.color(color)
.render()
.brushMode("1D-axes") // enable brushing
.reorderable();
.highlight(wrapData)
.createAxes();
parcoords.svg.selectAll("text")
.style("font", "14px");
/*
} else {
var wrapData2 = [];
for (var i=0; i<selectedPoints.length; i++){
var data = [];
for (var j=0; j< Object.keys(dataFeatures[selectedPoints[i].id]).length; j++){
for (m=0; m < len; m++){
if (j == Object.keys(dataFeatures[selectedPoints[i].id]).length -1){
if(format[0] == "diabetes"){
if (Object.values(dataFeatures[selectedPoints[i].id])[j] == 1){
Object.assign(data,{[Object.keys(dataFeatures[selectedPoints[i].id])[j]]:"Positive"}); // Push the values into the pcp
} else{
Object.assign(data,{[Object.keys(dataFeatures[selectedPoints[i].id])[j]]:"Negative"}); // Push the values into the pcp
}
} else{
Object.assign(data,{[Object.keys(dataFeatures[selectedPoints[i].id])[j]]:(Object.values(dataFeatures[selectedPoints[i].id])[j])}); // Push the values into the pcp
}
} else{
if (indices[m] == j){
Object.assign(data,{[Object.keys(dataFeatures[selectedPoints[i].id])[m]]:parseFloat(Object.values(dataFeatures[selectedPoints[i].id])[m]).toFixed(1)}); // Push the values into the pcp
}
}
}
}
wrapData2.push(data);
}
var AllPointsWrapData2 = [];
for (var i=0; i<points.length; i++){
var data = [];
for (var j=0; j< Object.keys(dataFeatures[points[i].id]).length; j++){
for (m=0; m < len; m++){
if (j == Object.keys(dataFeatures[points[i].id]).length -1){
if(format[0] == "diabetes"){
if (Object.values(dataFeatures[points[i].id])[j] == 1){
Object.assign(data,{[Object.keys(dataFeatures[points[i].id])[j]]:"Positive"}); // Push the values into the pcp
} else{
Object.assign(data,{[Object.keys(dataFeatures[points[i].id])[j]]:"Negative"}); // Push the values into the pcp
}
} else{
Object.assign(data,{[Object.keys(dataFeatures[points[i].id])[j]]:(Object.values(dataFeatures[points[i].id])[j])}); // Push the values into the pcp
}
} else{
if (indices[m] == j){
Object.assign(data,{[Object.keys(dataFeatures[points[i].id])[m]]:parseFloat(Object.values(dataFeatures[points[i].id])[m]).toFixed(1)}); // Push the values into the pcp
}
}
}
}
AllPointsWrapData2.push(data);
}
var radarChartOptions = { // Starplot options
w: width,
h: height,
margin: margin,
levels: 10,
roundStrokes: true,
};
if (all_labels[0] == undefined){
var colorScaleCat = d3.scaleOrdinal().domain(["No Category"]).range(["#C0C0C0"]);
}
else{
if(format[0] == "diabetes"){
for (var i=0; i<all_labels.length; i++){
if (all_labels[i] == 1){
all_labels[i] = "Positive";
} else{
all_labels[i] = "Negative";
}
}
}
var colorScaleCat = d3.scaleOrdinal().domain(all_labels).range(ColorsCategorical);
}
console.log(wrapData2);
parcoords
.data(AllPointsWrapData2)
.alpha(0.95)
.composite("darken")
.margin({ top: 20, left: 0, bottom: 5, right: -5 })
.mode("default")
.color(function(d){if(format[0] == "diabetes"){if(d[Category] == "Negative"){return colorScaleCat("Positive");}else{return colorScaleCat("Negative");}} else{console.log(d[Category]);return colorScaleCat(d[Category]);}})
.render()
.highlight(wrapData2)
.createAxes();
//Call function to draw the Radar chart (starplot)
RadarChart("#starPlot", wrapData, colorScl, IDS, radarChartOptions);*/
parcoords.svg.selectAll("text")
.style("font", "14px");
}
var ColSizeSelector = document.getElementById("param-neighborHood").value; // This is the mapping of the color/size in beta/KLD
@ -2730,7 +2853,7 @@ if (points.length) { // If points exist (at least 1 point)
pointsGeometry.vertices.push(vertex);
pointsGeometry.name = points[i].id;
geometry.vertices.push(vertex);
if(points[i].starplot == true){
if(points[i].pcp == true){
var color = new THREE.Color(colorScl(points[i].id));
} else if (points[i].DimON != null) {
let temp = points[i].DimON.match(/\d+/)[0];
@ -3002,13 +3125,22 @@ function highlightPoint(datum) {
var colorScaleCat = d3.scaleOrdinal().domain(["No Category"]).range(["#C0C0C0"]);
}
else{
if(format[0] == "diabetes"){
for (var i=0; i<all_labels.length; i++){
if (all_labels[i] == "Positive"){
all_labels[i] = 0;
} else{
all_labels[i] = 1;
}
}
}
var colorScaleCat = d3.scaleOrdinal().domain(all_labels).range(ColorsCategorical);
}
}
geometry.colors = [ new THREE.Color(colorScaleCat(datum[Category])) ];
let material = new THREE.PointsMaterial({
size: 26,
size: 35,
sizeAttenuation: false,
vertexColors: THREE.VertexColors,
map: circle_sprite,

@ -1,2 +0,0 @@
node_modules

@ -1,273 +0,0 @@
/////////////////////////////////////////////////////////
/////////////// The Radar Chart Function ////////////////
/////////////// Written by Nadieh Bremer ////////////////
////////////////// VisualCinnamon.com ///////////////////
/////////// Inspired by the code of alangrafu ///////////
/////////////////////////////////////////////////////////
function RadarChart(id, data, color, IDS, options) {
var cfg = {
w: 600, //Width of the circle
h: 600, //Height of the circle
margin: {top: 20, right: 20, bottom: 20, left: 20}, //The margins of the SVG
levels: 3, //How many levels or inner circles should there be drawn
maxValue: 1, //What is the value that the biggest circle will represent
labelFactor: 1.28, //How much farther than the radius of the outer circle should the labels be placed
wrapWidth: 100, //The number of pixels after which a label needs to be given a new line
opacityArea: 0.35, //The opacity of the area of the blob
dotRadius: 4, //The size of the colored circles of each blog
opacityCircles: 0.1, //The opacity of the circles of each blob
strokeWidth: 2, //The wivar colors = ['#a6cee3','#1f78b4','#b2df8a','#33a02c','#fb9a99','#e31a1c','#fdbf6f','#ff7f00','#cab2d6','#6a3d9a'];dth of the stroke around each blob
roundStrokes: false, //If true the area and stroke will follow a round path (cardinal-closed)
};
//Put all of the options into a variable called cfg
if('undefined' !== typeof options){
for(var i in options){
if('undefined' !== typeof options[i]){ cfg[i] = options[i]; }
}//for i
}//if
//If the supplied maxValue is smaller than the actual one, replace by the max in the data
var maxValue = Math.max(cfg.maxValue, d3v3.max(data, function(i){return d3v3.max(i.map(function(o){return o.value;}))}));
if (data.length != 0){
var allAxis = (data[0].map(function(i, j){return i.axis})), //Names of each axis
total = allAxis.length, //The number of different axes
radius = Math.min(cfg.w/2, cfg.h/2), //Radius of the outermost circle
Format = d3v3.format('.2f'), //Percentage formatting
angleSlice = Math.PI * 2 / total; //The width in radians of each "slice"
//Scale for the radius
var rScale = d3v3.scale.linear()
.range([0, radius])
.domain([0, maxValue]);
}
/////////////////////////////////////////////////////////
//////////// Create the container SVG and g /////////////
/////////////////////////////////////////////////////////
//Remove whatever chart with the same id/class was present before
d3v3.select(id).select("svg").remove();
//Initiate the radar chart SVG
var svg = d3v3.select(id).append("svg")
.attr("width", cfg.w + cfg.margin.left + cfg.margin.right)
.attr("height", cfg.h + cfg.margin.top + cfg.margin.bottom)
.attr("class", "radar"+id);
//Append a g element
var g = svg.append("g")
.attr("transform", "translate(" + (cfg.w/2 + cfg.margin.left) + "," + (cfg.h/2 + cfg.margin.top) + ")");
/////////////////////////////////////////////////////////
////////// Glow filter for some extra pizzazz ///////////
/////////////////////////////////////////////////////////
if (data.length != 0){
//Filter for the outside glow
var filter = g.append('defs').append('filter').attr('id','glow'),
feGaussianBlur = filter.append('feGaussianBlur').attr('stdDeviation','2.5').attr('result','coloredBlur'),
feMerge = filter.append('feMerge'),
feMergeNode_1 = feMerge.append('feMergeNode').attr('in','coloredBlur'),
feMergeNode_2 = feMerge.append('feMergeNode').attr('in','SourceGraphic');
/////////////////////////////////////////////////////////
/////////////// Draw the Circular grid //////////////////
/////////////////////////////////////////////////////////
//Wrapper for the grid & axes
var axisGrid = g.append("g").attr("class", "axisWrapper");
//Draw the background circles
axisGrid.selectAll(".levels")
.data(d3v3.range(1,(cfg.levels+1)).reverse())
.enter()
.append("circle")
.attr("class", "gridCircle")
.attr("r", function(d, i){return radius/cfg.levels*d;})
.style("fill", "#CDCDCD")
.style("stroke", "#CDCDCD")
.style("fill-opacity", cfg.opacityCircles)
.style("filter" , "url(#glow)");
//Text indicating at what % each level is
axisGrid.selectAll(".axisLabel")
.data(d3v3.range(1,(cfg.levels+1)).reverse())
.enter().append("text")
.attr("class", "axisLabel")
.attr("x", 4)
.attr("y", function(d){return -d*radius/cfg.levels;})
.attr("dy", "0.4em")
.style("font-size", "10px")
.attr("fill", "#737373")
.text(function(d,i) { return Format(maxValue * d/cfg.levels); });
/////////////////////////////////////////////////////////
//////////////////// Draw the axes //////////////////////
/////////////////////////////////////////////////////////
//Create the straight lines radiating outward from the center
var axis = axisGrid.selectAll(".axis")
.data(allAxis)
.enter()
.append("g")
.attr("class", "axis");
//Append the lines
axis.append("line")
.attr("x1", 0)
.attr("y1", 0)
.attr("x2", function(d, i){ return rScale(maxValue*1.1) * Math.cos(angleSlice*i - Math.PI/2); })
.attr("y2", function(d, i){ return rScale(maxValue*1.1) * Math.sin(angleSlice*i - Math.PI/2); })
.attr("class", "line")
.style("stroke", "white")
.style("stroke-width", "2px");
//Append the labels at each axis
axis.append("text")
.attr("class", "legend")
.style("font-size", "11px")
.attr("text-anchor", "middle")
.attr("dy", "0em")
.attr("x", function(d, i){ return rScale(maxValue * cfg.labelFactor) * Math.cos(angleSlice*i - Math.PI/2); })
.attr("y", function(d, i){ return rScale(maxValue * cfg.labelFactor) * Math.sin(angleSlice*i - Math.PI/2); })
.text(function(d){return d})
.call(wrap, cfg.wrapWidth);
/////////////////////////////////////////////////////////
///////////// Draw the radar chart blobs ////////////////
/////////////////////////////////////////////////////////
//The radial line function
var radarLine = d3v3.svg.line.radial()
.interpolate("linear-closed")
.radius(function(d) { return rScale(d.value); })
.angle(function(d,i) { return i*angleSlice; });
if(cfg.roundStrokes) {
radarLine.interpolate("cardinal-closed");
}
//Create a wrapper for the blobs
var blobWrapper = g.selectAll(".radarWrapper")
.data(data)
.enter().append("g")
.attr("class", "radarWrapper");
//Append the backgrounds
blobWrapper
.append("path")
.attr("class", "radarArea")
.attr("d", function(d,i) { return radarLine(d); })
.style("fill", function(d,i) { return color(IDS[i]); })
.style("fill-opacity", cfg.opacityArea)
.on('mouseover', function (d,i){
//Dim all blobs
d3v3.selectAll(".radarArea")
.transition().duration(200)
.style("fill-opacity", 0.1);
//Bring back the hovered over blob
d3v3.select(this)
.transition().duration(200)
.style("fill-opacity", 0.7);
})
.on('mouseout', function(){
//Bring back all blobs
d3v3.selectAll(".radarArea")
.transition().duration(200)
.style("fill-opacity", cfg.opacityArea);
});
//Create the outlines
blobWrapper.append("path")
.attr("class", "radarStroke")
.attr("d", function(d,i) { return radarLine(d); })
.style("stroke-width", cfg.strokeWidth + "px")
.style("stroke", function(d,i) { return color(IDS[i]); })
.style("fill", "none")
.style("filter" , "url(#glow)");
//Append the circles
blobWrapper.selectAll(".radarCircle")
.data(function(d,i) { return d; })
.enter().append("circle")
.attr("class", "radarCircle")
.attr("r", cfg.dotRadius)
.attr("cx", function(d,i){ return rScale(d.value) * Math.cos(angleSlice*i - Math.PI/2); })
.attr("cy", function(d,i){ return rScale(d.value) * Math.sin(angleSlice*i - Math.PI/2); })
.style("fill", function(d,i,j) { return color(IDS[j]); })
.style("fill-opacity", 0.8);
/////////////////////////////////////////////////////////
//////// Append invisible circles for tooltip ///////////
/////////////////////////////////////////////////////////
//Wrapper for the invisible circles on top
var blobCircleWrapper = g.selectAll(".radarCircleWrapper")
.data(data)
.enter().append("g")
.attr("class", "radarCircleWrapper");
//Append a set of invisible circles on top for the mouseover pop-up
blobCircleWrapper.selectAll(".radarInvisibleCircle")
.data(function(d,i) { return d; })
.enter().append("circle")
.attr("class", "radarInvisibleCircle")
.attr("r", cfg.dotRadius*1.5)
.attr("cx", function(d,i){ return rScale(d.value) * Math.cos(angleSlice*i - Math.PI/2); })
.attr("cy", function(d,i){ return rScale(d.value) * Math.sin(angleSlice*i - Math.PI/2); })
.style("fill", "none")
.style("pointer-events", "all")
.on("mouseover", function(d,i) {
newX = parseFloat(d3v3.select(this).attr('cx')) - 10;
newY = parseFloat(d3v3.select(this).attr('cy')) - 10;
tooltip
.attr('x', newX)
.attr('y', newY)
.text(Format(d.value))
.transition().duration(200)
.style('opacity', 1);
})
.on("mouseout", function(){
tooltip.transition().duration(200)
.style("opacity", 0);
});
//Set up the small tooltip for when you hover over a circle
var tooltip = g.append("text")
.attr("class", "tooltip")
.style("opacity", 0);
/////////////////////////////////////////////////////////
/////////////////// Helper Function /////////////////////
/////////////////////////////////////////////////////////
}
//Taken from http://bl.ocks.org/mbostock/7555321
//Wraps SVG text
function wrap(text, width) {
text.each(function() {
var text = d3v3.select(this),
words = text.text().split(/\s+/).reverse(),
word,
line = [],
lineNumber = 0,
lineHeight = 1.4, // ems
y = text.attr("y"),
x = text.attr("x"),
dy = parseFloat(text.attr("dy")),
tspan = text.text(null).append("tspan").attr("x", x).attr("y", y).attr("dy", dy + "em");
while (word = words.pop()) {
line.push(word);
tspan.text(line.join(" "));
if (tspan.node().getComputedTextLength() > width) {
line.pop();
tspan.text(line.join(" "));
line = [word];
tspan = text.append("tspan").attr("x", x).attr("y", y).attr("dy", ++lineNumber * lineHeight + dy + "em").text(word);
}
}
});
}//wrap
}//RadarChart

@ -207,7 +207,6 @@ pc.autoscale = function() {
};
__.dimensions.forEach(function(k) {
console.log(k);
yscale[k] = defaultScales[__.types[k]](k);
});

Loading…
Cancel
Save