本文整理汇总了TypeScript中d3.scale.linear方法的典型用法代码示例。如果您正苦于以下问题:TypeScript scale.linear方法的具体用法?TypeScript scale.linear怎么用?TypeScript scale.linear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类d3.scale
的用法示例。
在下文中一共展示了scale.linear方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createScales
export function createScales(props: PositionsBubbleChartProps) {
const ratio = 12.5
const { width, height } = props.size
const minR = 15
const maxR = 60
const offset = maxR / 2
const positionData = getPositionsDataFromSeries(props.data, props.currencyPairs)
const baseValues = _.map(positionData, (val: any) => {
return Math.abs(val[baseTradedAmountName])
})
const maxValue = _.max(baseValues) || 0
let minValue = _.min(baseValues) || 0
if (minValue === maxValue) minValue = 0
const scales = {
x: d3.scale.linear()
.domain([0, props.data.length])
.range([(-(width / ratio)), (width / ratio) - offset]),
y: d3.scale.linear()
.domain([0, props.data.length])
.range([-(height / (ratio)), height / ratio]),
r: d3.scale.sqrt()
.domain([minValue, maxValue])
.range([minR, maxR])}
return scales
}
示例2: render
public render(data: ICoordinate[]): d3.Selection<any> {
const x = d3.scale.linear().range([0, this.width]);
const y = d3.scale.linear().range([this.height, 0]);
const xAxis = d3.svg.axis().scale(x).orient('bottom');
const yAxis = d3.svg.axis().scale(y).orient('left');
const svg = this.element.append('svg')
.attr('width', this.chartWidth)
.attr('height', this.chartHeight)
.append('g')
.attr('transform', 'translate(' + this.margin.left + ',' + this.margin.top + ')');
x.domain(d3.extent(data, a => a.x));
y.domain(d3.extent(data, a => a.y));
const line = d3.svg.line<ICoordinate>()
.x(a => x(a.x))
.y(a => y(a.y));
svg.append('g')
.attr('class', 'x axis')
.attr('transform', 'translate(0,' + this.height + ')')
.call(xAxis);
svg.append('g')
.attr('class', 'y axis')
.call(yAxis);
svg.append('path')
.datum(data)
.attr('class', 'line')
.attr('d', line);
return svg;
}
示例3: GenerateGraph
function GenerateGraph(data_row, iter:number) {
// define dimensions of graph
let margins:number[] = [80, 80, 80, 80];
let width:number = 1000 - margins[1] - margins[3];
let height:number = 400 - margins[0] - margins[2];
// create a simple data array that we'll plot with a line (this array
// represents only the Y values, X will just be the index location)
// X scale will fit all values from data[] within pixels 0-w
let x = d3.scale.linear().domain([1977, 2014]).range([0, height]);
// Y scale will fit values from 0-10 within pixels h-0 (Note the inverted
// domain for the y-scale: bigger is up!)
let y = d3.scale.linear().domain([0, 10]).range([height, 0]);
// automatically determining max range can work something like this
// let y = d3.scale.linear().domain([0, d3.max(data)]).range([h, 0]);
// create a line function that can convert data[] into x and y points
let line = d3.svg.line()
.x(function(d) { return d[0]; })
.y(function(d) { return d[1]; })
.interpolate("basis");
// Add an SVG element with the desired dimensions and margin.
let div_element = "#graph_" + iter;
let graph = d3.select(div_element).append("svg:svg")
.attr("width", width + margins[1] + margins[3])
.attr("height", height + margins[0] + margins[2])
.append("svg:g")
.attr("transform", "translate(" + margins[3] + "," + margins[0] + ")");
// create yAxis
let xAxis = d3.svg.axis().scale(x).tickSize(-height); //.tickSubdivide(true);
// Add the x-axis.
graph.append("svg:g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
// create left yAxis
let yAxisLeft = d3.svg.axis().scale(y).ticks(4).orient("left");
// Add the y-axis to the left
graph.append("svg:g")
.attr("class", "y axis")
.attr("transform", "translate(-25,0)")
.call(yAxisLeft);
// Add the line by appending an svg:path element with the data line
// we created above do this AFTER the axes above so that the line is
// above the tick-lines
graph.append("svg:path").attr("d", line(data_row));
}
示例4: ngOnInit
ngOnInit() {
const data = [
{name: "First", value: 4},
{name: "Second", value: 8},
{name: "Third", value: 15},
{name: "Fourth", value: 16},
{name: "Fifth", value: 23},
{name: "Sixth", value: 42}];
const margin = {top: 20, right: 30, bottom: 30, left: 40},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
const x = d3.scale.ordinal()
.domain(data.map(function(d) { return d.name; }))
.rangeRoundBands([0, width], .1);
const y = d3.scale.linear()
.domain([0, d3.max(data, function(d) { return d.value; })])
.range([height, 0]);
const xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
const yAxis = d3.svg.axis()
.scale(y)
.orient("left");
const chart = d3.select(".chart")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
chart.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
chart.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Frequency");
chart.selectAll(".bar")
.data(data)
.enter().append("rect")
.attr("class", "bar")
.attr("x", function(d) { return x(d.name); })
.attr("y", function(d) { return y(d.value); })
.attr("height", function(d) { return height - y(d.value); })
.attr("width", x.rangeBand());
}
示例5: init
init() {
const {target, width, height, margin} = this;
// const {xTicks, yTicks, yRange} = this;
const {xTicks, yRange} = this;
const [w, h] = this.dimensions();
this.chart = d3.select(target)
.attr('width', width)
.attr('height', height)
.append('g')
.attr('transform', `translate(${margin.left}, ${margin.top})`);
this.x = d3.time.scale()
.range([0, w]);
this.y = d3.scale.linear()
.range(yRange);
this.xAxis = d3.svg.axis()
.orient('bottom')
.scale(this.x)
.ticks(xTicks)
.tickPadding(8)
.tickSize(-h);
this.chart.append('g')
.attr('class', 'x axis')
.attr('transform', `translate(0, ${h})`)
.call(this.xAxis);
his.details = this.chart.append('g')
.attr('class', 'details')
.style('display', 'none')
this.details.append('line')
.attr('class', 'x')
.attr('y1', 0)
.attr('y1', h)
this.details.append('text')
.attr('class', 'time')
this.details.append('g')
.attr('class', 'data')
this.overlay = this.chart.append('rect')
.attr('class', 'overlay')
.attr('width', w)
.attr('height', h)
.style('fill-opacity', 0)
.on('mousemove', _ => this.onMouseOver())
.on('mouseleave', _ => this.onMouseLeave());
this.xBisect = d3.bisector(d => d.time).left;
}
示例6: getYScale
public getYScale(axis: Axis): d3.scale.Linear<number, number> {
var min = this.series.min(name);
var start = this.canvas.plotArea.axisSize.top;
var end = this.canvas.plotArea.axisSize.top + this.canvas.plotArea.height;
axis.setScaleType(ScaleType.Linear);
return d3.scale.linear()
.domain([1, min < 0 ? -1 : 0])
.range([start, end]);
}
示例7: getXScale
public getXScale(axis: Axis): d3.scale.Linear<number, number> {
var min = this.series.min(name);
var start = this.canvas.plotArea.axisSize.left;
var end = this.canvas.plotArea.axisSize.left + this.canvas.plotArea.width;
axis.setScaleType(ScaleType.Linear);
return d3.scale.linear()
.domain([min < 0 ? -1 : 0, 1])
.range([start, end]);
}
示例8: getXScale
public getXScale(axis: Axis): d3.scale.Linear<number, number> {
var min = d3.min(this.series.items[0].data);
var max = d3.max(this.series.items[0].data);
var start = this.canvas.plotArea.axisSize.left;
var end = this.canvas.plotArea.axisSize.left + this.canvas.plotArea.width;
axis.setScaleType(ScaleType.Linear);
return d3.scale.linear()
.domain([min < 0 ? min : 0, max])
.nice() // adds additional ticks to add some whitespace
.range([start, end]);
}
示例9: getYScale
public getYScale(axis: Axis): d3.scale.Linear<number, number> {
var min = this.series.min(axis.name);
var max = this.series.max(axis.name);
var start = this.canvas.plotArea.axisSize.top;
var end = this.canvas.plotArea.axisSize.top + this.canvas.plotArea.height;
axis.setScaleType(ScaleType.Linear);
return d3.scale.linear()
.domain([max, min < 0 ? min : 0])
.nice() // adds additional ticks to add some whitespace
.range([start, end]);
}
示例10: createChart
createChart() {
let container = document.getElementsByClassName("chart")[0];
let margin = {top: 20, right: 20, bottom: 30, left: 40},
width = container.clientWidth - margin.left - margin.right,
height = 384 - margin.top - margin.bottom;
let x = d3.scale.ordinal()
.rangeRoundBands([0, width], .1);
let y = d3.scale.linear()
.range([height, 0]);
let xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
let yAxis = d3.svg.axis()
.scale(y)
.orient("left");
let svg = d3.select("div.chart").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
x.domain(this.optimalAllocs.map(function(d) { return d.name; }));
y.domain([0, d3.max(this.optimalAllocs, function(d) { return d.value; })]);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append('g')
.attr('class', 'y axis')
.call(yAxis);
svg.selectAll(".bar")
.data(this.optimalAllocs)
.enter().append("rect")
.attr("class", "bar")
.attr("x", function(d) { return x(d.name); })
.attr("width", x.rangeBand())
.attr("y", function(d) { return y(d.value); })
.attr("height", function(d) { return height - y(d.value); });
}