Skip to content

Commit 0b05ac5

Browse files
author
Daniel W Mane
committed
Merge pull request #118 from palantir/dev
Merge 0.1.4 into master
2 parents dae7f97 + 742061c commit 0b05ac5

File tree

13 files changed

+108
-28
lines changed

13 files changed

+108
-28
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
Plottable.js
22
============
33

4-
Plottable.js is a library for easily creating beautiful, flexible, interactive, and performant charts for the web. It is built on top of d3 and provides a higher level of abstraction: the developer does not need to worry about d3's low-level components and can easily access many chart renderers, interaction patterns, and a flexible layout engine. Plottable.js is being developed by Palantir Technologies, and is written in TypeScript.
4+
Plottable.js is a library for easily creating flexible, interactive, and performant charts for the web. It is built on top of d3 and provides a higher level of abstraction.
55

6-
Plottable.js is currently in early alpha and does not yet have a stable API.
6+
Plottable consists of three main pieces:
7+
- A grid-based layout engine which handles positioning, sizing, and alignment of components
8+
- "Components", such as LineRenderer or Axis, which process data and can be connected to d3 Scales
9+
- "Interactions", such as PanZoomInteraction or AreaInteraction, which easily allow for custom logic to be bound to common interaction patterns
710

11+
By virtue of being higher-level than D3, it is often much easier to create charts in Plottable.js, with less of a learning curve. Stylistic changes that would be a pain in D3 (e.g. changing font sizes) are trivially easy in Plottable.js (change the CSS and everything updates). On the other hand, if you want the full power and expressivity of D3, you can just write a new Component plugin in D3, and still get all of the benefits of Plottable's layout engine and other components.
12+
13+
Plottable.js is being developed by Palantir Technologies. It's developed in Typescript, and released in Javascript. Plottable is currently in alpha and the API is not yet stable.
814

915
=========
1016
Setup Instructions:

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "plottable.js",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"dependencies": {
55
"d3": "3.4.1"
66
},

examples/demo.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ module Demo {
5353
var yScale = new LinearScale();
5454
var rightAxes = [new YAxis(yScale, "right"), new YAxis(yScale, "right")];
5555
var rightAxesTable = new Table([rightAxes]);
56-
rightAxesTable.colWeight(0);
5756
var xAxis = new XAxis(xScale, "bottom");
5857
var data = makeRandomData(30);
5958
var renderArea = new LineRenderer(data, xScale, yScale);
@@ -75,10 +74,8 @@ module Demo {
7574
var yScale1 = new LinearScale();
7675
var leftAxes = [new YAxis(yScale1, "left"), new YAxis(yScale1, "left")];
7776
var leftAxesTable = new Table([leftAxes]);
78-
leftAxesTable.colWeight(0);
7977
var rightAxes = [new YAxis(yScale1, "right"), new YAxis(yScale1, "right")];
8078
var rightAxesTable = new Table([rightAxes]);
81-
rightAxesTable.colWeight(0);
8279
var data1 = makeRandomData(30, .0005);
8380
var renderer1 = new LineRenderer(data1, xScale1, yScale1);
8481
var row1: Component[] = [leftAxesTable, renderer1, rightAxesTable];
@@ -131,12 +128,10 @@ module Demo {
131128
var yAxisRight = new YAxis(yScale, "right");
132129
var yAxisRightLabel = new AxisLabel("bp y right qd", "vertical-right");
133130
var yAxisRightTable = new Table([[yAxisRight, yAxisRightLabel]]);
134-
yAxisRightTable.colWeight(0);
135131

136132
var yAxisLeft = new YAxis(yScale, "left");
137133
var yAxisLeftLabel = new AxisLabel("bp y left qd", "vertical-left");
138134
var yAxisLeftTable = new Table([[yAxisLeftLabel, yAxisLeft]]);
139-
yAxisLeftTable.colWeight(0);
140135

141136
var data = makeRandomData(30);
142137
var renderArea = new LineRenderer(data, xScale, yScale);

examples/demoDay.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ module DemoDay {
88
s.yScale = new LinearScale();
99
s.leftAxis = new YAxis(s.yScale, "left");
1010
var leftAxisTable = new Table([[new AxisLabel("y", "vertical-left"), s.leftAxis]]);
11-
leftAxisTable.colWeight(0);
1211
s.xAxis = new XAxis(s.xScale, "bottom");
1312
var xAxisTable = new Table([[s.xAxis], [new AxisLabel("x")]]);
14-
xAxisTable.rowWeight(0);
1513

1614
s.renderer = new CircleRenderer(data, s.xScale, s.yScale, null, null, 1.5);
1715
s.xSpark = new LinearScale();
@@ -37,9 +35,7 @@ module DemoDay {
3735
h.xAxis1 = new XAxis(h.xScale1, "bottom");
3836
h.yAxis1 = new YAxis(h.yScale1, "right");
3937
var labelX1Table = new Table([[h.xAxis1], [new AxisLabel("X values")]]);
40-
labelX1Table.rowWeight(0);
4138
var labelY1Table = new Table([[h.yAxis1, new AxisLabel("Counts", "vertical-right")]]);
42-
labelY1Table.colWeight(0);
4339
var table1 = new Table([[h.renderer1, labelY1Table], [labelX1Table, null]]);
4440

4541
var yExtent = d3.extent(data, (d) => d.y);
@@ -52,9 +48,7 @@ module DemoDay {
5248
h.xAxis2 = new XAxis(h.xScale2, "bottom");
5349
h.yAxis2 = new YAxis(h.yScale2, "right");
5450
var labelX2Table = new Table([[h.xAxis2], [new AxisLabel("Y values")]]);
55-
labelX2Table.rowWeight(0);
5651
var labelY2Table = new Table([[h.yAxis2, new AxisLabel("Counts", "vertical-right")]]);
57-
labelY2Table.colWeight(0);
5852
var table2 = new Table([[h.renderer2, labelY2Table], [labelX2Table, null]]);
5953

6054
h.table = new Table([[table1], [table2]]);

examples/simpleChart/demo.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
.demo-title { font-size: 24pt; }
3+
.quadratic-series circle {
4+
fill: red;
5+
}

examples/simpleChart/demo.details

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
name: Plottable.js Simple Chart Demo
3+
description: Creates a chart with an x-axis, y-axis, and circle renderer
4+
authors:
5+
- Justin Lan
6+
normalize_css: no
7+
...

examples/simpleChart/demo.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
2+
<script src="http://palantir.github.io/plottable/plottable.js"></script>
3+
<link rel="stylesheet" type="text/css" href="http://palantir.github.io/plottable/style.css">
4+
5+
<div class="demo-title">Simple Chart</div>
6+
<br>
7+
<svg id="simple-chart"></svg>

examples/simpleChart/demo.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
window.onload = function() {
2+
function makeQuadraticSeries(numPoints) {
3+
var data = [];
4+
for (var i = 0; i< numPoints; i++) {
5+
data.push({x: i, y: i*i});
6+
}
7+
return {data: data, seriesName: "quadratic-series"};
8+
}
9+
10+
var dataseries = makeQuadraticSeries(20);
11+
12+
var svg = d3.select("#simple-chart");
13+
svg.attr("width", 480).attr("height", 320);
14+
var xScale = new LinearScale();
15+
var yScale = new LinearScale();
16+
var xAxis = new XAxis(xScale, "bottom");
17+
var yAxis = new YAxis(yScale, "left");
18+
var renderAreaD1 = new CircleRenderer(dataseries, xScale, yScale);
19+
var basicTable = new Table([[yAxis, renderAreaD1],
20+
[null, xAxis]]);
21+
basicTable.anchor(svg).computeLayout().render();
22+
};

license_header.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
Plottable v0.1.3 (https://github.com/palantir/plottable)
2+
Plottable v0.1.4 (https://github.com/palantir/plottable)
33
Copyright 2014 Palantir Technologies
44
Licensed under MIT (https://github.com/palantir/plottable/blob/master/LICENSE)
55
*/

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "plottable.js",
3-
"version": "0.1.3",
4-
"description": "A library for easily creating charts within a grid layout.",
3+
"version": "0.1.4",
4+
"description": "Build flexible, performant, interactive charts using D3",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/palantir/plottable.git"

src/component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ class Component {
8484
}
8585
if (this.rowWeight() === 0 && this.rowMinimum() !== 0) {
8686
yOffset += (availableHeight - this.rowMinimum()) * this.yAlignProportion;
87-
availableHeight = this.rowMinimum();
87+
availableHeight = availableHeight > this.rowMinimum() ? this.rowMinimum() : availableHeight;
8888
}
8989
if (this.colWeight() === 0 && this.colMinimum() !== 0) {
9090
xOffset += (availableWidth - this.colMinimum()) * this.xAlignProportion;
91-
availableWidth = this.colMinimum();
91+
availableWidth = availableWidth > this.colMinimum() ? this.colMinimum() : availableWidth;
9292
}
9393
this.xOffset = xOffset;
9494
this.yOffset = yOffset;

src/table.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ class Table extends Component {
1818
private rowWeightSum: number;
1919
private colWeightSum: number;
2020

21-
constructor(rows: Component[][], rowWeightVal=1, colWeightVal=1) {
21+
private guessRowWeight = true;
22+
private guessColWeight = true;
23+
24+
constructor(rows: Component[][]) {
2225
super();
2326
this.classed(Table.CSS_CLASS, true);
2427
// Clean out any null components and replace them with base Components
@@ -28,7 +31,6 @@ class Table extends Component {
2831
this.cols = d3.transpose(rows);
2932
this.nRows = this.rows.length;
3033
this.nCols = this.cols.length;
31-
super.rowWeight(rowWeightVal).colWeight(colWeightVal);
3234
}
3335

3436
public anchor(element: D3.Selection) {
@@ -49,7 +51,7 @@ class Table extends Component {
4951
var freeWidth = this.availableWidth - this.colMinimum();
5052
var freeHeight = this.availableHeight - this.rowMinimum();
5153
if (freeWidth < 0 || freeHeight < 0) {
52-
throw new Error("InsufficientSpaceError");
54+
throw new Error("Insufficient Space");
5355
}
5456

5557
// distribute remaining height to rows
@@ -101,6 +103,33 @@ class Table extends Component {
101103
}
102104

103105
/* Getters */
106+
107+
public rowWeight(): number;
108+
public rowWeight(newVal: number): Table;
109+
public rowWeight(newVal?: number): any {
110+
if (newVal != null || !this.guessRowWeight) {
111+
this.guessRowWeight = false;
112+
return super.rowWeight(newVal);
113+
} else {
114+
var componentWeights: number[][] = this.rows.map((r) => r.map((c) => c.rowWeight()));
115+
var biggestWeight = d3.max(componentWeights.map((ws) => d3.max(ws)));
116+
return biggestWeight > 0 ? 1 : 0;
117+
}
118+
}
119+
120+
public colWeight(): number;
121+
public colWeight(newVal: number): Table;
122+
public colWeight(newVal?: number): any {
123+
if (newVal != null || !this.guessColWeight) {
124+
this.guessColWeight = false;
125+
return super.colWeight(newVal);
126+
} else {
127+
var componentWeights: number[][] = this.rows.map((r) => r.map((c) => c.colWeight()));
128+
var biggestWeight = d3.max(componentWeights.map((ws) => d3.max(ws)));
129+
return biggestWeight > 0 ? 1 : 0;
130+
}
131+
}
132+
104133
public rowMinimum(): number;
105134
public rowMinimum(newVal: number): Component;
106135
public rowMinimum(newVal?: number): any {

test/tableTests.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ var assert = chai.assert;
55
function generateBasicTable(nRows, nCols) {
66
// makes a table with exactly nRows * nCols children in a regular grid, with each
77
// child being a basic component
8-
var emptyDataset: IDataset = {data: [], seriesName: "blah"};
98
var rows: Component[][] = [];
109
var components: Component[] = [];
1110
for(var i=0; i<nRows; i++) {
1211
var cols = [];
1312
for(var j=0; j<nCols; j++) {
14-
var r = new Component();
13+
var r = new Component().rowWeight(1).colWeight(1);
1514
cols.push(r);
1615
components.push(r);
1716
}
@@ -34,13 +33,12 @@ describe("Tables", () => {
3433
assert.equal(component.constructor.name, "Component", "the component is a base Component");
3534
});
3635

37-
it("tables with insufficient space throw InsufficientSpaceError", () => {
36+
it("tables with insufficient space throw Insufficient Space", () => {
3837
var svg = generateSVG(200, 200);
39-
var c = new Component();
40-
c.rowMinimum(300).colMinimum(300);
38+
var c = new Component().rowMinimum(300).colMinimum(300);
4139
var t = new Table([[c]]);
4240
t.anchor(svg);
43-
assert.throws(() => t.computeLayout(), Error, "InsufficientSpaceError");
41+
assert.throws(() => t.computeLayout(), Error, "Insufficient Space");
4442
svg.remove();
4543
});
4644

@@ -133,4 +131,21 @@ describe("Tables", () => {
133131
assert.throws(() => table.rowMinimum(3), Error, "cannot be directly set");
134132
assert.throws(() => table.colMinimum(3), Error, "cannot be directly set");
135133
});
134+
135+
it("tables guess weights intelligently", () => {
136+
var c1 = new Component().rowWeight(0).colWeight(0);
137+
var c2 = new Component().rowWeight(0).colWeight(0);
138+
var table = new Table([[c1], [c2]]);
139+
assert.equal(table.rowWeight(), 0, "the first table guessed 0 for rowWeight");
140+
assert.equal(table.colWeight(), 0, "the first table guessed 0 for rowWeight");
141+
142+
c1.rowWeight(0);
143+
c2.rowWeight(3);
144+
145+
assert.equal(table.rowWeight(), 1, "the table now guesses 1 for rowWeight");
146+
assert.equal(table.colWeight(), 0, "the table still guesses 0 for colWeight");
147+
148+
assert.equal(table.rowWeight(2), table, "rowWeight returned the table");
149+
assert.equal(table.rowWeight(), 2, "the rowWeight was overridden explicitly");
150+
});
136151
});

0 commit comments

Comments
 (0)