@geoblocks/d3-helper
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -16,22 +16,26 @@ /** | ||
private lastPartD3Selector_; | ||
protected d3Selector_: string; | ||
protected height_: number; | ||
protected width_: number; | ||
protected margins_: Margins; | ||
protected svg_: any; | ||
protected chart_: any; | ||
private d3Selector_; | ||
height: number; | ||
width: number; | ||
margins: Margins; | ||
svg: any; | ||
chart: any; | ||
constructor(d3Selector: string); | ||
/** | ||
* Return the selector of the chart. | ||
*/ | ||
getD3Selector(): string; | ||
/** | ||
* Specify a supplementary path to the already defined d3Selector. | ||
* That's useful for multiple generated charts elements. | ||
*/ | ||
protected updateD3Selector_(chartPath: string): void; | ||
updateD3Selector(chartPath: string): void; | ||
/** | ||
* Set default margins. | ||
*/ | ||
protected setMargins_(margins: Margins): void; | ||
setMargins(margins: Margins): void; | ||
/** | ||
* Return svg size [width, height] without margins. | ||
*/ | ||
protected getDrawableSize_(): [number, number]; | ||
getDrawableSize(): [number, number]; | ||
/** | ||
@@ -41,7 +45,7 @@ * Update the size of the svg element. | ||
*/ | ||
protected updateSize_(element: Element): void; | ||
updateSize(element: Element): void; | ||
/** | ||
* Remove de SVG. | ||
*/ | ||
protected removeSVG_(): void; | ||
removeSVG(): void; | ||
/** | ||
@@ -51,3 +55,3 @@ * Draw the SVG with a 'chart' group inside. | ||
*/ | ||
protected drawSVG_(): void; | ||
drawSVG(): void; | ||
} |
@@ -10,11 +10,17 @@ import { select as d3Select } from 'd3-selection'; | ||
this.d3Selector_ = d3Selector; | ||
this.height_ = 250; | ||
this.width_ = 250; | ||
this.margins_ = { top: 60, right: 80, bottom: 60, left: 80 }; | ||
this.height = 250; | ||
this.width = 250; | ||
this.margins = { top: 60, right: 80, bottom: 60, left: 80 }; | ||
} | ||
/** | ||
* Return the selector of the chart. | ||
*/ | ||
getD3Selector() { | ||
return this.d3Selector_; | ||
} | ||
/** | ||
* Specify a supplementary path to the already defined d3Selector. | ||
* That's useful for multiple generated charts elements. | ||
*/ | ||
updateD3Selector_(chartPath) { | ||
updateD3Selector(chartPath) { | ||
this.d3Selector_ = `${chartPath} ${this.lastPartD3Selector_}`; | ||
@@ -25,4 +31,4 @@ } | ||
*/ | ||
setMargins_(margins) { | ||
Object.assign(this.margins_, margins); | ||
setMargins(margins) { | ||
Object.assign(this.margins, margins); | ||
} | ||
@@ -32,6 +38,6 @@ /** | ||
*/ | ||
getDrawableSize_() { | ||
getDrawableSize() { | ||
return [ | ||
this.width_ - this.margins_.left - this.margins_.right, | ||
this.height_ - this.margins_.top - this.margins_.bottom, | ||
this.width - this.margins.left - this.margins.right, | ||
this.height - this.margins.top - this.margins.bottom, | ||
]; | ||
@@ -43,5 +49,5 @@ } | ||
*/ | ||
updateSize_(element) { | ||
this.width_ = element.offsetWidth; | ||
this.height_ = element.offsetHeight; | ||
updateSize(element) { | ||
this.width = element.offsetWidth; | ||
this.height = element.offsetHeight; | ||
} | ||
@@ -51,3 +57,3 @@ /** | ||
*/ | ||
removeSVG_() { | ||
removeSVG() { | ||
d3Select(`${this.d3Selector_} svg`).remove(); | ||
@@ -59,10 +65,10 @@ } | ||
*/ | ||
drawSVG_() { | ||
this.svg_ = d3Select(this.d3Selector_) | ||
drawSVG() { | ||
this.svg = d3Select(this.d3Selector_) | ||
.append('svg:svg') | ||
.attr('viewBox', `0 0 ${this.width_} ${this.height_}`) | ||
.attr('viewBox', `0 0 ${this.width} ${this.height}`) | ||
.attr('preserveAspectRatio', 'xMinYMin') | ||
.attr('class', 'svg'); | ||
this.chart_ = this.svg_.append('g') | ||
.attr('transform', `translate(${this.margins_.left}, ${this.margins_.top})`) | ||
this.chart = this.svg.append('g') | ||
.attr('transform', `translate(${this.margins.left}, ${this.margins.top})`) | ||
.attr('class', 'chart'); | ||
@@ -69,0 +75,0 @@ } |
@@ -5,10 +5,8 @@ import { BaseD3ChartSVG, Margins } from './base-d3-chart-svg'; | ||
*/ | ||
export interface DataValue { | ||
value: string | number | Date; | ||
} | ||
export declare type DataValue = (string | number | Date); | ||
/** | ||
* One row of data | ||
* One row of data. | ||
*/ | ||
export interface DataRow { | ||
[Key: string]: DataValue; | ||
[Key: string]: any; | ||
} | ||
@@ -76,2 +74,6 @@ /** | ||
/** | ||
* Buffer (add space around left and right borders of data) or not. Default to false (not buffered). | ||
*/ | ||
domainAlwaysBuffered?: boolean; | ||
/** | ||
* Secondary opposite Axis configuration. Will need a second dataset to setup the axis. | ||
@@ -99,12 +101,15 @@ */ | ||
private config_; | ||
protected color_: number[]; | ||
protected domaineAlwaysBuffered_: boolean; | ||
protected xData_: DataValue[]; | ||
protected yData_: DataValue[]; | ||
protected oppositeYData_: DataValue[]; | ||
protected xScale_: any; | ||
protected yScale_: any; | ||
protected oppositeYScale_: any; | ||
color: number[]; | ||
xData: DataValue[]; | ||
yData: DataValue[]; | ||
oppositeYData: DataValue[]; | ||
xScale: any; | ||
yScale: any; | ||
oppositeYScale: any; | ||
constructor(d3Selector: string); | ||
/** | ||
* Get the config. | ||
*/ | ||
getConfig(): CartesianChartConfig; | ||
/** | ||
* Set the configuration of the cartesian chart. | ||
@@ -114,7 +119,7 @@ * The configuration must be set before to use other functions and not set between functions (except | ||
*/ | ||
protected setCartesianConfig_(config: CartesianChartConfig): void; | ||
setConfig(config: CartesianChartConfig): void; | ||
/** | ||
* Remove the svg an reset the cartesian. | ||
*/ | ||
protected cleanCartesian_(): void; | ||
cleanCartesian(): void; | ||
/** | ||
@@ -124,3 +129,3 @@ * Reset the chart. | ||
*/ | ||
protected removeUpdateDrawSVG_(): void; | ||
removeUpdateDrawSVG(): void; | ||
/** | ||
@@ -130,36 +135,43 @@ * Returns the axisColumn. | ||
*/ | ||
protected getAxisColumnName_(axisConfig: CartesianChartAxisConfig, data?: DataRow[]): string; | ||
getAxisColumnName(axisConfig: CartesianChartAxisConfig, data?: DataRow[]): string; | ||
/** | ||
* Return the AxisType of the first defined value of the given DataRow. | ||
*/ | ||
protected getDataType_(data: DataRow[], axisColumn: string): AxisType; | ||
getDataType(data: DataRow[], axisColumn: string): AxisType; | ||
/** | ||
* Get a value and return a DataValue or null. | ||
*/ | ||
castToDataValue(data: any): DataValue; | ||
/** | ||
* Set and draw the X axis using the config and the data. | ||
* Type will be determined from data values and must be an Axis Type type. | ||
*/ | ||
protected setXAxis_(data: DataRow[]): void; | ||
setXAxis(data: DataRow[]): void; | ||
/** | ||
* Set and draw the Y axis using the config and the data. | ||
* Type will be determined from data values and must be an Axis Type type. | ||
*/ | ||
protected setYAxis_(data: DataRow[]): void; | ||
setYAxis(data: DataRow[]): void; | ||
/** | ||
* Set and draw the opposite Y axis using the config and the data. | ||
* Type will be determined from data values and must be an Axis Type type. | ||
*/ | ||
protected setOppositeYAxis_(data: DataRow[]): void; | ||
setOppositeYAxis(data: DataRow[]): void; | ||
/** | ||
* Draw a title at the center of the chart. | ||
*/ | ||
protected drawTitle_(colors: number[], subTitle?: string): void; | ||
drawTitle(colors: number[], subTitle?: string): void; | ||
/** | ||
* Draw the X axis in the chart of the svg. | ||
*/ | ||
protected drawXAxis_(colors: number[], data?: DataRow[]): void; | ||
drawXAxis(colors: number[], data?: DataRow[]): void; | ||
/** | ||
* Draw the X axis in the chart of the svg. | ||
*/ | ||
protected drawYAxis_(colors: number[], data?: DataRow[]): void; | ||
drawYAxis(colors: number[], data?: DataRow[]): void; | ||
/** | ||
* Draw the opposite Y axis in the chart of the svg. | ||
*/ | ||
protected drawOppositeYAxis_(colors: number[], data?: DataRow[]): void; | ||
private wrapAxisLabels_; | ||
drawOppositeYAxis(colors: number[], data?: DataRow[]): void; | ||
wrapAxisLabels(text: any, width: number, x: number): void; | ||
/** | ||
@@ -171,7 +183,7 @@ * Set the ticks of the axis and add formatting and customisations if specified. | ||
*/ | ||
private setAxisTick_; | ||
setAxisTick(axisConfig: CartesianChartAxisConfig, baseAxis: any, data: DataRow[]): void; | ||
/** | ||
* Return a scale function adapted to the type of data of the axis. | ||
*/ | ||
private getScale_; | ||
getScale(axisData: any, axisType: string, range: number[]): any; | ||
/** | ||
@@ -181,7 +193,7 @@ * Create an array containing the min and the max value determining the domain used for the axis. | ||
*/ | ||
private determineDomain_; | ||
determineDomain(minValue: number | Date, maxValue: number | Date): (number | Date)[]; | ||
/** | ||
* Use the name of the key of the data of the axis as axis label if no label is configured for this axis. | ||
*/ | ||
protected useDataLabelAsDefaultForAxis_(axis: string): void; | ||
useDataLabelAsDefaultForAxis(axis: string): void; | ||
/** | ||
@@ -192,3 +204,3 @@ * Trunc text that is longer than a given number of characters. | ||
*/ | ||
protected truncText_(text: string, length?: number): string; | ||
truncText(text: string, length?: number): string; | ||
/** | ||
@@ -199,3 +211,3 @@ * Determine if a given value from the x or y axes can be found in one given data entry | ||
*/ | ||
private compareData_; | ||
compareData(value: DataValue, selectedValue: DataValue): boolean; | ||
} |
@@ -24,7 +24,11 @@ import { min as d3Min, max as d3Max } from 'd3-array'; | ||
super(d3Selector); | ||
this.d3Selector_ = d3Selector; | ||
this.domaineAlwaysBuffered_ = false; | ||
this.color_ = [100, 100, 100]; | ||
this.color = [100, 100, 100]; | ||
} | ||
/** | ||
* Get the config. | ||
*/ | ||
getConfig() { | ||
return this.config_; | ||
} | ||
/** | ||
* Set the configuration of the cartesian chart. | ||
@@ -34,20 +38,20 @@ * The configuration must be set before to use other functions and not set between functions (except | ||
*/ | ||
setCartesianConfig_(config) { | ||
setConfig(config) { | ||
this.config_ = config; | ||
if (this.config_.chartPath) { | ||
this.updateD3Selector_(this.config_.chartPath); | ||
this.updateD3Selector(this.config_.chartPath); | ||
} | ||
if (this.config_.xAxis.hideAxis) { | ||
this.margins_.right = 5; | ||
this.margins_.left = 5; | ||
this.margins.right = 5; | ||
this.margins.left = 5; | ||
} | ||
if (this.config_.yAxis.hideAxis) { | ||
this.margins_.top = 5; | ||
this.margins_.bottom = 5; | ||
this.margins.top = 5; | ||
this.margins.bottom = 5; | ||
} | ||
if (this.config_.margins) { | ||
this.setMargins_(this.config_.margins); | ||
this.setMargins(this.config_.margins); | ||
} | ||
if (this.config_.color) { | ||
this.color_ = this.config_.color; | ||
this.color = this.config_.color; | ||
} | ||
@@ -58,10 +62,10 @@ } | ||
*/ | ||
cleanCartesian_() { | ||
this.removeSVG_(); | ||
this.xData_ = null; | ||
this.yData_ = null; | ||
this.oppositeYData_ = null; | ||
this.xScale_ = null; | ||
this.yScale_ = null; | ||
this.oppositeYScale_ = null; | ||
cleanCartesian() { | ||
this.removeSVG(); | ||
this.xData = null; | ||
this.yData = null; | ||
this.oppositeYData = null; | ||
this.xScale = null; | ||
this.yScale = null; | ||
this.oppositeYScale = null; | ||
} | ||
@@ -72,7 +76,7 @@ /** | ||
*/ | ||
removeUpdateDrawSVG_() { | ||
const element = document.querySelector(this.d3Selector_); | ||
this.cleanCartesian_(); | ||
this.updateSize_(element); | ||
this.drawSVG_(); | ||
removeUpdateDrawSVG() { | ||
const element = document.querySelector(this.getD3Selector()); | ||
this.cleanCartesian(); | ||
this.updateSize(element); | ||
this.drawSVG(); | ||
} | ||
@@ -83,5 +87,5 @@ /** | ||
*/ | ||
getAxisColumnName_(axisConfig, data) { | ||
const axisColumn = axisConfig.axisColumn; | ||
if (data && data.length > 0 && !data[0][axisColumn]) { | ||
getAxisColumnName(axisConfig, data) { | ||
const axisColumn = axisConfig === null || axisConfig === void 0 ? void 0 : axisConfig.axisColumn; | ||
if (data && data.length > 0 && (data[0][axisColumn] === undefined || data[0][axisColumn] === null)) { | ||
return null; | ||
@@ -94,3 +98,3 @@ } | ||
*/ | ||
getDataType_(data, axisColumn) { | ||
getDataType(data, axisColumn) { | ||
const definedValues = data.find(dataRow => dataRow[axisColumn] !== null && dataRow[axisColumn] !== undefined); | ||
@@ -107,17 +111,27 @@ const definedValue = definedValues[axisColumn]; | ||
/** | ||
* Get a value and return a DataValue or null. | ||
*/ | ||
castToDataValue(data) { | ||
if (typeof data === 'string' || typeof data === 'number' || data instanceof Date) { | ||
return data; | ||
} | ||
return null; | ||
} | ||
/** | ||
* Set and draw the X axis using the config and the data. | ||
* Type will be determined from data values and must be an Axis Type type. | ||
*/ | ||
setXAxis_(data) { | ||
d3Select(`${this.d3Selector_} svg .xaxis`).remove(); | ||
const drawableWidth = this.getDrawableSize_()[0]; | ||
setXAxis(data) { | ||
d3Select(`${this.getD3Selector()} svg .xaxis`).remove(); | ||
const drawableWidth = this.getDrawableSize()[0]; | ||
const axisConfig = this.config_.xAxis; | ||
const axisColumn = this.getAxisColumnName_(axisConfig, data); | ||
const axisColumn = this.getAxisColumnName(axisConfig, data); | ||
if (!axisColumn) { | ||
return; | ||
} | ||
const axisType = this.getDataType_(data, axisConfig.tickLabelColumn || axisColumn); | ||
this.xData_ = data.map(value => value[axisColumn]); | ||
this.xScale_ = this.getScale_(this.xData_, axisType, [0, drawableWidth]); | ||
const axisType = this.getDataType(data, axisConfig.tickLabelColumn || axisColumn); | ||
this.xData = data.map(value => this.castToDataValue(value[axisColumn])); | ||
this.xScale = this.getScale(this.xData, axisType, [0, drawableWidth]); | ||
if (!this.config_.xAxis.hideAxis) { | ||
this.drawXAxis_(axisConfig.color || this.color_, data); | ||
this.drawXAxis(axisConfig.color || this.color, data); | ||
} | ||
@@ -127,16 +141,17 @@ } | ||
* Set and draw the Y axis using the config and the data. | ||
* Type will be determined from data values and must be an Axis Type type. | ||
*/ | ||
setYAxis_(data) { | ||
d3Select(`${this.d3Selector_} svg .yaxis`).remove(); | ||
const drawableHeight = this.getDrawableSize_()[1]; | ||
setYAxis(data) { | ||
d3Select(`${this.getD3Selector()} svg .yaxis`).remove(); | ||
const drawableHeight = this.getDrawableSize()[1]; | ||
const axisConfig = this.config_.yAxis; | ||
const axisColumn = this.getAxisColumnName_(axisConfig, data); | ||
const axisColumn = this.getAxisColumnName(axisConfig, data); | ||
if (!axisColumn) { | ||
return; | ||
} | ||
const axisType = this.getDataType_(data, axisConfig.tickLabelColumn || axisColumn); | ||
this.yData_ = data.map(value => value[axisColumn]); | ||
this.yScale_ = this.getScale_(this.yData_, axisType, [drawableHeight, 0]); | ||
const axisType = this.getDataType(data, axisConfig.tickLabelColumn || axisColumn); | ||
this.yData = data.map(value => this.castToDataValue(value[axisColumn])); | ||
this.yScale = this.getScale(this.yData, axisType, [drawableHeight, 0]); | ||
if (!this.config_.yAxis.hideAxis) { | ||
this.drawYAxis_(axisConfig.color || this.color_, data); | ||
this.drawYAxis(axisConfig.color || this.color, data); | ||
} | ||
@@ -146,15 +161,16 @@ } | ||
* Set and draw the opposite Y axis using the config and the data. | ||
* Type will be determined from data values and must be an Axis Type type. | ||
*/ | ||
setOppositeYAxis_(data) { | ||
d3Select(`${this.d3Selector_} svg .opposite-yaxis`).remove(); | ||
const drawableHeight = this.getDrawableSize_()[1]; | ||
setOppositeYAxis(data) { | ||
d3Select(`${this.getD3Selector()} svg .opposite-yaxis`).remove(); | ||
const drawableHeight = this.getDrawableSize()[1]; | ||
const axisConfig = this.config_.oppositeYAxis; | ||
const axisColumn = this.getAxisColumnName_(axisConfig, data); | ||
const axisColumn = this.getAxisColumnName(axisConfig, data); | ||
if (!axisColumn) { | ||
return; | ||
} | ||
const axisType = this.getDataType_(data, axisConfig.tickLabelColumn || axisColumn); | ||
this.oppositeYData_ = data.map(value => value[axisColumn]); | ||
this.oppositeYScale_ = this.getScale_(this.oppositeYData_, axisType, [drawableHeight, 0]); | ||
this.drawOppositeYAxis_(axisConfig.color || this.color_, data); | ||
const axisType = this.getDataType(data, axisConfig.tickLabelColumn || axisColumn); | ||
this.oppositeYData = data.map(value => this.castToDataValue(value[axisColumn])); | ||
this.oppositeYScale = this.getScale(this.oppositeYData, axisType, [drawableHeight, 0]); | ||
this.drawOppositeYAxis(axisConfig.color || this.color, data); | ||
} | ||
@@ -164,8 +180,8 @@ /** | ||
*/ | ||
drawTitle_(colors, subTitle) { | ||
drawTitle(colors, subTitle) { | ||
const title = this.config_.title; | ||
this.svg_.append('text') | ||
this.svg.append('text') | ||
.attr('class', 'title') | ||
.attr('x', this.width_ / 2) | ||
.attr('y', this.margins_.top / 2) | ||
.attr('x', this.width / 2) | ||
.attr('y', this.margins.top / 2) | ||
.attr('font-size', '1.2rem') | ||
@@ -175,6 +191,6 @@ .attr('fill', `rgb(${colors.join(',')})`) | ||
.text(title); | ||
this.svg_.append('text') | ||
this.svg.append('text') | ||
.attr('class', 'subtitle') | ||
.attr('x', this.width_ / 2) | ||
.attr('y', this.margins_.top / 2) | ||
.attr('x', this.width / 2) | ||
.attr('y', this.margins.top / 2) | ||
.attr('font-size', '1.2rem') | ||
@@ -188,6 +204,6 @@ .attr('fill', `rgb(${colors.join(',')})`) | ||
*/ | ||
drawXAxis_(colors, data) { | ||
const axis = this.setAxisTick_(this.config_.xAxis, d3AxisBottom(this.xScale_), data); | ||
const [drawableWidth, drawableHeight] = this.getDrawableSize_(); | ||
this.chart_.append('g') | ||
drawXAxis(colors, data) { | ||
const axis = this.setAxisTick(this.config_.xAxis, d3AxisBottom(this.xScale), data); | ||
const [drawableWidth, drawableHeight] = this.getDrawableSize(); | ||
this.chart.append('g') | ||
.attr('transform', `translate(0, ${drawableHeight})`) | ||
@@ -199,3 +215,3 @@ .attr('class', 'chart xaxis') | ||
.attr('x', drawableWidth / 2) | ||
.attr('y', this.margins_.bottom - 5) | ||
.attr('y', this.margins.bottom - 5) | ||
.attr('fill', `rgb(${colors.join(',')})`) | ||
@@ -205,4 +221,4 @@ .style('text-anchor', 'middle') | ||
.text(this.config_.xAxis.label); | ||
this.chart_.selectAll('.xaxis .tick text') | ||
.call(this.wrapAxisLabels_, this.margins_.bottom - 15, 0) | ||
this.chart.selectAll('.xaxis .tick text') | ||
.call(this.wrapAxisLabels, this.margins.bottom - 15, 0) | ||
.attr('transform', 'translate(0, 8) rotate(-36)') | ||
@@ -214,5 +230,5 @@ .attr('text-anchor', 'end'); | ||
*/ | ||
drawYAxis_(colors, data) { | ||
const axis = this.setAxisTick_(this.config_.yAxis, d3AxisLeft(this.yScale_), data); | ||
this.chart_.append('g') | ||
drawYAxis(colors, data) { | ||
const axis = this.setAxisTick(this.config_.yAxis, d3AxisLeft(this.yScale), data); | ||
this.chart.append('g') | ||
.attr('transform', 'translate(0,0)') | ||
@@ -229,4 +245,4 @@ .attr('class', 'chart yaxis') | ||
.text(this.config_.yAxis.label); | ||
this.chart_.selectAll('.yaxis .tick text') | ||
.call(this.wrapAxisLabels_, this.margins_.left - 15, -10); | ||
this.chart.selectAll('.yaxis .tick text') | ||
.call(this.wrapAxisLabels, this.margins.left - 15, -10); | ||
} | ||
@@ -236,6 +252,6 @@ /** | ||
*/ | ||
drawOppositeYAxis_(colors, data) { | ||
const drawableWidth = this.getDrawableSize_()[0]; | ||
const axis = this.setAxisTick_(this.config_.oppositeYAxis, d3AxisRight(this.oppositeYScale_), data); | ||
this.chart_.append('g') | ||
drawOppositeYAxis(colors, data) { | ||
const drawableWidth = this.getDrawableSize()[0]; | ||
const axis = this.setAxisTick(this.config_.oppositeYAxis, d3AxisRight(this.oppositeYScale), data); | ||
this.chart.append('g') | ||
.attr('transform', `translate(${drawableWidth}, 0)`) | ||
@@ -252,4 +268,4 @@ .attr('class', 'chart opposite-yaxis') | ||
.text(this.config_.oppositeYAxis.label); | ||
this.chart_.selectAll('.opposite-yaxis .tick text') | ||
.call(this.wrapAxisLabels_, this.margins_.right - 15, 10); | ||
this.chart.selectAll('.opposite-yaxis .tick text') | ||
.call(this.wrapAxisLabels, this.margins.right - 15, 10); | ||
} | ||
@@ -259,3 +275,3 @@ /* | ||
*/ | ||
wrapAxisLabels_(text, width, x) { | ||
wrapAxisLabels(text, width, x) { | ||
text.nodes().forEach((node) => { | ||
@@ -306,8 +322,8 @@ const textSelection = d3Select(node); | ||
*/ | ||
setAxisTick_(axisConfig, baseAxis, data) { | ||
setAxisTick(axisConfig, baseAxis, data) { | ||
const ticks = axisConfig.tickNumber || 5; | ||
const axisColumn = this.getAxisColumnName_(axisConfig, data); | ||
const axisType = this.getDataType_(data, axisConfig.tickLabelColumn || axisColumn); | ||
const axisColumn = this.getAxisColumnName(axisConfig, data); | ||
const axisType = this.getDataType(data, axisConfig.tickLabelColumn || axisColumn); | ||
const compareFn = (d) => { | ||
const dataRow = data.find(dataRow => this.compareData_(dataRow[axisColumn], d)); | ||
const dataRow = data.find(dataRow => this.compareData(dataRow[axisColumn], d)); | ||
return dataRow[axisConfig.tickLabelColumn || axisColumn]; | ||
@@ -336,3 +352,3 @@ }; | ||
*/ | ||
getScale_(axisData, axisType, range) { | ||
getScale(axisData, axisType, range) { | ||
let scale; | ||
@@ -352,3 +368,3 @@ if (axisType === AxisType.TEXT) { | ||
} | ||
scale.domain(this.determineDomain_(d3Min(axisData), d3Max(axisData))) | ||
scale.domain(this.determineDomain(d3Min(axisData), d3Max(axisData))) | ||
.nice() | ||
@@ -363,4 +379,5 @@ .range(range); | ||
*/ | ||
determineDomain_(minValue, maxValue) { | ||
if (minValue !== maxValue && !this.domaineAlwaysBuffered_) { | ||
determineDomain(minValue, maxValue) { | ||
var _a; | ||
if (minValue !== maxValue && !((_a = this.config_) === null || _a === void 0 ? void 0 : _a.domainAlwaysBuffered)) { | ||
return [minValue, maxValue]; | ||
@@ -386,6 +403,6 @@ } | ||
*/ | ||
useDataLabelAsDefaultForAxis_(axis) { | ||
useDataLabelAsDefaultForAxis(axis) { | ||
const axisConfig = this.config_[axis]; | ||
if (axisConfig && !axisConfig.label) { | ||
axisConfig.label = this.getAxisColumnName_(axisConfig) || ''; | ||
axisConfig.label = this.getAxisColumnName(axisConfig) || ''; | ||
} | ||
@@ -398,3 +415,3 @@ } | ||
*/ | ||
truncText_(text, length = 30) { | ||
truncText(text, length = 30) { | ||
if (text.length > length) { | ||
@@ -410,3 +427,3 @@ return `${text.substring(0, length)} ...`; | ||
*/ | ||
compareData_(value, selectedValue) { | ||
compareData(value, selectedValue) { | ||
// Comparison for date values | ||
@@ -413,0 +430,0 @@ if (value instanceof Date && selectedValue instanceof Date) { |
{ | ||
"name": "@geoblocks/d3-helper", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "d3 helper classes", | ||
@@ -5,0 +5,0 @@ "license": "bsd", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
46350
760