text: /* global d3, _, moment */
  
  var weight_for_age = {
      F: {
          'red': [
              {x: 0, y: 2},
              {x: 1, y: 2.7},
              {x: 2, y: 3.3},
              {x: 3, y: 3.9},
              {x: 4, y: 4.4},
              {x: 5, y: 4.8},
              {x: 6, y: 5.1},
              {x: 7, y: 5.3},
              {x: 8, y: 5.6},
              {x: 9, y: 5.8},
              {x: 10, y: 5.9},
              {x: 11, y: 6.1},
              {x: 12, y: 6.3},
              {x: 13, y: 6.4},
              {x: 14, y: 6.6},
              {x: 15, y: 6.7},
              {x: 16, y: 6.9},
              {x: 17, y: 7},
              {x: 18, y: 7.2},
              {x: 19, y: 7.3},
              {x: 20, y: 7.5},
              {x: 21, y: 7.6},
              {x: 22, y: 7.8},
              {x: 23, y: 7.9},
              {x: 24, y: 8.1},
              {x: 25, y: 8.2},
              {x: 26, y: 8.4},
              {x: 27, y: 8.5},
              {x: 28, y: 8.6},
              {x: 29, y: 8.8},
              {x: 30, y: 8.9},
              {x: 31, y: 9},
              {x: 32, y: 9.1},
              {x: 33, y: 9.3},
              {x: 34, y: 9.4},
              {x: 35, y: 9.5},
              {x: 36, y: 9.6},
              {x: 37, y: 9.7},
              {x: 38, y: 9.8},
              {x: 39, y: 9.9},
              {x: 40, y: 10.1},
              {x: 41, y: 10.2},
              {x: 42, y: 10.3},
              {x: 43, y: 10.4},
              {x: 44, y: 10.5},
              {x: 45, y: 10.6},
              {x: 46, y: 10.7},
              {x: 47, y: 10.8},
              {x: 48, y: 10.9},
              {x: 49, y: 11},
              {x: 50, y: 11.1},
              {x: 51, y: 11.2},
              {x: 52, y: 11.3},
              {x: 53, y: 11.4},
              {x: 54, y: 11.5},
              {x: 55, y: 11.6},
              {x: 56, y: 11.7},
              {x: 57, y: 11.8},
              {x: 58, y: 11.9},
              {x: 59, y: 12},
              {x: 60, y: 12.1},
          ],
          'orange': [
              {x: 0, y: 2.4},
              {x: 1, y: 3.1},
              {x: 2, y: 3.8},
              {x: 3, y: 4.4},
              {x: 4, y: 5},
              {x: 5, y: 5.4},
              {x: 6, y: 5.7},
              {x: 7, y: 6},
              {x: 8, y: 6.3},
              {x: 9, y: 6.5},
              {x: 10, y: 6.7},
              {x: 11, y: 6.9},
              {x: 12, y: 7},
              {x: 13, y: 7.2},
              {x: 14, y: 7.4},
              {x: 15, y: 7.6},
              {x: 16, y: 7.7},
              {x: 17, y: 7.9},
              {x: 18, y: 8.1},
              {x: 19, y: 8.2},
              {x: 20, y: 8.4},
              {x: 21, y: 8.6},
              {x: 22, y: 8.7},
              {x: 23, y: 8.9},
              {x: 24, y: 9},
              {x: 25, y: 9.2},
              {x: 26, y: 9.4},
              {x: 27, y: 9.5},
              {x: 28, y: 9.7},
              {x: 29, y: 9.8},
              {x: 30, y: 10},
              {x: 31, y: 10.1},
              {x: 32, y: 10.3},
              {x: 33, y: 10.4},
              {x: 34, y: 10.5},
              {x: 35, y: 10.7},
              {x: 36, y: 10.8},
              {x: 37, y: 10.9},
              {x: 38, y: 11.1},
              {x: 39, y: 11.2},
              {x: 40, y: 11.3},
              {x: 41, y: 11.5},
              {x: 42, y: 11.6},
              {x: 43, y: 11.7},
              {x: 44, y: 11.8},
              {x: 45, y: 12},
              {x: 46, y: 12.1},
              {x: 47, y: 12.2},
              {x: 48, y: 12.3},
              {x: 49, y: 12.4},
              {x: 50, y: 12.6},
              {x: 51, y: 12.7},
              {x: 52, y: 12.8},
              {x: 53, y: 12.9},
              {x: 54, y: 13},
              {x: 55, y: 13.2},
              {x: 56, y: 13.3},
              {x: 57, y: 13.4},
              {x: 58, y: 13.5},
              {x: 59, y: 13.6},
              {x: 60, y: 13.7},
          ],
          'green': [
              {x: 0, y: 4.2},
              {x: 1, y: 5.4},
              {x: 2, y: 6.5},
              {x: 3, y: 7.3},
              {x: 4, y: 8.2},
              {x: 5, y: 8.8},
              {x: 6, y: 9.3},
              {x: 7, y: 9.8},
              {x: 8, y: 10.2},
              {x: 9, y: 10.5},
              {x: 10, y: 10.9},
              {x: 11, y: 11.2},
              {x: 12, y: 11.5},
              {x: 13, y: 11.8},
              {x: 14, y: 12.1},
              {x: 15, y: 12.4},
              {x: 16, y: 12.6},
              {x: 17, y: 12.9},
              {x: 18, y: 13.2},
              {x: 19, y: 13.5},
              {x: 20, y: 13.7},
              {x: 21, y: 14},
              {x: 22, y: 14.3},
              {x: 23, y: 14.6},
              {x: 24, y: 14.8},
              {x: 25, y: 15.1},
              {x: 26, y: 15.4},
              {x: 27, y: 15.7},
              {x: 28, y: 16},
              {x: 29, y: 16.2},
              {x: 30, y: 16.5},
              {x: 31, y: 16.8},
              {x: 32, y: 17.1},
              {x: 33, y: 17.3},
              {x: 34, y: 17.6},
              {x: 35, y: 17.9},
              {x: 36, y: 18.1},
              {x: 37, y: 18.4},
              {x: 38, y: 18.7},
              {x: 39, y: 19},
              {x: 40, y: 19.2},
              {x: 41, y: 19.5},
              {x: 42, y: 19.8},
              {x: 43, y: 20.1},
              {x: 44, y: 20.4},
              {x: 45, y: 20.7},
              {x: 46, y: 20.9},
              {x: 47, y: 21.2},
              {x: 48, y: 21.5},
              {x: 49, y: 21.8},
              {x: 50, y: 22.1},
              {x: 51, y: 22.4},
              {x: 52, y: 22.6},
              {x: 53, y: 22.9},
              {x: 54, y: 23.2},
              {x: 55, y: 23.5},
              {x: 56, y: 23.8},
              {x: 57, y: 24.1},
              {x: 58, y: 24.4},
              {x: 59, y: 24.6},
              {x: 60, y: 24.9},
          ],
      },
      M: {
          'red': [
              {x: 0, y: 2.1},
              {x: 1, y: 2.9},
              {x: 2, y: 3.7},
              {x: 3, y: 4.3},
              {x: 4, y: 4.9},
              {x: 5, y: 5.3},
              {x: 6, y: 5.7},
              {x: 7, y: 5.9},
              {x: 8, y: 6.2},
              {x: 9, y: 6.4},
              {x: 10, y: 6.6},
              {x: 11, y: 6.8},
              {x: 12, y: 6.9},
              {x: 13, y: 7.1},
              {x: 14, y: 7.2},
              {x: 15, y: 7.4},
              {x: 16, y: 7.5},
              {x: 17, y: 7.7},
              {x: 18, y: 7.8},
              {x: 19, y: 8},
              {x: 20, y: 8.1},
              {x: 21, y: 8.2},
              {x: 22, y: 8.4},
              {x: 23, y: 8.5},
              {x: 24, y: 8.6},
              {x: 25, y: 8.8},
              {x: 26, y: 8.9},
              {x: 27, y: 9},
              {x: 28, y: 9.1},
              {x: 29, y: 9.2},
              {x: 30, y: 9.4},
              {x: 31, y: 9.5},
              {x: 32, y: 9.6},
              {x: 33, y: 9.7},
              {x: 34, y: 9.8},
              {x: 35, y: 9.9},
              {x: 36, y: 10},
              {x: 37, y: 10.1},
              {x: 38, y: 10.2},
              {x: 39, y: 10.3},
              {x: 40, y: 10.4},
              {x: 41, y: 10.5},
              {x: 42, y: 10.6},
              {x: 43, y: 10.7},
              {x: 44, y: 10.8},
              {x: 45, y: 10.9},
              {x: 46, y: 11},
              {x: 47, y: 11.1},
              {x: 48, y: 11.2},
              {x: 49, y: 11.3},
              {x: 50, y: 11.4},
              {x: 51, y: 11.5},
              {x: 52, y: 11.6},
              {x: 53, y: 11.7},
              {x: 54, y: 11.8},
              {x: 55, y: 11.9},
              {x: 56, y: 12},
              {x: 57, y: 12.1},
              {x: 58, y: 12.2},
              {x: 59, y: 12.3},
              {x: 60, y: 12.4},
          ],
          'orange': [
              {x: 0, y: 2.5},
              {x: 1, y: 3.3},
              {x: 2, y: 4.2},
              {x: 3, y: 4.9},
              {x: 4, y: 5.6},
              {x: 5, y: 6},
              {x: 6, y: 6.4},
              {x: 7, y: 6.7},
              {x: 8, y: 6.9},
              {x: 9, y: 7.1},
              {x: 10, y: 7.4},
              {x: 11, y: 7.6},
              {x: 12, y: 7.7},
              {x: 13, y: 7.9},
              {x: 14, y: 8.1},
              {x: 15, y: 8.3},
              {x: 16, y: 8.4},
              {x: 17, y: 8.6},
              {x: 18, y: 8.8},
              {x: 19, y: 8.9},
              {x: 20, y: 9.1},
              {x: 21, y: 9.2},
              {x: 22, y: 9.4},
              {x: 23, y: 9.5},
              {x: 24, y: 9.7},
              {x: 25, y: 9.8},
              {x: 26, y: 10},
              {x: 27, y: 10.1},
              {x: 28, y: 10.2},
              {x: 29, y: 10.4},
              {x: 30, y: 10.5},
              {x: 31, y: 10.7},
              {x: 32, y: 10.8},
              {x: 33, y: 10.9},
              {x: 34, y: 11},
              {x: 35, y: 11.2},
              {x: 36, y: 11.3},
              {x: 37, y: 11.4},
              {x: 38, y: 11.5},
              {x: 39, y: 11.6},
              {x: 40, y: 11.8},
              {x: 41, y: 11.9},
              {x: 42, y: 12},
              {x: 43, y: 12.1},
              {x: 44, y: 12.2},
              {x: 45, y: 12.4},
              {x: 46, y: 12.5},
              {x: 47, y: 12.6},
              {x: 48, y: 12.7},
              {x: 49, y: 12.8},
              {x: 50, y: 12.9},
              {x: 51, y: 13.1},
              {x: 52, y: 13.2},
              {x: 53, y: 13.3},
              {x: 54, y: 13.4},
              {x: 55, y: 13.5},
              {x: 56, y: 13.6},
              {x: 57, y: 13.7},
              {x: 58, y: 13.8},
              {x: 59, y: 14},
              {x: 60, y: 14.1},
          ],
          'green': [
              {x: 0, y: 4.4},
              {x: 1, y: 5.7},
              {x: 2, y: 6.9},
              {x: 3, y: 7.8},
              {x: 4, y: 8.7},
              {x: 5, y: 9.3},
              {x: 6, y: 9.8},
              {x: 7, y: 10.3},
              {x: 8, y: 10.7},
              {x: 9, y: 11},
              {x: 10, y: 11.4},
              {x: 11, y: 11.7},
              {x: 12, y: 12},
              {x: 13, y: 12.3},
              {x: 14, y: 12.6},
              {x: 15, y: 12.8},
              {x: 16, y: 13.1},
              {x: 17, y: 13.4},
              {x: 18, y: 13.7},
              {x: 19, y: 13.9},
              {x: 20, y: 14.2},
              {x: 21, y: 14.5},
              {x: 22, y: 14.7},
              {x: 23, y: 15},
              {x: 24, y: 15.3},
              {x: 25, y: 15.5},
              {x: 26, y: 15.8},
              {x: 27, y: 16.1},
              {x: 28, y: 16.3},
              {x: 29, y: 16.6},
              {x: 30, y: 16.9},
              {x: 31, y: 17.1},
              {x: 32, y: 17.4},
              {x: 33, y: 17.6},
              {x: 34, y: 17.8},
              {x: 35, y: 18.1},
              {x: 36, y: 18.3},
              {x: 37, y: 18.6},
              {x: 38, y: 18.8},
              {x: 39, y: 19},
              {x: 40, y: 19.3},
              {x: 41, y: 19.5},
              {x: 42, y: 19.7},
              {x: 43, y: 20},
              {x: 44, y: 20.2},
              {x: 45, y: 20.5},
              {x: 46, y: 20.7},
              {x: 47, y: 20.9},
              {x: 48, y: 21.2},
              {x: 49, y: 21.4},
              {x: 50, y: 21.7},
              {x: 51, y: 21.9},
              {x: 52, y: 22.2},
              {x: 53, y: 22.4},
              {x: 54, y: 22.7},
              {x: 55, y: 22.9},
              {x: 56, y: 23.2},
              {x: 57, y: 23.4},
              {x: 58, y: 23.7},
              {x: 59, y: 23.9},
              {x: 60, y: 24.2},
          ],
      },
  };
  
  var height_for_age = {
      M: {
          'red': [
              {x: 0, y: 44.200},
              {x: 1, y: 48.9},
              {x: 2, y: 52.4},
              {x: 3, y: 55.3},
              {x: 4, y: 57.6},
              {x: 5, y: 59.6},
              {x: 6, y: 61.2},
              {x: 7, y: 62.7},
              {x: 8, y: 64},
              {x: 9, y: 65.2},
              {x: 10, y: 66.4},
              {x: 11, y: 67.6},
              {x: 12, y: 68.6},
              {x: 13, y: 69.6},
              {x: 14, y: 70.6},
              {x: 15, y: 71.6},
              {x: 16, y: 72.5},
              {x: 17, y: 73.3},
              {x: 18, y: 74.2},
              {x: 19, y: 75},
              {x: 20, y: 75.8},
              {x: 21, y: 76.5},
              {x: 22, y: 77.2},
              {x: 23, y: 78},
              {x: 24, y: 78.7},
              {x: 25, y: 78.6},
              {x: 26, y: 79.3},
              {x: 27, y: 79.9},
              {x: 28, y: 80.5},
              {x: 29, y: 81.1},
              {x: 30, y: 81.7},
              {x: 31, y: 82.3},
              {x: 32, y: 82.8},
              {x: 33, y: 83.4},
              {x: 34, y: 83.9},
              {x: 35, y: 84.4},
              {x: 36, y: 85},
              {x: 37, y: 85.5},
              {x: 38, y: 86},
              {x: 39, y: 86.5},
              {x: 40, y: 87},
              {x: 41, y: 87.5},
              {x: 42, y: 88},
              {x: 43, y: 88.4},
              {x: 44, y: 88.9},
              {x: 45, y: 89.4},
              {x: 46, y: 89.8},
              {x: 47, y: 90.3},
              {x: 48, y: 90.7},
              {x: 49, y: 91.2},
              {x: 50, y: 91.6},
              {x: 51, y: 92.1},
              {x: 52, y: 92.5},
              {x: 53, y: 93},
              {x: 54, y: 93.4},
              {x: 55, y: 93.9},
              {x: 56, y: 94.3},
              {x: 57, y: 94.7},
              {x: 58, y: 95.2},
              {x: 59, y: 95.6},
              {x: 60, y: 96.1},
          ],
          'orange': [
              {x: 0, y: 46.1},
              {x: 1, y: 50.8},
              {x: 2, y: 54.4},
              {x: 3, y: 57.3},
              {x: 4, y: 59.7},
              {x: 5, y: 61.7},
              {x: 6, y: 63.3},
              {x: 7, y: 64.8},
              {x: 8, y: 66.2},
              {x: 9, y: 67.5},
              {x: 10, y: 68.7},
              {x: 11, y: 69.9},
              {x: 12, y: 71},
              {x: 13, y: 72.1},
              {x: 14, y: 73.1},
              {x: 15, y: 74.1},
              {x: 16, y: 75},
              {x: 17, y: 76},
              {x: 18, y: 76.9},
              {x: 19, y: 77.7},
              {x: 20, y: 78.6},
              {x: 21, y: 79.4},
              {x: 22, y: 80.2},
              {x: 23, y: 81},
              {x: 24, y: 81.7},
              {x: 25, y: 81.7},
              {x: 26, y: 82.5},
              {x: 27, y: 83.1},
              {x: 28, y: 83.8},
              {x: 29, y: 84.5},
              {x: 30, y: 85.1},
              {x: 31, y: 85.7},
              {x: 32, y: 86.4},
              {x: 33, y: 86.9},
              {x: 34, y: 87.5},
              {x: 35, y: 88.1},
              {x: 36, y: 88.7},
              {x: 37, y: 89.2},
              {x: 38, y: 89.8},
              {x: 39, y: 90.3},
              {x: 40, y: 90.9},
              {x: 41, y: 91.4},
              {x: 42, y: 91.9},
              {x: 43, y: 92.4},
              {x: 44, y: 93},
              {x: 45, y: 93.5},
              {x: 46, y: 94},
              {x: 47, y: 94.4},
              {x: 48, y: 94.9},
              {x: 49, y: 95.4},
              {x: 50, y: 95.9},
              {x: 51, y: 96.4},
              {x: 52, y: 96.9},
              {x: 53, y: 97.4},
              {x: 54, y: 97.8},
              {x: 55, y: 98.3},
              {x: 56, y: 98.8},
              {x: 57, y: 99.3},
              {x: 58, y: 99.7},
              {x: 59, y: 100.2},
              {x: 60, y: 100.7},
          ],
          'green': [
              {x: 0, y: 53.7},
              {x: 1, y: 58.6},
              {x: 2, y: 62.4},
              {x: 3, y: 65.5},
              {x: 4, y: 68},
              {x: 5, y: 70.1},
              {x: 6, y: 71.9},
              {x: 7, y: 73.5},
              {x: 8, y: 75},
              {x: 9, y: 76.5},
              {x: 10, y: 77.9},
              {x: 11, y: 79.2},
              {x: 12, y: 80.5},
              {x: 13, y: 81.8},
              {x: 14, y: 83},
              {x: 15, y: 84.2},
              {x: 16, y: 85.4},
              {x: 17, y: 86.5},
              {x: 18, y: 87.7},
              {x: 19, y: 88.8},
              {x: 20, y: 89.8},
              {x: 21, y: 90.9},
              {x: 22, y: 91.9},
              {x: 23, y: 92.9},
              {x: 24, y: 93.9},
              {x: 25, y: 94.2},
              {x: 26, y: 95.2},
              {x: 27, y: 96.1},
              {x: 28, y: 97},
              {x: 29, y: 97.9},
              {x: 30, y: 98.7},
              {x: 31, y: 99.6},
              {x: 32, y: 100.4},
              {x: 33, y: 101.2},
              {x: 34, y: 102},
              {x: 35, y: 102.7},
              {x: 36, y: 103.5},
              {x: 37, y: 104.2},
              {x: 38, y: 105},
              {x: 39, y: 105.7},
              {x: 40, y: 106.4},
              {x: 41, y: 107.1},
              {x: 42, y: 107.8},
              {x: 43, y: 108.5},
              {x: 44, y: 109.1},
              {x: 45, y: 109.8},
              {x: 46, y: 110.4},
              {x: 47, y: 111.1},
              {x: 48, y: 111.7},
              {x: 49, y: 112.4},
              {x: 50, y: 113},
              {x: 51, y: 113.6},
              {x: 52, y: 114.2},
              {x: 53, y: 114.9},
              {x: 54, y: 115.5},
              {x: 55, y: 116.1},
              {x: 56, y: 116.7},
              {x: 57, y: 117.4},
              {x: 58, y: 118},
              {x: 59, y: 118.6},
              {x: 60, y: 119.2},
          ],
      },
      F: {
          'red': [
              {x: 0, y: 43.6},
              {x: 1, y: 47.8},
              {x: 2, y: 51},
              {x: 3, y: 53.5},
              {x: 4, y: 55.6},
              {x: 5, y: 57.4},
              {x: 6, y: 58.9},
              {x: 7, y: 60.3},
              {x: 8, y: 61.7},
              {x: 9, y: 62.9},
              {x: 10, y: 64.1},
              {x: 11, y: 65.2},
              {x: 12, y: 66.3},
              {x: 13, y: 67.3},
              {x: 14, y: 68.3},
              {x: 15, y: 69.3},
              {x: 16, y: 70.2},
              {x: 17, y: 71.1},
              {x: 18, y: 72},
              {x: 19, y: 72.8},
              {x: 20, y: 73.7},
              {x: 21, y: 74.5},
              {x: 22, y: 75.2},
              {x: 23, y: 76},
              {x: 24, y: 76.7},
              {x: 25, y: 76.8},
              {x: 26, y: 77.5},
              {x: 27, y: 78.1},
              {x: 28, y: 78.8},
              {x: 29, y: 79.5},
              {x: 30, y: 80.1},
              {x: 31, y: 80.7},
              {x: 32, y: 81.3},
              {x: 33, y: 81.9},
              {x: 34, y: 82.5},
              {x: 35, y: 83.1},
              {x: 36, y: 83.6},
              {x: 37, y: 84.2},
              {x: 38, y: 84.7},
              {x: 39, y: 85.3},
              {x: 40, y: 85.8},
              {x: 41, y: 86.3},
              {x: 42, y: 86.8},
              {x: 43, y: 87.4},
              {x: 44, y: 87.9},
              {x: 45, y: 88.4},
              {x: 46, y: 88.9},
              {x: 47, y: 89.3},
              {x: 48, y: 89.8},
              {x: 49, y: 90.3},
              {x: 50, y: 90.7},
              {x: 51, y: 91.2},
              {x: 52, y: 91.7},
              {x: 53, y: 92.1},
              {x: 54, y: 92.6},
              {x: 55, y: 93},
              {x: 56, y: 93.4},
              {x: 57, y: 93.9},
              {x: 58, y: 94.3},
              {x: 59, y: 94.7},
              {x: 60, y: 95.2},
          ],
          'orange': [
              {x: 0, y: 45.4},
              {x: 1, y: 49.8},
              {x: 2, y: 53},
              {x: 3, y: 55.6},
              {x: 4, y: 57.8},
              {x: 5, y: 59.6},
              {x: 6, y: 61.2},
              {x: 7, y: 62.7},
              {x: 8, y: 64},
              {x: 9, y: 65.3},
              {x: 10, y: 66.5},
              {x: 11, y: 67.7},
              {x: 12, y: 68.9},
              {x: 13, y: 70},
              {x: 14, y: 71},
              {x: 15, y: 72},
              {x: 16, y: 73},
              {x: 17, y: 74},
              {x: 18, y: 74.9},
              {x: 19, y: 75.8},
              {x: 20, y: 76.7},
              {x: 21, y: 77.5},
              {x: 22, y: 78.4},
              {x: 23, y: 79.2},
              {x: 24, y: 80},
              {x: 25, y: 80},
              {x: 26, y: 80.8},
              {x: 27, y: 81.5},
              {x: 28, y: 82.2},
              {x: 29, y: 82.9},
              {x: 30, y: 83.6},
              {x: 31, y: 84.3},
              {x: 32, y: 84.9},
              {x: 33, y: 85.6},
              {x: 34, y: 86.2},
              {x: 35, y: 86.8},
              {x: 36, y: 87.4},
              {x: 37, y: 88},
              {x: 38, y: 88.6},
              {x: 39, y: 89.2},
              {x: 40, y: 89.8},
              {x: 41, y: 90.4},
              {x: 42, y: 90.9},
              {x: 43, y: 91.5},
              {x: 44, y: 92},
              {x: 45, y: 92.5},
              {x: 46, y: 93.1},
              {x: 47, y: 93.6},
              {x: 48, y: 94.1},
              {x: 49, y: 94.6},
              {x: 50, y: 95.1},
              {x: 51, y: 95.6},
              {x: 52, y: 96.1},
              {x: 53, y: 96.6},
              {x: 54, y: 97.1},
              {x: 55, y: 97.6},
              {x: 56, y: 98.1},
              {x: 57, y: 98.5},
              {x: 58, y: 99},
              {x: 59, y: 99.5},
              {x: 60, y: 99.9},
          ],
          'green': [
              {x: 0, y: 52.9},
              {x: 1, y: 57.6},
              {x: 2, y: 61.1},
              {x: 3, y: 64},
              {x: 4, y: 66.4},
              {x: 5, y: 68.5},
              {x: 6, y: 70.3},
              {x: 7, y: 71.9},
              {x: 8, y: 73.5},
              {x: 9, y: 75},
              {x: 10, y: 76.4},
              {x: 11, y: 77.8},
              {x: 12, y: 79.2},
              {x: 13, y: 80.5},
              {x: 14, y: 81.7},
              {x: 15, y: 83},
              {x: 16, y: 84.2},
              {x: 17, y: 85.4},
              {x: 18, y: 86.5},
              {x: 19, y: 87.6},
              {x: 20, y: 88.7},
              {x: 21, y: 89.8},
              {x: 22, y: 90.8},
              {x: 23, y: 91.9},
              {x: 24, y: 92.9},
              {x: 25, y: 93.1},
              {x: 26, y: 94.1},
              {x: 27, y: 95},
              {x: 28, y: 96},
              {x: 29, y: 96.9},
              {x: 30, y: 97.7},
              {x: 31, y: 98.6},
              {x: 32, y: 99.4},
              {x: 33, y: 100.3},
              {x: 34, y: 101.1},
              {x: 35, y: 101.9},
              {x: 36, y: 102.7},
              {x: 37, y: 103.4},
              {x: 38, y: 104.2},
              {x: 39, y: 105},
              {x: 40, y: 105.7},
              {x: 41, y: 106.4},
              {x: 42, y: 107.2},
              {x: 43, y: 107.9},
              {x: 44, y: 108.6},
              {x: 45, y: 109.3},
              {x: 46, y: 110},
              {x: 47, y: 110.7},
              {x: 48, y: 111.3},
              {x: 49, y: 112},
              {x: 50, y: 112.7},
              {x: 51, y: 113.3},
              {x: 52, y: 114},
              {x: 53, y: 114.6},
              {x: 54, y: 115.2},
              {x: 55, y: 115.9},
              {x: 56, y: 116.5},
              {x: 57, y: 117.1},
              {x: 58, y: 117.7},
              {x: 59, y: 118.3},
              {x: 60, y: 118.9},
          ],
      },
  };
  
  var weight_for_height = {
      M: {
          'red': [
              {x: 45, y: 1.9},
              {x: 45.5, y: 1.9},
              {x: 46, y: 2},
              {x: 46.5, y: 2.1},
              {x: 47, y: 2.1},
              {x: 47.5, y: 2.2},
              {x: 48, y: 2.3},
              {x: 48.5, y: 2.3},
              {x: 49, y: 2.4},
              {x: 49.5, y: 2.5},
              {x: 50, y: 2.6},
              {x: 50.5, y: 2.7},
              {x: 51, y: 2.7},
              {x: 51.5, y: 2.8},
              {x: 52, y: 2.9},
              {x: 52.5, y: 3},
              {x: 53, y: 3.1},
              {x: 53.5, y: 3.2},
              {x: 54, y: 3.3},
              {x: 54.5, y: 3.4},
              {x: 55, y: 3.6},
              {x: 55.5, y: 3.7},
              {x: 56, y: 3.8},
              {x: 56.5, y: 3.9},
              {x: 57, y: 4},
              {x: 57.5, y: 4.1},
              {x: 58, y: 4.3},
              {x: 58.5, y: 4.4},
              {x: 59, y: 4.5},
              {x: 59.5, y: 4.6},
              {x: 60, y: 4.7},
              {x: 60.5, y: 4.8},
              {x: 61, y: 4.9},
              {x: 61.5, y: 5},
              {x: 62, y: 5.1},
              {x: 62.5, y: 5.2},
              {x: 63, y: 5.3},
              {x: 63.5, y: 5.4},
              {x: 64, y: 5.5},
              {x: 64.5, y: 5.6},
              {x: 65, y: 5.7},
              {x: 65.5, y: 5.8},
              {x: 66, y: 5.9},
              {x: 66.5, y: 6},
              {x: 67, y: 6.1},
              {x: 67.5, y: 6.2},
              {x: 68, y: 6.3},
              {x: 68.5, y: 6.4},
              {x: 69, y: 6.5},
              {x: 69.5, y: 6.6},
              {x: 70, y: 6.6},
              {x: 70.5, y: 6.7},
              {x: 71, y: 6.8},
              {x: 71.5, y: 6.9},
              {x: 72, y: 7},
              {x: 72.5, y: 7.1},
              {x: 73, y: 7.2},
              {x: 73.5, y: 7.2},
              {x: 74, y: 7.3},
              {x: 74.5, y: 7.4},
              {x: 75, y: 7.5},
              {x: 75.5, y: 7.6},
              {x: 76, y: 7.6},
              {x: 76.5, y: 7.7},
              {x: 77, y: 7.8},
              {x: 77.5, y: 7.9},
              {x: 78, y: 7.9},
              {x: 78.5, y: 8},
              {x: 79, y: 8.1},
              {x: 79.5, y: 8.2},
              {x: 80, y: 8.2},
              {x: 80.5, y: 8.3},
              {x: 81, y: 8.4},
              {x: 81.5, y: 8.5},
              {x: 82, y: 8.5},
              {x: 82.5, y: 8.6},
              {x: 83, y: 8.7},
              {x: 83.5, y: 8.8},
              {x: 84, y: 8.9},
              {x: 84.5, y: 9},
              {x: 85, y: 9.1},
              {x: 85.5, y: 9.2},
              {x: 86, y: 9.3},
              {x: 86.5, y: 9.4},
              {x: 87, y: 9.5},
              {x: 87.5, y: 9.6},
              {x: 88, y: 9.7},
              {x: 88.5, y: 9.8},
              {x: 89, y: 9.9},
              {x: 89.5, y: 10},
              {x: 90, y: 10.1},
              {x: 90.5, y: 10.2},
              {x: 91, y: 10.3},
              {x: 91.5, y: 10.4},
              {x: 92, y: 10.5},
              {x: 92.5, y: 10.6},
              {x: 93, y: 10.7},
              {x: 93.5, y: 10.7},
              {x: 94, y: 10.8},
              {x: 94.5, y: 10.9},
              {x: 95, y: 11},
              {x: 95.5, y: 11.1},
              {x: 96, y: 11.2},
              {x: 96.5, y: 11.3},
              {x: 97, y: 11.4},
              {x: 97.5, y: 11.5},
              {x: 98, y: 11.6},
              {x: 98.5, y: 11.7},
              {x: 99, y: 11.8},
              {x: 99.5, y: 11.9},
              {x: 100, y: 12},
              {x: 100.5, y: 12.1},
              {x: 101, y: 12.2},
              {x: 101.5, y: 12.3},
              {x: 102, y: 12.4},
              {x: 102.5, y: 12.5},
              {x: 103, y: 12.6},
              {x: 103.5, y: 12.7},
              {x: 104, y: 12.8},
              {x: 104.5, y: 12.9},
              {x: 105, y: 13},
              {x: 105.5, y: 13.2},
              {x: 106, y: 13.3},
              {x: 106.5, y: 13.4},
              {x: 107, y: 13.5},
              {x: 107.5, y: 13.6},
              {x: 108, y: 13.7},
              {x: 108.5, y: 13.8},
              {x: 109, y: 14},
              {x: 109.5, y: 14.1},
              {x: 110, y: 14.2},
              {x: 110.5, y: 14.5},
              {x: 111, y: 14.6},
              {x: 111.5, y: 14.8},
              {x: 112, y: 14.9},
              {x: 112.5, y: 15},
              {x: 113, y: 15.2},
              {x: 113.5, y: 15.3},
              {x: 114, y: 15.4},
              {x: 114.5, y: 15.6},
              {x: 115, y: 15.7},
              {x: 115.5, y: 15.8},
              {x: 116, y: 16},
              {x: 116.5, y: 16.1},
              {x: 117, y: 16.2},
              {x: 117.5, y: 16.4},
              {x: 118, y: 16.5},
              {x: 118.5, y: 16.7},
              {x: 119, y: 16.8},
              {x: 119.5, y: 16.9},
              {x: 120, y: 17.1},
          ],
          'orange': [
              {x: 45, y: 2},
              {x: 45.5, y: 2.1},
              {x: 46, y: 2.2},
              {x: 46.5, y: 2.3},
              {x: 47, y: 2.3},
              {x: 47.5, y: 2.4},
              {x: 48, y: 2.5},
              {x: 48.5, y: 2.6},
              {x: 49, y: 2.6},
              {x: 49.5, y: 2.7},
              {x: 50, y: 2.8},
              {x: 50.5, y: 2.9},
              {x: 51, y: 3},
              {x: 51.5, y: 3.1},
              {x: 52, y: 3.2},
              {x: 52.5, y: 3.3},
              {x: 53, y: 3.4},
              {x: 53.5, y: 3.5},
              {x: 54, y: 3.6},
              {x: 54.5, y: 3.7},
              {x: 55, y: 3.8},
              {x: 55.5, y: 4},
              {x: 56, y: 4.1},
              {x: 56.5, y: 4.2},
              {x: 57, y: 4.3},
              {x: 57.5, y: 4.5},
              {x: 58, y: 4.6},
              {x: 58.5, y: 4.7},
              {x: 59, y: 4.8},
              {x: 59.5, y: 5},
              {x: 60, y: 5.1},
              {x: 60.5, y: 5.2},
              {x: 61, y: 5.3},
              {x: 61.5, y: 5.4},
              {x: 62, y: 5.6},
              {x: 62.5, y: 5.7},
              {x: 63, y: 5.8},
              {x: 63.5, y: 5.9},
              {x: 64, y: 6},
              {x: 64.5, y: 6.1},
              {x: 65, y: 6.2},
              {x: 65.5, y: 6.3},
              {x: 66, y: 6.4},
              {x: 66.5, y: 6.5},
              {x: 67, y: 6.6},
              {x: 67.5, y: 6.7},
              {x: 68, y: 6.8},
              {x: 68.5, y: 6.9},
              {x: 69, y: 7},
              {x: 69.5, y: 7.1},
              {x: 70, y: 7.2},
              {x: 70.5, y: 7.3},
              {x: 71, y: 7.4},
              {x: 71.5, y: 7.5},
              {x: 72, y: 7.6},
              {x: 72.5, y: 7.6},
              {x: 73, y: 7.7},
              {x: 73.5, y: 7.8},
              {x: 74, y: 7.9},
              {x: 74.5, y: 8},
              {x: 75, y: 8.1},
              {x: 75.5, y: 8.2},
              {x: 76, y: 8.3},
              {x: 76.5, y: 8.3},
              {x: 77, y: 8.4},
              {x: 77.5, y: 8.5},
              {x: 78, y: 8.6},
              {x: 78.5, y: 8.7},
              {x: 79, y: 8.7},
              {x: 79.5, y: 8.8},
              {x: 80, y: 8.9},
              {x: 80.5, y: 9},
              {x: 81, y: 9.1},
              {x: 81.5, y: 9.1},
              {x: 82, y: 9.2},
              {x: 82.5, y: 9.3},
              {x: 83, y: 9.4},
              {x: 83.5, y: 9.5},
              {x: 84, y: 9.6},
              {x: 84.5, y: 9.7},
              {x: 85, y: 9.8},
              {x: 85.5, y: 9.9},
              {x: 86, y: 10},
              {x: 86.5, y: 10.1},
              {x: 87, y: 10.2},
              {x: 87.5, y: 10.4},
              {x: 88, y: 10.5},
              {x: 88.5, y: 10.6},
              {x: 89, y: 10.7},
              {x: 89.5, y: 10.8},
              {x: 90, y: 10.9},
              {x: 90.5, y: 11},
              {x: 91, y: 11.1},
              {x: 91.5, y: 11.2},
              {x: 92, y: 11.3},
              {x: 92.5, y: 11.4},
              {x: 93, y: 11.5},
              {x: 93.5, y: 11.6},
              {x: 94, y: 11.7},
              {x: 94.5, y: 11.8},
              {x: 95, y: 11.9},
              {x: 95.5, y: 12},
              {x: 96, y: 12.1},
              {x: 96.5, y: 12.2},
              {x: 97, y: 12.3},
              {x: 97.5, y: 12.4},
              {x: 98, y: 12.5},
              {x: 98.5, y: 12.6},
              {x: 99, y: 12.7},
              {x: 99.5, y: 12.8},
              {x: 100, y: 12.9},
              {x: 100.5, y: 13},
              {x: 101, y: 13.2},
              {x: 101.5, y: 13.3},
              {x: 102, y: 13.4},
              {x: 102.5, y: 13.5},
              {x: 103, y: 13.6},
              {x: 103.5, y: 13.7},
              {x: 104, y: 13.9},
              {x: 104.5, y: 14},
              {x: 105, y: 14.1},
              {x: 105.5, y: 14.2},
              {x: 106, y: 14.4},
              {x: 106.5, y: 14.5},
              {x: 107, y: 14.6},
              {x: 107.5, y: 14.7},
              {x: 108, y: 14.9},
              {x: 108.5, y: 15},
              {x: 109, y: 15.1},
              {x: 109.5, y: 15.3},
              {x: 110, y: 15.4},
              {x: 110.5, y: 15.8},
              {x: 111, y: 15.9},
              {x: 111.5, y: 16},
              {x: 112, y: 16.2},
              {x: 112.5, y: 16.3},
              {x: 113, y: 16.5},
              {x: 113.5, y: 16.6},
              {x: 114, y: 16.8},
              {x: 114.5, y: 16.9},
              {x: 115, y: 17.1},
              {x: 115.5, y: 17.2},
              {x: 116, y: 17.4},
              {x: 116.5, y: 17.5},
              {x: 117, y: 17.7},
              {x: 117.5, y: 17.9},
              {x: 118, y: 18},
              {x: 118.5, y: 18.2},
              {x: 119, y: 18.3},
              {x: 119.5, y: 18.5},
              {x: 120, y: 18.6},
          ],
          'green': [
              {x: 45, y: 3},
              {x: 45.5, y: 3.1},
              {x: 46, y: 3.1},
              {x: 46.5, y: 3.2},
              {x: 47, y: 3.3},
              {x: 47.5, y: 3.4},
              {x: 48, y: 3.6},
              {x: 48.5, y: 3.7},
              {x: 49, y: 3.8},
              {x: 49.5, y: 3.9},
              {x: 50, y: 4},
              {x: 50.5, y: 4.1},
              {x: 51, y: 4.2},
              {x: 51.5, y: 4.4},
              {x: 52, y: 4.5},
              {x: 52.5, y: 4.6},
              {x: 53, y: 4.8},
              {x: 53.5, y: 4.9},
              {x: 54, y: 5.1},
              {x: 54.5, y: 5.3},
              {x: 55, y: 5.4},
              {x: 55.5, y: 5.6},
              {x: 56, y: 5.8},
              {x: 56.5, y: 5.9},
              {x: 57, y: 6.1},
              {x: 57.5, y: 6.3},
              {x: 58, y: 6.4},
              {x: 58.5, y: 6.6},
              {x: 59, y: 6.8},
              {x: 59.5, y: 7},
              {x: 60, y: 7.1},
              {x: 60.5, y: 7.3},
              {x: 61, y: 7.4},
              {x: 61.5, y: 7.6},
              {x: 62, y: 7.7},
              {x: 62.5, y: 7.9},
              {x: 63, y: 8},
              {x: 63.5, y: 8.2},
              {x: 64, y: 8.3},
              {x: 64.5, y: 8.5},
              {x: 65, y: 8.6},
              {x: 65.5, y: 8.7},
              {x: 66, y: 8.9},
              {x: 66.5, y: 9},
              {x: 67, y: 9.2},
              {x: 67.5, y: 9.3},
              {x: 68, y: 9.4},
              {x: 68.5, y: 9.6},
              {x: 69, y: 9.7},
              {x: 69.5, y: 9.8},
              {x: 70, y: 10},
              {x: 70.5, y: 10.1},
              {x: 71, y: 10.2},
              {x: 71.5, y: 10.4},
              {x: 72, y: 10.5},
              {x: 72.5, y: 10.6},
              {x: 73, y: 10.8},
              {x: 73.5, y: 10.9},
              {x: 74, y: 11},
              {x: 74.5, y: 11.2},
              {x: 75, y: 11.3},
              {x: 75.5, y: 11.4},
              {x: 76, y: 11.5},
              {x: 76.5, y: 11.6},
              {x: 77, y: 11.7},
              {x: 77.5, y: 11.9},
              {x: 78, y: 12},
              {x: 78.5, y: 12.1},
              {x: 79, y: 12.2},
              {x: 79.5, y: 12.3},
              {x: 80, y: 12.4},
              {x: 80.5, y: 12.5},
              {x: 81, y: 12.6},
              {x: 81.5, y: 12.7},
              {x: 82, y: 12.8},
              {x: 82.5, y: 13},
              {x: 83, y: 13.1},
              {x: 83.5, y: 13.2},
              {x: 84, y: 13.3},
              {x: 84.5, y: 13.5},
              {x: 85, y: 13.6},
              {x: 85.5, y: 13.7},
              {x: 86, y: 13.9},
              {x: 86.5, y: 14},
              {x: 87, y: 14.2},
              {x: 87.5, y: 14.3},
              {x: 88, y: 14.5},
              {x: 88.5, y: 14.6},
              {x: 89, y: 14.7},
              {x: 89.5, y: 14.9},
              {x: 90, y: 15},
              {x: 90.5, y: 15.1},
              {x: 91, y: 15.3},
              {x: 91.5, y: 15.4},
              {x: 92, y: 15.6},
              {x: 92.5, y: 15.7},
              {x: 93, y: 15.8},
              {x: 93.5, y: 16},
              {x: 94, y: 16.1},
              {x: 94.5, y: 16.3},
              {x: 95, y: 16.4},
              {x: 95.5, y: 16.5},
              {x: 96, y: 16.7},
              {x: 96.5, y: 16.8},
              {x: 97, y: 17},
              {x: 97.5, y: 17.1},
              {x: 98, y: 17.3},
              {x: 98.5, y: 17.5},
              {x: 99, y: 17.6},
              {x: 99.5, y: 17.8},
              {x: 100, y: 18},
              {x: 100.5, y: 18.1},
              {x: 101, y: 18.3},
              {x: 101.5, y: 18.5},
              {x: 102, y: 18.7},
              {x: 102.5, y: 18.8},
              {x: 103, y: 19},
              {x: 103.5, y: 19.2},
              {x: 104, y: 19.4},
              {x: 104.5, y: 19.6},
              {x: 105, y: 19.8},
              {x: 105.5, y: 20},
              {x: 106, y: 20.2},
              {x: 106.5, y: 20.4},
              {x: 107, y: 20.6},
              {x: 107.5, y: 20.8},
              {x: 108, y: 21},
              {x: 108.5, y: 21.2},
              {x: 109, y: 21.4},
              {x: 109.5, y: 21.7},
              {x: 110, y: 21.9},
              {x: 110.5, y: 22.4},
              {x: 111, y: 22.7},
              {x: 111.5, y: 22.9},
              {x: 112, y: 23.1},
              {x: 112.5, y: 23.4},
              {x: 113, y: 23.6},
              {x: 113.5, y: 23.9},
              {x: 114, y: 24.1},
              {x: 114.5, y: 24.4},
              {x: 115, y: 24.6},
              {x: 115.5, y: 24.9},
              {x: 116, y: 25.1},
              {x: 116.5, y: 25.4},
              {x: 117, y: 25.6},
              {x: 117.5, y: 25.9},
              {x: 118, y: 26.1},
              {x: 118.5, y: 26.4},
              {x: 119, y: 26.6},
              {x: 119.5, y: 26.9},
              {x: 120, y: 27.2},
          ],
      },
      F: {
          'red': [
              {x: 45, y: 1.9},
              {x: 45.5, y: 2},
              {x: 46, y: 2},
              {x: 46.5, y: 2.1},
              {x: 47, y: 2.2},
              {x: 47.5, y: 2.2},
              {x: 48, y: 2.3},
              {x: 48.5, y: 2.4},
              {x: 49, y: 2.4},
              {x: 49.5, y: 2.5},
              {x: 50, y: 2.6},
              {x: 50.5, y: 2.7},
              {x: 51, y: 2.8},
              {x: 51.5, y: 2.8},
              {x: 52, y: 2.9},
              {x: 52.5, y: 3},
              {x: 53, y: 3.1},
              {x: 53.5, y: 3.2},
              {x: 54, y: 3.3},
              {x: 54.5, y: 3.4},
              {x: 55, y: 3.5},
              {x: 55.5, y: 3.6},
              {x: 56, y: 3.7},
              {x: 56.5, y: 3.8},
              {x: 57, y: 3.9},
              {x: 57.5, y: 4},
              {x: 58, y: 4.1},
              {x: 58.5, y: 4.2},
              {x: 59, y: 4.3},
              {x: 59.5, y: 4.4},
              {x: 60, y: 4.5},
              {x: 60.5, y: 4.6},
              {x: 61, y: 4.7},
              {x: 61.5, y: 4.8},
              {x: 62, y: 4.9},
              {x: 62.5, y: 5},
              {x: 63, y: 5.1},
              {x: 63.5, y: 5.2},
              {x: 64, y: 5.3},
              {x: 64.5, y: 5.4},
              {x: 65, y: 5.5},
              {x: 65.5, y: 5.5},
              {x: 66, y: 5.6},
              {x: 66.5, y: 5.7},
              {x: 67, y: 5.8},
              {x: 67.5, y: 5.9},
              {x: 68, y: 6},
              {x: 68.5, y: 6.1},
              {x: 69, y: 6.1},
              {x: 69.5, y: 6.2},
              {x: 70, y: 6.3},
              {x: 70.5, y: 6.4},
              {x: 71, y: 6.5},
              {x: 71.5, y: 6.5},
              {x: 72, y: 6.6},
              {x: 72.5, y: 6.7},
              {x: 73, y: 6.8},
              {x: 73.5, y: 6.9},
              {x: 74, y: 6.9},
              {x: 74.5, y: 7},
              {x: 75, y: 7.1},
              {x: 75.5, y: 7.1},
              {x: 76, y: 7.2},
              {x: 76.5, y: 7.3},
              {x: 77, y: 7.4},
              {x: 77.5, y: 7.4},
              {x: 78, y: 7.5},
              {x: 78.5, y: 7.6},
              {x: 79, y: 7.7},
              {x: 79.5, y: 7.7},
              {x: 80, y: 7.8},
              {x: 80.5, y: 7.9},
              {x: 81, y: 8},
              {x: 81.5, y: 8.1},
              {x: 82, y: 8.1},
              {x: 82.5, y: 8.2},
              {x: 83, y: 8.3},
              {x: 83.5, y: 8.4},
              {x: 84, y: 8.5},
              {x: 84.5, y: 8.6},
              {x: 85, y: 8.7},
              {x: 85.5, y: 8.8},
              {x: 86, y: 8.9},
              {x: 86.5, y: 9},
              {x: 87, y: 9.1},
              {x: 87.5, y: 9.2},
              {x: 88, y: 9.3},
              {x: 88.5, y: 9.4},
              {x: 89, y: 9.5},
              {x: 89.5, y: 9.6},
              {x: 90, y: 9.7},
              {x: 90.5, y: 9.8},
              {x: 91, y: 9.9},
              {x: 91.5, y: 10},
              {x: 92, y: 10.1},
              {x: 92.5, y: 10.1},
              {x: 93, y: 10.2},
              {x: 93.5, y: 10.3},
              {x: 94, y: 10.4},
              {x: 94.5, y: 10.5},
              {x: 95, y: 10.6},
              {x: 95.5, y: 10.7},
              {x: 96, y: 10.8},
              {x: 96.5, y: 10.9},
              {x: 97, y: 11},
              {x: 97.5, y: 11.1},
              {x: 98, y: 11.2},
              {x: 98.5, y: 11.3},
              {x: 99, y: 11.4},
              {x: 99.5, y: 11.5},
              {x: 100, y: 11.6},
              {x: 100.5, y: 11.7},
              {x: 101, y: 11.8},
              {x: 101.5, y: 11.9},
              {x: 102, y: 12},
              {x: 102.5, y: 12.1},
              {x: 103, y: 12.3},
              {x: 103.5, y: 12.4},
              {x: 104, y: 12.5},
              {x: 104.5, y: 12.6},
              {x: 105, y: 12.7},
              {x: 105.5, y: 12.8},
              {x: 106, y: 13},
              {x: 106.5, y: 13.1},
              {x: 107, y: 13.2},
              {x: 107.5, y: 13.3},
              {x: 108, y: 13.5},
              {x: 108.5, y: 13.6},
              {x: 109, y: 13.7},
              {x: 109.5, y: 13.9},
              {x: 110, y: 14},
              {x: 110.5, y: 14.4},
              {x: 111, y: 14.5},
              {x: 111.5, y: 14.7},
              {x: 112, y: 14.8},
              {x: 112.5, y: 15},
              {x: 113, y: 15.1},
              {x: 113.5, y: 15.3},
              {x: 114, y: 15.4},
              {x: 114.5, y: 15.6},
              {x: 115, y: 15.7},
              {x: 115.5, y: 15.9},
              {x: 116, y: 16},
              {x: 116.5, y: 16.2},
              {x: 117, y: 16.3},
              {x: 117.5, y: 16.5},
              {x: 118, y: 16.6},
              {x: 118.5, y: 16.8},
              {x: 119, y: 16.9},
              {x: 119.5, y: 17.1},
              {x: 120, y: 17.3},
          ],
          'orange': [
              {x: 45, y: 2.1},
              {x: 45.5, y: 2.1},
              {x: 46, y: 2.2},
              {x: 46.5, y: 2.3},
              {x: 47, y: 2.4},
              {x: 47.5, y: 2.4},
              {x: 48, y: 2.5},
              {x: 48.5, y: 2.6},
              {x: 49, y: 2.6},
              {x: 49.5, y: 2.7},
              {x: 50, y: 2.8},
              {x: 50.5, y: 2.9},
              {x: 51, y: 3},
              {x: 51.5, y: 3.1},
              {x: 52, y: 3.2},
              {x: 52.5, y: 3.3},
              {x: 53, y: 3.4},
              {x: 53.5, y: 3.5},
              {x: 54, y: 3.6},
              {x: 54.5, y: 3.7},
              {x: 55, y: 3.8},
              {x: 55.5, y: 3.9},
              {x: 56, y: 4},
              {x: 56.5, y: 4.1},
              {x: 57, y: 4.3},
              {x: 57.5, y: 4.4},
              {x: 58, y: 4.5},
              {x: 58.5, y: 4.6},
              {x: 59, y: 4.7},
              {x: 59.5, y: 4.8},
              {x: 60, y: 4.9},
              {x: 60.5, y: 5},
              {x: 61, y: 5.1},
              {x: 61.5, y: 5.2},
              {x: 62, y: 5.3},
              {x: 62.5, y: 5.4},
              {x: 63, y: 5.5},
              {x: 63.5, y: 5.6},
              {x: 64, y: 5.7},
              {x: 64.5, y: 5.8},
              {x: 65, y: 5.9},
              {x: 65.5, y: 6},
              {x: 66, y: 6.1},
              {x: 66.5, y: 6.2},
              {x: 67, y: 6.3},
              {x: 67.5, y: 6.4},
              {x: 68, y: 6.5},
              {x: 68.5, y: 6.6},
              {x: 69, y: 6.7},
              {x: 69.5, y: 6.8},
              {x: 70, y: 6.9},
              {x: 70.5, y: 6.9},
              {x: 71, y: 7},
              {x: 71.5, y: 7.1},
              {x: 72, y: 7.2},
              {x: 72.5, y: 7.3},
              {x: 73, y: 7.4},
              {x: 73.5, y: 7.4},
              {x: 74, y: 7.5},
              {x: 74.5, y: 7.6},
              {x: 75, y: 7.7},
              {x: 75.5, y: 7.8},
              {x: 76, y: 7.8},
              {x: 76.5, y: 7.9},
              {x: 77, y: 8},
              {x: 77.5, y: 8.1},
              {x: 78, y: 8.2},
              {x: 78.5, y: 8.2},
              {x: 79, y: 8.3},
              {x: 79.5, y: 8.4},
              {x: 80, y: 8.5},
              {x: 80.5, y: 8.6},
              {x: 81, y: 8.7},
              {x: 81.5, y: 8.8},
              {x: 82, y: 8.8},
              {x: 82.5, y: 8.9},
              {x: 83, y: 9},
              {x: 83.5, y: 9.1},
              {x: 84, y: 9.2},
              {x: 84.5, y: 9.3},
              {x: 85, y: 9.4},
              {x: 85.5, y: 9.5},
              {x: 86, y: 9.7},
              {x: 86.5, y: 9.8},
              {x: 87, y: 9.9},
              {x: 87.5, y: 10},
              {x: 88, y: 10.1},
              {x: 88.5, y: 10.2},
              {x: 89, y: 10.3},
              {x: 89.5, y: 10.4},
              {x: 90, y: 10.5},
              {x: 90.5, y: 10.6},
              {x: 91, y: 10.7},
              {x: 91.5, y: 10.8},
              {x: 92, y: 10.9},
              {x: 92.5, y: 11},
              {x: 93, y: 11.1},
              {x: 93.5, y: 11.2},
              {x: 94, y: 11.3},
              {x: 94.5, y: 11.4},
              {x: 95, y: 11.5},
              {x: 95.5, y: 11.6},
              {x: 96, y: 11.7},
              {x: 96.5, y: 11.8},
              {x: 97, y: 12},
              {x: 97.5, y: 12.1},
              {x: 98, y: 12.2},
              {x: 98.5, y: 12.3},
              {x: 99, y: 12.4},
              {x: 99.5, y: 12.5},
              {x: 100, y: 12.6},
              {x: 100.5, y: 12.7},
              {x: 101, y: 12.8},
              {x: 101.5, y: 13},
              {x: 102, y: 13.1},
              {x: 102.5, y: 13.2},
              {x: 103, y: 13.3},
              {x: 103.5, y: 13.5},
              {x: 104, y: 13.6},
              {x: 104.5, y: 13.7},
              {x: 105, y: 13.8},
              {x: 105.5, y: 14},
              {x: 106, y: 14.1},
              {x: 106.5, y: 14.3},
              {x: 107, y: 14.4},
              {x: 107.5, y: 14.5},
              {x: 108, y: 14.7},
              {x: 108.5, y: 14.8},
              {x: 109, y: 15},
              {x: 109.5, y: 15.1},
              {x: 110, y: 15.3},
              {x: 110.5, y: 15.7},
              {x: 111, y: 15.8},
              {x: 111.5, y: 16},
              {x: 112, y: 16.2},
              {x: 112.5, y: 16.3},
              {x: 113, y: 16.5},
              {x: 113.5, y: 16.7},
              {x: 114, y: 16.8},
              {x: 114.5, y: 17},
              {x: 115, y: 17.2},
              {x: 115.5, y: 17.3},
              {x: 116, y: 17.5},
              {x: 116.5, y: 17.7},
              {x: 117, y: 17.8},
              {x: 117.5, y: 18},
              {x: 118, y: 18.2},
              {x: 118.5, y: 18.4},
              {x: 119, y: 18.5},
              {x: 119.5, y: 18.7},
              {x: 120, y: 18.9},
          ],
          'green': [
              {x: 45, y: 3},
              {x: 45.5, y: 3.1},
              {x: 46, y: 3.2},
              {x: 46.5, y: 3.3},
              {x: 47, y: 3.4},
              {x: 47.5, y: 3.5},
              {x: 48, y: 3.6},
              {x: 48.5, y: 3.7},
              {x: 49, y: 3.8},
              {x: 49.5, y: 3.9},
              {x: 50, y: 4},
              {x: 50.5, y: 4.2},
              {x: 51, y: 4.3},
              {x: 51.5, y: 4.4},
              {x: 52, y: 4.6},
              {x: 52.5, y: 4.7},
              {x: 53, y: 4.9},
              {x: 53.5, y: 5},
              {x: 54, y: 5.2},
              {x: 54.5, y: 5.3},
              {x: 55, y: 5.5},
              {x: 55.5, y: 5.7},
              {x: 56, y: 5.8},
              {x: 56.5, y: 6},
              {x: 57, y: 6.1},
              {x: 57.5, y: 6.3},
              {x: 58, y: 6.5},
              {x: 58.5, y: 6.6},
              {x: 59, y: 6.8},
              {x: 59.5, y: 6.9},
              {x: 60, y: 7.1},
              {x: 60.5, y: 7.3},
              {x: 61, y: 7.4},
              {x: 61.5, y: 7.6},
              {x: 62, y: 7.7},
              {x: 62.5, y: 7.8},
              {x: 63, y: 8},
              {x: 63.5, y: 8.1},
              {x: 64, y: 8.3},
              {x: 64.5, y: 8.4},
              {x: 65, y: 8.6},
              {x: 65.5, y: 8.7},
              {x: 66, y: 8.8},
              {x: 66.5, y: 9},
              {x: 67, y: 9.1},
              {x: 67.5, y: 9.2},
              {x: 68, y: 9.4},
              {x: 68.5, y: 9.5},
              {x: 69, y: 9.6},
              {x: 69.5, y: 9.7},
              {x: 70, y: 9.9},
              {x: 70.5, y: 10},
              {x: 71, y: 10.1},
              {x: 71.5, y: 10.2},
              {x: 72, y: 10.3},
              {x: 72.5, y: 10.5},
              {x: 73, y: 10.6},
              {x: 73.5, y: 10.7},
              {x: 74, y: 10.8},
              {x: 74.5, y: 10.9},
              {x: 75, y: 11},
              {x: 75.5, y: 11.1},
              {x: 76, y: 11.2},
              {x: 76.5, y: 11.4},
              {x: 77, y: 11.5},
              {x: 77.5, y: 11.6},
              {x: 78, y: 11.7},
              {x: 78.5, y: 11.8},
              {x: 79, y: 11.9},
              {x: 79.5, y: 12},
              {x: 80, y: 12.1},
              {x: 80.5, y: 12.3},
              {x: 81, y: 12.4},
              {x: 81.5, y: 12.5},
              {x: 82, y: 12.6},
              {x: 82.5, y: 12.8},
              {x: 83, y: 12.9},
              {x: 83.5, y: 13.1},
              {x: 84, y: 13.2},
              {x: 84.5, y: 13.3},
              {x: 85, y: 13.5},
              {x: 85.5, y: 13.6},
              {x: 86, y: 13.8},
              {x: 86.5, y: 13.9},
              {x: 87, y: 14.1},
              {x: 87.5, y: 14.2},
              {x: 88, y: 14.4},
              {x: 88.5, y: 14.5},
              {x: 89, y: 14.7},
              {x: 89.5, y: 14.8},
              {x: 90, y: 15},
              {x: 90.5, y: 15.1},
              {x: 91, y: 15.3},
              {x: 91.5, y: 15.5},
              {x: 92, y: 15.6},
              {x: 92.5, y: 15.8},
              {x: 93, y: 15.9},
              {x: 93.5, y: 16.1},
              {x: 94, y: 16.2},
              {x: 94.5, y: 16.4},
              {x: 95, y: 16.5},
              {x: 95.5, y: 16.7},
              {x: 96, y: 16.8},
              {x: 96.5, y: 17},
              {x: 97, y: 17.1},
              {x: 97.5, y: 17.3},
              {x: 98, y: 17.5},
              {x: 98.5, y: 17.6},
              {x: 99, y: 17.8},
              {x: 99.5, y: 18},
              {x: 100, y: 18.1},
              {x: 100.5, y: 18.3},
              {x: 101, y: 18.5},
              {x: 101.5, y: 18.7},
              {x: 102, y: 18.9},
              {x: 102.5, y: 19},
              {x: 103, y: 19.2},
              {x: 103.5, y: 19.4},
              {x: 104, y: 19.6},
              {x: 104.5, y: 19.8},
              {x: 105, y: 20},
              {x: 105.5, y: 20.2},
              {x: 106, y: 20.5},
              {x: 106.5, y: 20.7},
              {x: 107, y: 20.9},
              {x: 107.5, y: 21.1},
              {x: 108, y: 21.3},
              {x: 108.5, y: 21.6},
              {x: 109, y: 21.8},
              {x: 109.5, y: 22},
              {x: 110, y: 22.3},
              {x: 110.5, y: 22.9},
              {x: 111, y: 23.1},
              {x: 111.5, y: 23.4},
              {x: 112, y: 23.6},
              {x: 112.5, y: 23.9},
              {x: 113, y: 24.2},
              {x: 113.5, y: 24.4},
              {x: 114, y: 24.7},
              {x: 114.5, y: 25},
              {x: 115, y: 25.2},
              {x: 115.5, y: 25.5},
              {x: 116, y: 25.8},
              {x: 116.5, y: 26.1},
              {x: 117, y: 26.3},
              {x: 117.5, y: 26.6},
              {x: 118, y: 26.9},
              {x: 118.5, y: 27.2},
              {x: 119, y: 27.4},
              {x: 119.5, y: 27.7},
              {x: 120, y: 28},
          ],
      },
  };
  
  var url = hqImport('hqwebapp/js/initial_page_data').reverse;
  
  function AwcReportsController($scope, $http, $location, $routeParams, $log, DTOptionsBuilder, DTColumnBuilder, $compile, storageService, userLocationId, haveAccessToAllLocations, haveAccessToFeatures, isAlertActive) {
      var vm = this;
      vm.data = {};
      vm.label = "AWC Report";
      vm.tooltipPlacement = "right";
      vm.step = $routeParams.step;
      vm.filters = ['gender', 'age'];
      vm.userLocationId = userLocationId;
      vm.dataNotEntered = "Data Not Entered";
      vm.isAlertActive = isAlertActive;
  
      vm.dtOptions = DTOptionsBuilder.newOptions()
          .withOption('ajax', {
              url: url('awc_reports', vm.step),
              data: $location.search(),
              type: 'GET',
          })
          .withDataProp('data')
          .withOption('processing', true)
          .withOption('serverSide', true)
          .withOption('createdRow', compile)
          .withPaginationType('full_numbers')
          .withFixedHeader({
              bottom: true,
          })
          .withOption('oLanguage', {
              "sProcessing": "Loading. Please wait...",
          })
          .withOption('order', [[4, 'asc']])
          .withDOM('ltipr');
  
      if (vm.step === 'beneficiary') {
          vm.dtColumns = [
              DTColumnBuilder.newColumn('person_name').withTitle('Name').renderWith(renderPersonName).withClass('big-col'),
              DTColumnBuilder.newColumn('dob').withTitle('Date of Birth').renderWith(renderDateOfBirth).withClass('medium-col'),
              DTColumnBuilder.newColumn('age').withTitle('Current Age').renderWith(renderAge).withClass('medium-col'),
              DTColumnBuilder.newColumn('fully_immunized').withTitle('1 Year Immunizations Complete').renderWith(renderFullyImmunizedDate).withClass('medium-col'),
              DTColumnBuilder.newColumn('current_month_nutrition_status').withTitle('Weight-for-Age Status (in Month)').renderWith(renderWeightForAgeStatus).withClass('medium-col'),
              DTColumnBuilder.newColumn('current_month_wasting').withTitle('Weight-for-Height Status (in Month)').renderWith(renderWeightForHeightStatus).withClass('medium-col'),
              DTColumnBuilder.newColumn('current_month_stunting').withTitle('Height-for-Age Status (in Month)').renderWith(renderHeightForAgeStatus).withClass('medium-col'),
              DTColumnBuilder.newColumn('pse_days_attended').withTitle('PSE Attendance (Days)').renderWith(renderPseDaysAttended).withClass('medium-col'),
              DTColumnBuilder.newColumn('aww_phone_number').withTitle('AWW Phone Number').renderWith(renderAwwPhoneNumber).withClass('medium-col'),
              DTColumnBuilder.newColumn('mother_phone_number').withTitle('Mother Phone Number').renderWith(renderMotherPhoneNumber).withClass('medium-col'),
          ];
      } else if (vm.step === 'pregnant') {
          vm.dtColumns = [
              DTColumnBuilder.newColumn('person_name').withTitle('Name').renderWith(renderPersonNamePregnant).withClass('big-col'),
              DTColumnBuilder.newColumn('age').withTitle('Age').renderWith(renderAge).withClass('medium-col'),
              DTColumnBuilder.newColumn('closed').withTitle('Status').renderWith(renderClosed).withClass('medium-col'),
              DTColumnBuilder.newColumn('opened_on').withTitle('Pregnancy registration').renderWith(renderOpenedOn).withClass('medium-col'),
              DTColumnBuilder.newColumn('edd').withTitle('EDD').renderWith(renderEdd).withClass('medium-col'),
              DTColumnBuilder.newColumn('trimester').withTitle('Trimester').renderWith(renderTrimester).withClass('medium-col'),
              DTColumnBuilder.newColumn('anemic').withTitle('Anemia during last ANC (Y/N)').renderWith(renderAnemic).withClass('medium-col'),
              DTColumnBuilder.newColumn('num_anc_complete').withTitle('Number of ANC visits').renderWith(renderNumAncComplete).withClass('medium-col'),
              DTColumnBuilder.newColumn('beneficiary').withTitle('Beneficiary Status').renderWith(renderBeneficiary).withClass('medium-col'),
              DTColumnBuilder.newColumn('number_of_thrs_given').withTitle('Number of THRs given in current month').renderWith(renderNumberOfThrsGiven).withClass('medium-col'),
              DTColumnBuilder.newColumn('last_date_thr').withTitle('Date of last THR').renderWith(renderLastDateThr).withClass('medium-col'),
          ];
      } else if (vm.step === 'lactating') {
          vm.dtColumns = [
              DTColumnBuilder.newColumn('person_name').withTitle('Name').renderWith(renderPersonNameLactating).withClass('big-col'),
              DTColumnBuilder.newColumn('age').withTitle('Age').renderWith(renderAge).withClass('medium-col'),
              DTColumnBuilder.newColumn('add').withTitle('Date of Delivery').renderWith(renderAdd).withClass('medium-col'),
              DTColumnBuilder.newColumn('delivery_nature').withTitle('Type of Delivery').renderWith(renderDeliveryNature).withClass('medium-col'),
              DTColumnBuilder.newColumn('institutional_delivery').withTitle('Institutional Delivery (Y/N)').renderWith(renderInstitutionalDeliveryInMonth).withClass('medium-col'),
              DTColumnBuilder.newColumn('num_pnc_visits').withTitle('Number of PNC visits').renderWith(renderNumPncVisits).withClass('medium-col'),
              DTColumnBuilder.newColumn('breastfed_at_birth').withTitle('Breastfed within hour of birth').renderWith(renderBreastfedAtBirth).withClass('medium-col'),
              DTColumnBuilder.newColumn('is_ebf').withTitle('Exclusively breastfeeding at last home visit').renderWith(renderIsEbf).withClass('medium-col'),
              DTColumnBuilder.newColumn('num_rations_distributed').withTitle('Number of THRs given in current month').renderWith(renderNumRationsDistributed).withClass('medium-col'),
          ];
      }
  
      function compile(row) {
          $compile(window.angular.element(row).contents())($scope);
      }
  
      function renderPersonName(data, type, full) {
          return '<span class="pointer link" ng-click="$ctrl.goToBeneficiaryDetails(\''
              + full.case_id + '\')">' + full.person_name || vm.dataNotEntered + '</span>';
      }
  
      function renderPersonNamePregnant(data, type, full) {
          return '<span class="pointer link" ng-click="$ctrl.goToPregnantDetails(\''
              + full.case_id + '\')">' + full.person_name || vm.dataNotEntered + '</span>';
      }
  
      function renderPersonNameLactating(data, type, full) {
          return full.person_name || vm.dataNotEntered;
      }
  
      function renderDateOfBirth(data, type, full) {
          return full.dob || vm.dataNotEntered;
      }
  
      function renderAge(data, type, full) {
          return full.age || vm.dataNotEntered;
      }
  
      function renderClosed(data, type, full) {
          return full.closed ? 'Pregnancy terminated' : 'Pregnant';
      }
  
      function renderOpenedOn(data, type, full) {
          return full.opened_on || vm.dataNotEntered;
      }
  
      function renderEdd(data, type, full) {
          return full.edd || vm.dataNotEntered;
      }
  
      function renderTrimester(data, type, full) {
          return full.trimester || vm.dataNotEntered;
      }
  
      function renderAnemic(data, type, full) {
          return full.anemic || vm.dataNotEntered;
      }
  
      function renderNumAncComplete(data, type, full) {
          return full.num_anc_complete || vm.dataNotEntered;
      }
  
      function renderBeneficiary(data, type, full) {
          return full.beneficiary || vm.dataNotEntered;
      }
  
      function renderNumberOfThrsGiven(data, type, full) {
          return full.number_of_thrs_given || vm.dataNotEntered;
      }
  
      function renderLastDateThr(data, type, full) {
          return full.last_date_thr || vm.dataNotEntered;
      }
  
      function renderAdd(data, type, full) {
          return full.add || vm.dataNotEntered;
      }
  
      function renderBreastfedAtBirth(data, type, full) {
          return full.breastfed_at_birth || vm.dataNotEntered;
      }
  
      function renderIsEbf(data, type, full) {
          return full.is_ebf || vm.dataNotEntered;
      }
  
      function renderInstitutionalDeliveryInMonth(data, type, full) {
          return full.institutional_delivery || vm.dataNotEntered;
      }
  
      function renderDeliveryNature(data, type, full) {
          return full.delivery_nature || vm.dataNotEntered;
      }
  
      function renderNumPncVisits(data, type, full) {
          return full.num_pnc_visits || vm.dataNotEntered;
      }
  
      function renderNumRationsDistributed(data, type, full) {
          return full.num_rations_distributed || vm.dataNotEntered;
      }
  
      function renderFullyImmunizedDate(data, type, full) {
          return full.fully_immunized || vm.dataNotEntered;
      }
  
      function renderWeightForAgeStatus(data, type, full) {
          return '<span ng-class="row.nutrition_status.color" class="pointer" uib-popover-html="$ctrl.getPopoverContent(\''
              + full.recorded_weight + '\',\'' + full.recorded_height + '\',\'' + full.age_in_months
              + '\', \'weight\')" popover-placement="right" popover-trigger="\'mouseenter\'">'
              + full.current_month_nutrition_status.value + '</span>';
      }
  
      function renderHeightForAgeStatus(data, type, full) {
          return '<span ng-class="row.stunning.color" class="pointer" uib-popover-html="$ctrl.getPopoverContent(\''
              + full.recorded_weight + '\',\'' + full.recorded_height + '\',\'' + full.age_in_months
              + '\', \'height\')" popover-placement="right" popover-trigger="\'mouseenter\'">'
              + full.current_month_stunting.value + '</span>';
      }
  
      function renderWeightForHeightStatus(data, type, full) {
          return '<span ng-class="row.wasting.color" class="pointer" uib-popover-html="$ctrl.getPopoverContent(\''
              + full.recorded_weight + '\',\'' + full.recorded_height + '\',\'' + full.age_in_months
              + '\', \'both\')" popover-placement="right" popover-trigger="\'mouseenter\'">'
              + full.current_month_wasting.value + '</span>';
      }
  
      function renderPseDaysAttended(data, type, full) {
          return full.pse_days_attended || vm.dataNotEntered;
      }
  
      function renderAwwPhoneNumber(data, type, full) {
          return full.aww_phone_number || vm.dataNotEntered;
      }
  
      function renderMotherPhoneNumber(data, type, full) {
          return full.mother_phone_number || vm.dataNotEntered;
      }
  
      vm.showTable = true;
      vm.showBeneficiary = false;
      vm.beneficiary = null;
      vm.markers = {};
      vm.center = {
          lat: 22.10,
          lng: 78.22,
          zoom: 5,
      };
      if (Object.keys($location.search()).length === 0) {
          $location.search(storageService.getKey('search'));
      } else {
          storageService.setKey('search', $location.search());
      }
      vm.filtersData = $location.search();
      vm.selectedLocations = [];
      vm.xTicks = [];
      vm.message = true;
      vm.selectedLocationLevel = storageService.getKey('search')['selectedLocationLevel'] || 0;
  
      var caseId = $location.search().case_id;
  
      vm.getDataForStep = function (step) {
  
          if (step === 'beneficiary_details') {
              vm.showBeneficiaryDetails(caseId);
              vm.data = [];
              return;
          } else if (step === 'beneficiary') {
              vm.showBeneficiaryTable();
          } else if (step === 'pregnant_details') {
              vm.showPregnantDetails(caseId);
              vm.data = [];
              return;
          } else if (step === 'pregnant') {
              vm.showPregnantTable();
          } else if (step === 'lactating') {
              vm.showLactatingTable();
          }
  
          var get_url = url('awc_reports', step);
          if (parseInt(vm.selectedLocationLevel) === 4 && step !== 'beneficiary' && step !== 'pregnant'
              && step !== 'lactating') {
              vm.myPromise = $http({
                  method: "GET",
                  url: get_url,
                  params: $location.search(),
              }).then(
                  function (response) {
                      vm.data = response.data;
                      vm.message = false;
                      if (vm.data.map) {
                          vm.markers = vm.data.map.markers;
                          if (Object.keys(vm.markers).length > 0) {
                              vm.center = {
                                  lat: vm.markers[Object.keys(vm.markers)[0]].lat,
                                  lng: vm.markers[Object.keys(vm.markers)[0]].lng,
                                  zoom: 15,
                              };
                          } else {
                              vm.markers = [
                                  {
                                      lat: 22.10,
                                      lng: 78.22,
                                      draggable: false,
                                      icon: {
                                          type: 'div',
                                          iconSize: [350, 0],
                                          html: '<h1><strong>No GPS recorded</strong></h1>',
                                          popupAnchor: [0, 0],
                                      },
                                  },
                              ];
                          }
                      }
                  },
                  function (error) {
                      $log.error(error);
                  }
              );
          }
      };
  
      $scope.$on('filtersChange', function () {
          vm.getDataForStep(vm.step);
      });
  
      vm.getPopoverContent = function (weightRecorded, heightRecorded, ageInMonths, type) {
          var html = '';
  
          var recordedWeight = vm.dataNotEntered;
          var recordedHeight = vm.dataNotEntered;
          var age = vm.dataNotEntered;
  
          if (weightRecorded) {
              recordedWeight = d3.format(".2f")(weightRecorded) + ' kg';
          }
          if (heightRecorded && parseInt(heightRecorded) !== 0) {
              if (parseInt(heightRecorded) <= 45 || parseInt(heightRecorded) >= 120) {
                  recordedHeight = 'Data Not Valid';
              } else {
                  recordedHeight = d3.format(".2f")(heightRecorded) + ' cm';
              }
          }
          if (ageInMonths) {
              age = ageInMonths + ' months';
          }
  
          if (type === 'weight' || type === 'both') {
              html += '<div>Weight: ' + recordedWeight + '</div>';
          }
          if (type === 'height' || type === 'both') {
              html += '<div>Height: ' + recordedHeight + '</div>';
          }
          html += '<div>Age: ' + age + '</div>';
          return html;
      };
  
      vm.chartOptions = {
          chart: {
              type: 'multiBarChart',
              height: 450,
              width: 1100,
              margin: {
                  top: 20,
                  right: 20,
                  bottom: 50,
                  left: 80,
              },
              x: function (d) {
                  return d[0];
              },
              y: function (d) {
                  return d[1];
              },
              showValues: true,
              showControls: false,
              useInteractiveGuideline: true,
              showLegend: false,
              duration: 500,
              xAxis: {
                  axisLabel: '',
                  tickFormat: function (d) {
                      if (typeof d === 'number') {
                          return d3.time.format('%m/%d/%y')(new Date(d));
                      } else if (typeof d === 'string') {
                          return d;
                      }
                  },
              },
              yAxis: {
                  axisLabel: '',
              },
              interactiveLayer: {
                  tooltip: {
                      contentGenerator: function (key) {
                          return 'Total number of children between <strong>' + key.series[0].data[0] + ':</strong> ' + key.series[0].data[1];
                      },
                  },
              },
          },
      };
  
      vm.lineChartDaysPerWeekOptions = {
          chart: {
              type: 'multiBarChart',
              height: 450,
              width: 1100,
              margin: {
                  top: 20,
                  right: 20,
                  bottom: 150,
                  left: 80,
              },
              x: function (d) {
                  return d.x;
              },
              y: function (d) {
                  return d.y;
              },
              showValues: true,
              showControls: false,
              showLegend: false,
              useInteractiveGuideline: false,
              clipVoronoi: false,
              duration: 500,
              xAxis: {
                  axisLabel: 'Week',
                  tickFormat: function (d) {
                      return d3.time.format('Week of %d/%m')(new Date(d));
                  },
                  staggerLabels: true,
                  showMaxMin: false,
              },
              yAxis: {
                  axisLabel: 'Number of Days',
                  tickFormat: function (d) {
                      return d3.format('d')(d);
                  },
              },
              forceY: [0, 6],
              reduceXTicks: false,
              staggerLabels: false,
          },
      };
  
      vm.lineChartOptions = {
          chart: {
              type: 'lineChart',
              height: 450,
              width: 1100,
              margin: {
                  top: 20,
                  right: 50,
                  bottom: 100,
                  left: 80,
              },
              x: function (d) {
                  return d.x;
              },
              y: function (d) {
                  return d.attended;
              },
              showValues: true,
              showControls: false,
              useInteractiveGuideline: true,
              clipVoronoi: false,
              duration: 1000,
              xAxis: {
                  axisLabel: 'Day',
                  tickFormat: function (d) {
                      return d3.time.format('%d/%m/%Y')(new Date(d));
                  },
                  staggerLabels: true,
                  showMaxMin: false,
              },
              yAxis: {
                  axisLabel: 'Number of Children',
                  tickFormat: function (d) {
                      return d3.format('d')(d);
                  },
              },
              forceY: [0],
              callback: function (chart) {
                  var tooltip = chart.interactiveLayer.tooltip;
                  tooltip.contentGenerator(function (d) {
  
                      var day = _.find(vm.data.charts[1][0].values, function (num) {
                          return num['x'] === d.value;
                      });
  
                      var attended = day ? day.attended : '0';
                      var eligible = day ? day.eligible : '0';
  
                      var tooltipContent = "<p><strong>" + d3.time.format('%d/%m/%Y')(new Date(d.value)) + "</strong></p><br/>";
                      tooltipContent += "<div>Number of children who attended PSE: <strong>" + attended + "</strong></div>";
                      tooltipContent += "<div>Number of children who were eligible to attend PSE: <strong>" + eligible + "</strong></div>";
  
                      return tooltipContent;
                  });
                  return chart;
              },
              reduceXTicks: false,
              showLegend: false,
          },
      };
  
      vm.beneficiaryChartCallback = function (
          lineChartDataName,
          nominatorName,
          nominatorUnit,
          denominatorName,
          denominatorUnit
      ) {
          return function (chart) {
              var tooltip = chart.interactiveLayer.tooltip;
              tooltip.contentGenerator(function (d) {
                  var html = "";
                  var tooltipData = void(0);
                  // lineChartData can not be provided during generation
                  var lineChartData = null;
                  if (lineChartDataName === 'lineChartTwoData') {lineChartData = vm.lineChartTwoData;}
                  if (lineChartDataName === 'lineChartOneData') {lineChartData = vm.lineChartOneData;}
                  if (lineChartDataName === 'lineChartThreeData') {lineChartData = vm.lineChartThreeData;}
                  for (var i = 0; i < lineChartData.length; i++) {
                      if (lineChartData[i].x === d.value) {
                          tooltipData = lineChartData[i];
                      }
                  }
                  // search for imperfect values in tooltip in Weight For Height graph
                  if (lineChartDataName === 'lineChartThreeData' && tooltipData === void(0)) {
                      for (i = 0; i < lineChartData.length; i++) {
                          if (Math.abs(lineChartData[i].x - d.value) < 0.5) {
                              tooltipData = lineChartData[i];
                          }
                      }
                  }
                  var denominatorValue = d.value;
                  if (tooltipData) {
                      html = "<p>" + nominatorName + ": <strong>" + tooltipData.y + "</strong> " +
                          nominatorUnit + "</p>";
                      denominatorValue = tooltipData.x;  // show correct X value for imperfect WFH matches
                  } else {
                      html = "<p>" + nominatorName + ": <strong>Data Not Recorded</strong></p>";
                  }
                  if (denominatorUnit === 'month') {
                      denominatorUnit = denominatorValue === 1 ? "month" : "months";
                  }
                  html += "<p>" + denominatorName + ": <strong>" + denominatorValue + "</strong> " +
                      denominatorUnit + "</p>";
                  return html;
              });
              window.angular.forEach(d3.selectAll('g.nv-series-3 > path')[0], function (key) {
                  if (key.__data__[0].y !== null) key.classList.add('chart-dot');
              });
              return chart;
          };
      };
  
      vm.beneficiaryChartOptionsHFA = {
          chart: {
              type: 'lineChart',
              height: 450,
              margin: {
                  top: 20,
                  right: 20,
                  bottom: 50,
                  left: 80,
              },
              x: function (d) {
                  return d.x;
              },
              y: function (d) {
                  return d.y;
              },
              showControls: false,
              duration: 100,
              useInteractiveGuideline: true,
              forceX: [0],
              xAxis: {
                  axisLabel: 'Age (Months)',
                  showMaxMin: true,
                  tickValues: [0, 12, 24, 36, 48, 60],
              },
              yAxis: {
                  axisLabel: 'Height (Cm)',
                  tickFormat: function (d) {
                      return d3.format(".1f")(d);
                  },
                  rotateLabels: -90,
              },
              interactiveLayer: {
                  showGuideLine: true,
              },
              callback: vm.beneficiaryChartCallback(
                  'lineChartTwoData',
                  'Height',
                  'cm',
                  'Age',
                  'month'
              ),
          },
      };
  
      vm.beneficiaryChartOptionsWFA = {
          chart: {
              type: 'lineChart',
              height: 450,
              margin: {
                  top: 20,
                  right: 20,
                  bottom: 50,
                  left: 80,
              },
              x: function (d) {
                  return d.x;
              },
              y: function (d) {
                  return d.y;
              },
              showControls: false,
              duration: 100,
              useInteractiveGuideline: true,
              forceX: [0],
              xAxis: {
                  axisLabel: 'Age (Months)',
                  showMaxMin: true,
                  tickValues: [0, 12, 24, 36, 48, 60],
              },
              yAxis: {
                  axisLabel: 'Weight (Kg)',
                  tickFormat: function (d) {
                      return d3.format(".1f")(d);
                  },
                  rotateLabels: -90,
              },
              interactiveLayer: {
                  showGuideLine: true,
              },
              callback: vm.beneficiaryChartCallback(
                  'lineChartOneData',
                  'Weight',
                  'kg',
                  'Age',
                  'month'
              ),
          },
      };
  
      vm.beneficiaryChartOptionsWFH = {
          chart: {
              type: 'lineChart',
              height: 450,
              margin: {
                  top: 20,
                  right: 20,
                  bottom: 50,
                  left: 80,
              },
              x: function (d) {
                  return d.x;
              },
              y: function (d) {
                  return d.y;
              },
              showControls: false,
              duration: 100,
              useInteractiveGuideline: true,
              xDomain: [45, 120],
              forceY: [0],
              xAxis: {
                  axisLabel: 'Height (Cm)',
                  showMaxMin: true,
              },
              yAxis: {
                  axisLabel: 'Weight (Kg)',
                  tickFormat: function (d) {
                      return d3.format(".1f")(d);
                  },
                  rotateLabels: -90,
              },
              interactiveLayer: {
                  showGuideLine: true,
              },
              callback: vm.beneficiaryChartCallback(
                  'lineChartThreeData',
                  'Weight',
                  'kg',
                  'Height',
                  'cm'
              ),
          },
      };
  
      vm.beneficiaryChartOneData = [];
      vm.beneficiaryChartTwoData = [];
      vm.beneficiaryChartThreeData = [];
      vm.lineChartOneData = [];
      vm.lineChartTwoData = [];
      vm.lineChartthreeData = [];
  
      vm.goToBeneficiaryDetails = function (case_id) {
          var params = $location.search();
          params.case_id = case_id;
          $location.path('/awc_reports/beneficiary_details');
      };
  
      vm.showBeneficiaryDetails = function () {
          var params = $location.search();
          var get_url = url('awc_reports', 'beneficiary_details');
          var highest_age = 0;
  
          vm.filters.push('month');
  
          vm.myPromise = $http({
              method: "GET",
              url: get_url,
              params: params,
          }).then(
              function (response) {
                  vm.beneficiary = response.data;
                  highest_age = vm.beneficiary.age * 12;
                  vm.lineChartOneData = vm.beneficiary.weight;
                  vm.lineChartTwoData = vm.beneficiary.height;
                  vm.lineChartThreeData = vm.beneficiary.wfl;
  
                  vm.showBeneficiary = true;
                  vm.showTable = false;
  
                  vm.beneficiaryChartOneData = [
                      {
                          key: 'green',
                          type: 'area',
                          values: weight_for_age[vm.beneficiary.sex]['green'],
                          color: 'green',
                          area: true,
                      },
                      {
                          key: 'orange',
                          type: 'area',
                          values: weight_for_age[vm.beneficiary.sex]['orange'],
                          color: 'orange',
                          area: true,
                      },
                      {
                          key: 'red',
                          type: 'area',
                          values: weight_for_age[vm.beneficiary.sex]['red'],
                          color: 'red',
                          area: true,
                      },
                  ];
                  if (vm.lineChartOneData.length > 0) {
                      vm.beneficiaryChartOneData.push(
                          {
                              key: 'line',
                              type: 'line',
                              values: vm.lineChartOneData,
                              color: 'black',
                              strokeWidth: 2,
                              yAxis: 1,
                          }
                      );
                  }
                  vm.beneficiaryChartTwoData = [
                      {
                          key: 'green',
                          type: 'line',
                          values: height_for_age[vm.beneficiary.sex]['green'],
                          color: 'green',
                          area: true,
                      },
                      {
                          key: 'orange',
                          type: 'line',
                          values: height_for_age[vm.beneficiary.sex]['orange'],
                          color: 'orange',
                          area: true,
                      },
                      {
                          key: 'red',
                          type: 'line',
                          values: height_for_age[vm.beneficiary.sex]['red'],
                          color: 'red',
                          area: true,
                      },
                  ];
                  if (vm.lineChartTwoData.length > 0) {
                      vm.beneficiaryChartTwoData.push(
                          {
                              key: 'line',
                              type: 'line',
                              values: vm.lineChartTwoData,
                              color: 'black',
                              yAxis: 1,
                          }
                      );
                  }
                  vm.beneficiaryChartThreeData = [
                      {
                          key: 'green',
                          type: 'area',
                          values: weight_for_height[vm.beneficiary.sex]['green'],
                          color: 'green',
                          yAxis: 1,
                          area: true,
                      },
                      {
                          key: 'orange',
                          type: 'area',
                          values: weight_for_height[vm.beneficiary.sex]['orange'],
                          color: 'orange',
                          yAxis: 1,
                          area: true,
                      },
                      {
                          key: 'red',
                          type: 'area',
                          values: weight_for_height[vm.beneficiary.sex]['red'],
                          color: 'red',
                          yAxis: 1,
                          area: true,
                      },
                  ];
                  if (vm.lineChartThreeData.length > 0) {
                      vm.beneficiaryChartThreeData.push(
                          {
                              key: 'line',
                              type: 'line',
                              values: vm.lineChartThreeData,
                              color: 'black',
                              yAxis: 1,
                          }
                      );
                  }
  
              },
              function (error) {
                  $log.error(error);
              }
          );
      };
  
      vm.goToPregnantDetails = function (caseId) {
          var params = $location.search();
          params.case_id = caseId;
          $location.path('/awc_reports/pregnant_details');
      };
  
      vm.showPregnantDetails = function () {
          var params = $location.search();
          var getUrl = url('awc_reports', 'pregnant_details');
  
          vm.filters.push('month');
  
          vm.myPromise = $http({
              method: "GET",
              url: getUrl,
              params: params,
          }).then(
              function (response) {
                  vm.pregnantData = response.data['data'];
                  vm.showTable = false;
                  vm.pregnant = response.data['pregnant'];
                  vm.showPregnant = true;
              },
              function (error) {
                  $log.error(error);
              }
          );
      };
  
      vm.goToBeneficiaryTable = function () {
          $location.path(vm.steps.beneficiary.listRoute);
      };
  
      vm.showBeneficiaryTable = function () {
          vm.filters.pop();
          vm.beneficiary = null;
          vm.showBeneficiary = false;
          vm.showTable = true;
      };
  
      vm.goToPregnantTable = function () {
          $location.path(vm.steps.pregnant.listRoute);
      };
  
      vm.showPregnantTable = function () {
          vm.filters.push('month');
          vm.pregnant = null;
          vm.pregnantData = null;
          vm.showPregnant = false;
          vm.showTable = true;
      };
  
      vm.showLactatingTable = function () {
          vm.filters.push('month');
          vm.lactating = null;
          vm.showLactating = false;
          vm.showTable = true;
      };
  
      vm.steps = {
          // system_usage: { route: "/awc_reports/system_usage", label: "System Usage"},
          pse: {route: "/awc_reports/pse", label: "Pre School Education"},
          maternal_child: {route: "/awc_reports/maternal_child", label: "Maternal and Child Nutrition"},
          demographics: {route: "/awc_reports/demographics", label: "Demographics"},
          awc_infrastructure: {route: "/awc_reports/awc_infrastructure", label: "AWC Infrastructure"},
          beneficiary: {route: "/awc_reports/beneficiary", label: "Child Beneficiaries List"},
          pregnant: {route: "/awc_reports/pregnant", label: "Pregnant Women"},
          lactating: {route: "/awc_reports/lactating", label: "Lactating Women"},
      };
  
      if (vm.step === 'beneficiary_details') {
          vm.steps.beneficiary = {
              route: '/awc_reports/beneficiary_details',
              label: 'Beneficiary Details',
              listRoute: '/awc_reports/beneficiary',
          };
      } else if (vm.step === 'pregnant_details') {
          vm.steps.pregnant = {
              route: '/awc_reports/pregnant_details',
              label: 'Pregnant Details',
              listRoute: '/awc_reports/pregnant',
          };
      }
  
      vm.getDisableIndex = function () {
          var i = -1;
          if (!haveAccessToAllLocations) {
              window.angular.forEach(vm.selectedLocations, function (key, value) {
                  if (key !== null && key.location_id !== 'all' && !key.user_have_access) {
                      i = value;
                  }
              });
          }
          return i;
      };
  
      vm.moveToLocation = function (loc, index) {
          if (loc === 'national') {
              $location.search('location_id', '');
              $location.search('selectedLocationLevel', -1);
              $location.search('location_name', '');
          } else {
              $location.search('location_id', loc.location_id);
              $location.search('selectedLocationLevel', index);
              $location.search('location_name', loc.name);
          }
      };
  
      vm.layers = {
          baselayers: {
              mapbox_light: {
                  name: 'Mapbox Light',
                  url: 'https://api.mapbox.com/styles/v1/dimagi/cj2rl1t0w001f2rnr0y8hfhho/tiles/{z}/{x}/{y}?access_token={apikey}',
                  type: 'xyz',
                  layerOptions: {
                      apikey: 'pk.eyJ1IjoiZGltYWdpIiwiYSI6ImpZWWQ4dkUifQ.3FNy5rVvLolWLycXPxKVEA',
                  },
              },
              osm: {
                  name: 'OpenStreetMap',
                  url: 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
                  type: 'xyz',
              },
          },
      };
  
      vm.getDataForStep(vm.step);
  }
  
  AwcReportsController.$inject = ['$scope', '$http', '$location', '$routeParams', '$log', 'DTOptionsBuilder', 'DTColumnBuilder', '$compile', 'storageService', 'userLocationId', 'haveAccessToAllLocations', 'haveAccessToFeatures', 'isAlertActive'];
  
  window.angular.module('icdsApp').directive('awcReports', function () {
      return {
          restrict: 'E',
          templateUrl: url('icds-ng-template', 'awc-reports'),
          bindToController: true,
          controller: AwcReportsController,
          controllerAs: '$ctrl',
      };
  });
  