1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
let donut_chart_div_width_height = 80;
let tippy_instance_donut;

const opacity_shown_in_view = 0.9;
const opacity_rest = 0.5;

function initialize_donut_chart_context_div() {

    let donut_chart_div = d3.select('#' + item_plot_preferences[0].id).append('div')
        .attr('id', id_donut_chart_div)
        .style('position', 'absolute')
        .style('bottom', 'var(--padding)')
        .style('right', 'var(--padding)')
        .style('width', donut_chart_div_width_height + 'px')
        .style('height', donut_chart_div_width_height + 'px')
        .style('z-index', 10);

    let svg = donut_chart_div
        .append("svg")
        .attr("width", donut_chart_div_width_height + 'px')
        .attr("height", donut_chart_div_width_height + 'px')
        .append("g")
        .attr("transform", "translate(" + donut_chart_div_width_height / 2 + "," + donut_chart_div_width_height / 2 + ")");


}

function append_data_to_donut_chart_div() {
    let svg = d3.select('#' + id_donut_chart_div).select('svg').select('g');
    svg.selectAll('*').remove();

    //let outer_circle_div = svg.append('circle').attr("cx", 0)
    //    .attr("cy", 0)
    //    .attr("r", (donut_chart_div_width_height - 2) / 2)
    //    .style('fill', 'white');

    //let inner_circle_div = svg.append('circle').attr("cx", 0)
    //    .attr("cy", 0)
     //   .attr("r", (donut_chart_div_width_height - 2) / 4)
     //   .style('fill', 'white');

    // set the color scale
    let color = color_scale_descriptive_statistics;

    // Compute the position of each group on the pie:
    let pie = d3.pie()
        .sort(null)
        .value(function (d) {
            return d.value;
        });

    let data = {};
    column_values_grouped.forEach(function (col) {
        data[col[key_id]] = 1;
    });
    // Create dummy data
    let data_ready = pie(d3.entries(data))


    let arc = d3.arc()
        .innerRadius((donut_chart_div_width_height - 2) / 4)
        .outerRadius((donut_chart_div_width_height - 2) / 2);

    //let arc_hovering = d3.arc()
    //    .innerRadius((donut_chart_div_width_height - 2) / 4)
    //    .outerRadius((donut_chart_div_width_height - 2) / 2);

// Build the pie chart: Basically, each part of the pie is a path that we build using the arc function.
    let path = svg.selectAll('path')
        .data(data_ready);

    // let gradient = svg.append("defs").append("radialGradient")
    //     .attr("id", "radial_gradient")
    //     .attr("cx", "50%")    //not really needed, since 50% is the default
    //     .attr("cy", "50%")    //not really needed, since 50% is the default
    //     .attr("r", "50%");    //not really needed, since 50% is the default
        // .selectAll("stop")
        // .data([])
        // .enter()
        // .append("stop")
        // .attr("offset", function (d) {
        //     return d.offset;
        // })
        // .attr("stop-color", function (d) {
        //     return d.color;
        // });

    //update_color_data_gradient(column_values_grouped[0].id, column_values_grouped);

    /*function update_color_data_gradient(index_name, column_values_grouped) {
        let data_circle = [];
        if (column_values_grouped.filter(x=>x.id === index_name)[0].type_element_group === "group") {
            let linear_scale_percentage = d3.scaleLinear().domain([0, 100]).range([50, 100]);

            let current_dimension = column_values_grouped.filter(x => x.id === index_name)[0];
            current_dimension.loading_variables.sort((a, b) => a.value < b.value ? 1 : -1);

            let contri_sum = 0;
            current_dimension.loading_variables.forEach(function (loading) {
                let contri = current_dimension.contributing_variables.filter(x => x.column_id === loading.column_id)[0];

                data_circle.push({
                    offset: linear_scale_percentage(contri_sum + contri.value),
                    color: color_scale_loading(loading.value)
                });

                data_circle.push({
                    offset: linear_scale_percentage(contri_sum + contri.value + 0.001),
                    color: color_scale_loading(loading.value)
                });

                contri_sum += contri.value;
            });

            console.log(data_circle)
            d3.select('#' + 'radial_gradient').remove();


            svg.append("defs").append("radialGradient")
                .attr("id", "radial_gradient")
                .attr("cx", "50%")    //not really needed, since 50% is the default
                .attr("cy", "50%")    //not really needed, since 50% is the default
                .attr("r", "50%")    //not really needed, since 50% is the default
                .selectAll("stop")
                .data(data_circle)
                .enter()
                .append("stop")
                .attr("offset", function (d) {
                    return d.offset;
                })
                .attr("stop-color", function (d) {
                    return d.color;
                });

            outer_circle_div.style("fill", "url(#radial_gradient)");
        } else {
            outer_circle_div.style("fill", "darkgrey");
        }
    }*/


    path.enter().append("path")
        .style("fill", function (d, i) {

            if (column_values_grouped.filter(x=> x.id === d.data.key)[0].type_element_group === "group") {
                return "#8c96c6";
            }
            return 'lightgrey';//'#D1CBCA'; //color(i);
            //if (i === 0) {
            //    return 'grey';
            //} else if (i > 0 && i < dimensions_count_shown) {
            //    return "lightgrey";
            //}
            // return "white";
        })
        .style("stroke", function (d, i) {
            if (i === 0) {
                return "black";
            }
            return "grey";
        })
        .style('opacity', function (d, i) {
            if (i === 0) {
                return 1;
            } else if (i > 0 && i < dimensions_count_shown) {
                return opacity_shown_in_view;
            }
            return opacity_rest;
            //if (i === 0) {
            //    return 0;
            //}
            //return 1;
        })
        .attr("d", arc)
        .on('mouseover', function (d, i) {
            d3.select(this).style('opacity', 1);
            d3.select(this).style('stroke', 'black');


            //d3.select(this).attr('d', arc_hovering);
            //d3.select(this).style('opacity', 0);


            //update_color_data_gradient(d.data.key, column_values_grouped);
        })
        .on('mouseout', function (d, i) {
            if (i > selectedIndex && dimensions.includes(d.data.key)) {
                d3.select(this).style('opacity', opacity_shown_in_view);
                d3.select(this).style('stroke', 'grey');
            } else if (selectedIndex !== i) {
                d3.select(this).style('opacity', opacity_rest);
                d3.select(this).style('stroke', 'grey');
            }

            /*if (i !== 0) {
                d3.select(this).style('opacity', 1);
            }

            if (i > selectedIndex && dimensions.includes(d.data.key)) {
                d3.select(this).style('fill', 'lightgrey');
                d3.select(this).style('stroke', 'grey');

            } else if (selectedIndex !== i) {
                d3.select(this).style('fill', 'white');
                d3.select(this).style('stroke', 'grey');

            }
            d3.select(this).attr('d', arc);*/
        })
        .on('click', function (d, i) {

            highlight_dimension(d.data.key);
            highlight_circles(d.data.key);
        })
        .attr('data-tippy-content', function (d, i) {
            return column_values_grouped[i][key_header];
        });

    tippy_instance_donut = tippy(svg.selectAll('path').nodes());

    path.attr("d", arc);
}

function update_donut_chart_color() {
    let svg = d3.select('#' + id_donut_chart_div).select('svg').select('g');

// set the color scale
    svg.selectAll('path').each(function (d, i) {

        tippy_instance_donut[i].setContent(column_values_cleaned[i][key_header]);

        d3.select(this).style('fill', column_values_cleaned[i][id_applied_color]);
    });


}

function highlight_donut_chart_after_rotation() {
    let svg = d3.select('#' + id_donut_chart_div).select('svg').select('g');


// set the color scale
    svg.selectAll('path').each(function (d, i) {

        let index_for_emphasis;
        if (selectedIndex < 0) {
            index_for_emphasis = column_values_grouped.length + selectedIndex - (parseInt(selectedIndex / column_values_grouped.length + "") * column_values_grouped.length);

            if (index_for_emphasis > column_values_grouped.length - 1) {
                index_for_emphasis = 0;
            }
        } else {
            index_for_emphasis = selectedIndex - (parseInt(selectedIndex / column_values_grouped.length + "") * column_values_grouped.length);

        }

        if (i === index_for_emphasis) {
            d3.select(this).style('opacity', 1);
            d3.select(this).style('stroke', 'black');
        } else if (dimensions.includes(d.data.key)) {
            d3.select(this).style('opacity', opacity_shown_in_view);
            d3.select(this).style('stroke', 'grey');
        } else {
            d3.select(this).style('opacity', opacity_rest);
            d3.select(this).style('stroke', 'grey');
        }

        if (dimensions_brushed_filtered.includes(d.data.key)) {
            d3.select(this).style('fill', color_upper_vis_variance);
        }

        d3.select(this).attr('data-tippy-content', column_values_grouped[index_for_emphasis][key_header]);
    });

}