Compare commits

..

No commits in common. 'main' and 'rename-eventCallbacs-to-events-#26-2' have entirely different histories.

  1. 6
      demo/demo_pod.ts
  2. 2
      package.json
  3. 12
      src/VueChartwerkPodMixin.ts
  4. 40
      src/index.ts
  5. 6
      src/models/options.ts
  6. 3
      src/models/series.ts
  7. 15
      src/models/state.ts
  8. 1
      src/types.ts
  9. 9
      tsconfig.json

6
demo/demo_pod.ts

@ -51,6 +51,12 @@ class DemoPod extends ChartwerkPod<Serie, Options> {
.attr('d', this.lineGenerator); .attr('d', this.lineGenerator);
} }
onMouseMove(): void {}
onMouseOver(): void {}
onMouseOut(): void {}
onMouseClick(): void {}
renderSharedCrosshair(values): void {}
hideSharedCrosshair(): void {}
} }
export { DemoPod }; export { DemoPod };

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "@chartwerk/core", "name": "@chartwerk/core",
"version": "0.6.26", "version": "0.6.21",
"description": "Chartwerk core", "description": "Chartwerk core",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

12
src/VueChartwerkPodMixin.ts

@ -39,9 +39,9 @@ export default {
}, },
methods: { methods: {
// it's "abstract" method. "children" components should override it // it's "abstract" method. "children" components should override it
render() {}, render() { },
renderSharedCrosshair(values: { x?: number, y?: number }) {}, renderSharedCrosshair(values: { x?: number, y?: number }) { },
hideSharedCrosshair() {}, hideSharedCrosshair() { },
onPanningRescale(event) { onPanningRescale(event) {
this.pod.rescaleMetricAndAxis(event); this.pod.rescaleMetricAndAxis(event);
}, },
@ -63,9 +63,6 @@ export default {
if(has(this.$listeners, 'zoomOut')) { if(has(this.$listeners, 'zoomOut')) {
this.options.events.zoomOut = this.zoomOut.bind(this); this.options.events.zoomOut = this.zoomOut.bind(this);
} }
if(has(this.$listeners, 'mouseOver')) {
this.options.events.mouseOver = this.mouseOver.bind(this);
}
if(has(this.$listeners, 'mouseMove')) { if(has(this.$listeners, 'mouseMove')) {
this.options.events.mouseMove = this.mouseMove.bind(this); this.options.events.mouseMove = this.mouseMove.bind(this);
} }
@ -100,9 +97,6 @@ export default {
zoomOut(centers) { zoomOut(centers) {
this.$emit('zoomOut', centers); this.$emit('zoomOut', centers);
}, },
mouseOver() {
this.$emit('mouseOver');
},
mouseMove(evt) { mouseMove(evt) {
this.$emit('mouseMove', evt); this.$emit('mouseMove', evt);
}, },

40
src/index.ts

@ -37,7 +37,7 @@ import debounce from 'lodash/debounce';
const DEFAULT_TICK_SIZE = 2; const DEFAULT_TICK_SIZE = 2;
class ChartwerkPod<T extends Serie, O extends Options> { abstract class ChartwerkPod<T extends Serie, O extends Options> {
protected series: CoreSeries<T>; protected series: CoreSeries<T>;
protected options: CoreOptions<O>; protected options: CoreOptions<O>;
@ -79,8 +79,7 @@ class ChartwerkPod<T extends Serie, O extends Options> {
_series: T[] = [], _series: T[] = [],
_options: O _options: O
) { ) {
// need to call explicitly because option lazyStyleTag // TODO: test if it's necessary
// in webpack style-loader
styles.use(); styles.use();
this.options = new CoreOptions(_options); this.options = new CoreOptions(_options);
@ -116,7 +115,6 @@ class ChartwerkPod<T extends Serie, O extends Options> {
this.renderLegend(); this.renderLegend();
this.renderYLabel(); this.renderYLabel();
this.renderY1Label();
this.renderXLabel(); this.renderXLabel();
this.options.callbackRenderEnd(); this.options.callbackRenderEnd();
@ -153,13 +151,13 @@ class ChartwerkPod<T extends Serie, O extends Options> {
this.series.updateSeries(newSeries); this.series.updateSeries(newSeries);
} }
protected renderMetrics(): void {} protected abstract renderMetrics(): void;
protected onMouseOver(): void {} protected abstract onMouseOver(): void;
protected onMouseOut(): void {} protected abstract onMouseOut(): void;
protected onMouseMove(): void {} protected abstract onMouseMove(): void;
protected onMouseClick(): void {} protected abstract onMouseClick(): void;
public renderSharedCrosshair(values: { x?: number, y?: number }): void {} public abstract renderSharedCrosshair(values: { x?: number, y?: number }): void;
public hideSharedCrosshair(): void {} public abstract hideSharedCrosshair(): void;
protected initPodState(): void { protected initPodState(): void {
const boxPararms = { const boxPararms = {
@ -510,8 +508,8 @@ class ChartwerkPod<T extends Serie, O extends Options> {
return; return;
} }
this.chartContainer.append('text') this.chartContainer.append('text')
.attr('y', -this.margin.left) .attr('y', 0 - this.margin.left)
.attr('x', -(this.height / 2)) .attr('x', 0 - (this.height / 2))
.attr('dy', '1em') .attr('dy', '1em')
.attr('class', 'y-axis-label') .attr('class', 'y-axis-label')
.attr('transform', 'rotate(-90)') .attr('transform', 'rotate(-90)')
@ -521,22 +519,6 @@ class ChartwerkPod<T extends Serie, O extends Options> {
.text(this.options.axis.y.label); .text(this.options.axis.y.label);
} }
protected renderY1Label(): void {
if(this.options.axis.y1?.label === undefined) {
return;
}
this.chartContainer.append('text')
.attr('y', -this.width - this.margin.right)
.attr('x', (this.height / 2))
.attr('dy', '1em')
.attr('class', 'y-axis-label')
.attr('transform', 'rotate(90)')
.style('text-anchor', 'middle')
.style('font-size', '14px')
.style('fill', 'currentColor')
.text(this.options.axis.y1.label);
}
protected renderXLabel(): void { protected renderXLabel(): void {
if(this.options.axis.x.label === undefined) { if(this.options.axis.x.label === undefined) {
return; return;

6
src/models/options.ts

@ -226,12 +226,6 @@ export class CoreOptions<O extends Options> {
} }
} }
callbackMouseOver(): void {
if(has(this._options.events, 'mouseOver')) {
this._options.events.mouseOver();
}
}
callbackMouseMove(event): void { callbackMouseMove(event): void {
if(has(this._options.events, 'mouseMove')) { if(has(this._options.events, 'mouseMove')) {
this._options.events.mouseMove(event); this._options.events.mouseMove(event);

3
src/models/series.ts

@ -35,7 +35,6 @@ export class CoreSeries<T extends Serie> {
_series: Array<T> = []; _series: Array<T> = [];
constructor(series: T[], private _podDefaults?: Partial<T>) { constructor(series: T[], private _podDefaults?: Partial<T>) {
// TODO: create separate Serie class, and store instances in this._series
this.setSeries(series); this.setSeries(series);
} }
@ -84,7 +83,7 @@ export class CoreSeries<T extends Serie> {
get isSeriesAvailable(): boolean { get isSeriesAvailable(): boolean {
if(this.visibleSeries.length > 0) { if(this.visibleSeries.length > 0) {
const seriesEmptiness = lodashMap(this.visibleSeries, this._isSerieEmpty.bind(this)); const seriesEmptiness = lodashMap(this.visibleSeries, this._isSerieEmpty.bind(this));
return lodashIncludes(seriesEmptiness, false); return lodashIncludes(seriesEmptiness, false);
} }
return false; return false;

15
src/models/state.ts

@ -1,4 +1,4 @@
import { Serie, Options, yAxisOrientation } from '../types'; import { Serie, Options } from '../types';
import { CoreSeries } from './series'; import { CoreSeries } from './series';
import { CoreOptions } from './options'; import { CoreOptions } from './options';
@ -89,15 +89,6 @@ export class PodState<T extends Serie, O extends Options> {
this._transform = { x: 0, y: 0, k: 1 }; this._transform = { x: 0, y: 0, k: 1 };
} }
getYScaleByOrientation(orientation?: yAxisOrientation): d3.ScaleLinear<number, number> {
// TODO: we set defaults in Series class, so we don't expect `undefined` here
// we can remove this check when we implement Serie class (see TODO in `series.ts`)
if(orientation === undefined) {
return this._yScale;
}
return orientation === yAxisOrientation.LEFT ? this._yScale : this._y1Scale;
}
get yScale(): d3.ScaleLinear<number, number> { get yScale(): d3.ScaleLinear<number, number> {
return this._yScale; return this._yScale;
} }
@ -196,7 +187,7 @@ export class PodState<T extends Serie, O extends Options> {
if(this.coreOptions.axis.y1.range !== undefined) { if(this.coreOptions.axis.y1.range !== undefined) {
return min(this.coreOptions.axis.y1.range); return min(this.coreOptions.axis.y1.range);
} }
return this.coreSeries.minValueY1; return this.coreSeries.minValueY;
} }
public getMaxValueY1(): number { public getMaxValueY1(): number {
@ -206,7 +197,7 @@ export class PodState<T extends Serie, O extends Options> {
if(this.coreOptions.axis.y1.range !== undefined) { if(this.coreOptions.axis.y1.range !== undefined) {
return max(this.coreOptions.axis.y1.range); return max(this.coreOptions.axis.y1.range);
} }
return this.coreSeries.maxValueY1; return this.coreSeries.maxValueY;
} }
// getters for correct transform // getters for correct transform

1
src/types.ts

@ -20,7 +20,6 @@ export type Events = {
panning?: (event: { ranges: AxisRange[], d3Event: any }) => void, panning?: (event: { ranges: AxisRange[], d3Event: any }) => void,
panningEnd?: (range: AxisRange[]) => void, panningEnd?: (range: AxisRange[]) => void,
zoomOut?: (centers: {x: number, y: number}) => void, zoomOut?: (centers: {x: number, y: number}) => void,
mouseOver?: () => void,
mouseMove?: (evt: any) => void, mouseMove?: (evt: any) => void,
mouseClick?: (evt: any) => void, mouseClick?: (evt: any) => void,
mouseOut?: () => void, mouseOut?: () => void,

9
tsconfig.json

@ -15,11 +15,6 @@
"noImplicitUseStrict": false, "noImplicitUseStrict": false,
"noImplicitAny": false, "noImplicitAny": false,
"noUnusedLocals": false, "noUnusedLocals": false,
"moduleResolution": "node", "moduleResolution": "node"
}, }
"exclude": [
"node_modules",
"dist",
"demo"
]
} }

Loading…
Cancel
Save