cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              #report(v-bind:class="{ 'is-active': isActive, 'is-loading': isLoading }")
  header.header
    .header__container
      h1.header__title SURF REPORT
      h2.header__subtitle {{ subtitle }}
  .locations
    .locations__container
      .locations__option(v-for="surfBreak in surfBreaks")
        input(type="radio" name="breaks" v-model="current" v-bind:value="surfBreak" v-bind:id="surfBreak.id" v-bind:class="{ 'surfbreak': true, 'surfbreak--is-active': surfBreak.id === activeSurfBreak.id }")
        label(v-bind:for="surfBreak.id")
          span {{ surfBreak.name }}
  .components
    .components__row.components__row--2-1
      .component.component--red.component--big(data-type="surf-height")
        header.component__title
          h4 SURF HEIGHT
        main.component__main
          span.txt-large(v-if="surfRange !== ' - <span>ft</span>'" v-html="surfRange")
          ul.column-breakdown.column-breakdown--swell
            li(v-for="swell in swells")
              | {{ swell.height }}&rsquo; <span>{{swell.period}}sec {{ swell.direction }}</span>

      .component.component--blue.component--small(data-type="temperature")
        header.component__title
          h4 SWELL MAP
        main.component__main
          .map
          .compass
            .compass__dir(v-for="swell in swells")
              div(:style="'transform: rotate(' + swell.angle + 'deg)'")
                svg(xmlns="http://www.w3.org/2000/svg" width="156.1" height="405.1" viewBox="0 0 156.1 405.1")
                  g(fill="#fff")
                    path(d="M131.7 130.3c-34.4-6.9-70.7-7.2-107.3.1l-9.8-49c43.2-8.6 86.1-8.2 126.8-.1l-9.7 49z")
                    path(d="M146.3 56.7c-43.8-8.7-90-9.2-136.6.1L0 7.8C53.2-2.8 106-2.3 156.1 7.7l-9.8 49z")
                    //- circle(cx="78.1" cy="400.1" r="5")

    .components__row.components__row--2-1
      .component.component--blue.component--big(data-type="tide")
        header.component__title
          h4 TIDE
        main.component__main
          #tide-graph
          ul.column-breakdown.column-breakdown--tide(:data-count="tide.extremes.length")
            li(v-for="extreme in tide.extremes")
              h4 {{ extreme.height }}&rsquo;
                span {{ extreme.type }}
                span {{ extreme.time }}

      .component.component--blue.component--small(data-type="wind")
        header.component__title
          h4 WIND
        main.component__main
          span.txt-large(v-if="wind.speed !== ''") {{wind.speed}} <span>kts</span>
          span {{wind.direction}}

    .components__row.components__row--1-1
      .component.component--blue(data-type="sun")
        header.component__title
          h4 SUNSET/SUNRISE
        main.component__main
          span.txt-medium(v-if="sunRange !== ' - '" v-html="sunRange")

      .component.component--blue.component--big(data-type="temperature")
        header.component__title
          h4 TEMPERATURE
        main.component__main
          span.txt-large(v-if="tempRange !== ' - '") {{temperature.min}} - {{temperature.max}}º
          span(v-if="tempRange !== ' - '") farenheit
            
          
!
            
              /**
  EXTERNAL
**/
@use lost;
@use postcss-nested;
@use postcss-simple-vars;
@import url('https://fonts.googleapis.com/css?family=Lato:400,700,900');

/**
  VARS
**/
$row-width:     1200px;
$gutter:        2rem;
$c-body-bg:     #222;
$c-body-font:   #fff;
$c-red:         #FA5A43;
$c-red--dark:   #DC4F3B;
$c-blue:        #313E51;
$c-blue--fade:  #202835;

@lost gutter $gutter;

/**
  ANIMATION
**/
@keyframes spin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/**
  RESET
**/
*, *:before, *:after {
  box-sizing: border-box;
}

/**
  LAYOUT
**/
body {
  background-color: $c-body-bg;
  font-family: 'Lato', 'Helvetica Neue', sans-serif;
  color: $c-body-font;
}

/**
  HEADER
**/
.header {
  padding: $gutter $gutter 0;
  &__container {
    text-align: center;
    lost-center: $row-width;
    @media screen and (min-width: 768px) {
      display: flex;
      align-items: baseline;
      text-align: left;
    }
  }
  &__title,
  &__subtitle {
    margin: 0 0 calc($gutter/2);
    line-height: 1;
  }
  &__title {
    font-weight: 900;
    @media screen and (min-width: 768px) {
      font-size: 2.5rem;
      margin-bottom: 0;
    }
  }
  &__subtitle {
    font-size: .875rem;
    font-weight: 400;
    margin-bottom: 0;
    @media screen and (min-width: 768px) {
      flex-grow: 1;
      text-align: right;
    }
  }
}

.locations {
  padding: $gutter 0;
  max-width: 100vw;
  overflow: scroll;
  -webkit-overflow-scrolling: touch;
  &__container {
  }
  &__option {
    position: relative;
    display: inline-block;
    height: 80px;
    width: 120px;
    margin-right: $gutter;
    .surfbreak {
      opacity: 0;
      width: 0;
      height: 0;
      overflow: hidden;
      margin: 0;
      padding: 0;
      &--is-active + label {
        color: #fff;
        background-image:
          url('//unsplash.it/300/200?image=1041'),
          linear-gradient(to bottom right, $c-red, $c-red--dark);
        background-size: cover;
        background-blend-mode: soft-light;
        transform: scale(1.1);
        &:before {
          opacity: 0;
          .is-loading.is-active & {
            opacity: 1;
          }
        }
      }
    }
    label {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      overflow: hidden;
      border-radius: 6px;
      color: #222;
      background-image: linear-gradient(to bottom right, #eee, #ddd);
      cursor: pointer;
      transition: transform ease-out 150ms;
      &:before {
        content: "";
        position: absolute;
        top: calc(50% - 10px);
        right: calc(50% - 10px);
        width: 20px;
        height: 20px;
        border: 5px solid rgba(255, 255, 255, .25);
        border-bottom-color: rgba(255, 255, 255, .5);
        border-radius: 50%;
        animation: spin 1s infinite linear;
        opacity: 0;
      }
    }
    span {
      position: absolute;
      left: calc($gutter / 4);
      bottom: calc($gutter / 4);
      width: calc(100% - $gutter/2);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      height: 1rem;
      font-size: .875rem;
      font-weight: 600;
    }
  }
}

/**
  COMPONENTS
**/
.components {
  padding: 0 $gutter;
  &__row {
    lost-center: $row-width;
    
    @media screen and (min-width: 768px) {
      display: flex;
    }
  }
}

.component {
  lost-utility: clearfix;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: $gutter;
  background-color: #111;
  opacity: .25;
  transition: all ease-out 150ms;

  .is-active & {
    opacity: 1;
  }

  .is-loading.is-active & {
    opacity: .5;
    pointer-events: none;
    transition-delay: 150ms;
  }
  
  &__title {
    height: calc($gutter + 1.25rem);
    padding: calc($gutter/2);
    background-color: rgba(0,0,0,.125);
    opacity: 0;
    transition: opacity ease-out 150ms;
    .is-active & {
      opacity: 1;
    }

    h4 {
      margin: 0;
      font-size: 1.25rem;
      font-weight: 700;
      letter-spacing: .05rem;
      line-height: 1;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
  &__main {
    overflow: hidden;
    height: calc(100% - ($gutter + 1.25rem));
    position: relative;
    padding: calc($gutter/2);
    &--np {
      padding: 0;
    }
    
    @media screen and (min-width: 768px) {
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
    }

    > span {
      display: block;
      line-height: 1;
      text-align: center;
      font-size: 1.375rem;
      margin-top: calc($gutter/2);
      &.txt-large {
        font-size: 3rem;
        text-shadow: 1px 1px 0 rgba(0,0,0,.125);
        margin-top: 0;
        @media screen and (min-width: 768px) {
          font-size: 7rem;
        }
        span {
          font-size: 2rem;
          font-weight: 600;
          @media screen and (min-width: 768px) {
            font-size: 4rem;
          }
        }
      }
      &.txt-medium {
        margin: 0;
        font-size: 2rem;
        font-weight: 600;
        @media screen and (min-width: 768px) {
          font-size: 4rem;
        }
      }
    }
  }
  &--red {
    .is-active & {
      background-color: $c-red;
    }
  }
  &--blue {
    .is-active & {
      background-color: $c-blue;
    }
  }
}

@media screen and (min-width: 768px) {
  .component {
    &--big {
      .components__row--2-1 & {
        lost-column: 2/3 2;
      }
    }
    &--small {
      .components__row--2-1 & {
        lost-column: 1/3 2;
      }
    }
    .components__row--1-1 & {
      lost-column: 1/2 2;
    }
  }
}

.map {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.compass {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 50%;
  transform: rotate(50deg) scale(1.1);
  @media screen and (min-width: 768px) {
    padding-bottom: 100%;
    transform: rotate(50deg) scale(.75);
  }
  &__dir {
    position: absolute;
    width: 100%;
    height: 100%;
    div {
      position: absolute;
      width: 100%;
      height: 100%;
      transition: transform 150ms ease-out;
    }
    svg {
      position: absolute;
      width: 79%;
      height: 59%;
      transform: rotate(-45deg);
      @media screen and (min-width: 768px) {
        width: 59%;
      }
      
      path {
        fill: #646E7C;
      }
    }
  }
}

.column-breakdown {
  display: block;
  width: 100%;
  font-size: 1.5rem;
  margin: calc($gutter/2) 0 0;
  padding: calc($gutter/2) 0 0;
  list-style: none;
  line-height: 1.25;
  text-align: center;
  border-top: rgba(0,0,0,.125) 2px solid;
  &--swell {
    li {
      lost-column: 1/3 3;
    }
    span {
      display: block;
      font-size: .85rem;
      color: rgba(255,255,255,.75);
    }
  }
  &--tide {
    li {
      lost-column: 1/4 4;
    }

    &[data-count="3"] {
      li { lost-column: 1/3 3; }
    }

    h4 {
      font-weight: 200;
      margin: 0;
    }
    span {
      display: block;
      font-size: .85rem;
      color: rgba(255,255,255,.75);
    }
  }
}

#tide-graph {
  width: 100%;
  svg {
    display: block;
    width: 100%;
    text {
      font-size: .75rem;
      fill: #fff;
      pointer-events: none;
    }
    rect {
      fill: $c-blue--fade;
      transition: all 250ms ease-out;
      cursor: pointer;
    }
  }
}
            
          
!
            
              /*
  HELPERS
*/

function average(arr) {
  let sum = arr.reduce((memo, num) => {
    return memo + num
  }, 0)
  return sum / ((arr.length === 0) ? 1 : arr.length)
}

function roundTenths(num) {
  return Math.round(num * 10) / 10
}

function roundHundreths(num) {
  return Math.round(num * 100) / 100
}

function roundHalf(num) {
  return Math.round(num * 2) / 2
}

function degToCompass(num) {
  let val = Math.floor((num / 22.5) + 0.5),
      dirs = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW']
  return dirs[(val % 16)]
}

/*
  APP
*/
const corsProxy = 'https://cors-anywhere.herokuapp.com/'
const breakOptions = [
      {
        id: '5538',
        name: 'Ala Moana',
        url: corsProxy + 'https://api.surfline.com/v1/forecasts/5538?resources=surf,wind,tide,weather&days=1&getAllSpots=false&units=e&interpolate=false&showOptimal=false'
      },
      {
        id: '4756',
        name: 'Chuns',
        url: corsProxy + 'https://api.surfline.com/v1/forecasts/4756?resources=surf,wind,tide,weather&days=1&getAllSpots=false&units=e&interpolate=false&showOptimal=false'
      },
      {
        id: '10845',
        name: 'Makaha',
        url: corsProxy + 'https://api.surfline.com/v1/forecasts/10845?resources=surf,wind,tide,weather&days=1&getAllSpots=false&units=e&interpolate=false&showOptimal=false'
      },
      {
        id: '5540',
        name: 'Makapuu Beach',
        url: corsProxy + 'https://api.surfline.com/v1/forecasts/5540?resources=surf,wind,tide,weather&days=1&getAllSpots=false&units=e&interpolate=false&showOptimal=false'
      },
      {
        id: '10838',
        name: 'Popoia Island',
        url: corsProxy + 'https://api.surfline.com/v1/forecasts/10838?resources=surf,wind,tide,weather&days=1&getAllSpots=false&units=e&interpolate=false&showOptimal=false'
      },  
      {
        id: '5533',
        name: 'Populars',
        url: corsProxy + 'https://api.surfline.com/v1/forecasts/5533?resources=surf,wind,tide,weather&days=1&getAllSpots=false&units=e&interpolate=false&showOptimal=false'
      },
      {
        id: '10837',
        name: 'Sandys Beach Park',
        url: corsProxy + 'https://api.surfline.com/v1/forecasts/10837?resources=surf,wind,tide,weather&days=1&getAllSpots=false&units=e&interpolate=false&showOptimal=false'
      },
      {
        id: '4746',
        name: 'Sunset',
        url: corsProxy + 'https://api.surfline.com/v1/forecasts/4746?resources=surf,wind,tide,weather&days=1&getAllSpots=false&units=e&interpolate=false&showOptimal=false'
      },
      // {
      //   id: null,
      //   name: '–––',
      //   url: null
      // },
      {
        id: '5015',
        name: 'Fort Point',
        url: corsProxy + 'https://api.surfline.com/v1/forecasts/5015?resources=surf,wind,tide,weather&days=1&getAllSpots=false&units=e&interpolate=false&showOptimal=false'
      },
      {
        id: '4127',
        name: 'Ocean Beach',
        url: corsProxy + 'https://api.surfline.com/v1/forecasts/4127?resources=surf,wind,tide,weather&days=1&getAllSpots=false&units=e&interpolate=false&showOptimal=false'
      },
      {
        id: '5013',
        name: 'Pacifica',
        url: corsProxy + 'https://api.surfline.com/v1/forecasts/5013?resources=surf,wind,tide,weather&days=1&getAllSpots=false&units=e&interpolate=false&showOptimal=false'
      },
      {
        id: '5090',
        name: 'Stinson Beach',
        url: corsProxy + 'https://api.surfline.com/v1/forecasts/5090?resources=surf,wind,tide,weather&days=1&getAllSpots=false&units=e&interpolate=false&showOptimal=false'
      }
    ]

let mapScript = document.createElement('script')
mapScript.type = 'text/javascript'
mapScript.src = '//maps.googleapis.com/maps/api/js?key=AIzaSyDsIY-GESpfBfIGFHnpcmzcBZkhSPThyto'
mapScript.defer = true
mapScript.async = true
let s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(mapScript, s);

let report = new Vue({
  el: '#report',
  data: {
    isActive: false,
    isLoading: false,
    subtitle: 'Choose a surf break below',
    surfBreaks: breakOptions,
    activeSurfBreak: breakOptions[0],
    current: '',
    min: '',
    max: '',
    location: {
      lat: '',
      lng: ''
    },
    swells: [],
    wind: {
      speed: '',
      direction: ''
    },
    sun: {
      rise: '',
      set: ''
    },
    tide: {
      graph: '',
      data: '',
      extremes: []
    },
    temperature: {
      min: '',
      max: ''
    }
  },
  created: function() {
    this.setWidth()
  },
  mounted: function() {
    this.isActive = true;
    this.getSurf(breakOptions[0]);
  },
  computed: {
    surfRange: function () {
      return this.min + ' - ' + this.max + '<span>ft</span>'
    },
    sunRange: function () {
      return this.sun.rise + ' - ' + this.sun.set
    },
    tempRange: function () {
      return this.temperature.min + ' - ' + this.temperature.max
    }
  },
  watch: {
    current: function(selection) {
      if (!selection.id) return
      if (!this.isActive) this.isActive = true

      this.getSurf(selection)
    }
  },
  methods: {
    setWidth: function() {
      let locationList = document.querySelector('.locations__container'),
          firstEl = document.querySelectorAll('.locations__option')[0],
          titleLeft = document.querySelector('.header__title').getBoundingClientRect().left,
          width = firstEl.getBoundingClientRect().width + parseInt(window.getComputedStyle(firstEl)['margin-right']),
          count = this.surfBreaks.length

      locationList.style.paddingLeft = `${titleLeft}px`
      locationList.style.paddingRight = `${titleLeft}px`
      locationList.style.width = `${count * width + titleLeft * 2}px`
    },
    getSurf: function(selection) {
      this.isLoading = true
      this.activeSurfBreak = selection

      axios.get(selection.url)
        .then((response) => {
          this.isLoading = false
          let result = {
            date: response.data.Surf.startDate_pretty_LOCAL,
            surfMax: response.data.Surf.surf_max[0],
            surfMin: response.data.Surf.surf_min[0],
            location: {
              longitude: response.data.lon,
              latitude: response.data.lat
            },
            swells: [
              {
                angle: response.data.Surf.swell_direction1[0],
                height: response.data.Surf.spot.swell_height1[0],
                period: response.data.Surf.spot.swell_period1[0]
              },
              {
                angle: response.data.Surf.swell_direction2[0],
                height: response.data.Surf.spot.swell_height2[0],
                period: response.data.Surf.spot.swell_period2[0]
              },
              {
                angle: response.data.Surf.swell_direction3[0],
                height: response.data.Surf.spot.swell_height3[0],
                period: response.data.Surf.spot.swell_period3[0]
              }
            ],
            sun: {
              rise: response.data.Tide.SunPoints[0].Rawtime,
              set: response.data.Tide.SunPoints[1].Rawtime
            },
            temperature: {
              min: response.data.Weather.temp_min,
              max: response.data.Weather.temp_max
            },
            tide: {
              data: response.data.Tide.dataPoints,
              extremes: response.data.Tide.dataPoints
            },
            wind: {
              speed: response.data.Wind.wind_speed[0],
              angle: response.data.Wind.wind_direction[0]
            }
          }
          
          this.subtitle = 'Actual data from ' + moment(result.date, 'MMMM DD, YYYY kk:mm:ss').format('M/D/YYYY')

          this.max = (average(result.surfMax) < .5) ? 'flat' : roundHalf(average(result.surfMax))
          this.min = (average(result.surfMin) < .5) ? 'flat' : roundHalf(average(result.surfMin))

          this.location.lng = result.location.longitude
          this.location.lat = result.location.latitude
          this.buildMap(this.location.lat, this.location.lng)
        
          result.swells.forEach((obj, index) => {
            this.swells[index] = {
              angle: average(result.swells[index].angle),
              direction: degToCompass(average(result.swells[index].angle)),
              height: roundTenths(average(result.swells[index].height)),
              period: roundTenths(average(result.swells[index].period))
            }
          })

          this.sun.rise = moment(result.sun.rise, 'MMMM DD, YYYY HH:mm:ss').format('h:mma')
          this.sun.set = moment(result.sun.set, 'MMMM DD, YYYY HH:mm:ss').format('h:mma')

          this.temperature.min = roundTenths(average(result.temperature.min))
          this.temperature.max = roundTenths(average(result.temperature.max))

          this.tide.data = result.tide.data
            .filter(dataPoint => dataPoint.type == 'NORMAL')
            .filter((dataPoint) => {
              let dataTime = moment(dataPoint.Rawtime, 'MMMM DD, YYYY HH:mm:ss').format('MM/DD'),
                  startTime = moment(result.tide.data[0].Rawtime, 'MMMM DD, YYYY HH:mm:ss').format('MM/DD')
              return dataTime === startTime
            })
            .map((dataPoint)=>{
              return {
                time: moment(dataPoint.Rawtime, 'MMMM DD, YYYY HH:mm:ss').format('h:mma'),
                height: dataPoint.height
              }
            })
          this.buildTide(this.tide.data)
          this.tide.extremes = result.tide.data
            .filter(dataPoint => (dataPoint.type == 'High' || dataPoint.type == 'Low'))
            .filter((dataPoint) => {
              let dataTime = moment(dataPoint.Rawtime, 'MMMM DD, YYYY HH:mm:ss').format('MM/DD'),
                  startTime = moment(result.tide.data[0].Rawtime, 'MMMM DD, YYYY HH:mm:ss').format('MM/DD')
              return dataTime === startTime
            })
            .map((dataPoint)=>{
              return {
                time: moment(dataPoint.Rawtime, 'MMMM DD, YYYY HH:mm:ss').format('h:mma'),
                height: dataPoint.height,
                type: dataPoint.type
              }
            })

          this.wind.speed = Math.round(average(result.wind.speed))
          this.wind.direction = degToCompass(average(result.wind.angle))
        })
        .catch((error) => {
          this.isLoading = false
          console.error(error)
        });
    },
    buildMap: function(lat, lng) {
      this.center = {lat: parseFloat(lat), lng: parseFloat(lng)}

      if (this.map) {
        this.map.panTo(this.center)
        return
      }

      this.map = new google.maps.Map(document.querySelector('.map'), {
        center: this.center,
        zoom: 10,
        disableDefaultUI: true,
        styles: [{"featureType":"water","elementType":"geometry","stylers":[{"color":"#313E51"}]},{"featureType":"landscape","elementType":"geometry","stylers":[{"color":"#313E51"},{"lightness":-25}]},{"featureType":"road","elementType":"geometry","stylers":[{"color":"#313E51"},{"lightness":-40}]},{"featureType":"poi","elementType":"geometry","stylers":[{"visibility":"off"}]},{"featureType":"transit","elementType":"geometry","stylers":[{"visibility":"off"}]},{"elementType":"labels.text.stroke","stylers":[{"visibility":"off"}]},{"elementType":"labels.text.fill","stylers":[{"visibility":"off"}]},{"featureType":"administrative","elementType":"geometry","stylers":[{"visibility":"off"}]},{"elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"poi.park","elementType":"geometry","stylers":[{"visibility":"off"}]}]
      })

      window.addEventListener('resize', () => {
        this.map.panTo(this.center)
      }, true)
    },
    buildTide: function(data) {
      let margin = {top: 0, right: 0, bottom: 0, left: 0},
          width = 400,
          widthBar = (width/data.length),
          height = 150,
          graph = d3.select('#tide-graph')

      const HEIGHTS = d3.set(data, (d) => {
              return d.height
            }),
            TIMES = d3.set(data, (d) => {
              return d.time
            }),
            EXTENT_TIMES = d3.extent(TIMES.values(), (d)=>{
              return d
            }),
            EXTENT_HEIGHTS = d3.extent(HEIGHTS.values(), (d)=>{
              return d
            }),
            X_SCALE = d3.scaleTime()
              .domain([EXTENT_TIMES[0], EXTENT_TIMES[1]])
              .range([0, width]),
            Y_SCALE = d3.scaleLinear()
              .domain([0, Math.ceil(EXTENT_HEIGHTS[1])])
              .range([height/10, height])

      if (!graph.select('svg').nodes().length) {
        graph
          .append('svg')
            .attr('viewBox', `0 0 ${width} ${height}`)
            .attr('preserveAspectRatio', 'xMidYMid meet')
      } else {
        graph
          .selectAll('rect')
          .remove()
      }
      
      graph.select('svg')
        .selectAll('rect')
        .data(data)
        .enter()
          .append('rect')
          .on('mouseover', function(d, i, elements) {
            let thisNode = d3.select(this),
                thisHeight = roundTenths(d.height),
                thisTime = d.time

            graph.select('svg')
              .append('text')
              .attr('x', 8)
              .attr('y', height - 8)
              .html(thisHeight + '’ @ ' + thisTime)

            d3.selectAll(elements)
              .filter(':not(:hover)')
              .style('fill-opacity', .5)
          })
          .on('mouseout', function(d, i, elements) {
            d3.selectAll(elements)
              .style('fill-opacity', 1)

            graph.selectAll('text')
              .remove()
          })
          .attr('width', widthBar - widthBar/2)
          .attr('x', (d, i) => i * widthBar + widthBar/4)
          .attr('y', height)
          .attr('ry', widthBar/4)
          .attr('rx', widthBar/4)
          .transition()
          .duration(500)
          .attr('height', (d) => {
            return Y_SCALE(d.height)
          })
          .attr('y', (d) => {
            return height - Y_SCALE(d.height)
          })

      
    }
  }
})
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console