本文整理匯總了TypeScript中d3.scaleLog函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript scaleLog函數的具體用法?TypeScript scaleLog怎麽用?TypeScript scaleLog使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了scaleLog函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: addLogYAxis
function addLogYAxis() {
let log_base = panel.yAxis.logBase;
let {y_min, y_max} = adjustLogRange(data.heatmapStats.minLog, data.heatmapStats.max, log_base);
y_min = panel.yAxis.min && panel.yAxis.min !== '0' ? adjustLogMin(panel.yAxis.min, log_base) : y_min;
y_max = panel.yAxis.max !== null ? adjustLogMax(panel.yAxis.max, log_base) : y_max;
// Set default Y min and max if no data
if (_.isEmpty(data.buckets)) {
y_max = Math.pow(log_base, 2);
y_min = 1;
}
scope.yScale = yScale = d3.scaleLog()
.base(panel.yAxis.logBase)
.domain([y_min, y_max])
.range([chartHeight, 0]);
let domain = yScale.domain();
let tick_values = logScaleTickValues(domain, log_base);
let decimalsAuto = getPrecision(y_min);
let decimals = panel.yAxis.decimals || decimalsAuto;
// Calculate scaledDecimals for log scales using tick size (as in jquery.flot.js)
let flot_tick_size = getFlotTickSize(y_min, y_max, tick_values.length, decimalsAuto);
let scaledDecimals = getScaledDecimals(decimals, flot_tick_size);
ctrl.decimals = decimals;
ctrl.scaledDecimals = scaledDecimals;
data.yAxis = {
min: y_min,
max: y_max,
ticks: tick_values.length
};
let yAxis = d3.axisLeft(yScale)
.tickValues(tick_values)
.tickFormat(tickValueFormatter(decimals, scaledDecimals))
.tickSizeInner(0 - width)
.tickSizeOuter(0)
.tickPadding(Y_AXIS_TICK_PADDING);
heatmap.append("g")
.attr("class", "axis axis-y")
.call(yAxis);
// Calculate Y axis width first, then move axis into visible area
let posY = margin.top;
let posX = getYAxisWidth(heatmap) + Y_AXIS_TICK_PADDING;
heatmap.select(".axis-y").attr("transform", "translate(" + posX + "," + posY + ")");
// Set first tick as pseudo 0
if (y_min < 1) {
heatmap.select(".axis-y").select(".tick text").text("0");
}
// Remove vertical line in the right of axis labels (called domain in d3)
heatmap.select(".axis-y").select(".domain").remove();
}
示例2: scaleFor
export function scaleFor(column: ChartColumn<any>, values: number[], minRange: number, maxRange: number, scaleName: string | null | undefined): d3.ScaleContinuousNumeric<number, number> {
if (scaleName == "ZeroMax")
return d3.scaleLinear()
.domain([0, d3.max(values)!])
.range([minRange, maxRange])
.nice();
if (scaleName == "MinMax") {
if (column.type == "Date" || column.type == "DateTime") {
const scale = d3.scaleTime()
.domain(values)
.range([minRange, maxRange]);
const f = function (d: string) { return scale(new Date(d)); } as any as d3.ScaleContinuousNumeric<number, number>;
f.ticks = scale.ticks as any;
f.tickFormat = scale.tickFormat as any;
return f;
}
else {
return d3.scaleLinear()
.domain([d3.min(values)!, d3.max(values)!])
.range([minRange, maxRange])
.nice();
}
}
if (scaleName == "Log")
return d3.scaleLog()
.domain([d3.min(values)!, d3.max(values)!])
.range([minRange, maxRange])
.nice();
if (scaleName == "Sqrt")
return d3.scalePow().exponent(.5)
.domain([d3.min(values)!, d3.max(values)!])
.range([minRange, maxRange]);
throw Error("Unexpected scale: " + scaleName);
}
示例3: addLogYAxis
addLogYAxis() {
const log_base = this.panel.yAxis.logBase;
let { y_min, y_max } = this.adjustLogRange(this.data.heatmapStats.minLog, this.data.heatmapStats.max, log_base);
y_min =
this.panel.yAxis.min && this.panel.yAxis.min !== '0' ? this.adjustLogMin(this.panel.yAxis.min, log_base) : y_min;
y_max = this.panel.yAxis.max !== null ? this.adjustLogMax(this.panel.yAxis.max, log_base) : y_max;
// Set default Y min and max if no data
if (_.isEmpty(this.data.buckets)) {
y_max = Math.pow(log_base, 2);
y_min = 1;
}
this.scope.yScale = this.yScale = d3
.scaleLog()
.base(this.panel.yAxis.logBase)
.domain([y_min, y_max])
.range([this.chartHeight, 0]);
const domain = this.yScale.domain();
const tick_values = this.logScaleTickValues(domain, log_base);
const decimalsAuto = ticksUtils.getPrecision(y_min);
const decimals = this.panel.yAxis.decimals || decimalsAuto;
// Calculate scaledDecimals for log scales using tick size (as in jquery.flot.js)
const flot_tick_size = ticksUtils.getFlotTickSize(y_min, y_max, tick_values.length, decimalsAuto);
const scaledDecimals = ticksUtils.getScaledDecimals(decimals, flot_tick_size);
this.ctrl.decimals = decimals;
this.ctrl.scaledDecimals = scaledDecimals;
this.data.yAxis = {
min: y_min,
max: y_max,
ticks: tick_values.length,
};
const yAxis = d3
.axisLeft(this.yScale)
.tickValues(tick_values)
.tickFormat(this.tickValueFormatter(decimals, scaledDecimals))
.tickSizeInner(0 - this.width)
.tickSizeOuter(0)
.tickPadding(Y_AXIS_TICK_PADDING);
this.heatmap
.append('g')
.attr('class', 'axis axis-y')
.call(yAxis);
// Calculate Y axis width first, then move axis into visible area
const posY = this.margin.top;
const posX = this.getYAxisWidth(this.heatmap) + Y_AXIS_TICK_PADDING;
this.heatmap.select('.axis-y').attr('transform', 'translate(' + posX + ',' + posY + ')');
// Set first tick as pseudo 0
if (y_min < 1) {
this.heatmap
.select('.axis-y')
.select('.tick text')
.text('0');
}
// Remove vertical line in the right of axis labels (called domain in d3)
this.heatmap
.select('.axis-y')
.select('.domain')
.remove();
}