|
|
@ -49,7 +49,7 @@ const zoom_plugin = { |
|
|
|
|
|
|
|
|
|
|
|
let hovered = false; |
|
|
|
let hovered = false; |
|
|
|
const trigger_legend_hover = function (legendItem, chart) { |
|
|
|
const trigger_legend_hover = function (legendItem, chart) { |
|
|
|
if (legendItem.hidden || hovered) { |
|
|
|
if (chart.legend.legendItems[legendItem.datasetIndex].hidden || hovered) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
hovered = true; |
|
|
|
hovered = true; |
|
|
@ -75,10 +75,10 @@ const trigger_legend_click = function (item) { |
|
|
|
if (c_chart.isDatasetVisible(item.datasetIndex)) { |
|
|
|
if (c_chart.isDatasetVisible(item.datasetIndex)) { |
|
|
|
trigger_legend_leave(c_chart) |
|
|
|
trigger_legend_leave(c_chart) |
|
|
|
c_chart.hide(item.datasetIndex); |
|
|
|
c_chart.hide(item.datasetIndex); |
|
|
|
item.hidden = true; |
|
|
|
c_chart.legend.legendItems[item.datasetIndex].hidden = true; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
c_chart.show(item.datasetIndex); |
|
|
|
c_chart.show(item.datasetIndex); |
|
|
|
item.hidden = false; |
|
|
|
c_chart.legend.legendItems[item.datasetIndex].hidden = false; |
|
|
|
trigger_legend_hover(item, c_chart) |
|
|
|
trigger_legend_hover(item, c_chart) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
@ -107,6 +107,19 @@ const get_create_LegendList = (chart, id) => { |
|
|
|
const htmlLegendPlugin = { |
|
|
|
const htmlLegendPlugin = { |
|
|
|
id: 'htmlLegend', |
|
|
|
id: 'htmlLegend', |
|
|
|
afterUpdate(chart, args, options) { |
|
|
|
afterUpdate(chart, args, options) { |
|
|
|
|
|
|
|
function sort_legend(a,b) { |
|
|
|
|
|
|
|
const a_values = chart.data.datasets[a.datasetIndex].data |
|
|
|
|
|
|
|
const b_values = chart.data.datasets[b.datasetIndex].data |
|
|
|
|
|
|
|
const a_value = a_values[a_values.length - 1].y; |
|
|
|
|
|
|
|
const b_value = b_values[b_values.length - 1].y; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (a_value > b_value) { |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
} else if (a_value < b_value) { |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
//console.log("update")
|
|
|
|
//console.log("update")
|
|
|
|
const legendList = get_create_LegendList(chart, options.containerID); |
|
|
|
const legendList = get_create_LegendList(chart, options.containerID); |
|
|
|
const ul = legendList.list; |
|
|
|
const ul = legendList.list; |
|
|
@ -114,7 +127,9 @@ const htmlLegendPlugin = { |
|
|
|
// Reuse the built-in legendItems generator
|
|
|
|
// Reuse the built-in legendItems generator
|
|
|
|
const items = chart.options.plugins.legend.labels.generateLabels(chart); |
|
|
|
const items = chart.options.plugins.legend.labels.generateLabels(chart); |
|
|
|
|
|
|
|
|
|
|
|
items.forEach(item => { |
|
|
|
items.sort(sort_legend); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
items.forEach((item, i) => { |
|
|
|
if (legendList.created) { |
|
|
|
if (legendList.created) { |
|
|
|
const li = document.createElement('li'); |
|
|
|
const li = document.createElement('li'); |
|
|
|
li.classList.add("legend-element"); |
|
|
|
li.classList.add("legend-element"); |
|
|
@ -142,7 +157,7 @@ const htmlLegendPlugin = { |
|
|
|
ul.appendChild(li); |
|
|
|
ul.appendChild(li); |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const list_element = ul.querySelector(`li.legend-element:nth-of-type(${item.datasetIndex+1})`); |
|
|
|
const list_element = ul.querySelector(`li.legend-element:nth-of-type(${i+1})`); |
|
|
|
const boxSpan = list_element.querySelector("span"); |
|
|
|
const boxSpan = list_element.querySelector("span"); |
|
|
|
const textContainer = list_element.querySelector("p"); |
|
|
|
const textContainer = list_element.querySelector("p"); |
|
|
|
boxSpan.style.background = item.fillStyle; |
|
|
|
boxSpan.style.background = item.fillStyle; |
|
|
@ -276,7 +291,7 @@ async function create_charts() { |
|
|
|
display: false, |
|
|
|
display: false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
htmlLegend: { |
|
|
|
htmlLegend: { |
|
|
|
containerID: 'combined-chart-legend', |
|
|
|
containerID: 'legend-rank-graph', |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
scales: { |
|
|
|
scales: { |
|
|
@ -309,7 +324,7 @@ async function create_charts() { |
|
|
|
display: false, |
|
|
|
display: false, |
|
|
|
}, |
|
|
|
}, |
|
|
|
htmlLegend: { |
|
|
|
htmlLegend: { |
|
|
|
containerID: 'combined-chart-legend', |
|
|
|
containerID: 'legend-progress-graph', |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
scales: { |
|
|
|
scales: { |
|
|
@ -458,16 +473,20 @@ function toggle_combined_chart() { |
|
|
|
const comb_charts = this.parentNode.parentNode.querySelectorAll(`.leaderboard>.graph-wrapper`); |
|
|
|
const comb_charts = this.parentNode.parentNode.querySelectorAll(`.leaderboard>.graph-wrapper`); |
|
|
|
const chart = this.parentNode.parentNode.querySelector(`.graph-wrapper.${this.id}`); |
|
|
|
const chart = this.parentNode.parentNode.querySelector(`.graph-wrapper.${this.id}`); |
|
|
|
const buttons = document.querySelectorAll("button.open-general-graph"); |
|
|
|
const buttons = document.querySelectorAll("button.open-general-graph"); |
|
|
|
|
|
|
|
const legend = document.querySelector(`#combined-chart-legends #legend-${this.id}`) |
|
|
|
|
|
|
|
const all_legends = document.querySelectorAll(`#combined-chart-legends .chart-legend`); |
|
|
|
|
|
|
|
all_legends.forEach(element => {element.classList.add("hidden")}); |
|
|
|
|
|
|
|
legend.classList.remove("hidden"); |
|
|
|
if (chart.classList.contains("closed")) { |
|
|
|
if (chart.classList.contains("closed")) { |
|
|
|
comb_charts.forEach(element => element.classList.add("closed")); |
|
|
|
comb_charts.forEach(element => element.classList.add("closed")); |
|
|
|
buttons.forEach(element => element.classList.remove("dropdown-open")); |
|
|
|
buttons.forEach(element => element.classList.remove("dropdown-open")); |
|
|
|
chart.classList.remove("closed"); |
|
|
|
chart.classList.remove("closed"); |
|
|
|
this.classList.add("dropdown-open"); |
|
|
|
this.classList.add("dropdown-open"); |
|
|
|
document.querySelector("#combined-chart-legend").classList.remove("hidden"); |
|
|
|
document.querySelector("#combined-chart-legends").classList.remove("hidden"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
chart.classList.add("closed"); |
|
|
|
chart.classList.add("closed"); |
|
|
|
this.classList.remove("dropdown-open"); |
|
|
|
this.classList.remove("dropdown-open"); |
|
|
|
document.querySelector("#combined-chart-legend").classList.add("hidden"); |
|
|
|
document.querySelector("#combined-chart-legends").classList.add("hidden"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|