Files
old-spike/client/d3/base.js

53 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-02-13 16:49:32 -06:00
import extend from 'extend';
2016-02-12 15:51:06 -06:00
const DEFAULTS = {
outer_width: 500,
outer_height: 300,
2016-02-15 16:09:40 -06:00
margin: {top: 30, left: 70, bottom: 50, right: 20},
2016-02-12 15:51:06 -06:00
domain_ticks: 10,
range_ticks: 8,
container: "container",
time_series: false,
range_label: undefined,
domain_attr: undefined,
range_attr: undefined,
titleize: function(series, datum){
2016-02-15 16:09:40 -06:00
var s = datum ? datum.title : series.title;
2016-02-13 16:49:32 -06:00
if (!s) return '';
var words = s.split(' '),
2016-02-12 15:51:06 -06:00
array = [];
for (var i=0; i<words.length; ++i) {
array.push(words[i].charAt(0).toUpperCase() + words[i].toLowerCase().slice(1));
}
return array.join(' ');
},
toClass: function(series){
return series ? series.title.toLowerCase().replace(/\s+/g, '-') : "";
}
};
class Chart {
constructor(options){
var chart = this;
2016-02-15 11:38:41 -06:00
chart = extend(chart, chart.chart_options, options);
2016-02-12 15:51:06 -06:00
chart.height = chart.outer_height - chart.margin.top - chart.margin.bottom;
chart.width = chart.outer_width - chart.margin.left - chart.margin.right;
chart.svg = d3.select(chart.container).append("svg")
.attr("width", chart.outer_width)
.attr("height", chart.outer_height)
.append("g")
.attr("transform", "translate(" + chart.margin.left + "," + chart.margin.top + ")");
chart.defineAxes();
if (chart.afterAxes) chart.afterAxes();
}
}
2016-02-13 16:49:32 -06:00
Chart.DEFAULTS = DEFAULTS;
2016-02-12 15:51:06 -06:00
export default Chart;