|
|
|
|
@ -1,10 +1,10 @@
|
|
|
|
|
class Shape {
|
|
|
|
|
static globalIndex = 0
|
|
|
|
|
|
|
|
|
|
constructor(ctx, value, name, x, y) {
|
|
|
|
|
constructor(ctx, value, colId, x, y) {
|
|
|
|
|
this.ctx = ctx
|
|
|
|
|
this.value = value
|
|
|
|
|
this.name = name
|
|
|
|
|
this.colId = colId
|
|
|
|
|
this.x = x
|
|
|
|
|
this.y = y
|
|
|
|
|
this.index = Shape.globalIndex++
|
|
|
|
|
@ -14,8 +14,8 @@ class Shape {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Rectangle extends Shape {
|
|
|
|
|
constructor(ctx, value, name, x, y, w, h) {
|
|
|
|
|
super(ctx, value, name, x, y)
|
|
|
|
|
constructor(ctx, value, colId, x, y, w, h) {
|
|
|
|
|
super(ctx, value, colId, x, y)
|
|
|
|
|
this.w = w
|
|
|
|
|
this.h = h
|
|
|
|
|
}
|
|
|
|
|
@ -29,8 +29,8 @@ class Rectangle extends Shape {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Circle extends Shape {
|
|
|
|
|
constructor(ctx, value, name, x, y, r) {
|
|
|
|
|
super(ctx, value, name, x, y)
|
|
|
|
|
constructor(ctx, value, colId, x, y, r) {
|
|
|
|
|
super(ctx, value, colId, x, y)
|
|
|
|
|
this.r = r
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -43,8 +43,8 @@ class Circle extends Shape {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PieSlice extends Circle {
|
|
|
|
|
constructor(ctx, value, name, x, y, r, sAngle, eAngle) {
|
|
|
|
|
super(ctx, value, name, x, y, r)
|
|
|
|
|
constructor(ctx, value, colId, x, y, r, sAngle, eAngle) {
|
|
|
|
|
super(ctx, value, colId, x, y, r)
|
|
|
|
|
this.sAngle = sAngle
|
|
|
|
|
this.eAngle = eAngle
|
|
|
|
|
}
|
|
|
|
|
@ -60,8 +60,8 @@ class PieSlice extends Circle {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class DonutSlice extends PieSlice {
|
|
|
|
|
constructor(ctx, value, name, x, y, r, sAngle, eAngle, r2) {
|
|
|
|
|
super(ctx, value, name, x, y, r, sAngle, eAngle)
|
|
|
|
|
constructor(ctx, value, colId, x, y, r, sAngle, eAngle, r2) {
|
|
|
|
|
super(ctx, value, colId, x, y, r, sAngle, eAngle)
|
|
|
|
|
this.r2 = r2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -100,6 +100,11 @@ function getSmallest(data) {
|
|
|
|
|
return smallest
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lighten or darken a hex color
|
|
|
|
|
function adjustColor(color, amount) {
|
|
|
|
|
return '#' + color.replace(/^#/, '').replace(/../g, color => ('0'+Math.min(255, Math.max(0, parseInt(color, 16) + amount)).toString(16)).substr(-2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Chart {
|
|
|
|
|
constructor(canvas, data, settings) {
|
|
|
|
|
this.data = data
|
|
|
|
|
@ -143,14 +148,6 @@ class Chart {
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*checkHit(pos) {
|
|
|
|
|
for (let i = 0; i < this.objects.length; i++)
|
|
|
|
|
if (this.objects[i].checkHit(pos.x, pos.y))
|
|
|
|
|
return this.objects[i]
|
|
|
|
|
|
|
|
|
|
return null
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
drawTitle() {
|
|
|
|
|
let x = this.canvas.width / 2
|
|
|
|
|
let y = 25
|
|
|
|
|
@ -175,10 +172,11 @@ class Chart {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resizeCanvas(parent, legendHeight = 0) {
|
|
|
|
|
resizeCanvas() {
|
|
|
|
|
this.clear()
|
|
|
|
|
//set size
|
|
|
|
|
this.canvas.width = parent.clientWidth
|
|
|
|
|
this.canvas.height = parent.clientHeight - legendHeight
|
|
|
|
|
this.canvas.width = this.canvas.clientWidth
|
|
|
|
|
this.canvas.height = this.canvas.clientHeight
|
|
|
|
|
|
|
|
|
|
this.updateBounds()
|
|
|
|
|
}
|
|
|
|
|
@ -201,6 +199,9 @@ class Chart {
|
|
|
|
|
ctx.moveTo(0.5, 0.5)
|
|
|
|
|
ctx.lineWidth = 3
|
|
|
|
|
|
|
|
|
|
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height)
|
|
|
|
|
ctx.fill()
|
|
|
|
|
ctx.stroke()
|
|
|
|
|
this.objects.forEach(object => {
|
|
|
|
|
let color = "#" + object.index.toString(16).padStart(6, '0')
|
|
|
|
|
ctx.fillStyle = color
|
|
|
|
|
@ -212,7 +213,7 @@ class Chart {
|
|
|
|
|
|
|
|
|
|
drawEffect(ctx, objects) {
|
|
|
|
|
objects.forEach(object => {
|
|
|
|
|
ctx.globalCompositeOperation = "source-over"
|
|
|
|
|
/*ctx.globalCompositeOperation = "source-over"
|
|
|
|
|
ctx.fillStyle = 'rgba(0,0,0,1)'
|
|
|
|
|
ctx.strokeStyle = 'rgba(0,0,0,0)'
|
|
|
|
|
object.draw(ctx)
|
|
|
|
|
@ -228,6 +229,13 @@ class Chart {
|
|
|
|
|
ctx.fillStyle = 'rgba(255,255,255,0.2)'
|
|
|
|
|
ctx.strokeStyle = 'rgba(0,0,0,0)'
|
|
|
|
|
object.draw(ctx)
|
|
|
|
|
ctx.stroke()*/
|
|
|
|
|
let color = this.data[object.colId].color
|
|
|
|
|
let lighterColor = adjustColor(color, 20)
|
|
|
|
|
ctx.fillStyle = lighterColor
|
|
|
|
|
ctx.strokeStyle = 'rgba(0,0,0,0.3)'
|
|
|
|
|
ctx.lineWidth = 3
|
|
|
|
|
object.draw(ctx)
|
|
|
|
|
ctx.stroke()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|