datavis-tech / topologica

Minimal library for reactive dataflow programming. Based on topological sort.
MIT License
50 stars 1 forks source link

Accept String as Dependencies #23

Closed curran closed 6 years ago

curran commented 6 years ago

As far as developer comfort goes, this would be a huge improvement.

As far as additional complexity, the impact is minimal.

Example usage:

const initState = selection => {
  const g = selection.append('g');
  const xAxisG = g.append('g');
  const yAxisG = g.append('g');

  const xScale = ({ data, innerWidth, xValue }) =>
    scaleLinear()
      .domain([0, max(data, xValue)]
      .range([0, innerWidth]);
  xScale.dependencies = 'data, innerWidth, xValue';

  const yScale = ({ data, innerHeight, yValue }) =>
    scaleBand()
      .domain(data.map(yValue))
      .range([0, innerHeight]);
  yScale.dependencies = 'data, innerHeight, yValue';

  const marks = ({ data, xScale, yScale, xValue, yValue }) => {
    const circles = g.selectAll('circle').data(data);
    circles.enter().append('circle')
      .merge(circles)
        .attr('cx', d => xScale(xValue(d)))
        .attr('cy', d => yScale(yValue(d)));
  };
  marks.dependencies = 'data, xScale, yScale';

  // const marks = props => circleMarks(g, props);
  // marks.dependencies = 'data, xScale, yScale';

  // const marks = curry(circleMarks)(g);
  // marks.dependencies = 'data, xScale, yScale';

  return Topologica({ xScale, yScale, marks });
};

const stateLocal = local();

const state = selection =>
  stateLocal.get(selection.node()) ||
    stateLocal.set(selection.node(), initState(selection));

const scatterPlot = (selection, props) => {
  state(selection).set(props);
};