Browse Source

use metric container from core

merge-requests/12/head
vargburz 3 years ago
parent
commit
16618409a2
  1. 2
      dist/index.d.ts
  2. 4
      dist/index.js
  3. 2
      examples/demo.html
  4. 6
      package-lock.json
  5. 2
      package.json
  6. 20
      src/index.ts

2
dist/index.d.ts vendored

@ -2,9 +2,9 @@ import { ChartwerkPod, TickOrientation, TimeFormat } from '@chartwerk/core';
import { LineTimeSerie, LineOptions, Mode } from './types'; import { LineTimeSerie, LineOptions, Mode } from './types';
export declare class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { export declare class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
lineGenerator: any; lineGenerator: any;
metricContainer: any;
constructor(_el: HTMLElement, _series?: LineTimeSerie[], _options?: LineOptions); constructor(_el: HTMLElement, _series?: LineTimeSerie[], _options?: LineOptions);
renderMetrics(): void; renderMetrics(): void;
clearAllMetrics(): void;
initLineGenerator(): void; initLineGenerator(): void;
appendData(data: [number, number][]): void; appendData(data: [number, number][]): void;
_renderDots(datapoints: number[][], serieIdx: number): void; _renderDots(datapoints: number[][], serieIdx: number): void;

4
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
examples/demo.html

@ -16,7 +16,7 @@
const data2 = Array.from({ length: arrayLength }, (el, idx) => [startTime + idx * 10000, Math.floor(Math.random() * 100)]); const data2 = Array.from({ length: arrayLength }, (el, idx) => [startTime + idx * 10000, Math.floor(Math.random() * 100)]);
const data3 = Array.from({ length: arrayLength }, (el, idx) => [startTime + idx * 10000, Math.floor(Math.random() * 20) + 90]); const data3 = Array.from({ length: arrayLength }, (el, idx) => [startTime + idx * 10000, Math.floor(Math.random() * 20) + 90]);
const zoomIn = (ranges) => { pod.render(); } const zoomIn = (ranges) => { pod.render(); }
const zoomOut = (ranges) => { console.log('zoomout'); options.axis.x.range = undefined; pod.updateData(undefined, options) } const zoomOut = (ranges) => { pod.state.xValueRange = [startTime, startTime + arrayLength * 10000]; pod.render(); }
let options = { let options = {
renderLegend: false, usePanning: false, axis: { y: { invert: false, range: [0, 350] }, x: { format: 'time' } }, renderLegend: false, usePanning: false, axis: { y: { invert: false, range: [0, 350] }, x: { format: 'time' } },
eventsCallbacks: { zoomIn: zoomIn, zoomOut } eventsCallbacks: { zoomIn: zoomIn, zoomOut }

6
package-lock.json generated

@ -5,9 +5,9 @@
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@chartwerk/core": { "@chartwerk/core": {
"version": "0.3.0", "version": "0.3.1",
"resolved": "https://registry.npmjs.org/@chartwerk/core/-/core-0.3.0.tgz", "resolved": "https://registry.npmjs.org/@chartwerk/core/-/core-0.3.1.tgz",
"integrity": "sha512-Dnw/akMqBvWEQDlzcendAzHsqzLE+jcWVU7fYnsXLFKCZT+JJL2cMpBv/aZ24/pw7WZQg2ORdLgAfLc3Ph9kuA==" "integrity": "sha512-7uTNeV2+ln2WFQQpbJaYR8o0DmCoLhiMjQagLH8VsETVVCxI7YmgxYVVhx6OGE25miJHXwhRlplopDs6dWF5KQ=="
}, },
"@types/d3": { "@types/d3": {
"version": "5.16.4", "version": "5.16.4",

2
package.json

@ -15,7 +15,7 @@
"author": "CorpGlory", "author": "CorpGlory",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@chartwerk/core": "^0.3.0" "@chartwerk/core": "^0.3.1"
}, },
"devDependencies": { "devDependencies": {
"@types/d3": "5.16.4", "@types/d3": "5.16.4",

20
src/index.ts

@ -11,14 +11,13 @@ const CROSSHAIR_BACKGROUND_OPACITY = 0.3;
export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> { export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
lineGenerator = null; lineGenerator = null;
metricContainer = null;
constructor(_el: HTMLElement, _series: LineTimeSerie[] = [], _options: LineOptions = {}) { constructor(_el: HTMLElement, _series: LineTimeSerie[] = [], _options: LineOptions = {}) {
super(d3, _el, _series, _options); super(d3, _el, _series, _options);
} }
renderMetrics(): void { renderMetrics(): void {
this.d3.select('.metrics-container').remove(); this.clearAllMetrics();
this.updateCrosshair(); this.updateCrosshair();
this.initLineGenerator(); this.initLineGenerator();
@ -29,18 +28,6 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
return; return;
} }
// TODO: move to core, and create only one container
// container for clip path
const clipContatiner = this.chartContainer
.append('g')
.attr('clip-path', `url(#${this.rectClipId})`)
.attr('class', 'metrics-container');
// container for panning
this.metricContainer = clipContatiner
.append('g')
.attr('class', 'metrics-rect')
for(let idx = 0; idx < this.series.length; ++idx) { for(let idx = 0; idx < this.series.length; ++idx) {
if(this.series[idx].visible === false) { if(this.series[idx].visible === false) {
continue; continue;
@ -67,6 +54,11 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
} }
} }
clearAllMetrics(): void {
// TODO: temporary hack before it will be implemented in core.
this.d3.selectAll('.metric-el').remove();
}
initLineGenerator(): void { initLineGenerator(): void {
this.lineGenerator = this.d3.line() this.lineGenerator = this.d3.line()
.x(d => this.xScale(d[0])) .x(d => this.xScale(d[0]))

Loading…
Cancel
Save