Skip to content

A full-featured download manager.

feat: task bitfield graphic

Dr_rOotc5962041cb44
diff --git a/src/renderer/components/TaskGraphic/Atom.vue b/src/renderer/components/TaskGraphic/Atom.vue
new file mode 100644
index 00000000..fe34bab6
--- /dev/null
+++ b/src/renderer/components/TaskGraphic/Atom.vue
@@ -0,0 +1,71 @@
+<template>
+ <rect
+ :class="klass"
+ :status="status"
+ :width="width"
+ :height="height"
+ :rx="radius"
+ :ry="radius"
+ :x="x"
+ :y="y"
+ >
+ </rect>
+</template>
+
+<script>
+ export default {
+ name: 'mo-task-graphic-atom',
+ props: {
+ status: {
+ type: Number
+ },
+ width: {
+ type: Number,
+ default: 10
+ },
+ height: {
+ type: Number,
+ default: 10
+ },
+ radius: {
+ type: Number,
+ default: 2
+ },
+ x: {
+ type: Number
+ },
+ y: {
+ type: Number
+ }
+ },
+ computed: {
+ klass () {
+ const { status } = this
+ return `graphic-atom graphic-atom-s${status}`
+ }
+ }
+ }
+</script>
+
+<style lang="scss">
+.graphic-atom {
+ shape-rendering: geometricPrecision;
+ outline-offset: -1px;
+}
+.graphic-atom-s1 {
+ fill: $--graphic-atom-color-1;
+ outline: 1px solid $--graphic-atom-outline-color;
+}
+.graphic-atom-s2 {
+ fill: $--graphic-atom-color-2;
+ outline: 1px solid $--graphic-atom-outline-color;
+}
+.graphic-atom-s3 {
+ fill: $--graphic-atom-color-3;
+ outline: 1px solid $--graphic-atom-outline-color;
+}
+.graphic-atom-s4 {
+ fill: $--graphic-atom-color-4;
+ outline: 1px solid $--graphic-atom-outline-color;
+}
+</style>
diff --git a/src/renderer/components/TaskGraphic/Index.vue b/src/renderer/components/TaskGraphic/Index.vue
new file mode 100644
index 00000000..5a7edfaf
--- /dev/null
+++ b/src/renderer/components/TaskGraphic/Index.vue
@@ -0,0 +1,127 @@
+<template>
+ <svg version="1.1"
+ xmlns="http://www.w3.org/2000/svg"
+ class="svg-task-graphic"
+ :width="width"
+ :height="height"
+ :viewBox="box">
+ <g v-for="(row, index) in atoms" :key="`g-${index}`" >
+ <mo-task-graphic-atom
+ v-for="atom in row"
+ :key="`atom-${atom.id}`"
+ :status="atom.status"
+ :width="atomWidth"
+ :height="atomHeight"
+ :radius="atomRadius"
+ :x="atom.x"
+ :y="atom.y"
+ />
+ </g>
+ </svg>
+</template>
+
+<script>
+ import Atom from './Atom'
+
+ export default {
+ name: 'mo-task-graphic',
+ components: {
+ [Atom.name]: Atom
+ },
+ props: {
+ bitfield: {
+ type: String,
+ default: ''
+ },
+ width: {
+ type: Number,
+ default: 240
+ },
+ atomWidth: {
+ type: Number,
+ default: 10
+ },
+ atomHeight: {
+ type: Number,
+ default: 10
+ },
+ atomGutter: {
+ type: Number,
+ default: 3
+ },
+ atomRadius: {
+ type: Number,
+ default: 2
+ }
+ },
+ computed: {
+ len () {
+ return this.bitfield.length
+ },
+ atomWG () {
+ return this.atomWidth + this.atomGutter
+ },
+ atomHG () {
+ return this.atomHeight + this.atomGutter
+ },
+ columnCount () {
+ const { width, atomWidth, atomWG } = this
+ const result = parseInt((width - atomWidth) / atomWG, 10) + 1
+ return result
+ },
+ rowCount () {
+ const { len, columnCount } = this
+ const result = parseInt((len / columnCount), 10) + 1
+ return result
+ },
+ offset () {
+ const { width, atomWidth, atomWG, columnCount } = this
+ const totalWidth = atomWG * (columnCount - 1) + atomWidth
+ const result = (width - totalWidth) / 2
+ return parseInt(result, 10)
+ },
+ height () {
+ const { atomHeight, atomHG, rowCount, offset } = this
+ const result = atomHG * (rowCount - 1) + atomHeight + offset * 2
+ return parseInt(result, 10)
+ },
+ box () {
+ return `0 0 ${this.width} ${this.height}`
+ },
+ atoms () {
+ const { len, columnCount } = this
+ const result = []
+ let row = []
+ for (let i = 0; i < len; i++) {
+ row.push(this.buildAtom(i))
+
+ if ((i + 1) % columnCount === 0) {
+ result.push(row)
+ row = []
+ }
+ }
+ result.push(row)
+
+ return result
+ }
+ },
+ methods: {
+ buildAtom (index) {
+ const { bitfield, offset, atomWG, atomHG, columnCount } = this
+ const hIndex = index + 1
+ let chIndex = index % columnCount
+ let rhIndex = parseInt((index / columnCount), 10)
+ chIndex = chIndex < 0 ? 0 : chIndex
+ rhIndex = rhIndex < 0 ? 0 : rhIndex
+ const result = {
+ id: `${hIndex}`,
+ status: Math.floor(parseInt(bitfield[index], 16) / 4) + 1,
+ x: offset + chIndex * atomWG,
+ y: offset + rhIndex * atomHG
+ }
+
+ return result
+ }
+ }
+ }
+</script>
diff --git a/src/renderer/components/Theme/Dark.scss b/src/renderer/components/Theme/Dark.scss
index c66c9e15..d97bdd6e 100644
--- a/src/renderer/components/Theme/Dark.scss
+++ b/src/renderer/components/Theme/Dark.scss
@@ -105,6 +105,15 @@
color: $--dk-no-task-color;
}
+ .graphic-box {
+ border-color: $--dk-task-detail-box-border;
+ background-color: $--dk-graphic-box-background;
+ }
+
+ .graphic-atom-s1 {
+ fill: $--dk-graphic-atom-color-1;
+ }
+
/* Element UI
-------------------------- */
.el-progress-bar__outer {
diff --git a/src/renderer/components/Theme/Dark/Variables.scss b/src/renderer/components/Theme/Dark/Variables.scss
index 54a43288..d8c79f35 100644
--- a/src/renderer/components/Theme/Dark/Variables.scss
+++ b/src/renderer/components/Theme/Dark/Variables.scss
@@ -67,6 +67,11 @@ $--dk-speedometer-primary-color: $--color-primary !default;
$--dk-speedometer-stopped-color: #9b9b9b !default;
$--dk-speedometer-text-color: #9b9b9b !default;
+/* Task Graphic
+-------------------------- */
+$--dk-graphic-box-background: #3f3f3f !default;
+$--dk-graphic-atom-color-1: #161b22 !default;
+
/* Element UI
-------------------------- */
$--dk-dialog-background: #343434 !default;
diff --git a/src/renderer/components/Theme/Default.scss b/src/renderer/components/Theme/Default.scss
index 3edf10c5..781f55c6 100644
--- a/src/renderer/components/Theme/Default.scss
+++ b/src/renderer/components/Theme/Default.scss
@@ -250,6 +250,15 @@ iframe {
background: $--form-actions-background;
}
+.graphic-box {
+ padding: 0.5rem;
+ margin-bottom: 1.5rem;
+ font-size: 0;
+ line-height: 0;
+ border: 1px solid $--task-detail-box-border;
+ border-radius: $--border-radius-base;
+}
+
@media only screen and (max-width:567px) {
.hidden-xs-only {
display:none!important
diff --git a/src/renderer/components/Theme/Light/Variables.scss b/src/renderer/components/Theme/Light/Variables.scss
index 3771eac8..7ee767ed 100644
--- a/src/renderer/components/Theme/Light/Variables.scss
+++ b/src/renderer/components/Theme/Light/Variables.scss
@@ -68,6 +68,15 @@ $--speedometer-primary-color: $--color-primary !default;
$--speedometer-stopped-color: #9b9b9b !default;
$--speedometer-text-color: #9b9b9b !default;
+/* Task Graphic
+-------------------------- */
+$--graphic-box-background: transparent !default;
+$--graphic-atom-outline-color: rgba(27, 31, 35, 0.06) !default;
+$--graphic-atom-color-1: #ebedf0 !default;
+$--graphic-atom-color-2: #9be9a8 !default;
+$--graphic-atom-color-3: #40c463 !default;
+$--graphic-atom-color-4: #30a14e !default;
+
/* Element UI
-------------------------- */
$--dialog-background: #fff !default;