Browse Source

use npm core

merge-requests/2/head
vargburz 3 years ago
parent
commit
44d90f605d
  1. 10
      demo.html
  2. 16
      dist/index.d.ts
  3. 2
      dist/index.js
  4. 5
      package-lock.json
  5. 2
      package.json
  6. 27
      src/index.ts

10
demo.html

@ -13,16 +13,16 @@
var pod = new ChartwerkBarPod( var pod = new ChartwerkBarPod(
document.getElementById('chart'), document.getElementById('chart'),
[ [
{ target: 'test11', datapoints: [[15, 100], [20, 110], [10, 300]], matchedKey: 'm-1', color: 'red' }, { target: 'test11', datapoints: [[100, 15], [110, 20], [300, 10]], matchedKey: 'm-1', color: 'red' },
{ target: 'test12', datapoints: [[10, 100], [20, 200], [10, 300]], matchedKey: 'm-1', color: 'green' }, { target: 'test12', datapoints: [[100, 10], [200, 20], [300, 10]], matchedKey: 'm-1', color: 'green' },
{ target: 'test21', datapoints: [[10, 130], [26, 230], [15, 330]], matchedKey: 'm-2', color: 'yellow'}, { target: 'test21', datapoints: [[130, 10], [230, 26], [330, 15]], matchedKey: 'm-2', color: 'yellow'},
{ target: 'test22', datapoints: [[10, 130], [27, 230], [10, 330]], matchedKey: 'm-2', color: 'blue' }, { target: 'test22', datapoints: [[130, 10], [230, 27], [330, 10]], matchedKey: 'm-2', color: 'blue' },
], ],
{ {
usePanning: false, usePanning: false,
axis: { axis: {
x: { format: 'custom', invert: false, valueFormatter: (value) => { return 'L' + value; } }, x: { format: 'custom', invert: false, valueFormatter: (value) => { return 'L' + value; } },
y: { invert: false, range: [0, 30], valueFormatter: (value) => { return value + '%'; } } y: { format: 'custom', invert: false, range: [0, 30], valueFormatter: (value) => { return value + '%'; } }
}, },
stacked: true, stacked: true,
matching: true, matching: true,

16
dist/index.d.ts vendored

@ -11,7 +11,10 @@ export declare class ChartwerkBarPod extends ChartwerkPod<BarTimeSerie, BarOptio
get seriesUniqKeys(): string[]; get seriesUniqKeys(): string[];
get seriesForMatching(): BarTimeSerie[][]; get seriesForMatching(): BarTimeSerie[][];
getZippedDataForRender(series: BarTimeSerie[]): RowValues[]; getZippedDataForRender(series: BarTimeSerie[]): RowValues[];
renderSharedCrosshair(timestamp: number): void; renderSharedCrosshair(values: {
x?: number;
y?: number;
}): void;
hideSharedCrosshair(): void; hideSharedCrosshair(): void;
onMouseMove(): void; onMouseMove(): void;
getSeriesPointFromMousePosition(eventX: number): any[] | undefined; getSeriesPointFromMousePosition(eventX: number): any[] | undefined;
@ -52,18 +55,27 @@ export declare const VueChartwerkBarChartObject: {
options(): void; options(): void;
}; };
mounted(): void; mounted(): void;
destroyed(): void;
methods: { methods: {
render(): void; render(): void;
renderSharedCrosshair(values: {
x?: number;
y?: number;
}): void;
hideSharedCrosshair(): void;
onPanningRescale(event: any): void;
renderChart(): void; renderChart(): void;
appendEvents(): void; appendEvents(): void;
zoomIn(range: any): void; zoomIn(range: any): void;
zoomOut(center: any): void; zoomOut(centers: any): void;
mouseMove(evt: any): void; mouseMove(evt: any): void;
mouseOut(): void; mouseOut(): void;
onLegendClick(idx: any): void; onLegendClick(idx: any): void;
panningEnd(range: any): void; panningEnd(range: any): void;
panning(range: any): void; panning(range: any): void;
contextMenu(evt: any): void; contextMenu(evt: any): void;
sharedCrosshairMove(event: any): void;
renderEnd(): void;
}; };
}[]; }[];
methods: { methods: {

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

5
package-lock.json generated

@ -5,8 +5,9 @@
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@chartwerk/core": { "@chartwerk/core": {
"version": "github:chartwerk/core#880b8e064f6df9430df337c6fafb03cc658cb24f", "version": "0.3.4",
"from": "github:chartwerk/core#880b8e064f6df9430df337c6fafb03cc658cb24f" "resolved": "https://registry.npmjs.org/@chartwerk/core/-/core-0.3.4.tgz",
"integrity": "sha512-dDk+xjcR0XVzTrsQnXlQh6syg41gdn2yh6+q+HPMHwG28+OpFoyRufIPhxzobWp8orINn0PtlfnzgYkfnuSIPg=="
}, },
"@types/d3": { "@types/d3": {
"version": "5.16.4", "version": "5.16.4",

2
package.json

@ -15,7 +15,7 @@
"author": "CorpGlory", "author": "CorpGlory",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@chartwerk/core": "github:chartwerk/core#880b8e064f6df9430df337c6fafb03cc658cb24f" "@chartwerk/core": "^0.3.4"
}, },
"devDependencies": { "devDependencies": {
"@types/d3": "^5.7.2", "@types/d3": "^5.7.2",

27
src/index.ts

@ -123,8 +123,8 @@ export class ChartwerkBarPod extends ChartwerkPod<BarTimeSerie, BarOptions> {
if(series.length === 0) { if(series.length === 0) {
throw new Error('There is no visible series'); throw new Error('There is no visible series');
} }
const keysColumn = _.map(series[0].datapoints, row => row[1]); const keysColumn = _.map(series[0].datapoints, row => row[0]);
const valuesColumns = _.map(series, serie => _.map(serie.datapoints, row => row[0])); const valuesColumns = _.map(series, serie => _.map(serie.datapoints, row => row[1]));
// @ts-ignore // @ts-ignore
const additionalValuesColumns = _.map(series, serie => _.map(serie.datapoints, row => row[2] !== undefined ? row[2] : null)); const additionalValuesColumns = _.map(series, serie => _.map(serie.datapoints, row => row[2] !== undefined ? row[2] : null));
const zippedAdditionalValuesColumn = _.zip(...additionalValuesColumns); const zippedAdditionalValuesColumn = _.zip(...additionalValuesColumns);
@ -135,10 +135,10 @@ export class ChartwerkBarPod extends ChartwerkPod<BarTimeSerie, BarOptions> {
return data; return data;
} }
public renderSharedCrosshair(timestamp: number): void { public renderSharedCrosshair(values: { x?: number, y?: number }): void {
this.crosshair.style('display', null); this.crosshair.style('display', null);
const x = this.xScale(timestamp); const x = this.xScale(values.x);
this.crosshair.select('#crosshair-line-x') this.crosshair.select('#crosshair-line-x')
.attr('x1', x) .attr('x1', x)
.attr('x2', x); .attr('x2', x);
@ -247,11 +247,11 @@ export class ChartwerkBarPod extends ChartwerkPod<BarTimeSerie, BarOptions> {
get barWidth(): number { get barWidth(): number {
// TODO: here we use first value + timeInterval as bar width. It is not a good idea // TODO: here we use first value + timeInterval as bar width. It is not a good idea
const xAxisStartValue = _.first(this.series[0].datapoints)[1]; const xAxisStartValue = _.first(this.series[0].datapoints)[0];
let width = this.xScale(xAxisStartValue + this.timeInterval) / 2; let width = this.xScale(xAxisStartValue + this.timeInterval) / 2;
if(this.options.barWidth !== undefined) { if(this.options.barWidth !== undefined) {
// barWidth now has axis-x dimension // barWidth now has axis-x dimension
width = this.xScale(this.minValueX + this.options.barWidth); width = this.xScale(this.state.getMinValueX() + this.options.barWidth);
} }
let rectColumns = this.visibleSeries.length; let rectColumns = this.visibleSeries.length;
if(this.options.stacked === true) { if(this.options.stacked === true) {
@ -299,15 +299,15 @@ export class ChartwerkBarPod extends ChartwerkPod<BarTimeSerie, BarOptions> {
get yScale(): d3.ScaleLinear<number, number> { get yScale(): d3.ScaleLinear<number, number> {
if( if(
this.minValue === undefined || this.state.getMinValueY() === undefined ||
this.maxValue === undefined this.state.getMaxValueY() === undefined
) { ) {
return this.d3.scaleLinear() return this.d3.scaleLinear()
.domain([1, 0]) .domain([1, 0])
.range([0, this.height]); .range([0, this.height]);
} }
return this.d3.scaleLinear() return this.d3.scaleLinear()
.domain([this.maxValue, Math.min(this.minValue, 0)]) .domain([this.maxValue, Math.min(this.state.getMinValueY(), 0)])
.range([0, this.height]); .range([0, this.height]);
} }
@ -322,20 +322,21 @@ export class ChartwerkBarPod extends ChartwerkPod<BarTimeSerie, BarOptions> {
if(this.options.stacked === true) { if(this.options.stacked === true) {
if(this.options.matching === true && this.seriesUniqKeys.length > 0) { if(this.options.matching === true && this.seriesUniqKeys.length > 0) {
const maxValues = this.seriesForMatching.map(series => { const maxValues = this.seriesForMatching.map(series => {
const valuesColumns = _.map(series, serie => _.map(serie.datapoints, row => row[0])); const valuesColumns = _.map(series, serie => _.map(serie.datapoints, row => row[1]));
const zippedValuesColumn = _.zip(...valuesColumns); const zippedValuesColumn = _.zip(...valuesColumns);
return maxValue = _.max(_.map(zippedValuesColumn, row => _.sum(row))); return maxValue = _.max(_.map(zippedValuesColumn, row => _.sum(row)));
}); });
return _.max(maxValues); return _.max(maxValues);
} else { } else {
const valuesColumns = _.map(this.visibleSeries, serie => _.map(serie.datapoints, row => row[0])); const valuesColumns = _.map(this.visibleSeries, serie => _.map(serie.datapoints, row => row[1]));
const zippedValuesColumn = _.zip(...valuesColumns); const zippedValuesColumn = _.zip(...valuesColumns);
maxValue = _.max(_.map(zippedValuesColumn, row => _.sum(row))); maxValue = _.max(_.map(zippedValuesColumn, row => _.sum(row)));
} }
} else { } else {
console.log('else')
maxValue = _.max( maxValue = _.max(
this.visibleSeries.map( this.visibleSeries.map(
serie => _.maxBy<number[]>(serie.datapoints, dp => dp[0])[0] serie => _.maxBy<number[]>(serie.datapoints, dp => dp[1])[0]
) )
); );
} }
@ -358,8 +359,10 @@ export const VueChartwerkBarChartObject = {
mixins: [VueChartwerkPodMixin], mixins: [VueChartwerkPodMixin],
methods: { methods: {
render() { render() {
console.time('bar-render');
const pod = new ChartwerkBarPod(document.getElementById(this.id), this.series, this.options); const pod = new ChartwerkBarPod(document.getElementById(this.id), this.series, this.options);
pod.render(); pod.render();
console.timeEnd('bar-render');
} }
} }
}; };

Loading…
Cancel
Save