d3-format#formatPrefix JavaScript Examples
The following examples show how to use
d3-format#formatPrefix.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: tickFormat.js From cs-wiki with GNU General Public License v3.0 | 6 votes |
export default function tickFormat(start, stop, count, specifier) {
var step = tickStep(start, stop, count),
precision;
specifier = formatSpecifier(specifier == null ? ",f" : specifier);
switch (specifier.type) {
case "s": {
var value = Math.max(Math.abs(start), Math.abs(stop));
if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
return formatPrefix(specifier, value);
}
case "":
case "e":
case "g":
case "p":
case "r": {
if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
break;
}
case "f":
case "%": {
if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
break;
}
}
return format(specifier);
}
Example #2
Source File: tickFormat.js From cs-wiki with GNU General Public License v3.0 | 6 votes |
export default function(start, stop, count, specifier) {
var step = tickStep(start, stop, count),
precision;
specifier = formatSpecifier(specifier == null ? ",f" : specifier);
switch (specifier.type) {
case "s": {
var value = Math.max(Math.abs(start), Math.abs(stop));
if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
return formatPrefix(specifier, value);
}
case "":
case "e":
case "g":
case "p":
case "r": {
if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
break;
}
case "f":
case "%": {
if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
break;
}
}
return format(specifier);
}
Example #3
Source File: tickFormat.js From gamedesign with GNU General Public License v3.0 | 6 votes |
export default function(domain, count, specifier) {
var start = domain[0],
stop = domain[domain.length - 1],
step = tickStep(start, stop, count == null ? 10 : count),
precision;
specifier = formatSpecifier(specifier == null ? ",f" : specifier);
switch (specifier.type) {
case "s": {
var value = Math.max(Math.abs(start), Math.abs(stop));
if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
return formatPrefix(specifier, value);
}
case "":
case "e":
case "g":
case "p":
case "r": {
if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
break;
}
case "f":
case "%": {
if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
break;
}
}
return format(specifier);
}
Example #4
Source File: indexRollupNext.js From t-viSNE with MIT License | 4 votes |
helper = {
d3_drawShapes: function d3_drawShapes(shape, shapes, shapeHeight, shapeWidth, shapeRadius, path) {
if (shape === "rect") {
shapes.attr("height", shapeHeight).attr("width", shapeWidth);
} else if (shape === "circle") {
shapes.attr("r", shapeRadius);
} else if (shape === "line") {
shapes.attr("x1", 0).attr("x2", shapeWidth).attr("y1", 0).attr("y2", 0);
} else if (shape === "path") {
shapes.attr("d", path);
}
},
d3_addText: function d3_addText(svg, enter, labels, classPrefix, labelWidth) {
enter.append("text").attr("class", classPrefix + "label");
var text = svg.selectAll('g.' + classPrefix + 'cell text.' + classPrefix + 'label').data(labels).text(d3_identity);
if (labelWidth) {
svg.selectAll('g.' + classPrefix + 'cell text.' + classPrefix + 'label').call(d3_textWrapping, labelWidth);
}
return text;
},
d3_calcType: function d3_calcType(scale, ascending, cells, labels, labelFormat, labelDelimiter) {
var type = scale.invertExtent ? d3_quantLegend(scale, labelFormat, labelDelimiter) : scale.ticks ? d3_linearLegend(scale, cells, labelFormat) : d3_ordinalLegend(scale);
//for d3.scaleSequential that doesn't have a range function
var range = scale.range && scale.range() || scale.domain();
type.labels = d3_mergeLabels(type.labels, labels, scale.domain(), range);
if (ascending) {
type.labels = d3_reverse(type.labels);
type.data = d3_reverse(type.data);
}
return type;
},
d3_filterCells: function d3_filterCells(type, cellFilter) {
var filterCells = type.data.map(function (d, i) {
return { data: d, label: type.labels[i] };
}).filter(cellFilter);
var dataValues = filterCells.map(function (d) {
return d.data;
});
var labelValues = filterCells.map(function (d) {
return d.label;
});
type.data = type.data.filter(function (d) {
return dataValues.indexOf(d) !== -1;
});
type.labels = type.labels.filter(function (d) {
return labelValues.indexOf(d) !== -1;
});
return type;
},
d3_placement: function d3_placement(orient, cell, cellTrans, text, textTrans, labelAlign) {
cell.attr("transform", cellTrans);
text.attr("transform", textTrans);
if (orient === "horizontal") {
text.style("text-anchor", labelAlign);
}
},
d3_addEvents: function d3_addEvents(cells, dispatcher) {
cells.on("mouseover.legend", function (d) {
d3_cellOver(dispatcher, d, this);
}).on("mouseout.legend", function (d) {
d3_cellOut(dispatcher, d, this);
}).on("click.legend", function (d) {
d3_cellClick(dispatcher, d, this);
});
},
d3_title: function d3_title(svg, title, classPrefix, titleWidth) {
if (title !== "") {
var titleText = svg.selectAll('text.' + classPrefix + 'legendTitle');
titleText.data([title]).enter().append('text').attr('class', classPrefix + 'legendTitle');
svg.selectAll('text.' + classPrefix + 'legendTitle').text(title);
if (titleWidth) {
svg.selectAll('text.' + classPrefix + 'legendTitle').call(d3_textWrapping, titleWidth);
}
var cellsSvg = svg.select('.' + classPrefix + 'legendCells');
var yOffset = svg.select('.' + classPrefix + 'legendTitle').nodes().map(function (d) {
return d.getBBox().height;
})[0],
xOffset = -cellsSvg.nodes().map(function (d) {
return d.getBBox().x;
})[0];
cellsSvg.attr('transform', 'translate(' + xOffset + ',' + yOffset + ')');
}
},
d3_defaultLocale: {
format: format,
formatPrefix: formatPrefix
},
d3_defaultFormatSpecifier: '.01f',
d3_defaultDelimiter: 'to'
}