Browse Source

New options for line pod

svg-version-test
Alexander Velikiy 3 years ago
parent
commit
71cecfe507
  1. 2
      dist/index.d.ts
  2. 4
      dist/index.js
  3. 2
      dist/types.d.ts
  4. 2
      examples/demo.html
  5. 8
      package-lock.json
  6. 4
      package.json
  7. 18
      src/index.ts
  8. 2
      src/types.ts

2
dist/index.d.ts vendored

@ -43,7 +43,7 @@ export declare class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
onMouseOut(): void; onMouseOut(): void;
protected zoomOut(): void; protected zoomOut(): void;
} }
export declare const VueChartwerkLineChartObject: { export declare const VueChartwerkLinePod: {
render(createElement: any): any; render(createElement: any): any;
mixins: { mixins: {
props: { props: {

4
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/types.d.ts vendored

@ -6,6 +6,8 @@ declare type LineTimeSerieParams = {
renderDots: boolean; renderDots: boolean;
renderLines: boolean; renderLines: boolean;
useOutOfRange: boolean; useOutOfRange: boolean;
dashArray: string;
class: string;
}; };
export declare enum Mode { export declare enum Mode {
STANDARD = "Standard", STANDARD = "Standard",

2
examples/demo.html

@ -28,7 +28,7 @@
var pod = new LinePod( var pod = new LinePod(
document.getElementById('chart'), document.getElementById('chart'),
[ [
{ target: 'test1', datapoints: data1, color: 'green' }, { target: 'test1', datapoints: data1, color: 'green', dashArray: '5,3', class: 'first' },
{ target: 'test2', datapoints: data2, color: 'blue' }, { target: 'test2', datapoints: data2, color: 'blue' },
{ target: 'test3', datapoints: data3, color: 'orange' }, { target: 'test3', datapoints: data3, color: 'orange' },
], ],

8
package-lock.json generated

@ -1,13 +1,13 @@
{ {
"name": "@chartwerk/line-pod", "name": "@chartwerk/line-pod",
"version": "0.4.6", "version": "0.4.8",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@chartwerk/core": { "@chartwerk/core": {
"version": "0.3.3", "version": "0.3.4",
"resolved": "https://registry.npmjs.org/@chartwerk/core/-/core-0.3.3.tgz", "resolved": "https://registry.npmjs.org/@chartwerk/core/-/core-0.3.4.tgz",
"integrity": "sha512-aauWwYLPeMuLF727twW74GW6Uw2yqPXD8vYuFle/4nN4xjKbjWJvU7/9wlF4xh/azrpOrYWdD4l4SD25u8DzUg==" "integrity": "sha512-dDk+xjcR0XVzTrsQnXlQh6syg41gdn2yh6+q+HPMHwG28+OpFoyRufIPhxzobWp8orINn0PtlfnzgYkfnuSIPg=="
}, },
"@types/d3": { "@types/d3": {
"version": "5.16.4", "version": "5.16.4",

4
package.json

@ -1,6 +1,6 @@
{ {
"name": "@chartwerk/line-pod", "name": "@chartwerk/line-pod",
"version": "0.4.7", "version": "0.4.8",
"description": "Chartwerk line chart", "description": "Chartwerk line chart",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
@ -15,7 +15,7 @@
"author": "CorpGlory", "author": "CorpGlory",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@chartwerk/core": "^0.3.3" "@chartwerk/core": "^0.3.4"
}, },
"devDependencies": { "devDependencies": {
"@types/d3": "5.16.4", "@types/d3": "5.16.4",

18
src/index.ts

@ -56,7 +56,7 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
clearAllMetrics(): void { clearAllMetrics(): void {
// TODO: temporary hack before it will be implemented in core. // TODO: temporary hack before it will be implemented in core.
this.d3.selectAll('.metric-el').remove(); this.chartContainer.selectAll('.metric-el').remove();
} }
initLineGenerator(): void { initLineGenerator(): void {
@ -101,11 +101,13 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
} }
_renderDots(datapoints: number[][], serieIdx: number): void { _renderDots(datapoints: number[][], serieIdx: number): void {
const customClass = this.series[serieIdx].class || '';
this.metricContainer.selectAll(null) this.metricContainer.selectAll(null)
.data(datapoints) .data(datapoints)
.enter() .enter()
.append('circle') .append('circle')
.attr('class', `metric-circle-${serieIdx} metric-el`) .attr('class', `metric-circle-${serieIdx} metric-el ${customClass}`)
.attr('fill', this.getSerieColor(serieIdx)) .attr('fill', this.getSerieColor(serieIdx))
.attr('r', METRIC_CIRCLE_RADIUS) .attr('r', METRIC_CIRCLE_RADIUS)
.style('pointer-events', 'none') .style('pointer-events', 'none')
@ -114,15 +116,19 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
} }
_renderLines(datapoints: number[][], serieIdx: number): void { _renderLines(datapoints: number[][], serieIdx: number): void {
const dashArray = this.series[serieIdx].dashArray !== undefined ? this.series[serieIdx].dashArray : '0';
const customClass = this.series[serieIdx].class || ''
this.metricContainer this.metricContainer
.append('path') .append('path')
.datum(datapoints) .datum(datapoints)
.attr('class', `metric-path-${serieIdx} metric-el`) .attr('class', `metric-path-${serieIdx} metric-el ${customClass}`)
.attr('fill', 'none') .attr('fill', 'none')
.attr('stroke', this.getSerieColor(serieIdx)) .attr('stroke', this.getSerieColor(serieIdx))
.attr('stroke-width', 1) .attr('stroke-width', 1)
.attr('stroke-opacity', 0.7) .attr('stroke-opacity', 0.7)
.attr('pointer-events', 'none') .attr('pointer-events', 'none')
.style('stroke-dasharray', dashArray)
.attr('d', this.lineGenerator); .attr('d', this.lineGenerator);
} }
@ -490,14 +496,14 @@ export class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
} }
} }
// it is used with Vue.component, e.g.: Vue.component('chartwerk-line-pod', VueChartwerkLineChartObject) // it is used with Vue.component, e.g.: Vue.component('chartwerk-line-pod', VueChartwerkLinePod)
export const VueChartwerkLineChartObject = { export const VueChartwerkLinePod = {
// alternative to `template: '<div class="chartwerk-line-pod" :id="id" />'` // alternative to `template: '<div class="chartwerk-line-pod" :id="id" />'`
render(createElement) { render(createElement) {
return createElement( return createElement(
'div', 'div',
{ {
class: { 'chartwerk-line-chart': true }, class: { 'chartwerk-line-pod': true },
attrs: { id: this.id } attrs: { id: this.id }
} }
); );

2
src/types.ts

@ -7,6 +7,8 @@ type LineTimeSerieParams = {
renderDots: boolean, renderDots: boolean,
renderLines: boolean, // TODO: refactor same as scatter-pod renderLines: boolean, // TODO: refactor same as scatter-pod
useOutOfRange: boolean, // It's temporary hack. Need to refactor getValueInterval() method useOutOfRange: boolean, // It's temporary hack. Need to refactor getValueInterval() method
dashArray: string; // dasharray attr, only for lines
class: string; // option to add custom class to each serie element
} }
export enum Mode { export enum Mode {
STANDARD = 'Standard', STANDARD = 'Standard',

Loading…
Cancel
Save