All files / app/assets/javascripts/notebook/cells/output index.vue

4.08% Statements 2/49
0% Branches 0/23
0% Functions 0/5
4.08% Lines 2/49

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134                      5x 5x                                                                                                                                                                                                                                                  
<!-- eslint-disable vue/multi-word-component-names -->
<script>
import CodeOutput from '../code/index.vue';
import HtmlOutput from './html.vue';
import ImageOutput from './image.vue';
import LatexOutput from './latex.vue';
import MarkdownOutput from './markdown.vue';
import ErrorOutput from './error.vue';
import DataframeOutput from './dataframe.vue';
import { isDataframe } from './dataframe_util';
 
const TEXT_MARKDOWN = 'text/markdown';
const ERROR_OUTPUT_TYPE = 'error';
 
export default {
  props: {
    count: {
      type: Number,
      required: false,
      default: 0,
    },
    outputs: {
      type: Array,
      required: true,
    },
    metadata: {
      type: Object,
      default: () => ({}),
      required: false,
    },
  },
  methods: {
    outputType(output) {
      Iif (output.text) {
        return 'text/plain';
      }
      Iif (output.output_type === ERROR_OUTPUT_TYPE) {
        return 'error';
      }
      Iif (output.data['image/png']) {
        return 'image/png';
      }
      Iif (output.data['image/jpeg']) {
        return 'image/jpeg';
      }
      Iif (output.data['text/html']) {
        return 'text/html';
      }
      Iif (output.data['text/latex']) {
        return 'text/latex';
      }
      Iif (output.data['image/svg+xml']) {
        return 'image/svg+xml';
      }
      Iif (output.data[TEXT_MARKDOWN]) {
        return TEXT_MARKDOWN;
      }
 
      return 'text/plain';
    },
    dataForType(output, type) {
      let data = output.data[type];
 
      Iif (typeof data === 'object' && this.outputType(output) !== TEXT_MARKDOWN) {
        data = data.join('');
      }
 
      return data;
    },
    getComponent(output) {
      Iif (output.text) {
        return CodeOutput;
      }
      Iif (output.output_type === ERROR_OUTPUT_TYPE) {
        return ErrorOutput;
      }
      Iif (output.data['image/png']) {
        return ImageOutput;
      }
      Iif (output.data['image/jpeg']) {
        return ImageOutput;
      }
      Iif (isDataframe(output)) {
        return DataframeOutput;
      }
      Iif (output.data['text/html']) {
        return HtmlOutput;
      }
      Iif (output.data['text/latex']) {
        return LatexOutput;
      }
      Iif (output.data['image/svg+xml']) {
        return HtmlOutput;
      }
      Iif (output.data[TEXT_MARKDOWN]) {
        return MarkdownOutput;
      }
 
      return CodeOutput;
    },
    rawCode(output) {
      Iif (output.text) {
        Iif (typeof output.text === 'string') {
          return output.text;
        }
        return output.text.join('');
      }
 
      Iif (output.output_type === ERROR_OUTPUT_TYPE) {
        return output.traceback;
      }
 
      return this.dataForType(output, this.outputType(output));
    },
  },
};
</script>
 
<template>
  <div>
    <component
      :is="getComponent(output)"
      v-for="(output, index) in outputs"
      :key="index"
      type="output"
      :output-type="outputType(output)"
      :count="count"
      :index="index"
      :raw-code="rawCode(output)"
      :metadata="metadata"
    />
  </div>
</template>