Created
August 26, 2015 18:21
-
-
Save kenyonj/732149c1bdf81c2878a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BenchmarksChart { | |
constructor(type, data) { | |
this.type = type; | |
this.data = data; | |
this.chart = new Chartist.Bar(".ct-${this.type}-chart", this.data, this._options) | |
this.chart.on("draw", function(data) { | |
if(data.type === "bar") { | |
let barWidth = 40; | |
if(data.value.x < 0) { | |
let barHorizontalRight = (data.x2 + 8); | |
} else { | |
let barHorizontalRight = (data.x2 - 8); | |
} | |
let barVerticalCenter = (data.y1 + (barWidth * .12)); | |
let labelText = data.value.x; | |
let label; | |
data.element.attr({ label: labelText }, "ct:series"); | |
label = new Chartist.Svg("text"); | |
label.text(labelText); | |
label.attr({ | |
x: barHorizontalRight, | |
y: barVerticalCenter, | |
"text-anchor": "middle" | |
}); | |
data.group.append(label); | |
} | |
}); | |
} | |
_options() { | |
return { | |
seriesBarDistance: 10, | |
high: 100, | |
low: -100, | |
reverseData: true, | |
horizontalBars: true, | |
height: 1800, | |
axisY: { | |
offset: 80 | |
}, | |
axisX: { | |
showGrid: true, | |
showLabel: true, | |
type: Chartist.FixedScaleAxis, | |
ticks: [-100, -75, -50, -25, 0, 25, 50, 75, 100] | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment