Browse Source

remove strange options

merge-requests/24/head
vargburz 2 years ago
parent
commit
f9d505fd92
  1. 63
      src/index.ts
  2. 4
      src/models/line-series.ts
  3. 8
      src/types.ts

63
src/index.ts

@ -1,5 +1,5 @@
import { ChartwerkPod, VueChartwerkPodMixin, TimeFormat, CrosshairOrientation, BrushOrientation } from '@chartwerk/core';
import { LineTimeSerie, LineOptions, Mode } from './types';
import { LineTimeSerie, LineOptions } from './types';
import { LineSeries } from './models/line-series';
@ -17,9 +17,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
constructor(_el: HTMLElement, _series: LineTimeSerie[] = [], _options: LineOptions = {}) {
super(_el, _series, _options);
console.log('coreSeries', this.coreSeries);
this.coreSeries = new LineSeries(_series);
console.log('lineseries', this.coreSeries);
}
renderMetrics(): void {
@ -34,7 +32,6 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
return;
}
console.log('series', this.coreSeries.visibleSeries)
for(const serie of this.coreSeries.visibleSeries) {
this._renderMetric(serie);
}
@ -129,30 +126,6 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
}
_renderMetric(serie: LineTimeSerie): void {
if(serie.mode === Mode.CHARGE) {
const dataPairs = d3.pairs(serie.datapoints);
this.metricContainer.selectAll(null)
.data(dataPairs)
.enter()
.append('line')
.attr('x1', d => this.state.xScale(d[0][0]))
.attr('x2', d => this.state.xScale(d[1][0]))
.attr('y1', d => this.state.yScale(d[0][1]))
.attr('y2', d => this.state.yScale(d[1][1]))
.attr('stroke-opacity', 0.7)
.style('stroke-width', 1)
.style('stroke', d => {
if(d[1][0] > d[0][0]) {
return 'green';
} else if (d[1][0] < d[0][0]) {
return 'red';
} else {
return 'gray';
}
});
return;
}
if(serie.renderLines === true) {
this._renderLines(serie);
}
@ -349,7 +322,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
let points = []; // datapoints in each metric that is closest to xValue/yValue position
this.coreSeries.visibleSeries.forEach((serie: LineTimeSerie) => {
const closestDatapoint = this.getClosestDatapoint(serie, xValue, yValue);
if(closestDatapoint === undefined || this.isOutOfRange(closestDatapoint, xValue, yValue, serie.useOutOfRange)) {
if(closestDatapoint === undefined) {
this.hideCrosshairCircle(serie.idx);
return;
}
@ -367,36 +340,6 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
return points;
}
isOutOfRange(closestDatapoint: [number, number], xValue: number, yValue: number, useOutOfRange = true): boolean {
// find is mouse position more than xRange/yRange from closest point
// TODO: refactor getValueInterval to remove this!
if(useOutOfRange === false) {
return false;
}
let columnIdx; // 1 for y value, 0 for x value
let value; // xValue ot y Value
switch(this.coreOptions.crosshair.orientation) {
case CrosshairOrientation.VERTICAL:
columnIdx = 0;
value = xValue;
break;
case CrosshairOrientation.HORIZONTAL:
columnIdx = 1;
value = yValue;
break;
case CrosshairOrientation.BOTH:
// TODO: maybe use voronoi
columnIdx = 1;
value = yValue;
default:
throw new Error(`Unknown type of crosshair orientaion: ${this.coreOptions.crosshair.orientation}`);
}
const range = Math.abs(closestDatapoint[columnIdx] - value);
const interval = this.getValueInterval(columnIdx); // interval between points
// do not move crosshair circles, it mouse to far from closest point
return interval === undefined || range > interval / 2;
}
onMouseOver(): void {
this.crosshair.style('display', null);
this.crosshair.selectAll('.crosshair-circle')
@ -488,4 +431,4 @@ export const VueChartwerkLinePod = {
}
};
export { LineTimeSerie, LineOptions, Mode, TimeFormat };
export { LineTimeSerie, LineOptions, TimeFormat };

4
src/models/line-series.ts

@ -1,13 +1,11 @@
import { CoreSeries } from '@chartwerk/core';
import { LineTimeSerie, Mode } from '../types';
import { LineTimeSerie } from '../types';
const LINE_SERIE_DEFAULTS = {
mode: Mode.STANDARD,
maxLength: undefined,
renderDots: false,
renderLines: true,
useOutOfRange: true, //?
dashArray: '0',
class: '',
renderArea: false,

8
src/types.ts

@ -1,19 +1,13 @@
import { Serie, Options } from '@chartwerk/core';
type LineTimeSerieParams = {
confidence: number,
mode: Mode,
maxLength: number,
renderDots: boolean,
renderLines: boolean, // TODO: refactor same as scatter-pod
useOutOfRange: boolean, // It's temporary hack. Need to refactor getValueInterval() method
dashArray: string; // dasharray attr, only for lines
class: string; // option to add custom class to each serie element
renderArea: boolean; // TODO: move to render type
}
export enum Mode {
STANDARD = 'Standard',
CHARGE = 'Charge'
}
export type LineTimeSerie = Serie & Partial<LineTimeSerieParams>;
export type LineOptions = Options;

Loading…
Cancel
Save