diff --git a/package.json b/package.json index 3971461..2a84566 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chartwerk/core", - "version": "0.6.25", + "version": "0.6.26", "description": "Chartwerk core", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index dfb5abf..bcfc47a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -116,6 +116,7 @@ class ChartwerkPod { this.renderLegend(); this.renderYLabel(); + this.renderY1Label(); this.renderXLabel(); this.options.callbackRenderEnd(); @@ -509,8 +510,8 @@ class ChartwerkPod { return; } this.chartContainer.append('text') - .attr('y', 0 - this.margin.left) - .attr('x', 0 - (this.height / 2)) + .attr('y', -this.margin.left) + .attr('x', -(this.height / 2)) .attr('dy', '1em') .attr('class', 'y-axis-label') .attr('transform', 'rotate(-90)') @@ -520,6 +521,22 @@ class ChartwerkPod { .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 { if(this.options.axis.x.label === undefined) { return; diff --git a/src/models/series.ts b/src/models/series.ts index 15a9f59..746fc5c 100644 --- a/src/models/series.ts +++ b/src/models/series.ts @@ -35,6 +35,7 @@ export class CoreSeries { _series: Array = []; constructor(series: T[], private _podDefaults?: Partial) { + // TODO: create separate Serie class, and store instances in this._series this.setSeries(series); } @@ -83,7 +84,7 @@ export class CoreSeries { get isSeriesAvailable(): boolean { if(this.visibleSeries.length > 0) { const seriesEmptiness = lodashMap(this.visibleSeries, this._isSerieEmpty.bind(this)); - + return lodashIncludes(seriesEmptiness, false); } return false; diff --git a/src/models/state.ts b/src/models/state.ts index bb2c726..7b37fa9 100755 --- a/src/models/state.ts +++ b/src/models/state.ts @@ -1,4 +1,4 @@ -import { Serie, Options } from '../types'; +import { Serie, Options, yAxisOrientation } from '../types'; import { CoreSeries } from './series'; import { CoreOptions } from './options'; @@ -89,6 +89,15 @@ export class PodState { this._transform = { x: 0, y: 0, k: 1 }; } + getYScaleByOrientation(orientation?: yAxisOrientation): d3.ScaleLinear { + // 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 { return this._yScale; }