Skip to content

Commit

Permalink
feat: change chart to origin
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 21, 2020
1 parent cfc245e commit ffc1e2b
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div #baseElement id="markdown-radar">
<div id="chart"></div>
<div id="chart" #chart></div>
<markdown-rating
class="rating-list"
id="rating"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
align-items: flex-start;
}

#chart {
height: 800px;
width: 800px;
}

.rating-list {
margin-top: 5em;
margin-left: 5em;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { AfterViewInit, Component, ElementRef, forwardRef, OnInit, ViewChild } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import MarkdownHelper from '../model/markdown.helper';
import { MarkdownListModel } from '../model/markdown.model';
import * as echarts from "echarts";
import ChartOptions from '../../support/chart-options';
import MarkdownHelper from '../model/markdown.helper';

@Component({
selector: 'component-markdown-radar-chart',
Expand All @@ -17,6 +19,8 @@ import { MarkdownListModel } from '../model/markdown.model';
})
export class MarkdownRadarChartComponent implements OnInit, AfterViewInit, ControlValueAccessor {
@ViewChild('baseElement', {}) baseElement: ElementRef;
@ViewChild('chart', {}) chartEl: ElementRef;

items: any[];
data: any[] = [];
value: any;
Expand Down Expand Up @@ -67,24 +71,26 @@ export class MarkdownRadarChartComponent implements OnInit, AfterViewInit, Contr

private taskToData() {
const current: any[] = [];
const future: any[] = [];
for (const task of this.items) {
const item: MarkdownListModel = task.item;
MarkdownHelper.buildRatingValue(item);

current.push({axis: item.chartText, value: item.chartValue});
future.push({axis: item.chartText, value: item.chartFutureValue});
current.push({name: item.text});
}

return [current, future];
return current;
}

/* tslint:disable */
render() {
if (!this.items) {
return;
}
this.data = this.taskToData();

const myChart = echarts.init(this.chartEl.nativeElement);
let option = ChartOptions.buildRadarChartOption({
name: '',
children: this.data
});
myChart.setOption(option)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<mat-slider
min="1" max="5" step="1"
*ngIf="isParent"
[(ngModel)]="item.chartFutureValue"
[(ngModel)]="item.chartValue"
(change)="updateValue($event)"
>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ export class MarkdownRatingItemComponent implements OnInit {
writeValue(obj: any): void {
if (obj !== null && obj !== undefined) {
this.item = obj;
if (this.item && !this.item.completed) {
this.item.completed = false;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, forwardRef, Input, OnInit } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import {MarkdownTaskItemService} from '../markdown-task-item.service';
import MarkdownHelper from '../../model/markdown.helper';

@Component({
selector: 'markdown-rating',
Expand Down Expand Up @@ -55,9 +56,9 @@ export class MarkdownRatingComponent implements OnInit, ControlValueAccessor {
const execArray = /(.*)\:\s*(\d)/.exec(item.originText);
if (execArray && execArray.length >= 3) {
const text = execArray[1];
item.originText = text + ':' + item.value;
item.originText = text + ': ' + item.value;
} else {
item.originText = item.originText + ':' + item.value;
item.originText = item.originText + ': ' + item.value;
}

const list = this.markdownTaskItemService.updateTask(null, item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ export class MarkdownRenderComponent implements OnInit, OnChanges, AfterViewInit
let top = 0;
if (this.drawerEl) {
top = this.drawerEl.elementRef.nativeElement.scrollTop;
console.log(top);
}

if (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || top > 64) {
Expand Down Expand Up @@ -133,7 +132,6 @@ export class MarkdownRenderComponent implements OnInit, OnChanges, AfterViewInit
this.route.fragment.subscribe((fragment: string) => {
if (!!fragment) {
const element = this.myElement.nativeElement.querySelector('#' + fragment);
console.log(element);
if (!!element) {
element.scrollIntoView();
}
Expand Down
15 changes: 3 additions & 12 deletions src/app/shared/components/model/markdown.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,13 @@ const MarkdownHelper = {
let text = item.text;
let value = 3;

const execArray = /(.*)\:\s*(\d),?\s*(\d)?/.exec(text);
const execArray = /(.*):\s*(\d)/.exec(text);
if (execArray && execArray.length >= 3) {
text = execArray[1];
value = parseInt(execArray[2], 10);

item.chartText = text;
item.chartValue = value;
item.chartFutureValue = value;

if (execArray.length === 4 && execArray[3]) {
item.chartFutureValue = parseInt(execArray[3], 10);
}
}

return item;
Expand All @@ -216,13 +211,9 @@ const MarkdownHelper = {
const execArray = /(.*)\:\s*(\d)/.exec(item.text);
if (execArray && execArray.length >= 3) {
const text = execArray[1];
item.text = text + ':' + item.chartValue;
item.text = text + ': ' + item.chartValue;
} else {
item.text = item.text + ':' + item.chartValue;
}

if (!!item.chartFutureValue) {
item.text = item.text + ',' + item.chartFutureValue;
item.text = item.text + ': ' + item.chartValue;
}

return item;
Expand Down

0 comments on commit ffc1e2b

Please sign in to comment.