Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.init(function(datasets, opts) {
var step = plot.xset()(datasets).length; // Number of x axis labels
var slots = step * (datasets.length + 1); // ~How many boxes to fit
var space = opts.gwidth / slots; // Space available for each box
r = d3.min([(space * 0.8) / 2, 20]); // "radius" of box (use 80%)
wr = r / 2; // "radius" of whiskers
var width = (datasets.length - 1) * space;
datasets.forEach(function(dataset, i) {
offsets[plot.id()(dataset)] = i * space - width / 2;
});
})
.render(function(dataset) {
var width = this.width
var height = this.height
var data = this.data
var selector = this.selector
var self = this
var entries = data.entries;
var nrow = data.nrow
var ncol = data.ncol
// automatically scale stroke width by number of cells
var strokeWidth = Math.max(1 - 0.00009 * nrow * ncol, 0.1);
// get min and max of matrix value data
var zmin = d3.min(entries, function(d) {
return d.z
});
var zmax = d3.max(entries, function(d) {
return d.z
});
// create colormap
function colormap(name) {
return colorbrewer[name][9]
}
// set up colormap
var name = data.colormap ? data.colormap : self.defaultColormap
var color = colormap(name)
var zdomain = utils.linspace(zmin, zmax, 9)
var z = d3.scale.linear().domain(zdomain).range(color);
// ensure vals and ranges are date objects
_.each(stats, function(d) {
if (type == 'time') {
d.val = '2000-01-01T' + d.val;
d.range = _.map(d.range, function(v) { return '2000-01-01T'+v; });
}
d.val = new Date(d.val);
d.range = _.map(d.range, function(v) {return new Date(v);})
})
}
stats = _.sortBy(stats, 'val');
var getx = function(d) { return d.val; },
gety = function(d) { return d.count },
xdomain = util.getXDomain(stats, type, getx),
ydomain = [ d3.min(stats, gety), d3.max(stats, gety) ];
if (ydomain[0] == ydomain[1] || ydomain[0] > 0)
ydomain[0] = 0;
return {
stats: stats,
type: type,
xdomain: xdomain,
ydomain: ydomain,
selection: [],
ready: true
};
},
const draw = function () {
// Set Margins
const margin = {
top: 50,
right: 10,
bottom: 20,
left: yAxisLabel ? 70 : 50,
};
const navBarHeight = 36;
const navBarBuffer = 10;
const width = slice.width() - margin.left - margin.right;
const height = slice.height() - margin.top - margin.bottom - navBarHeight - navBarBuffer;
// set number of ticks
const maxTicks = 20;
const numTicks = d3.min([maxTicks, numBins]);
// Set Histogram objects
const x = d3.scale.linear();
const y = d3.scale.linear();
const xAxis = d3.svg.axis()
.scale(x)
.orient('bottom')
.ticks(numTicks, 's');
const yAxis = d3.svg.axis()
.scale(y)
.orient('left')
.ticks(numTicks, 's');
// Set the x-values
const max = d3.max(data, d => d3.max(d.values));
const min = d3.min(data, d => d3.min(d.values));
selection.each(function(datasets) {
// If no min/max defined, base on min/max from data
if (yMin == undefined) { yMin = d3.min(datasets, function(d) { return d3.min(d.y); }) }
if (yMax == undefined) { yMax = d3.max(datasets, function(d) { return d3.max(d.y); }) }
//
// Create the plot.
//
let margin = {top: 8, right: 8, bottom: 20, left: 32};
let innerwidth = width - margin.left - margin.right;
let innerheight = height - margin.top - margin.bottom;
let x_scale = d3.scaleLinear()
.range([0, innerwidth])
.domain([ d3.min(datasets, function(d) { return d3.min(d.x); }),
d3.max(datasets, function(d) { return d3.max(d.x); }) ]) ;
let y_scale = d3.scaleLinear()
.range([innerheight, 0])
.domain([ yMin, yMax ]);
}
var labelRightPos = boundingRect.right;
if (labelRightPos > containerBoundingClientRect.right) {
right.push(containerBoundingClientRect.right - labelRightPos);
}
var labelLeftPos = boundingRect.left;
if (labelLeftPos < containerBoundingClientRect.left) {
left.push(labelLeftPos - containerBoundingClientRect.left);
}
});
var topOffset = top.length ? d3.min(top) : 0;
var bottomOffset = bottom.length ? d3.min(bottom) : 0;
var rightOffset = right.length ? d3.min(right) : 0;
var leftOffset = left.length ? d3.min(left) : 0;
var smallerOffset = 0;
if (topOffset < 0) {
smallerOffset += topOffset;
}
if (bottomOffset < 0) {
smallerOffset += bottomOffset;
}
if (rightOffset < 0) {
smallerOffset += rightOffset;
}
if (leftOffset < 0) {
smallerOffset += leftOffset;
}
public d3GetYAxis() {
let chart = this.props.chart as BarChart;
let yScale = d3.scale.linear();
yScale.range([chart.height - this._margin.bottom, this._margin.top])
yScale.domain([
chart.yScale.min != null ? chart.yScale.min : d3.min(chart.yColumns, (d) => d3.min(chart.dataset.rows, (r) => +r[d])),
chart.yScale.max != null ? chart.yScale.max : d3.max(chart.yColumns, (d) => d3.max(chart.dataset.rows, (r) => +r[d]))
]);
if (chart.yScale.min == null && chart.yScale.max == null) {
yScale.nice();
}
let yAxis = d3.svg.axis().scale(yScale).orient("left");
return { yScale, yAxis };
}
const minY = d3.min(data, d => {
return d3.min(keys, key => {
return d[key];
});
});
if (minY >= 0) return;
svg = svg.select('g');
if(color&&color.domain){
var names = data.map(seriesNames);
color.domain(names);
}
var indexes = data.map(seriesValues).map(function(list){
return list.map(pointIndexes);
}).reduce(function(curr, res){
return res.concat(curr);
}, []);
x.domain(d3.extent(indexes));
y.domain([
d3.min(data, function(c) { return d3.min(seriesValues(c), pointValues); }),
d3.max(data, function(c) { return d3.max(seriesValues(c), pointValues); })
]);
var xAxisGroup = svg.selectAll('g.x.axis');
if(!xAxisGroup[0][0]){
xAxisGroup = svg.append('g')
.attr('class', 'x axis')
.attr('transform', 'translate(0,' + h + ')');
}
xAxisGroup.call(xAxis);
var yAxisGroup = svg.selectAll('g.y.axis');
if(!yAxisGroup[0][0]){
yAxisGroup = svg.append('g')
.attr('class', 'y axis');
if(yAxisTitle){
var maxGDP = d3.max(data, (d) => d[_measure[1]]);
var minGDP = d3.min(data, (d) => d[_measure[1]]);
var rScale = d3.scaleLinear()
.domain([minGDP, maxGDP])
.range([5, 25]);
var maxx = d3.max(data, (d) => d[_measure[2]]);
var minx = d3.min(data, (d) => d[_measure[2]]);
x.rangeRound([0, plotWidth])
.domain([minx, maxx]);
var maxy = d3.max(data, (d) => d[_measure[0]]);
var miny = d3.min(data, (d) => d[_measure[0]]);
y.rangeRound([plotHeight - 40, 0])
.domain([miny, maxy]);
var _localXLabels = data.map(function (d) {
return d[_dimension[0]];
});
_localXGrid = d3.axisBottom()
.ticks(_localXLabels.length)
.tickFormat('')
.tickSize(-plotHeight + 40);
_localYGrid = d3.axisLeft()
.tickFormat('')
.tickSize(-plotWidth);