Skip to content

Commit

Permalink
fit canvas prop, prod updates
Browse files Browse the repository at this point in the history
  • Loading branch information
camargo committed Mar 9, 2017
1 parent f3ce5a7 commit 16d4356
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
*.log
index.js
index.d.ts
11 changes: 11 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
example
node_modules
src
.editorconfig
.gitignore
build.sh
clean.sh
index.ts
tsconfig.json
tslint.json
webpack.config.js
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@

This is a Web Component that wraps [gl-plot2d](https://github.com/gl-vis/gl-plot2d).

![Line Graph](http:https://i.imgur.com/WMq7o80.png)
![Stacked Graphs](http:https://i.imgur.com/YpSzWKL.png)

## Build & Run
## Installation

```
npm install gl-plot-2d --save
```

## Example

- `<gl-plot-2d> in React` - [Code](https://github.com/camargo/gl-plot-2d/tree/master/example)

## Build & Run Example

```
npm install
Expand Down
8 changes: 5 additions & 3 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class App extends Component {
debug: this.debug1,
height: this.height1,
width: this.width1,
fitViewBox: true,
plotOptions: this.plotOptions1
});
}
Expand Down Expand Up @@ -183,13 +184,13 @@ class App extends Component {
labelFont: ["sans-serif", "sans-serif"],
labelColor: [[0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 0], [0, 0, 0, 0]],
ticks: [axes.x, axes.y],
tickEnable: [false, true, false, false],
tickPad: [20, 20, 0, 0],
tickEnable: [true, true, false, false],
tickPad: [15, 20, 0, 0],
tickAngle: [0, 0, 0, 0],
tickColor: [[0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 0], [0, 0, 0, 0]],
tickMarkWidth: [1, 1, 1, 1],
tickMarkLength: [4, 4, 4, 4],
tickMarkColor: [[0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 0], [0, 0, 0, 0]],
tickMarkColor: [[0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 0], [0, 0, 0, 0]],
gridLineEnable: [false, true],
gridLineColor: [[0, 0, 0, 0.5], [0, 0, 0, 0.5]],
gridLineWidth: [0.5, 0.5],
Expand All @@ -204,6 +205,7 @@ class App extends Component {
debug: this.debug2,
height: this.height2,
width: this.width2,
fitViewBox: true,
plotOptions: this.plotOptions2
});
}
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"devDependencies": {
"babel-core": "6.23.1",
"babel-loader": "6.3.2",
"babel-loader": "6.4.0",
"babel-plugin-transform-runtime": "6.23.0",
"babel-preset-es2015": "6.22.0",
"babel-preset-react": "6.23.0",
Expand Down
2 changes: 2 additions & 0 deletions example/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ module.exports = {
entry: {
app: './app.js'
},

output: {
path: __dirname,
filename: '[name].js',
chunkFilename: '[id].js'
},

module: {
loaders: [
{ test: /\.(js|jsx)$/,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"tslib": "1.6.0",
"tslint": "4.5.1",
"typescript": "2.2.1",
"uglifyjs-webpack-plugin": "0.3.0",
"webpack": "2.2.1"
},
"browserify": {
Expand Down
25 changes: 10 additions & 15 deletions src/GlPlot2dComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class GlPlot2dComponent extends skate.Component<GlPlot2dComponentProps> {
debug: skate.prop.boolean({ attribute: true }),
height: skate.prop.string({ attribute: true }),
width: skate.prop.string({ attribute: true }),
fitViewBox: skate.prop.boolean({ attribute: true }),
plotOptions: skate.prop.object<GlPlot2dComponent, GlPlot2dOptions>({ attribute: true })
};
}
Expand Down Expand Up @@ -124,6 +125,11 @@ export class GlPlot2dComponent extends skate.Component<GlPlot2dComponentProps> {
this['width'] = newValue;
}
break;
case 'fitViewBox':
if (newValue) {
this['fitViewBox'] = newValue;
}
break;
case 'plot-options':
if (newValue) {
this['plotOptions'] = JSON.parse(newValue);
Expand Down Expand Up @@ -234,18 +240,6 @@ export class GlPlot2dComponent extends skate.Component<GlPlot2dComponentProps> {
this.canvas.onmousedown = (event: MouseEvent) => {
this.onMouseDown(event);
};

this.canvas.onmouseup = () => {
// TODO.
};

this.canvas.onmousemove = () => {
// TODO.
};

this.canvas.onmouseover = () => {
// TODO.
};
}
}

Expand Down Expand Up @@ -281,9 +275,10 @@ export class GlPlot2dComponent extends skate.Component<GlPlot2dComponentProps> {
if (div) {
const boundingClientRect = div.getBoundingClientRect();

// Set the viewBox to contain the entire surrounding div.
// TODO: Parameterize the viewBox.
this['plotOptions'].viewBox = [45, 1, boundingClientRect.width - 1, boundingClientRect.height - 1];
// Set the viewBox to contain the entire surrounding div if fitViewBox is true.
if (this['fitViewBox']) {
this['plotOptions'].viewBox = [45, 1, boundingClientRect.width - 1, boundingClientRect.height - 1];
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/GlPlot2dComponentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export interface GlPlot2dComponentProps {
debug: boolean;
height: string;
width: string;
fitViewBox: boolean;
plotOptions: GlPlot2dOptions; // Specific to gl-plot2d.
}
2 changes: 1 addition & 1 deletion src/GlPlot2dUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export function getMaxFromPositions(positions: number[]): Point {

/**
* Gets ticks by type for x and y Axes.
* Supported types are linear, log, and pow.
* Supported types are linear and log.
*
* @export
* @param {string} type
Expand Down
5 changes: 5 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
entry: __dirname + '/index.ts',
Expand All @@ -20,6 +21,10 @@ module.exports = {
libraryTarget: 'umd'
},

plugins: [
new UglifyJSPlugin()
],

performance: {
hints: false
}
Expand Down

0 comments on commit 16d4356

Please sign in to comment.