-
-
Save andrewprofile/4023eb8c610d0288cac8 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
| module.exports = arcChartFactory | |
| var d3 = require('d3'); | |
| var arcChart = require('./primitive') | |
| var SIZE = 110 | |
| var STROKE_WIDTH = 6 | |
| var padding = STROKE_WIDTH * -2 | |
| var center = SIZE / 2 | |
| function arcChartFactory(el, options) { | |
| var del = d3.select(el) | |
| .attr('data-type', options.type) | |
| var svg = del.append('svg') | |
| .attr({ width: SIZE, height: SIZE }) | |
| var chart = arcChart(svg.node()) | |
| .param('stroke-width', STROKE_WIDTH) | |
| .param('point-radius', 0) | |
| function draw(value) { | |
| var label | |
| var after | |
| var duration | |
| if (options.type === 'stars') { | |
| label = value * 100 | |
| after = '%' | |
| subLabel = '★☆☆' | |
| } else { | |
| var tmp = value.toFixed(2).split('.') | |
| value = 1 | |
| label = tmp[0] | |
| after = '.' + tmp[1] | |
| subLabel = 'minutes' | |
| } | |
| chart.param('after', after) | |
| data = { | |
| value: value | |
| , label: label | |
| , subLabel: subLabel | |
| } | |
| chart.data(data) | |
| .draw( | |
| center | |
| , center | |
| , SIZE + padding | |
| , SIZE + padding | |
| ) | |
| } | |
| return { draw: draw } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment