JSFiddle - React, Tailwind, and code Playground

anchor resolving

by Jimmy Chandra

JavaScript

(function() {

  'use strict';
	
  let rects = [
  	{ x1: 10, y1: 10, x2: 50, y2: 20, data: 'INV#'},
    { x1: 85, y1: 10, x2: 145, y2: 15, data: '1234'}
  ];
  
  let anchor = {
    src: [
    	{ x1: 10, y1: 10, x2: 50, y2: 20 }
    ],
    grid: {
      bbox: { x1: 80, y1: 5, x2: 150, y2: 15 },
      columns: [ {x1: 80, y1: 150 } ],
      rules: [
      	{ type: 'extractcell', row: 0, col: 0, variable: 'tmp1' },
        { type: 'vartocanonical', variable: 'tmp1', canonical: 'invoice-no'  }
      ]
    }
  };
  
  let varToCanonicalRule = anchor.grid.rules.filter(f => f.type === 'vartocanonical');
  
  if (varToCanonicalRule.length) {
    varToCanonicalRule = varToCanonicalRule[0];
    let canonicalName = varToCanonicalRule.canonical;

  	console.log('Found canonical mapping', canonicalName);

		anchor.src.forEach((s) => {
    	rects.filter(r => s.x1 <= r.x1 && s.y1 <= r.y1 && r.x2 <= s.x2 && r.y2 <= s.y2)
      	.forEach((r) => {
        	console.log('label', r.data);
          //buffer it up
        });
    });

    var cellExtractorCell = anchor.grid.rules.filter(f => f.type === 'extractcell')
    	.map(function(f) { return { row: f.row, col: f.col }; });
    if (cellExtractorCell) {
    	console.log(cellExtractorCell[0]);
      
      
    }
  }

}());