Pen Settings

HTML

CSS

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

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="app">
  <div id="top" :style="bgc">
    <div class="labels">
      <div style="width: 80%;">Type in a phrase</div>
      <div class="score">Score</div>
    </div>
    <div class="interactive">
      <textarea v-model="phrase"></textarea>
      <p class="score">{{analysis.comparative}}</p>
    </div>
  </div>
  <div id="middle">
    <template v-for="emoji in emojis">
      <div class="emoji" 
           v-bind:style="{ backgroundColor: getBgc(emoji)}">
        {{emoji}}
      </div>
    </template>
  </div>
  <div id="positive" class="word-list">
    <div class="list-head">Positive Words</div>
    <ul>
      <li v-for="word in analysis.positive">
        {{word}}
      </li>
    </ul>
  </div>
  <div id="negative" class="word-list">
    <div class="list-head">Negative Words</div>
    <ul>
      <li v-for="word in analysis.negative">
        {{word}}
      </li>
    </ul>
  </div>
  <div id="footer" :style="bgc">
    Score is based on (weighted) sum of positive words and negative words, divided by number of words
  </div>
</div>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700");

body {
  font-family: "Open Sans", sans-serif;
}

#app {
  display: grid;
  grid-template-rows: 40vh 1fr 30vh 1fr;
  grid-template-columns: repeat(8, 1fr);
}

#top {
  grid-column: 1/9;
  grid-row: 1/2;
  font-size: 2em;
  display: flex;
  flex-direction: column;
/*   justify-content: center; */
  padding: 1em 2em;
}

textarea {
  resize: none;
  font-size: 1em;
  padding-bottom: 5px;
  text-align: left;
  outline: none;
  width: 80%;
  background-color: transparent;
  border-color: transparent;
  border-bottom: black solid 1px;
}

.labels {
  display: flex;
  justify-content: flex-start;
  font-size: 16px;
  text-align: left;
  margin-bottom: 10px;;
}

.interactive {
  display: flex;
}

.score {
  width: 20%;
  margin-left: 0 10px;
  text-align: left;
}

#middle {
  grid-column: 1/9;
  grid-row: 2/3;
  display: flex;
  justify-content: space-evenly;
  align-content: center;
  font-size: 3em;
}

.emoji {
  flex-grow: 1;
  display: flex;
  justify-content: center;
  padding: 1em 0;
}

.word-list {
  color: white;
  overflow-y: scroll;
  padding-top: 1em;
  padding-left: 1em;
}

#positive {
  grid-column: 1/5;
  grid-row: 3/4;
  background-color: #1a237e;
}

#negative {
  grid-column: 5/9;
  grid-row: 3/4;
  background-color: #b71c1c;
}

.list-head {
  font-size: 1.3em;
  padding-bottom: 10px;
  text-decoration: bold;
}

li {
  padding: 5px 0 5px 10px;
}

#footer {
  grid-column: 1/9;
  grid-row: 4/5;
  text-align: center;
  padding: 1em;
}
              
            
!

JS

              
                // we've imported the @trainorpj/sentiment library
const { scaleThreshold, scaleOrdinal } = d3;

const analyze = phrase => {
  const val = sentiment(phrase);
  return {
    comparative: val.comparative,
    negative: val.negative,
    positive: val.positive
  };
};

const emojis = ["😍", "🙂", "😑", "🙁", "😠"];
const colors = ["#2979FF", "#81D4FA", "#EDE7F6", "#F48FB1", "#E53935"];

const emojiColor = scaleOrdinal()
  .domain(emojis)
  .range(colors);

const emojiSentiment = scaleThreshold()
  .domain([-3, -1, 1, 3, 5])
  .range([...emojis].reverse());

var app = new Vue({
  el: "#app",
  data() {
    return {
      emojis,
      phrase: `I love waffles 😁....
but hate pancakes 💩`
    };
  },
  computed: {
    analysis: function() {
      const { comparative, positive, negative } = sentiment(this.phrase);
      return {
        comparative: comparative.toFixed(2),
        positive,
        negative
      };
    },
    bgc: function() {
      const emoji = emojiSentiment(this.analysis.comparative);
      const color = emojiColor(emoji);
      return { backgroundColor: color }
    }
  },
  methods: {
    changeBgc(val) {
      const emoji = emojiSentiment(val);
      const color = emojiColor(emoji);
      this.bgc.backgroundColor = color;
    },
    getBgc(emj) {
      return emojiColor(emj);
    }
  }
});

              
            
!
999px

Console