Browse Source

use core 060

merge-requests/24/head
vargburz 3 years ago
parent
commit
b65b04c574
  1. 40
      src/index.ts
  2. 6
      yarn.lock

40
src/index.ts

@ -17,7 +17,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
constructor(_el: HTMLElement, _series: LineTimeSerie[] = [], _options: LineOptions = {}) {
super(_el, _series, _options);
this.coreSeries = new LineSeries(_series);
this.series = new LineSeries(_series);
}
renderMetrics(): void {
@ -27,12 +27,12 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
this.initLineGenerator();
this.initAreaGenerator();
if(!this.coreSeries.isSeriesAvailable) {
if(!this.series.isSeriesAvailable) {
this.renderNoDataPointsMessage();
return;
}
for(const serie of this.coreSeries.visibleSeries) {
for(const serie of this.series.visibleSeries) {
this._renderMetric(serie);
}
}
@ -111,7 +111,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
appendCrosshairCircles(): void {
// circle for each serie
this.coreSeries.visibleSeries.forEach((serie: LineTimeSerie, serieIdx: number) => {
this.series.visibleSeries.forEach((serie: LineTimeSerie, serieIdx: number) => {
this.appendCrosshairCircle(serieIdx);
});
}
@ -124,7 +124,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
.attr('cx', -CROSSHAIR_BACKGROUND_RAIDUS)
.attr('cy', -CROSSHAIR_BACKGROUND_RAIDUS)
.attr('clip-path', `url(#${this.rectClipId})`)
.attr('fill', this.coreSeries.visibleSeries[serieIdx].color)
.attr('fill', this.series.visibleSeries[serieIdx].color)
.style('opacity', CROSSHAIR_BACKGROUND_OPACITY)
.style('pointer-events', 'none');
@ -134,7 +134,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
.attr('cy', -CROSSHAIR_CIRCLE_RADIUS)
.attr('class', `crosshair-circle-${serieIdx}`)
.attr('clip-path', `url(#${this.rectClipId})`)
.attr('fill', this.coreSeries.visibleSeries[serieIdx].color)
.attr('fill', this.series.visibleSeries[serieIdx].color)
.attr('r', CROSSHAIR_CIRCLE_RADIUS)
.style('pointer-events', 'none');
}
@ -146,7 +146,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
this.moveCrosshairLine(eventX, eventY);
const datapoints = this.findAndHighlightDatapoints(values.x, values.y);
this.coreOptions.callbackSharedCrosshairMove({
this.options.callbackSharedCrosshairMove({
datapoints: datapoints,
eventX, eventY
});
@ -157,7 +157,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
}
moveCrosshairLine(xPosition: number, yPosition: number): void {
switch(this.coreOptions.crosshair.orientation) {
switch(this.options.crosshair.orientation) {
case CrosshairOrientation.VERTICAL:
this.crosshair.select('#crosshair-line-x')
.attr('x1', xPosition)
@ -177,7 +177,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
.attr('y2', yPosition);
return;
default:
throw new Error(`Unknown type of crosshair orientaion: ${this.coreOptions.crosshair.orientation}`);
throw new Error(`Unknown type of crosshair orientaion: ${this.options.crosshair.orientation}`);
}
}
@ -205,7 +205,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
getClosestIndex(datapoints: [number, number][], xValue: number, yValue: number): number {
let columnIdx; // 0 for x value, 1 for y value,
let value; // xValue to y Value
switch(this.coreOptions.crosshair.orientation) {
switch(this.options.crosshair.orientation) {
case CrosshairOrientation.VERTICAL:
columnIdx = 0;
value = xValue;
@ -219,7 +219,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
columnIdx = 1;
value = yValue;
default:
throw new Error(`Unknown type of crosshair orientaion: ${this.coreOptions.crosshair.orientation}`);
throw new Error(`Unknown type of crosshair orientaion: ${this.options.crosshair.orientation}`);
}
// TODO: d3.bisect is not the best way. Use binary search
@ -248,7 +248,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
// columnIdx: 1 for y, 0 for x
// inverval: x/y value interval between data points
// TODO: move it to base/state instead of timeInterval
const intervals = _.map(this.coreSeries.visibleSeries, serie => {
const intervals = _.map(this.series.visibleSeries, serie => {
if(serie.datapoints.length < 2) {
return undefined;
}
@ -272,7 +272,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
// TDOO: is shift key pressed
// TODO: need to refactor this object
this.coreOptions.callbackMouseMove({
this.options.callbackMouseMove({
x: d3.event.pageX,
y: d3.event.pageY,
xVal: xValue,
@ -284,11 +284,11 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
}
findAndHighlightDatapoints(xValue: number, yValue: number): { value: [number, number], color: string, label: string }[] {
if(!this.coreSeries.isSeriesAvailable) {
if(!this.series.isSeriesAvailable) {
return [];
}
let points = []; // datapoints in each metric that is closest to xValue/yValue position
this.coreSeries.visibleSeries.forEach((serie: LineTimeSerie) => {
this.series.visibleSeries.forEach((serie: LineTimeSerie) => {
const closestDatapoint = this.getClosestDatapoint(serie, xValue, yValue);
if(closestDatapoint === undefined) {
this.hideCrosshairCircle(serie.idx);
@ -315,21 +315,21 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
}
onMouseOut(): void {
this.coreOptions.callbackMouseOut();
this.options.callbackMouseOut();
this.crosshair.style('display', 'none');
}
isDoubleClickActive(): boolean {
return this.coreOptions.doubleClickEvent.isActive;
return this.options.doubleClickEvent.isActive;
}
// methods below rewrite cores, (move more methods here)
// methods below rewrite s, (move more methods here)
protected zoomOut(): void {
if(d3.event.type === 'dblclick' && !this.isDoubleClickActive()) {
return;
}
// TODO: its not clear, why we use this orientation here. Mb its better to use separate option
const orientation: BrushOrientation = this.coreOptions.mouseZoomEvent.orientation;
const orientation: BrushOrientation = this.options.mouseZoomEvent.orientation;
const xInterval = this.state.xValueRange[1] - this.state.xValueRange[0];
const yInterval = this.state.yValueRange[1] - this.state.yValueRange[0];
switch(orientation) {
@ -364,7 +364,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
x: xAxisMiddleValue,
y: yAxisMiddleValue
}
this.coreOptions.callbackZoomOut(centers);
this.options.callbackZoomOut(centers);
}
}

6
yarn.lock

@ -6,12 +6,12 @@ __metadata:
cacheKey: 8
"@chartwerk/core@npm:latest":
version: 0.5.8
resolution: "@chartwerk/core@npm:0.5.8"
version: 0.6.0
resolution: "@chartwerk/core@npm:0.6.0"
dependencies:
d3: ^5.7.2
lodash: ^4.14.149
checksum: 24b403af2703cc99ef3dee4793318ed71f4b02ed50bee6940774ccb392b8fbb53bb5353e91903b2c1ec815a8d2b830f2a2a2925d8e4380c64895ee2002b2baed
checksum: db368ea1ba1f9b48583c3da953998206329ea552eaff4e9f13cb02b25e0289464eca268baa86f045d62552a0859fc3ee2ccf70e7df95b58327bba217f9888169
languageName: node
linkType: hard

Loading…
Cancel
Save