CSNW / d3.compose

Compose complex, data-driven visualizations from reusable charts and components with d3
http://CSNW.github.io/d3.compose/
MIT License
698 stars 24 forks source link

Initial work on extensible line-bar chart #1

Closed timhall closed 10 years ago

timhall commented 10 years ago

Key points:

Hierarchy:

Base (width, height, data)
|_ Container (rawData, chartBase, bounds)
   |_ LineBarChart (includes BarChart and CenteredLineChartWithLabels)
|_ XYBase (x, y, scales)
   |_ ValueBase (updates x, y for values)
      |_ CenteredValueBase (itemWidth, itemPadding)
         |_ BarChart
         |_ CenteredLineChart
         |_ CenteredDataLabelsChart
         |_ CenteredLineChartWithLabels (includes CenteredLineChart and CenteredDataLabelsChart)
timhall commented 10 years ago

@john-clarke I think this is ready to merge to kickoff the iteration process on a smaller level

Recommendation: Can we rename the repo to d3.chart.csnw.configurable? I think it fits better with the larger goal of creating a chart from configuration and line-bar is a little limiting.

Key points:

Updated Hierarchy:

Base (width, height, data)
|_ Container (rawData, chartBase, chartMargins, attachChart, attachComponent)
   |_ ConfigurableChart (attaches components and charts by options)
|_ Component (positioning)
   |_ Axis
   |_ Legend
|_ Chart (x, y, scales)
   |_ Labels (labels)
   |_ ChartWithLabels (chart with labels attached)
      |_ Bars
      |_ Line
      |_ LineValues

Example Usage:

var chart1 = d3.select('#chart_1')
  .append('svg')
  .chart('Configurable', {
    charts: [
      {
        type: 'Bars', 
        dataKey: 'peopleParticipating', 
        yScale: {domain: [0, 20000]}, 
        labelFontSize: 14,
        labelOffset: 10,
        labelPosition: 'top|bottom' // (top if positive or 0, bottom if negative)
      },
      {
        type: 'LineValues', 
        dataKey: 'deathsPrevented', 
        yScale: {domain: [0, 70]}, 
        labelPosition: 'top'
      }
    ],
    axes: [
      {
        type: 'AxisValues',
        dataKey: 'peopleParticipating',
        axisPosition: 'bottom'
      },
      {
        type: 'AxisValues',
        dataKey: 'peopleParticipating',
        axisPosition: 'left'
      },
      {
        type: 'AxisValues',
        dataKey: 'deathsPrevented',
        axisPosition: 'right'
      }
    ],
    legend: {
      type: 'InsetLegend',
      legendPosition: {x: 10, y: 0}
    }
  })
  .width(600)
  .height(400)
  .chartMargins({top: 10});
john-clarke commented 10 years ago

Looks great, Tim. I've made the name change as requested.