Bläddra i källkod

[192-webreport] Fixed colors of matches, added navigation to MatchTable

Evgeni 4 år sedan
förälder
incheckning
074e5b6e3c

+ 13 - 1
report-viewer/src/assets/double_arrow_white_24dp.svg

@@ -1 +1,13 @@
-<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#FFFFFF"><g><rect fill="none" height="24" width="24"/><rect fill="none" height="24" width="24"/></g><g><g><path d="M20.08,11.42l-4.04-5.65C15.7,5.29,15.15,5,14.56,5h0c-1.49,0-2.35,1.68-1.49,2.89L16,12l-2.93,4.11 c-0.87,1.21,0,2.89,1.49,2.89h0c0.59,0,1.15-0.29,1.49-0.77l4.04-5.65C20.33,12.23,20.33,11.77,20.08,11.42z"/><path d="M13.08,11.42L9.05,5.77C8.7,5.29,8.15,5,7.56,5h0C6.07,5,5.2,6.68,6.07,7.89L9,12l-2.93,4.11C5.2,17.32,6.07,19,7.56,19h0 c0.59,0,1.15-0.29,1.49-0.77l4.04-5.65C13.33,12.23,13.33,11.77,13.08,11.42z"/></g></g></svg>
+<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px"
+     fill="#f3eed9">
+    <g>
+        <rect fill="none" height="24" width="24"/>
+        <rect fill="none" height="24" width="24"/>
+    </g>
+    <g>
+        <g>
+            <path d="M20.08,11.42l-4.04-5.65C15.7,5.29,15.15,5,14.56,5h0c-1.49,0-2.35,1.68-1.49,2.89L16,12l-2.93,4.11 c-0.87,1.21,0,2.89,1.49,2.89h0c0.59,0,1.15-0.29,1.49-0.77l4.04-5.65C20.33,12.23,20.33,11.77,20.08,11.42z"/>
+            <path d="M13.08,11.42L9.05,5.77C8.7,5.29,8.15,5,7.56,5h0C6.07,5,5.2,6.68,6.07,7.89L9,12l-2.93,4.11C5.2,17.32,6.07,19,7.56,19h0 c0.59,0,1.15-0.29,1.49-0.77l4.04-5.65C13.33,12.23,13.33,11.77,13.08,11.42z"/>
+        </g>
+    </g>
+</svg>

+ 12 - 0
report-viewer/src/assets/keyboard_double_arrow_left_white_18dp.svg

@@ -0,0 +1,12 @@
+<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 20 20" height="18px" viewBox="0 0 20 20" width="18px"
+     fill="#f3eed9">
+    <g>
+        <rect fill="none" height="20" width="20"/>
+    </g>
+    <g>
+        <g>
+            <path d="M15.37,14.47L15.37,14.47c0.29-0.29,0.29-0.77,0-1.06L11.96,10l3.41-3.41c0.29-0.29,0.29-0.77,0-1.06l0,0 c-0.29-0.29-0.77-0.29-1.06,0l-3.76,3.76c-0.39,0.39-0.39,1.02,0,1.41l3.76,3.76C14.6,14.76,15.07,14.76,15.37,14.47z"/>
+            <path d="M9.43,14.47L9.43,14.47c0.29-0.29,0.29-0.77,0-1.06L6.02,10l3.41-3.41c0.29-0.29,0.29-0.77,0-1.06l0,0 c-0.29-0.29-0.77-0.29-1.06,0L4.6,9.29c-0.39,0.39-0.39,1.02,0,1.41l3.76,3.76C8.66,14.76,9.13,14.76,9.43,14.47z"/>
+        </g>
+    </g>
+</svg>

+ 13 - 0
report-viewer/src/assets/keyboard_double_arrow_left_white_24dp.svg

@@ -0,0 +1,13 @@
+<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px"
+     fill="#f3eed9">
+    <g>
+        <rect fill="none" height="24" width="24"/>
+        <rect fill="none" height="24" width="24"/>
+    </g>
+    <g>
+        <g>
+            <path d="M18.29,17.29L18.29,17.29c0.39-0.39,0.39-1.02,0-1.41L14.42,12l3.88-3.88c0.39-0.39,0.39-1.02,0-1.41l0,0 c-0.39-0.39-1.02-0.39-1.41,0l-4.59,4.59c-0.39,0.39-0.39,1.02,0,1.41l4.59,4.59C17.27,17.68,17.9,17.68,18.29,17.29z"/>
+            <path d="M11.7,17.29L11.7,17.29c0.39-0.39,0.39-1.02,0-1.41L7.83,12l3.88-3.88c0.39-0.39,0.39-1.02,0-1.41l0,0 c-0.39-0.39-1.02-0.39-1.41,0l-4.59,4.59c-0.39,0.39-0.39,1.02,0,1.41l4.59,4.59C10.68,17.68,11.31,17.68,11.7,17.29z"/>
+        </g>
+    </g>
+</svg>

+ 8 - 7
report-viewer/src/components/CodePanel.vue

@@ -13,11 +13,10 @@
                 :color="coloringArray[index]"
                 :line-number="index"
                 :text="line"
-                :id="panelId.concat(title).concat(index)"
-                :match-link="linksArray[index]"
+                :id="String(panelId).concat(title).concat(index)"
                 :is-last="isLast[index]"
                 :is-first="isFirst[index]"
-                  @click="$emit('lineSelected', $event, fileIndex, linksArray[index] )"/>
+                  @click="$emit('lineSelected', $event, linksArray[index].panel, linksArray[index].file, linksArray[index].line )"/>
     </div>
   </div>
 </template>
@@ -25,6 +24,7 @@
 <script>
 import {ref, defineComponent, watchEffect} from "vue";
 import LineOfCode from "./LineOfCode";
+import {generateLineCodeLink} from "@/utils/Utils";
 
 export default defineComponent({
   name: "CodePanel",
@@ -44,7 +44,7 @@ export default defineComponent({
       type: Array
     },
     panelId: {
-      type: String
+      type: Number
     },
     collapse: {
       type: Boolean
@@ -62,7 +62,7 @@ export default defineComponent({
     props.matches.forEach(m => {
       for (let i = m.start; i <= m.end; i++) {
         coloringArray.value[i] = m.color
-        linksArray.value[i] = m.link
+        linksArray.value[i] = { panel : m.linked_panel, file : m.linked_file, line : m.linked_line }
         if(i === m.start) {
           isFirst.value[i] = true
         }
@@ -96,6 +96,8 @@ export default defineComponent({
 .code-panel-container {
   display: flex;
   flex-direction: column;
+  margin-left: 1%;
+  margin-right: 1%;
   margin-bottom: 3%;
   border-radius: 10px;
   box-shadow: var(--shadow-color) 2px 3px 3px;
@@ -117,10 +119,9 @@ export default defineComponent({
   align-items: flex-start;
   margin: 1%;
   padding: 1%;
-  height: 100vw;
   background: var(--background-color-accent);
   box-shadow: inset var(--shadow-color) 0 0 3px 1px;
-  overflow: scroll;
+  overflow: auto;
 }
 
 .collapse-button {

+ 2 - 5
report-viewer/src/components/LineOfCode.vue

@@ -19,7 +19,6 @@ export default defineComponent({
       required: true
     },
     color: {
-      type: String,
       required:true
     },
     startOfMatch: {
@@ -28,9 +27,6 @@ export default defineComponent({
     fileIndex: {
       type: Number,
     },
-    matchLink: {
-      type: String
-    },
     isFirst: {
       type: Boolean,
     },
@@ -38,7 +34,8 @@ export default defineComponent({
       type: Boolean,
     }
   },
-  setup() {
+  setup(props) {
+    console.log(props.color)
     return {
     }
   }

+ 99 - 0
report-viewer/src/components/MatchTable.vue

@@ -0,0 +1,99 @@
+<template>
+<div class="match-table-container">
+  <table>
+    <tr>
+      <th>{{ id1 }}</th>
+      <th>{{ id2 }}</th>
+    </tr>
+    <tr>
+      <th>File 1</th>
+      <th>File 2</th>
+      <th>Tokens</th>
+    </tr>
+    <tr v-for="( match, index ) in matches" :key="String(index).concat(match.start_in_first).concat(match.start_in_second)"
+        @click="$emit('matchSelected', $event, match)"
+        :style="{ background : match.color }">
+      <td>
+        <div class="td-content">
+          <p>{{ match.first_file_name }}</p>
+          <p>({{ match.start_in_first }} - {{ match.end_in_first }})</p>
+        </div>
+      </td>
+      <td>
+        <div class="td-content">
+          <p>{{ match.second_file_name }}</p>
+          <p>({{ match.start_in_second }} - {{ match.start_in_second }})</p>
+        </div>
+      </td>
+      <td>TODO</td>
+    </tr>
+  </table>
+</div>
+</template>
+
+<script>
+import { defineComponent } from "vue";
+
+export default defineComponent({
+  name: "MatchTable",
+  props: {
+    matches : {
+      type: Array
+    },
+    id1: {
+      type: String
+    },
+    id2: {
+      type: String
+    }
+  },
+  setup(props) {
+
+    return {
+
+    }
+  }
+})
+</script>
+
+<style scoped>
+.match-table-container {
+  width: 100%;
+  margin-top: 2%;
+  padding: 1%;
+  background: var(--quaternary-color);
+  border-radius: 10px;
+  overflow: auto;
+}
+
+.td-content {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  flex-wrap: nowrap;
+  padding: 5%;
+}
+
+.td-content > p {
+  margin: 0;
+}
+
+table {
+  border-collapse: collapse;
+  width: 100%;
+}
+
+th {
+  color: var(--on-primary-color);
+  text-align: center;
+
+}
+
+td {
+  font-size: small;
+  text-align: center;
+  padding: 2%;
+  border-bottom: solid var(--quaternary-color);
+  border-top: solid var(--quaternary-color);
+}
+</style>

+ 27 - 4
report-viewer/src/utils/Utils.ts

@@ -1,9 +1,12 @@
 export function convertToFilesByName(files: Array<Record<string, unknown>>): Record<string, unknown> {
     return files.reduce( (acc: Record<string, unknown>, val: Record<string, unknown>) => {
         if(!acc[val.file_name as string]) {
-            acc[val.file_name as string] = []
+            acc[val.file_name as string] = {}
+        }
+        acc[val.file_name as string] = {
+            lines: val.lines,
+            collapsed: false
         }
-        acc[val.file_name as string] = val.lines
         return acc;
     }, {})
 }
@@ -18,7 +21,9 @@ export function groupMatchesByFileName(matches: Array<Record<string, unknown>>,
             const newVal = {
                 start : val.start_in_first,
                 end: val.end_in_first,
-                link: "2".concat(val.second_file_name as string).concat(String(val.start_in_second as number)),
+                linked_panel: 2,
+                linked_file: val.second_file_name,
+                linked_line: val.start_in_second,
                 color: val.color
             }
             acc[name].push(newVal)
@@ -26,7 +31,9 @@ export function groupMatchesByFileName(matches: Array<Record<string, unknown>>,
             const newVal = {
                 start : val.start_in_second,
                 end: val.end_in_second,
-                link: "1".concat(val.first_file_name as string).concat(String(val.start_in_first as number)),
+                linked_panel: 1,
+                linked_file: val.first_file_name,
+                linked_line: val.start_in_first,
                 color: val.color
             }
             acc[name].push(newVal)
@@ -35,6 +42,10 @@ export function groupMatchesByFileName(matches: Array<Record<string, unknown>>,
     }, {})
 }
 
+export function generateLineCodeLink(index: number, fileName: string, line: number): string {
+    return String(index).concat(fileName).concat(String(line))
+}
+
 export function generateColoringArray(array: Array<Record<string, unknown>>, fileToConsider: number): Array<Record<string, unknown>> {
     switch (fileToConsider) {
         case 1:
@@ -56,4 +67,16 @@ export function generateColor(): string {
     for (let i = 0; i < 3; i++)
         color += ("0" + Math.floor(((1 + Math.random()) * Math.pow(16, 2)) / 2).toString(16)).slice(-2);
     return color;
+}
+
+export function generateColorsForMatches( num : number ): Array<unknown> {
+    const colors = []
+    const hueDelta = Math.trunc(360 / (num) )
+
+    for( let i = 0; i < num; i++ ) {
+        const hue = i * hueDelta
+
+        colors.push(`hsla(${hue}, 80%, 50%, 0.5)`)
+    }
+    return colors
 }

+ 63 - 28
report-viewer/src/views/ComparisonView2.vue

@@ -1,41 +1,46 @@
 <template>
   <div class="container">
-    <button id="show-button" v-bind:class="{hidden : !hideLeftPanel}" @click="togglePanel" title="Show sidebar">
+    <button id="show-button" :class="{hidden : !hideLeftPanel}" @click="togglePanel" title="Show sidebar">
       <img src="@/assets/double_arrow_white_24dp.svg" alt="show">
     </button>
     <div id="sidebar" :class="{ hidden : hideLeftPanel }">
-      <button id="hide-button" @click="togglePanel" title="Hide sidebar"><img src="@/assets/double_arrow_white_24dp.svg" alt="hide"></button>
+      <div class="title-section">
+        <h1>JPlag Comparison</h1>
+        <button id="hide-button" @click="togglePanel" title="Hide sidebar">
+          <img src="@/assets/keyboard_double_arrow_left_white_24dp.svg" alt="hide"></button>
+      </div>
       <TextInformation label="Submission 1" :value="id1" :has-additional-info="false"/>
       <TextInformation label="Submission 2" :value="id2" :has-additional-info="false"/>
       <TextInformation label="Match %" :value="json.match_percentage" :has-additional-info="false"/>
+      <MatchTable :matches="coloredMatches" :id1="id1" :id2="id2" @match-selected="showMatch" />
     </div>
     <div class="files-container" id="files1">
       <VueDraggableNext>
       <CodePanel v-for="(file, index) in Object.keys(filesOfFirst)"
-                 :lines="filesOfFirst[file]"
+                 :lines="filesOfFirst[file].lines"
                  :title="file"
                  :file-index="index"
                  :matches="!matchesInFirst[file] ? [] : matchesInFirst[file]"
                  :key="file.concat(index)"
-                 :collapse="filesOfFirstCollapsed[index]"
-                 @toggle-collapse="toggleCollapseFirst(index)"
+                 :collapse="filesOfFirst[file].collapsed"
+                 @toggle-collapse="toggleCollapseFirst(file)"
                  @line-selected="showMatchInSecond"
-                 panel-id="1"
+                 :panel-id="1"
       />
       </VueDraggableNext>
     </div>
     <div class="files-container" id="files2">
       <VueDraggableNext>
         <CodePanel v-for="(file, index) in Object.keys(filesOfSecond)"
-                   :lines="filesOfSecond[file]"
+                   :lines="filesOfSecond[file].lines"
                    :title="file"
                    :file-index="index"
                    :matches="!matchesInSecond[file] ? [] : matchesInSecond[file]"
                    :key="file.concat(index)"
-                   :collapse="filesOfSecondCollapsed[index]"
-                   @toggle-collapse="toggleCollapseSecond(index)"
+                   :collapse="filesOfSecond[file].collapsed"
+                   @toggle-collapse="toggleCollapseSecond(file)"
                    @line-selected="showMatchInFirst"
-                   panel-id="2"
+                   :panel-id="2"
                    />
       </VueDraggableNext>
     </div>
@@ -44,14 +49,15 @@
 
 <script>
 import { defineComponent, ref } from "vue";
-import {convertToFilesByName, generateColor, groupMatchesByFileName} from "@/utils/Utils";
+import {convertToFilesByName, generateColor, generateColorsForMatches,generateLineCodeLink, groupMatchesByFileName} from "@/utils/Utils";
 import { VueDraggableNext } from 'vue-draggable-next'
 import CodePanel from "@/components/CodePanel";
 import TextInformation from "@/components/TextInformation";
+import MatchTable from "@/components/MatchTable";
 
 export default defineComponent({
   name: "ComparisonView2",
-  components: {TextInformation, VueDraggableNext, CodePanel},
+  components: {MatchTable, TextInformation, VueDraggableNext, CodePanel},
   props: {
     id1: {
       type: String,
@@ -65,28 +71,35 @@ export default defineComponent({
     // eslint-disable-next-line @typescript-eslint/no-var-requires
     const json = require(`../files/${fileName}.json`)
 
-    const filesOfFirst = convertToFilesByName(json.files_of_first_submission)
-    const filesOfSecond = convertToFilesByName(json.files_of_second_submission)
-    const filesOfFirstCollapsed = ref(Object.keys(filesOfFirst).map( _ => false ))
-    const filesOfSecondCollapsed = ref(Object.keys(filesOfSecond).map( _ => false ))
-    const coloredMatches = json.matches.map( m => { return {...m, color : generateColor()} })
+    const filesOfFirst = ref(convertToFilesByName(json.files_of_first_submission))
+    const filesOfSecond = ref(convertToFilesByName(json.files_of_second_submission))
+    const filesOfFirstCollapsed = ref(Object.keys(filesOfFirst.value).map( _ => false ))
+    const filesOfSecondCollapsed = ref(Object.keys(filesOfSecond.value).map( _ => false ))
+    const colors = generateColorsForMatches(json.matches.length)
+    const coloredMatches = json.matches.map( (m, index) => { return {...m, color : colors[index]} })
 
     const matchesInFirst = groupMatchesByFileName(coloredMatches, 1)
     const matchesInSecond = groupMatchesByFileName(coloredMatches, 2)
 
-    const toggleCollapseFirst = (index) => { filesOfFirstCollapsed.value[index] = !filesOfFirstCollapsed.value[index] }
-    const toggleCollapseSecond = (index) => { filesOfSecondCollapsed.value[index] = !filesOfSecondCollapsed.value[index] }
+    const toggleCollapseFirst = (title) => { filesOfFirst.value[title].collapsed = !filesOfFirst.value[title].collapsed }
+    const toggleCollapseSecond = (title) => { filesOfSecond.value[title].collapsed = !filesOfSecond.value[title].collapsed }
 
-    const showMatchInFirst = ( e, fileIndex, matchLink ) => {
-      if( !filesOfFirstCollapsed.value[fileIndex] ) { toggleCollapseFirst(fileIndex) }
-      document.getElementById(matchLink).scrollIntoView()
+    const showMatchInFirst = ( e, panel, file, line ) => {
+      if( !filesOfFirst.value[file].collapsed ) { toggleCollapseFirst(file) }
+      document.getElementById(generateLineCodeLink(panel, file, line)).scrollIntoView()
     }
 
-    const showMatchInSecond = ( e, fileIndex, matchLink ) => {
-      if( !filesOfSecondCollapsed.value[fileIndex] ) { toggleCollapseSecond(fileIndex) }
-      document.getElementById(matchLink).scrollIntoView()
+    const showMatchInSecond = ( e, panel, file, line ) => {
+      if( !filesOfSecond.value[file].collapsed ) { toggleCollapseSecond(file) }
+      document.getElementById(generateLineCodeLink(panel, file, line)).scrollIntoView()
     }
 
+    const showMatch = ( e, match ) => {
+      showMatchInFirst(e, 1, match.first_file_name, match.start_in_first)
+      showMatchInSecond(e, 2, match.second_file_name, match.start_in_second)
+    }
+
+
     const hideLeftPanel = ref(true)
     const togglePanel = () => {
       hideLeftPanel.value = !hideLeftPanel.value
@@ -100,12 +113,14 @@ export default defineComponent({
       filesOfSecondCollapsed,
       matchesInFirst,
       matchesInSecond,
+      coloredMatches,
       hideLeftPanel,
 
       toggleCollapseFirst,
       toggleCollapseSecond,
       showMatchInFirst,
       showMatchInSecond,
+      showMatch,
       togglePanel
     }
   }
@@ -126,12 +141,20 @@ export default defineComponent({
   display: flex;
   flex-wrap: nowrap;
   flex-direction: column;
+  padding-top: 1%;
   width: 100%;
-  height: max-content;
-  padding: 1%;
   overflow: auto;
 }
 
+.title-section {
+  display: flex;
+  justify-content: space-between;
+}
+
+.title-section > h1 {
+  color: var(--on-primary-color);
+}
+
 .hidden {
   display: none !important;
 }
@@ -139,16 +162,28 @@ export default defineComponent({
 #sidebar {
   display: flex;
   flex-direction: column;
-  height: 100%;
+  flex-wrap: nowrap;
+  width: 60%;
   background: var(--primary-color-light);
   padding: 1%;
+  border-top-right-radius: 10px;
+  border-bottom-right-radius: 10px;
 }
 
 #hide-button {
+  display: flex;
+  flex-direction: column;
   background: transparent;
+  border-radius: 10px;
+  height: max-content;
   border: none;
 }
 
+#hide-button:hover {
+  cursor: pointer;
+  background: var(--primary-color-dark);
+}
+
 #show-button {
   position: absolute;
   z-index: 1000;

+ 0 - 1
report-viewer/src/views/Overview.vue

@@ -94,7 +94,6 @@ export default defineComponent({
 
 <style scoped>
 h1 {
-  font-family: "League Spartan";
   text-align: left;
   margin-top: 2%;
   color: var(--on-background-color);