{{#> layout}}

  <g transform="translate({{spec.profile.padding.x}}, {{spec.profile.padding.y}})">
    <g transform="translate(391, 322)">
      <text x="0" y="0" font-size="36" font-weight="600" text-anchor="middle" fill="{{spec.raw.fill}}" dy="10">{{raw.mark}}</text>
      {{#with spec.raw.circle as | circle |}}
        {{gauge circle.R circle.r circle.brs circle.angles circle.direction fill="#F4F4F5"}}

        {{#each @root.raw.stops as | stop stopIndex |}}
          {{setVar "p1" (polarToCartesian circle.r stop.angle)}}
          {{setVar "p2" (polarToCartesian circle.R stop.angle)}}
          <line x1="{{p1.x}}" y1="{{p1.y}}" x2="{{p2.x}}" y2="{{p2.y}}" stroke="white"/>
          {{setVar "p" (polarToCartesian (math circle.r '-' 20) stop.angle)}}
          <text x="{{p.x}}" y="{{p.y}}" text-anchor="middle" fill="#D4D4D8" font-size="14" font-weight="500" dy="3">{{stop.mark}}</text>

          {{#unless @first}}
            {{setVar "prevStopAngle" (lookup (lookup @root.raw.stops (math stopIndex '-' 1)) 'angle')}}
            {{setVar "thetam" (math (math stop.angle '+' prevStopAngle) '/' 2)}}
            {{setVar "pm" (polarToCartesian (math circle.R '+' 30) thetam)}}
            <g transform="translate({{pm.x}}, {{pm.y}})">
              {{setVar "interpret" (lookup @root.spec.raw.interprets (math stopIndex '-' 1))}}
              {{setVar "isChosen" (boolean interpret.eng '===' @root.raw.interpretation)}}
              {{setVar "betMinus180AndMinus90" (boolean (boolean (toDeg thetam) '>' -180) '&&' (boolean (toDeg thetam) '<' -90))}}
              <circle cx="0" cy="0" r="{{ternary isChosen 3.5 2.5}}" fill="{{ternary isChosen @root.spec.raw.fill '#D4D4D8'}}"/>
              <text x="{{ternary betMinus180AndMinus90 -15 15}}" y="0" text-anchor="{{ternary betMinus180AndMinus90 'start' 'end'}}" fill="{{ternary isChosen @root.spec.raw.fill '#A1A1AA'}}" font-weight="{{ternary isChosen 600 400}}" font-size="{{ternary isChosen 16 14}}" dy="3">{{interpret.fr}}</text>
            </g>

            {{setVar "halt" false}}
            {{setVar "toAngle" stop.angle}}
            {{#if (ternary circle.direction (boolean @root.raw.angle '>=' stop.angle) (boolean @root.raw.angle '<=' stop.angle))}}
              {{setVar "toAngle" @root.raw.angle}}
              {{#if (ternary circle.direction (boolean @root.raw.angle '>=' prevStopAngle) (boolean @root.raw.angle '<=' prevStopAngle))}}
                {{setVar "halt" true}}
              {{/if}}
            {{/if}}
            {{#unless halt}}
              {{gauge circle.R circle.r circle.brs (object start=prevStopAngle end=toAngle) circle.direction fill=@root.spec.raw.fill fill-opacity=interpret.opacity}}
            {{/unless}}
          {{/unless}}
        {{/each}}
      {{/with}}
    </g>
  </g>

{{/layout}}