<commit_before>React = require 'react'
drawingTools = require '../../drawing-tools'

module.exports = React.createClass
  displayName: 'MarkingsRenderer'

  getDefaultProps: ->
    classification: null
    annotation: null
    workflow: null
    scale: null

  getInitialState: ->
    selection: null
    oldSetOfMarks: []

  componentWillReceiveProps: (nextProps) ->
    # console.log 'Old marks were', @state.oldSetOfMarks
    newSetOfMarks = []
    # Automatically select new marks.
    annotations = nextProps.classification?.annotations ? []
    annotation = annotations[annotations.length - 1]
    if annotation?
      taskDescription = @props.workflow?.tasks[annotation.task]
    if taskDescription?.type is 'drawing' and Array.isArray annotation.value
      for mark in annotation.value
        newSetOfMarks.push mark
        if nextProps.annotation is @props.annotation and mark not in @state.oldSetOfMarks
          # console.log 'New mark!', mark
          @setState selection: mark
    else
      @setState selection: null
    @setState oldSetOfMarks: newSetOfMarks
    # console.log 'Marks are now', newSetOfMarks

  render: ->
    skippedMarks = 0
    <g>
      {for annotation in @props.classification?.annotations ? []      
        annotation._key ?= Math.random()
        isPriorAnnotation = annotation isnt @props.annotation
        taskDescription = @props.workflow.tasks[annotation.task]
        if taskDescription.type is 'drawing'
          <g key={annotation._key} className="marks-for-annotation" data-disabled={isPriorAnnotation || null}>
            {for mark, i in annotation.value when @props.workflow?.configuration.multi_image_clone_markers or parseInt(mark.frame) is parseInt(@props.frame)
              mark._key ?= Math.random()

              if skippedMarks < @props.classification._hideMarksBefore and not @props.classification.completed
                skippedMarks += 1
                continue

              if mark._copy?
                continue

              toolDescription = taskDescription.tools[mark.tool]

              toolEnv =
                containerRect: @props.containerRect
                scale: @props.scale
                disabled: isPriorAnnotation
                selected: mark is @state.selection and not isPriorAnnotation
                getEventOffset: @props.getEventOffset
                preferences: @props.preferences

              toolProps =
                classification: @props.classification
                mark: mark
                details: toolDescription.details
                color: toolDescription.color
                size: toolDescription.size

              toolMethods =
                onChange: @handleChange.bind this, i
                onSelect: @handleSelect.bind this, annotation, mark
                onDeselect: @handleDeselect
                onDestroy: @handleDestroy.bind this, annotation, mark
                normalizeDifference: @props.normalizeDifference
                getScreenCurrentTransformationMatrix: @props.getScreenCurrentTransformationMatrix

              ToolComponent = drawingTools[toolDescription.type]
              <ToolComponent key={mark._key} {...toolProps} {...toolEnv} {...toolMethods} />}
          </g>}
    </g>

  handleChange: (markIndex, mark) ->
    @props.annotation.value[markIndex] = mark
    @props.onChange @props.annotation
<commit_msg>Hide mark details unless frame numbers match Fixes #3132<commit_after>React = require 'react'
drawingTools = require '../../drawing-tools'

module.exports = React.createClass
  displayName: 'MarkingsRenderer'

  getDefaultProps: ->
    classification: null
    annotation: null
    workflow: null
    scale: null

  getInitialState: ->
    selection: null
    oldSetOfMarks: []

  componentWillReceiveProps: (nextProps) ->
    # console.log 'Old marks were', @state.oldSetOfMarks
    newSetOfMarks = []
    # Automatically select new marks.
    annotations = nextProps.classification?.annotations ? []
    annotation = annotations[annotations.length - 1]
    if annotation?
      taskDescription = @props.workflow?.tasks[annotation.task]
    if taskDescription?.type is 'drawing' and Array.isArray annotation.value
      for mark in annotation.value
        newSetOfMarks.push mark
        if nextProps.annotation is @props.annotation and mark not in @state.oldSetOfMarks
          # console.log 'New mark!', mark
          @setState selection: mark
    else
      @setState selection: null
    @setState oldSetOfMarks: newSetOfMarks
    # console.log 'Marks are now', newSetOfMarks

  render: ->
    skippedMarks = 0
    <g>
      {for annotation in @props.classification?.annotations ? []      
        annotation._key ?= Math.random()
        isPriorAnnotation = annotation isnt @props.annotation
        taskDescription = @props.workflow.tasks[annotation.task]
        if taskDescription.type is 'drawing'
          <g key={annotation._key} className="marks-for-annotation" data-disabled={isPriorAnnotation || null}>
            {for mark, i in annotation.value when @props.workflow?.configuration.multi_image_clone_markers or parseInt(mark.frame) is parseInt(@props.frame)
              mark._key ?= Math.random()

              if skippedMarks < @props.classification._hideMarksBefore and not @props.classification.completed
                skippedMarks += 1
                continue

              if mark._copy?
                continue

              toolDescription = taskDescription.tools[mark.tool]
              
              if parseInt(mark.frame) is parseInt(@props.frame)
                {details} = toolDescription
              else
                details = null

              toolEnv =
                containerRect: @props.containerRect
                scale: @props.scale
                disabled: isPriorAnnotation
                selected: mark is @state.selection and not isPriorAnnotation
                getEventOffset: @props.getEventOffset
                preferences: @props.preferences

              toolProps =
                classification: @props.classification
                mark: mark
                details: details
                color: toolDescription.color
                size: toolDescription.size

              toolMethods =
                onChange: @handleChange.bind this, i
                onSelect: @handleSelect.bind this, annotation, mark
                onDeselect: @handleDeselect
                onDestroy: @handleDestroy.bind this, annotation, mark
                normalizeDifference: @props.normalizeDifference
                getScreenCurrentTransformationMatrix: @props.getScreenCurrentTransformationMatrix

              ToolComponent = drawingTools[toolDescription.type]
              <ToolComponent key={mark._key} {...toolProps} {...toolEnv} {...toolMethods} />}
          </g>}
    </g>

  handleChange: (markIndex, mark) ->
    @props.annotation.value[markIndex] = mark
    @props.onChange @props.annotation

{'fraction_non_alphanumeric': 0.08543940264215968, 'fraction_numerical': 0.0014359563469270534, 'mean_word_length': 2.260767790262172, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, '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': '1882955', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1718, 'n_words': 423}