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.

            
              div.container
  h1 Van der Waal Equation Exploration
  hr
  div#app(class="v-cloak")
    div(class="columns")
      .column
        .box
          h2 Molecule
          //- div {{ selectedMolecule }} {{ a }} {{ b }}
          .control
            .select
              select(v-model="selectedMolecule")
                //- option(disabled value="") Select a molecule
                option(v-for="molecule in molecules" v-bind:value="molecule.name") {{ molecule.name }}
          
      .column
        .box
          h2 a
          input(type="range" v-model="a" min="0" max="50" step="0.5")
          input(type="number" v-model="a")
      
      .column
        .box
          h2 b
          input(type="range" v-model="b" min="0" max="0.3" step="0.01")
          input(type="number" v-model="b")

      .column
        .box
          h2 T
          input(type="range" v-model="T" min="0" max="1000" step="10")
          input(type="number" v-model="T")
       
      .column
        .box
          h2 n
          input(type="range" v-model="n" min="0.1" max="10" step="0.5")
          input(type="number" v-model="n")

    hr
    
    canvas(id="myChart" width="800" height="400")

    div.tabs
      p {{ pVdW }}
            //- p {{ v }}
            //- p {{ data }}
            //- p {{ idealData }}
            //- p {{ idealData }}
            //- p {{ ctx }}
            
          
!
            
              const molecules = [
  { name: "CO2", a: 3.64, b: 0.04267 },
  { name: "Acetic acid"  , a:  17.71 , b:  0.1065 },
  { name: "Acetic anhydride" , a:  20.158, b:  0.1263 },
  { name: "Acetone"  , a:  16.02 , b:  0.1124 },
  { name: "Acetonitrile" , a:  17.81 , b:  0.1168 },
  { name: "Acetylene"  , a:  4.516 , b:  0.0522 },
  { name: "Ammonia"  , a:  4.170 , b:  0.0371 },
  { name: "Argon"   , a: 1.355  , b: 0.03201 },
  { name: "Benzene"  , a:  18.24 , b:  0.1154 },
  { name: "Bromobenzene" , a:  28.94 , b:  0.1539 },
  { name: "Butane" , a:  14.66 , b:  0.1226 },
  // { name: "Carbon dioxide"  , a: 3.640  , b: 0.04267 },
  { name: "Carbon disulfide"  , a: 11.77  , b: 0.07685 },
  { name: "Carbon monoxide"   , a: 1.505  , b: 0.03985 },
  { name: "Carbon tetrachloride"   , a:19.7483 , b:  0.1281 },
  { name: "Chlorine"  , a: 6.579  , b: 0.05622 },
  { name: "Chlorobenzene"  , a:  25.77 , b:  0.1453 },
  { name: "Chloroethane"  , a: 11.05  , b: 0.08651 },
  { name: "Chloromethane"   , a: 7.570  , b: 0.06483 },
  { name: "Cyanogen"  , a: 7.769  , b: 0.06901 },
  { name: "Cyclohexane"  , a:  23.11 , b:  0.1424 },
  { name: "Diethyl ether"  , a:  17.61 , b:  0.1344 },
  { name: "Diethyl sulfide"  , a:  19.00 , b:  0.1214 },
  { name: "Dimethyl ether"  , a: 8.180  , b: 0.07246 },
  { name: "Dimethyl sulfide"  , a: 13.04  , b: 0.09213 },
  { name: "Ethane" , a:  5.562 , b:  0.0638 },
  { name: "Ethanethiol"   , a: 11.39  , b: 0.08098 },
  { name: "Ethanol"   , a: 12.18  , b: 0.08407 },
  { name: "Ethyl acetate"  , a:  20.72 , b:  0.1412 },
  { name: "Ethylamine"  , a: 10.74  , b: 0.08409 },
  { name: "Fluorobenzene"  , a:  20.19 , b:  0.1286 },
  { name: "Fluoromethane"   , a: 4.692  , b: 0.05264 },
  { name: "Freon"  , a:  10.78 , b:  0.0998 },
  { name: "Germanium tetrachloride"  , a:  22.90 , b:  0.1485 },
  { name: "Helium" , a:  0.0346, b:  0.0238 },
  { name: "Hexane" , a:  24.71 , b:  0.1735 },
  { name: "Hydrogen"  , a: 0.2476 , b: 0.02661 },
  { name: "Hydrogen bromide"  , a: 4.510  , b: 0.04431 },
  { name: "Hydrogen chloride"   , a: 3.716  , b: 0.04081 },
  { name: "Hydrogen selenide"   , a: 5.338  , b: 0.04637 },
  { name: "Hydrogen sulfide"  , a: 4.490  , b: 0.04287 },
  { name: "Iodobenzene"  , a:  33.52 , b:  0.1656 },
  { name: "Krypton"   , a: 2.349  , b: 0.03978 },
  { name: "Mercury"   , a: 8.200  , b: 0.01696 },
  { name: "Methane"   , a: 2.283  , b: 0.04278 },
  { name: "Methanol"  , a: 9.649  , b: 0.06702 },
  { name: "Neon"  , a: 0.2135 , b: 0.01709 },
  { name: "Nitric oxide"  , a: 1.358  , b: 0.02789 },
  { name: "Nitrogen" , a:  1.370 , b:  0.0387 },
  { name: "Nitrogen dioxide"  , a: 5.354  , b: 0.04424 },
  { name: "Nitrous oxide"   , a: 3.832  , b: 0.04415 },
  { name: "Oxygen"  , a: 1.382  , b: 0.03186 },
  { name: "Pentane" , a:   19.26, b:   0.146 },
  { name: "Phosphine"   , a: 4.692  , b: 0.05156 },
  { name: "Propane"   , a: 8.779  , b: 0.08445 },
  { name: "Radon"   , a: 6.601  , b: 0.06239 },
  { name: "Silane"  , a: 4.377  , b: 0.05786 },
  { name: "Silicon tetrafluoride"   , a: 4.251  , b: 0.05571 },
  { name: "Sulfur dioxide"  , a: 6.803  , b: 0.05636 },
  { name: "Tin tetrachloride"  , a:  27.27 , b:  0.1642 },
  { name: "Water"   , a: 5.536  , b: 0.03049 },
  { name: "Xenon"   , a: 4.250  , b: 0.05105 },
]

let vm = new Vue({
  el: '#app',
  data () {
    return {
      a: 3.640, // for CO2
      b: 0.04267, // for CO2
      T: 273, // Kelvin
      n: 1, // mol / dm3
      R: 8.314, // standard unit (?)
      v: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1,1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],
      ctx: {},
      molecules,
      selectedMolecule: molecules[0].name
      // p: []
    }
  },
  computed: {
//     a () {
      
//       let mol = this.molecules.find(isSelectedMolecule)
//       return mol.a
//     },
    // b () {
    //   return this.selectedMolecule.b
    // },
    pVdW () {
      let pressure = []
      for (i = 0; i < this.v.length; i++) {
        pressure.push( (this.n * this.R * this.T)/(this.v[i] - (this.n * this.b) ) - ((this.a * (this.n * this.n)) / (this.v[i] * this.v[i])) )
      }
      return pressure
    },
    pIdeal () {
      let pressure = []
      for (i = 0; i < this.v.length; i++) {
        pressure.push( (this.n * this.R * this.T)/(this.v[i]) )
      }
      return pressure
    },
    data () {
      let tempData = []
      for (i = 0; i < this.v.length; i++) {
        let pair = { x: this.v[i], y: this.pVdW[i] }
        tempData.push(pair)
      }
        // { x: this.p, 
        //        y: this.v, 
        //        type: 'scatter' }
      return tempData
    },
    idealData () {
      let tempData = []
      for (i = 0; i < 25; i++) {
        console.log(this.pIdeal[i])
        console.log(this.pVdW[i])
        let pair = { x: this.v[i], y: this.pIdeal[i] }
        tempData.push(pair)
      }
        // { x: this.p, 
        //        y: this.v, 
        //        type: 'scatter' }
      return tempData
    }
  },
  watch: {
    selectedMolecule () {  
      for (i = 0; i < this.molecules.length; i++) {
        if (this.molecules[i].name === this.selectedMolecule) {
          this.a = this.molecules[i].a
          this.b = this.molecules[i].b
          return
        }
      }
    },
  },
  methods: {
    plotGraph () {
      this.ctx = document.getElementById("myChart")
    var scatterChart = new Chart(this.ctx, {
      type: 'scatter',
      data: {
          datasets: [{
              label: 'with VdW adjustment',
              data: this.data,
              backgroundColor: "",
              borderColor: "red", // The main line color
              // borderCapStyle: 'square',
              // borderDash: [], // try [5, 15] for instance
              // borderDashOffset: 0.0,
              // borderJoinStyle: 'miter',
              // pointBorderColor: "black",
              // pointBackgroundColor: "white",
              // pointBorderWidth: 1,
              // pointHoverRadius: 8,
              // pointHoverBackgroundColor: "yellow",
              // pointHoverBorderColor: "brown",
              // pointHoverBorderWidth: 2,
              // pointRadius: 4,
              // pointHitRadius: 10,
          },
                    {
                      label: 'Ideal gas',
              data: this.idealData,
                    }]
      },
      options: {
          scales: {
              xAxes: [{
                  type: 'linear',
                  position: 'bottom',
                  ticks: {
                    suggestedMin: 0,
                    max: 20
                  }
              }],
              yAxes: [{
                  type: 'linear',
                  ticks: {
                    suggestedMin: 0,
                    max: 40000
                  }
              }]
          },
        // Container for zoom options
        zoom: {
            // Boolean to enable zooming
            enabled: true,
          drag: true,
            
            // Zooming directions. Remove the appropriate direction to disable 
            // Eg. 'y' would only allow zooming in the y direction
            mode: 'xy',
        }
      }
      
    });  
    }
  },
  updated () {
    this.plotGraph()
  },
  mounted () {
    this.plotGraph()
  }
})

// Plotly.newPlot('myDiv', vm.data)
            
          
!
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