Browse Source

Merge branch '0.5.0-beta' into 'main'

external d3 and lodash

See merge request chartwerk/core!17
merge-requests/18/merge
rozetko 2 years ago
parent
commit
93a6177032
  1. 1
      build/webpack.base.conf.js
  2. 4323
      package-lock.json
  3. 9
      package.json
  4. 7
      src/components/grid.ts
  5. 4
      src/index.ts
  6. 8
      src/state.ts
  7. 2
      src/types.ts
  8. 3
      tsconfig.json
  9. 3068
      yarn.lock

1
build/webpack.base.conf.js

@ -8,6 +8,7 @@ module.exports = {
context: resolve('src'), context: resolve('src'),
entry: './index.ts', entry: './index.ts',
plugins: [], plugins: [],
externals: ['lodash', 'd3'],
module: { module: {
rules: [ rules: [
{ {

4323
package-lock.json generated

File diff suppressed because it is too large Load Diff

9
package.json

@ -1,6 +1,6 @@
{ {
"name": "@chartwerk/core", "name": "@chartwerk/core",
"version": "0.4.1", "version": "0.5.0-beta3",
"description": "Chartwerk core", "description": "Chartwerk core",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
@ -15,11 +15,12 @@
}, },
"author": "CorpGlory Inc.", "author": "CorpGlory Inc.",
"license": "ISC", "license": "ISC",
"dependencies": {
"d3": "^5.7.2",
"lodash": "^4.14.149"
},
"devDependencies": { "devDependencies": {
"@types/d3": "^5.7.2",
"@types/lodash": "^4.14.149",
"css-loader": "^3.4.2", "css-loader": "^3.4.2",
"lodash": "^4.17.15",
"style-loader": "^1.1.3", "style-loader": "^1.1.3",
"ts-loader": "^6.2.1", "ts-loader": "^6.2.1",
"typescript": "^3.8.3", "typescript": "^3.8.3",

7
src/components/grid.ts

@ -1,7 +1,5 @@
import { GridOptions, SvgElParams } from '../types'; import { GridOptions, SvgElParams } from '../types';
// we import only d3 types here
import * as d3 from 'd3'; import * as d3 from 'd3';
import defaultsDeep from 'lodash/defaultsDeep'; import defaultsDeep from 'lodash/defaultsDeep';
@ -29,7 +27,6 @@ export class Grid {
protected gridOptions: GridOptions; protected gridOptions: GridOptions;
constructor( constructor(
private _d3: typeof d3,
private _svgEl: d3.Selection<SVGElement, unknown, null, undefined>, private _svgEl: d3.Selection<SVGElement, unknown, null, undefined>,
private _svgElParams: SvgElParams, private _svgElParams: SvgElParams,
_gridOptions: GridOptions, _gridOptions: GridOptions,
@ -60,7 +57,7 @@ export class Grid {
.attr('class', 'grid x-grid') .attr('class', 'grid x-grid')
.style('pointer-events', 'none') .style('pointer-events', 'none')
.call( .call(
this._d3.axisBottom(this._svgElParams.xScale) d3.axisBottom(this._svgElParams.xScale)
.ticks(this.gridOptions.x.ticksCount) .ticks(this.gridOptions.x.ticksCount)
.tickSize(-this._svgElParams.height) .tickSize(-this._svgElParams.height)
.tickFormat(() => '') .tickFormat(() => '')
@ -76,7 +73,7 @@ export class Grid {
.attr('class', 'grid y-grid') .attr('class', 'grid y-grid')
.style('pointer-events', 'none') .style('pointer-events', 'none')
.call( .call(
this._d3.axisLeft(this._svgElParams.yScale) d3.axisLeft(this._svgElParams.yScale)
.ticks(this.gridOptions.y.ticksCount) .ticks(this.gridOptions.y.ticksCount)
.tickSize(-this._svgElParams.width) .tickSize(-this._svgElParams.width)
.tickFormat(() => '') .tickFormat(() => '')

4
src/index.ts

@ -243,7 +243,7 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
height: this.height, height: this.height,
width: this.width, width: this.width,
} }
this.state = new PodState(this.d3, boxPararms, this.series, this.options); this.state = new PodState(boxPararms, this.series, this.options);
} }
protected initComponents(): void { protected initComponents(): void {
@ -256,7 +256,7 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
yScale: this.state.yScale, yScale: this.state.yScale,
} }
this.grid = new Grid(this.d3, this.chartContainer, svgElParams, this.options.grid); this.grid = new Grid(this.chartContainer, svgElParams, this.options.grid);
} }
protected renderMetricsContainer(): void { protected renderMetricsContainer(): void {

8
src/state.ts

@ -1,6 +1,5 @@
import { TimeSerie, Options, yAxisOrientation } from './types'; import { TimeSerie, Options, yAxisOrientation } from './types';
// we import only d3 types here
import * as d3 from 'd3'; import * as d3 from 'd3';
import cloneDeep from 'lodash/cloneDeep'; import cloneDeep from 'lodash/cloneDeep';
@ -33,7 +32,6 @@ export class PodState<T extends TimeSerie, O extends Options> {
private _y1Scale: d3.ScaleLinear<number, number>; private _y1Scale: d3.ScaleLinear<number, number>;
constructor( constructor(
protected _d3: typeof d3,
protected boxParams: { height: number, width: number }, protected boxParams: { height: number, width: number },
protected series: T[], protected series: T[],
protected options: O, protected options: O,
@ -60,14 +58,14 @@ export class PodState<T extends TimeSerie, O extends Options> {
if(this.options.axis.y.invert === true) { if(this.options.axis.y.invert === true) {
domain = reverse(domain); domain = reverse(domain);
} }
this._yScale = this._d3.scaleLinear() this._yScale = d3.scaleLinear()
.domain(domain) .domain(domain)
.range([this.boxParams.height, 0]); // inversed, because d3 y-axis goes from top to bottom; .range([this.boxParams.height, 0]); // inversed, because d3 y-axis goes from top to bottom;
} }
protected setXScale(): void { protected setXScale(): void {
const domain = this._xValueRange; const domain = this._xValueRange;
this._xScale = this._d3.scaleLinear() this._xScale = d3.scaleLinear()
.domain(domain) .domain(domain)
.range([0, this.boxParams.width]); .range([0, this.boxParams.width]);
} }
@ -78,7 +76,7 @@ export class PodState<T extends TimeSerie, O extends Options> {
if(this.options.axis.y1.invert === true) { if(this.options.axis.y1.invert === true) {
domain = reverse(domain); domain = reverse(domain);
} }
this._y1Scale = this._d3.scaleLinear() this._y1Scale = d3.scaleLinear()
.domain(domain) .domain(domain)
.range([this.boxParams.height, 0]); // inversed, because d3 y-axis goes from top to bottom .range([this.boxParams.height, 0]); // inversed, because d3 y-axis goes from top to bottom
} }

2
src/types.ts

@ -1,3 +1,5 @@
import * as d3 from 'd3';
export type Margin = { top: number, right: number, bottom: number, left: number }; export type Margin = { top: number, right: number, bottom: number, left: number };
export type Timestamp = number; export type Timestamp = number;

3
tsconfig.json

@ -16,6 +16,7 @@
"noImplicitUseStrict": false, "noImplicitUseStrict": false,
"noImplicitAny": false, "noImplicitAny": false,
"noUnusedLocals": false, "noUnusedLocals": false,
"baseUrl": "./src" "baseUrl": "./src",
"moduleResolution": "node"
} }
} }

3068
yarn.lock

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save