<template>
  <div>
    <div class="row align-items-center">
      <div class="col-lg-2"><p>Positive</p></div>
      <div class="col-lg-8"><div id="slider-stepPos"></div></div>
      <div class="col-lg-2"><p id="value-stepPos"></p></div>
    </div>
    <div class="row align-items-center">
      <div class="col-lg-2"><p>Negative</p></div>
      <div class="col-lg-8"><div id="slider-stepNeg"></div></div>
      <div class="col-lg-2"><p id="value-stepNeg"></p></div>
    </div>
  </div>
</template>

<script>
import { EventBus } from '../main.js'
import { sliderBottom } from 'd3-simple-slider'
import * as d3Base from 'd3'

// attach all d3 plugins to the d3 library
const d3 = Object.assign(d3Base, { sliderBottom })

export default {
  name: 'Slider',
  data () {
    return {
    }
  },
  methods: {
    InitSliders () {  
      var dataCorrect = [55.0, 60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0];
      var dataWrong = [5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0];

        var sliderStepPos = d3
          .sliderBottom()
          .min(d3.min(dataCorrect))
          .max(d3.max(dataCorrect))
          .width(300)
          .tickFormat(d3.format(".0f"))
          .ticks(9)
          .step(5)
          .default(75.0)
          .on('onchange', val => {
            d3.select('p#value-stepPos').text(d3.format(".0f")(val));
            EventBus.$emit('SendtheChangeinRangePos', d3.format(".0f")(val))
          });

        var gStepPos = d3
          .select('div#slider-stepPos')
          .append('svg')
          .attr('width', 500)
          .attr('height', 100)
          .append('g')
          .attr('transform', 'translate(30,30)');

        gStepPos.call(sliderStepPos);

        d3.select('p#value-stepPos').text(d3.format(".0f")(sliderStepPos.value()));

        var sliderStepNeg = d3
          .sliderBottom()
          .min(d3.min(dataWrong))
          .max(d3.max(dataWrong))
          .width(300)
          .tickFormat(d3.format(".0f"))
          .ticks(9)
          .step(5)
          .default(25.0)
          .on('onchange', val => {
            d3.select('p#value-stepNeg').text(d3.format(".0f")(val));
            EventBus.$emit('SendtheChangeinRangeNeg', d3.format(".0f")(val))
          });

        var gStepNeg = d3
          .select('div#slider-stepNeg')
          .append('svg')
          .attr('width', 500)
          .attr('height', 100)
          .append('g')
          .attr('transform', 'translate(30,30)');

        gStepNeg.call(sliderStepNeg);

        d3.select('p#value-stepNeg').text(d3.format(".0f")(sliderStepNeg.value()));
    },
    reset () {
      EventBus.$emit('reset')
      EventBus.$emit('alternateFlagLock')
    },
    initialize () {
      EventBus.$emit('ConfirmDataSet')
    }
  },
  mounted () {
    this.InitSliders()
  },
}
</script>
