<commit_before>import React from "react"
import {scaleBand, scaleLinear, scaleOrdinal} from "d3"
import {IGraphModel} from "./graph-model"
import {GraphLayout} from "./graph-layout"
import {GraphAttrRole, IAttributeDescriptionSnapshot}
  from "./data-configuration-model"
import {IDataSet} from "../../../data-model/data-set"
import {
  AxisPlace,
  EmptyAxisModel,
  CategoricalAxisModel,
  ICategoricalAxisModel,
  INumericAxisModel,
  NumericAxisModel, axisPlaceToAttrPlace, attrPlaceToAxisPlace
} from "./axis-model"
import {PlotType} from "../graphing-types"
import {matchCirclesToData, setNiceDomain} from "../utilities/graph-utils"
import {CodapV2Document} from "../../../v2/codap-v2-document"
import {ICodapV2GraphStorage, IGuidLink} from "../../../v2/codap-v2-types"

const plotChoices: Record<string, Record<string, PlotType>> = {
  empty: {empty: 'casePlot', numeric: 'dotPlot', categorical: 'dotChart'},
  numeric: {empty: 'dotPlot', numeric: 'scatterPlot', categorical: 'dotPlot'},
  categorical: {empty: 'dotChart', numeric: 'dotPlot', categorical: 'dotChart'}
}

export interface IGraphControllerProps {
  graphModel: IGraphModel
  layout: GraphLayout
  dataset: IDataSet | undefined
  enableAnimation: React.MutableRefObject<boolean>
  instanceId: string
  dotsRef: React.RefObject<SVGSVGElement>
  v2Document?: CodapV2Document
}

export class GraphController {
  graphModel: IGraphModel
  layout: GraphLayout
  dataset: IDataSet | undefined
  enableAnimation: React.MutableRefObject<boolean>
  instanceId: string
  dotsRef: React.RefObject<SVGSVGElement>
  v2Document?: CodapV2Document


  constructor(props: IGraphControllerProps) {
    this.graphModel = props.graphModel
    this.layout = props.layout
    this.dataset = props.dataset
    this.instanceId = props.instanceId
    this.enableAnimation = props.enableAnimation
    this.dotsRef = props.dotsRef
    this.v2Document = props.v2Document
    if (this.dataset) {
      this.graphModel.config.setDataset(this.dataset)
    }
    // Presumably a new dataset is now being used. So we have to set things up for an empty graph
    this.initializeGraph()
  }

  initializeGraph() {
    const {graphModel, layout, dotsRef, enableAnimation, instanceId, v2Document} = this,
      dataConfig = graphModel.config
    if (v2Document) {
      this.processV2Document()
    } else {
      graphModel.setGraphProperties({
        axes: {bottom: EmptyAxisModel.create({place: 'bottom'}),
          left: EmptyAxisModel.create({place: 'left'})}, plotType: 'casePlot'
      })
      layout.setAxisScale('bottom', scaleOrdinal())
      layout.setAxisScale('left', scaleOrdinal())
    }
    if (dotsRef.current) {
      matchCirclesToData({
        caseIDs: dataConfig.cases, dotsElement: dotsRef.current,
        pointRadius: graphModel.getPointRadius(), enableAnimation, instanceId
      })
    }
  }
<commit_msg>address console warning about observer conflicts   once dotsRef has an svg value in place,   we should not attempt to create a new EmptyAccess model,   but we should `matchCirclesToData` on the nodes already in place<commit_after>import React from "react"
import {scaleBand, scaleLinear, scaleOrdinal} from "d3"
import {IGraphModel} from "./graph-model"
import {GraphLayout} from "./graph-layout"
import {GraphAttrRole, IAttributeDescriptionSnapshot}
  from "./data-configuration-model"
import {IDataSet} from "../../../data-model/data-set"
import {
  AxisPlace,
  EmptyAxisModel,
  CategoricalAxisModel,
  ICategoricalAxisModel,
  INumericAxisModel,
  NumericAxisModel, axisPlaceToAttrPlace, attrPlaceToAxisPlace
} from "./axis-model"
import {PlotType} from "../graphing-types"
import {matchCirclesToData, setNiceDomain} from "../utilities/graph-utils"
import {CodapV2Document} from "../../../v2/codap-v2-document"
import {ICodapV2GraphStorage, IGuidLink} from "../../../v2/codap-v2-types"

const plotChoices: Record<string, Record<string, PlotType>> = {
  empty: {empty: 'casePlot', numeric: 'dotPlot', categorical: 'dotChart'},
  numeric: {empty: 'dotPlot', numeric: 'scatterPlot', categorical: 'dotPlot'},
  categorical: {empty: 'dotChart', numeric: 'dotPlot', categorical: 'dotChart'}
}

export interface IGraphControllerProps {
  graphModel: IGraphModel
  layout: GraphLayout
  dataset: IDataSet | undefined
  enableAnimation: React.MutableRefObject<boolean>
  instanceId: string
  dotsRef: React.RefObject<SVGSVGElement>
  v2Document?: CodapV2Document
}

export class GraphController {
  graphModel: IGraphModel
  layout: GraphLayout
  dataset: IDataSet | undefined
  enableAnimation: React.MutableRefObject<boolean>
  instanceId: string
  dotsRef: React.RefObject<SVGSVGElement>
  v2Document?: CodapV2Document


  constructor(props: IGraphControllerProps) {
    this.graphModel = props.graphModel
    this.layout = props.layout
    this.dataset = props.dataset
    this.instanceId = props.instanceId
    this.enableAnimation = props.enableAnimation
    this.dotsRef = props.dotsRef
    this.v2Document = props.v2Document
    if (this.dataset) {
      this.graphModel.config.setDataset(this.dataset)
    }
    // Presumably a new dataset is now being used. So we have to set things up for an empty graph
    this.initializeGraph()
  }

  initializeGraph() {
    const {graphModel, layout, dotsRef, enableAnimation, instanceId, v2Document} = this,
      dataConfig = graphModel.config

    if (v2Document) {
      this.processV2Document()
    }

    else {
      if (!dotsRef.current){
        graphModel.setGraphProperties({
          axes: {bottom: EmptyAxisModel.create({place: 'bottom'}),
          left: EmptyAxisModel.create({place: 'left'})}, plotType: 'casePlot'
        })
      }
      if (dotsRef.current) {
        matchCirclesToData({
          caseIDs: dataConfig.cases, dotsElement: dotsRef.current,
          pointRadius: graphModel.getPointRadius(), enableAnimation, instanceId
        })
      }
      layout.setAxisScale('bottom', scaleOrdinal())
      layout.setAxisScale('left', scaleOrdinal())
    }
  }

{'fraction_non_alphanumeric': 0.114, 'fraction_numerical': 0.005333333333333333, 'mean_word_length': 4.1290598290598295, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5390003', 'n_tokens_mistral': 1850, 'n_tokens_neox': 1789, 'n_words': 429}