How to use the d3.scaleBand function in d3

To help you get started, we’ve selected a few d3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wangqianwen0418 / DNN-Genealogy / src / components / PerformanceCompare / BarChart.tsx View on Github external
compare.forEach((cp: any) => {
            console.log(cp)
            let svg = d3.select(`.CorpusCompare .tab${cp.idx}`).insert('svg')
                .attr('width', '100%')
                .attr('height', '100%')
                .style('margin-top', '20px')
                .append('g')

            let x = d3.scaleLinear().range([0, width]),
                y = d3.scaleBand().range([height, 0]),
                y_group = d3.scaleBand().padding(0.05)

            let g = svg.append('g').attr('transform', 'translate(' + margin.left + ',' + 0 + ')')
            //    .attr("transform", "translate(" + margin.left + "," + margin.top + ")")
        
            let data = cp.performance,
                keys = cp.nns
            
            let min: number, max: number;
            min = Math.floor(Math.min.apply(null, data.reduce((prev: any, cur: any) => {
                return prev.concat(keys.map((k: string) => cur[k]))
            },                                                [])) * 0.9)
            max = Math.ceil(Math.max.apply(null, data.reduce((prev: any, cur: any) => {
                return prev.concat(keys.map((k: string) => cur[k]))
            },                                               [])) * 1.1)
            x.domain([min, max])
github john-guerra / navio / shipyard / src / components / playground / navio-container / Navio.js View on Github external
function updateScales(levelToUpdate) {
    console.log("Update scales");
    var before = performance.now();
    // yScales=[];
    var lastLevel = dataIs.length-1;

    console.log("Delete unnecessary scales")
    // Delete unnecessary scales
    yScales.splice(lastLevel+1, yScales.length);
    levelToUpdate = levelToUpdate!==undefined ? levelToUpdate : lastLevel;
    yScales[levelToUpdate] = d3.scaleBand()
      .range([y0, h-nn.margin - 30])
      .paddingInner(0.0)
      .paddingOuter(0);



    console.log("Compute representatives")
    var representatives = [];
    if (dataIs[levelToUpdate].length>h) {
      var itemsPerpixel = Math.max(Math.floor(dataIs[levelToUpdate].length / (h*2)), 1);
      console.log("itemsPerpixel", itemsPerpixel);
      dataIs[levelToUpdate].itemsPerpixel = itemsPerpixel;
      for (var i = 0; i< dataIs[levelToUpdate].length; i+=itemsPerpixel ) {
        representatives.push(dataIs[levelToUpdate][i]);
      }
    } else {
github unfetter-discover / unfetter-ui / src / app / threat-dashboard / bar-chart / bar-chart.component.ts View on Github external
if (graphElement.empty()) {
            return;
        }
        graphElement.select('svg').remove();

        const margin = { top: 8, right: 20, bottom: 30, left: 40 };
        let width = 1024;
        let height = 200;
        graphElement.append('svg')
            .attr('width', width)
            .attr('height', height);

        const svg = graphElement.select('svg');
        width = +svg.attr('width') - margin.left - margin.right;
        height = +svg.attr('height') - margin.top - margin.bottom;
        const x = d3.scaleBand().rangeRound([0, width]).padding(0.1);
        const y = d3.scaleLinear().rangeRound([height, 0]);
        const bottom = graphElement.property('offsetHeight') + margin.bottom;

        const g = svg.append('g')
            .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');

        let normalized = [];
        let tooltipDiv = graphElement.append('div').attr('class', 'bar-chart-tooltip')
            .style('max-height', height + 'px');

        data.forEach((el) => {
            // normalize frequency ratio to float
            normalized.push({'name': el.name, 'frequency': +el.frequency / 100, 'patterns': el.patterns});
        });

        x.domain(normalized.map((d) => d.name));
github jamesleesaunders / d3-ez / src / component / radarArea.js View on Github external
// Slice calculation on circle
		angleSlice = (Math.PI * 2 / columnKeys.length);

		if (typeof radius === "undefined") {
			radius = Math.min(width, height) / 2;
		}

		if (typeof colorScale === "undefined") {
			colorScale = d3.scaleOrdinal()
				.domain(columnKeys)
				.range(colors);
		}

		if (typeof xScale === "undefined") {
			xScale = d3.scaleBand()
				.domain(columnKeys)
				.range([0, 360]);
		}

		if (typeof yScale === "undefined") {
			yScale = d3.scaleLinear()
				.domain(valueExtent)
				.range([0, radius])
				.nice();
		}
	}
github jamesleesaunders / d3-ez / src / chart / barChartVertical.js View on Github external
chartH = height - (margin.top + margin.bottom);

		const { seriesNames, columnKeys, valueMax } = dataTransform(data).summary();
		const valueExtent = [0, valueMax];

		if (typeof yAxisLabel === "undefined") {
			yAxisLabel = seriesNames;
		}

		if (typeof colorScale === "undefined") {
			colorScale = d3.scaleOrdinal()
				.domain(columnKeys)
				.range(colors);
		}

		xScale = d3.scaleBand()
			.domain(columnKeys)
			.rangeRound([0, chartW])
			.padding(0.15);

		yScale = d3.scaleLinear()
			.domain(valueExtent)
			.range([chartH, 0])
			.nice();
	}
github AnSavvides / d3act / src / components / BarChart.js View on Github external
getScaleX() {
        return d3.scaleBand().range([0, this.props.width], 0.1);
    }
github viz-centric / flair-visualizations / js / charts / stackedverticalbar.js View on Github external
_textColor = [],
        _displayColor = [],
        _borderColor = [],
        _displayColorExpression = [],
        _textColorExpression = [],
        _fontSize = [],
        _print,
        broadcast,
        filterParameters,
        isLiveEnabled = false,
        _notification = false,
        _data,
        _isFilterGrid = false,
        _showSorting = true;

    var x = d3.scaleBand(), y = d3.scaleLinear();

    var _x = d3.scaleBand(), _y = d3.scaleLinear(), brush = d3.brushX();;

    var FilterControlHeight = 100;

    var margin = {
        top: 0,
        right: 0,
        bottom: 0,
        left: 45
    };

    var _local_svg, svgFilter, _Local_data, _originalData, _localLabelStack = [], legendBreakCount = 1;
    var _localXAxis,
        _localYAxis,
        _localXGrid,
github artyomtrityak / d3-explorer / static / javascript / components / bar-charts / horizontal1.js View on Github external
createScaleY() {
    return d3
      .scaleBand()
      .domain(this.state.data)
      .range([0, this.props.height - OFFSETS.top - OFFSETS.bottom])
      .padding(0.1);
  }
github spring-cloud / spring-cloud-dataflow-ui / ui / src / app / analytics / charts / bar-chart / bar-chart.component.ts View on Github external
parseFloat(computedStyle.paddingRight);
    const heightToUse = this.height;

    const localThis = this;

    if (!this.chartData) {
      return;
    } else {
      this.loggerService.log(`Render Chart - width=${widthToUse}, height=${heightToUse}, data: ${this.chartData} - ` +
        Array.isArray(this.chartData));
    }

    const xValuesRange = [0, d3.max(localThis.chartDataToUse)];
    localThis.xScale = d3.scaleLinear().rangeRound([0, widthToUse]).domain(xValuesRange);

    localThis.yScale = d3.scaleBand()
      .domain(d3.range(localThis.chartDataToUse.length).map(d => d.toString()))
      .range([heightToUse, 0 + 20])
      .round(true)
      .paddingInner(0.05);

    localThis.chart = d3.select(chartElement).append('svg')
        .attr('width', widthToUse)
        .attr('height',  heightToUse);

    /**
     * Define x-axis
     */
    localThis.xAxis = d3.axisTop(localThis.xScale)
      .ticks(10);

    /**
github ft-interactive / visual-vocabulary-templates / xy-heatmap-quantile / xyHeatmapQuantile.js View on Github external
export function draw() {
    let yScale = d3.scaleBand();
    let xScale = d3.scaleBand();
    let seriesNames = [];
    let showValues = false;
    let yAxisAlign = 'right';
    let rem = 16;
    const colourScale = d3.scaleOrdinal()
        .domain(seriesNames);

    function chart(parent) {
        xScale.paddingInner(0);
        yScale.paddingInner(0);

        parent.attr('transform', d => `translate(0, ${yScale(d.name)})`)
            .attr('width', xScale.bandwidth());

        const block = parent.selectAll('g')