Compare commits

...

2 Commits

Author SHA1 Message Date
vargburz 46910fa3da grid styles 3 years ago
vargburz 81b66f971b chart background 3 years ago
  1. 1
      dist/index.d.ts
  2. 2
      dist/index.js
  3. 6
      dist/types.d.ts
  4. 12
      src/components/grid.ts
  5. 9
      src/css/style.css
  6. 20
      src/index.ts
  7. 6
      src/types.ts

1
dist/index.d.ts vendored

@ -62,6 +62,7 @@ declare abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
protected renderYAxis(): void; protected renderYAxis(): void;
protected renderY1Axis(): void; protected renderY1Axis(): void;
protected renderCrosshair(): void; protected renderCrosshair(): void;
updateBackground(): void;
protected addEvents(): void; protected addEvents(): void;
protected initBrush(): void; protected initBrush(): void;
protected filterByKeyEvent(key: KeyEvent): () => boolean; protected filterByKeyEvent(key: KeyEvent): () => boolean;

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

6
dist/types.d.ts vendored

@ -45,6 +45,9 @@ export declare type Options = {
orientation?: CrosshairOrientation; orientation?: CrosshairOrientation;
color?: string; color?: string;
}; };
background?: {
color?: string;
};
timeInterval?: { timeInterval?: {
timeFormat?: TimeFormat; timeFormat?: TimeFormat;
count?: number; count?: number;
@ -96,6 +99,9 @@ export declare type Options = {
renderLegend?: boolean; renderLegend?: boolean;
}; };
export declare type GridOptions = { export declare type GridOptions = {
color?: string;
opacity?: number;
strokeWidth?: number;
x?: { x?: {
enabled?: boolean; enabled?: boolean;
ticksCount?: number; ticksCount?: number;

12
src/components/grid.ts

@ -8,6 +8,9 @@ import defaultsDeep from 'lodash/defaultsDeep';
const DEFAULT_GRID_TICK_COUNT = 5; const DEFAULT_GRID_TICK_COUNT = 5;
const DEFAULT_GRID_OPTIONS: GridOptions = { const DEFAULT_GRID_OPTIONS: GridOptions = {
color: 'lightgray',
opacity: 0.7,
strokeWidth: 0.5,
x: { x: {
enabled: true, enabled: true,
ticksCount: DEFAULT_GRID_TICK_COUNT, ticksCount: DEFAULT_GRID_TICK_COUNT,
@ -85,9 +88,12 @@ export class Grid {
updateStylesOfTicks(): void { updateStylesOfTicks(): void {
// TODO: add options for these actions // TODO: add options for these actions
this._svgEl.selectAll('.grid').selectAll('.tick') this._svgEl.selectAll('.grid').selectAll('.tick').select('line')
.attr('opacity', '0.5'); .attr('stroke', this.gridOptions.color)
.attr('stroke-opacity', this.gridOptions.opacity)
.style('stroke-width', this.gridOptions.strokeWidth + 'px');
this._svgEl.selectAll('.grid').select('.domain') this._svgEl.selectAll('.grid').select('.domain')
.style('pointer-events', 'none'); .style('pointer-events', 'none')
.style('stroke-width', 0);
} }
} }

9
src/css/style.css

@ -1,9 +0,0 @@
.grid path {
stroke-width: 0;
}
.grid line {
stroke: lightgrey;
stroke-opacity: 0.7;
shape-rendering: crispEdges;
}

20
src/index.ts

@ -2,8 +2,6 @@ import VueChartwerkPodMixin from './VueChartwerkPodMixin';
import { PodState } from './state'; import { PodState } from './state';
import { Grid } from './components/grid'; import { Grid } from './components/grid';
import styles from './css/style.css';
import { import {
Margin, Margin,
TimeSerie, TimeSerie,
@ -98,6 +96,9 @@ const DEFAULT_OPTIONS: Options = {
format: AxisFormat.NUMERIC format: AxisFormat.NUMERIC
} }
}, },
background: {
color: 'none',
},
crosshair: { crosshair: {
orientation: CrosshairOrientation.VERTICAL, orientation: CrosshairOrientation.VERTICAL,
color: 'red' color: 'red'
@ -146,9 +147,6 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
_series: T[] = [], _series: T[] = [],
_options: O _options: O
) { ) {
// TODO: test if it's necessary
styles.use();
let options = cloneDeep(_options); let options = cloneDeep(_options);
defaultsDeep(options, DEFAULT_OPTIONS); defaultsDeep(options, DEFAULT_OPTIONS);
this.options = options; this.options = options;
@ -172,11 +170,11 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
} }
public render(): void { public render(): void {
this.renderAxes();
this.renderGrid();
this.renderClipPath(); this.renderClipPath();
this.addEvents(); this.addEvents();
this.updateBackground();
this.renderAxes();
this.renderGrid();
this.renderCrosshair(); this.renderCrosshair();
this.renderMetricsContainer(); this.renderMetricsContainer();
@ -395,6 +393,12 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
} }
} }
updateBackground(): void {
// TODO: background should be a separate component
const background = this.chartContainer.select('.overlay') || this.chartContainer.select('.custom-overlay');
background.attr('fill', this.options.background.color);
}
protected addEvents(): void { protected addEvents(): void {
// TODO: refactor for a new mouse/scroll events // TODO: refactor for a new mouse/scroll events
const panKeyEvent = this.options.zoomEvents.mouse.pan.keyEvent; const panKeyEvent = this.options.zoomEvents.mouse.pan.keyEvent;

6
src/types.ts

@ -37,6 +37,9 @@ export type Options = {
orientation?: CrosshairOrientation; orientation?: CrosshairOrientation;
color?: string; color?: string;
} }
background?: {
color?: string;
};
timeInterval?: { timeInterval?: {
timeFormat?: TimeFormat; timeFormat?: TimeFormat;
count?: number; count?: number;
@ -88,6 +91,9 @@ export type Options = {
renderLegend?: boolean; renderLegend?: boolean;
}; };
export type GridOptions = { export type GridOptions = {
color?: string,
opacity?: number,
strokeWidth?: number,
x?: { x?: {
enabled?: boolean; enabled?: boolean;
ticksCount?: number; ticksCount?: number;

Loading…
Cancel
Save