You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.5 KiB
74 lines
2.5 KiB
/**
|
|
* PointChart class extends the Chart class to represent data with points
|
|
*/
|
|
class PointChart extends Chart {
|
|
/**
|
|
* Constructor for the PointChart class
|
|
* @param {HTMLElement} canvas - The canvas element to draw the chart on
|
|
* @param {Array} data - The data array containing values for the chart
|
|
* @param {Object} settings - The settings object for configuring the chart
|
|
*/
|
|
constructor(canvas, data, settings) {
|
|
// Call the constructor of the parent class (Chart)
|
|
super(canvas, data, settings)
|
|
}
|
|
|
|
/**
|
|
* Draws the data points on the chart
|
|
* @param {Array} values - The array of values to be plotted
|
|
* @param {string} name - The name or label associated with the values
|
|
* @param {string} color - The color to use for drawing the points
|
|
*/
|
|
drawPoints(values, name, color) {
|
|
// Set the fill and stroke styles for the points
|
|
this.ctx.fillStyle = color
|
|
|
|
// Set border values if enabled
|
|
if (this.settings.pointBorderSize > 0) {
|
|
this.ctx.lineWidth = this.settings.pointBorderSize
|
|
this.ctx.strokeStyle = this.settings.pointBorderColor
|
|
}
|
|
|
|
/*console.log(values)
|
|
console.log(this.dataLen)*/
|
|
|
|
// Iterate over the values to plot each data point
|
|
for (let i = 0; i < this.dataLen; i++) {
|
|
|
|
// Skip empty points
|
|
if (values[i] === null || values[i] === undefined)
|
|
continue
|
|
|
|
// Calculate the x and y coordinates for the data point
|
|
let x = Math.round(this.bounds.left + this.bounds.width / (this.dataLen - 1) * i)
|
|
let y = Math.round(this.bounds.xAxis - values[i] / this.extreme * this.scale)
|
|
|
|
// Create a new Circle object for the data point
|
|
let new_object = new Circle(this.ctx, values[i], name, x, y, this.settings.pointSize)
|
|
new_object.draw()
|
|
this.objects.push(new_object)
|
|
|
|
// Draw a border if enabled
|
|
if (this.settings.pointBorderSize > 0)
|
|
this.ctx.stroke()
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Draws the entire PointChart
|
|
*/
|
|
draw() {
|
|
// Clear the canvas and draw the axis
|
|
this.clear()
|
|
this.drawAxis()
|
|
|
|
// Draw the data points
|
|
if (this.settings.displayPoints)
|
|
setTimeout(() => {
|
|
console.time("1")
|
|
this.data.forEach((categ, colId) => {this.drawPoints(categ.values, colId, categ.color)})
|
|
console.timeEnd("1")
|
|
}, 0);
|
|
}
|
|
}
|