mirror of https://github.com/vitalif/dimple
Patched Order Rules
parent
660ba1d868
commit
f4ae0a014a
|
@ -1,5 +1,5 @@
|
|||
<div id="chartContainer">
|
||||
<script src="/lib/d3.v3.min.js"></script>
|
||||
<script src="/lib/d3.v3.4.8.min.js"></script>
|
||||
<script src="/dist/dimple.v2.0.0.js"></script>
|
||||
<script type="text/javascript">
|
||||
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div id="chartContainer">
|
||||
<script src="/lib/d3.v3.min.js"></script>
|
||||
<script src="/lib/d3.v3.4.8.min.js"></script>
|
||||
<script src="/dist/dimple.v2.0.0.js"></script>
|
||||
<script type="text/javascript">
|
||||
// This is the simple vertical grouped stacked 100% bar example
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div id="chartContainer">
|
||||
<script src="/lib/d3.v3.min.js"></script>
|
||||
<script src="/lib/d3.v3.4.8.min.js"></script>
|
||||
<script src="/dist/dimple.v2.0.0.js"></script>
|
||||
<script type="text/javascript">
|
||||
// Start off with a couple of rows of data
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div id="chartContainer">
|
||||
<script src="/lib/d3.v3.min.js"></script>
|
||||
<script src="/lib/d3.v3.4.8.min.js"></script>
|
||||
<script src="/dist/dimple.v2.0.0.js"></script>
|
||||
<script type="text/javascript">
|
||||
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div id="chartContainer">
|
||||
<script src="/lib/d3.v3.min.js"></script>
|
||||
<script src="/lib/d3.v3.4.8.min.js"></script>
|
||||
<script src="/dist/dimple.v2.0.0.js"></script>
|
||||
<script type="text/javascript">
|
||||
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div id="chartContainer">
|
||||
<script src="/lib/d3.v3.min.js"></script>
|
||||
<script src="/lib/d3.v3.4.8.min.js"></script>
|
||||
<script src="/dist/dimple.v2.0.0.js"></script>
|
||||
<script type="text/javascript">
|
||||
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
||||
|
|
|
@ -1,19 +1,34 @@
|
|||
<div id="chartContainer">
|
||||
<script src="/lib/d3.v3.min.js"></script>
|
||||
<script src="/dist/dimple.v2.0.0.js"></script>
|
||||
<script src="/lib/d3.v3.4.8.min.js"></script>
|
||||
<script src="/dist/dimple.v2.0.2.js"></script>
|
||||
<script type="text/javascript">
|
||||
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
||||
d3.tsv("/data/example_data.tsv", function (data) {
|
||||
var myChart = new dimple.chart(svg, data);
|
||||
myChart.setBounds(60, 50, 460, 280);
|
||||
var monthAxis = myChart.addCategoryAxis("x", "Month");
|
||||
monthAxis.addOrderRule("Date");
|
||||
var volumeAxis = myChart.addMeasureAxis("y", "Unit Sales");
|
||||
var profitAxis = myChart.addMeasureAxis("y", "Operating Profit");
|
||||
myChart.addSeries("Quantity", dimple.plot.line, [monthAxis, volumeAxis]);
|
||||
myChart.addSeries("Op. Profit", dimple.plot.line, [monthAxis, profitAxis]);
|
||||
myChart.addLegend(200, 10, 380, 20, "right");
|
||||
myChart.draw();
|
||||
|
||||
data = [
|
||||
{ "Int": 1, "Float": 234, "Text": "XFBGR", "Date": "12/5/99", "Group": "A"},
|
||||
{ "Int": 2, "Float": 54.35, "Text": "YTREB", "Date": "1/1/00", "Group": "A"},
|
||||
{ "Int": 3, "Float": -453, "Text": "XGFDY", "Date": "2 February 2007", "Group": "B"},
|
||||
{ "Int": 4, "Float": 5436546, "Text": "XGFDE", "Date": "2000-03-01", "Group": "B"},
|
||||
{ "Int": 5, "Float": 4323, "Text": "YTREB", "Date": "10/10/2000", "Group": "C"},
|
||||
{ "Int": 6, "Float": 0, "Text": "GFDHN", "Date": "11/10/2000", "Group": "C"},
|
||||
{ "Int": 7, "Float": -453, "Text": "TRET", "Date": "10/9/2000", "Group": "D"},
|
||||
{ "Int": 1, "Float": 5436546, "Text": "GFDGFDHG", "Date": "10/10/2000", "Group": "E"}
|
||||
];
|
||||
var s = dimple._getOrderedList(data, "Int", { ordering : "Text" });
|
||||
console.log(s);
|
||||
//
|
||||
//
|
||||
// var monthAxis = myChart.addCategoryAxis("x", "Owner");
|
||||
// monthAxis.addOrderRule("Brand");
|
||||
// var volumeAxis = myChart.addMeasureAxis("y", "Unit Sales");
|
||||
// var profitAxis = myChart.addMeasureAxis("y", "Operating Profit");
|
||||
// myChart.addSeries("Quantity", dimple.plot.line, [monthAxis, volumeAxis]);
|
||||
// myChart.addSeries("Op. Profit", dimple.plot.line, [monthAxis, profitAxis]);
|
||||
// myChart.addLegend(200, 10, 380, 20, "right");
|
||||
// myChart.draw();
|
||||
});
|
||||
</script>
|
||||
</div>
|
|
@ -3939,6 +3939,7 @@
|
|||
mainArray = [].concat(mainField),
|
||||
fields = [].concat(mainField),
|
||||
defs = [];
|
||||
|
||||
// Force the level definitions into an array
|
||||
if (levelDefinitions !== null && levelDefinitions !== undefined) {
|
||||
defs = defs.concat(levelDefinitions);
|
||||
|
@ -3947,7 +3948,9 @@
|
|||
defs = defs.concat({ ordering: mainArray, desc: false });
|
||||
// Exclude fields if this does not contain a function
|
||||
defs.forEach(function (def) {
|
||||
var field;
|
||||
var field,
|
||||
values = [],
|
||||
tempFields = [];
|
||||
if (typeof def.ordering === "function") {
|
||||
for (field in data[0]) {
|
||||
if (data[0].hasOwnProperty(field) && fields.indexOf(field) === -1) {
|
||||
|
@ -3956,6 +3959,21 @@
|
|||
}
|
||||
} else if (!(def.ordering instanceof Array)) {
|
||||
fields.push(def.ordering);
|
||||
} else {
|
||||
// We now receive fields as an array or values as an array which is a bit of an oversight in the API
|
||||
// We will therefore check the values of the array against the fields in the data
|
||||
for (field = 0; field < def.ordering.length; field += 1) {
|
||||
if (data[0].hasOwnProperty(def.ordering[field])) {
|
||||
tempFields.push(def.ordering[field]);
|
||||
}
|
||||
values.push(def.ordering[field]);
|
||||
}
|
||||
// If more than half of the values are fields we will assume that these are fields and not dimension values
|
||||
if (tempFields.length > values.length / 2) {
|
||||
fields.concat(tempFields);
|
||||
} else {
|
||||
def.values = values;
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
rollupData = dimple._rollUp(data, mainArray, fields);
|
||||
|
@ -3968,7 +3986,6 @@
|
|||
var desc = (def.desc === null || def.desc === undefined ? false : def.desc),
|
||||
ordering = def.ordering,
|
||||
orderArray = [],
|
||||
field = (typeof ordering === "string" ? ordering : null),
|
||||
sum = function (array) {
|
||||
var total = 0,
|
||||
i;
|
||||
|
@ -4003,12 +4020,12 @@
|
|||
sortStack.push(function (a, b) {
|
||||
return (desc ? -1 : 1) * ordering(a, b);
|
||||
});
|
||||
} else if (ordering instanceof Array) {
|
||||
} else if (def.values && def.values.length > 0) {
|
||||
// The order list may be an array of arrays
|
||||
// combine the values with pipe delimiters.
|
||||
// The delimiter is irrelevant as long as it is consistent
|
||||
// with the sort predicate below
|
||||
ordering.forEach(function (d) {
|
||||
def.values.forEach(function (d) {
|
||||
orderArray.push(([].concat(d)).join("|"));
|
||||
}, this);
|
||||
// Sort according to the axis position
|
||||
|
@ -4035,16 +4052,18 @@
|
|||
return (desc ? -1 : 1) * (aIx - bIx);
|
||||
});
|
||||
} else {
|
||||
// Sort the data
|
||||
sortStack.push(function (a, b) {
|
||||
// The result value
|
||||
var result = 0;
|
||||
// Find the field
|
||||
if (a[field] !== undefined && b[field] !== undefined) {
|
||||
// Compare just the first mapped value
|
||||
result = compare([].concat(a[field]), [].concat(b[field]));
|
||||
}
|
||||
return (desc ? -1 : 1) * result;
|
||||
([].concat(def.ordering)).forEach(function (field) {
|
||||
// Sort the data
|
||||
sortStack.push(function (a, b) {
|
||||
// The result value
|
||||
var result = 0;
|
||||
// Find the field
|
||||
if (a[field] !== undefined && b[field] !== undefined) {
|
||||
// Compare just the first mapped value
|
||||
result = compare([].concat(a[field]), [].concat(b[field]));
|
||||
}
|
||||
return (desc ? -1 : 1) * result;
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -8,6 +8,7 @@
|
|||
mainArray = [].concat(mainField),
|
||||
fields = [].concat(mainField),
|
||||
defs = [];
|
||||
|
||||
// Force the level definitions into an array
|
||||
if (levelDefinitions !== null && levelDefinitions !== undefined) {
|
||||
defs = defs.concat(levelDefinitions);
|
||||
|
@ -16,7 +17,9 @@
|
|||
defs = defs.concat({ ordering: mainArray, desc: false });
|
||||
// Exclude fields if this does not contain a function
|
||||
defs.forEach(function (def) {
|
||||
var field;
|
||||
var field,
|
||||
values = [],
|
||||
tempFields = [];
|
||||
if (typeof def.ordering === "function") {
|
||||
for (field in data[0]) {
|
||||
if (data[0].hasOwnProperty(field) && fields.indexOf(field) === -1) {
|
||||
|
@ -25,6 +28,21 @@
|
|||
}
|
||||
} else if (!(def.ordering instanceof Array)) {
|
||||
fields.push(def.ordering);
|
||||
} else {
|
||||
// We now receive fields as an array or values as an array which is a bit of an oversight in the API
|
||||
// We will therefore check the values of the array against the fields in the data
|
||||
for (field = 0; field < def.ordering.length; field += 1) {
|
||||
if (data[0].hasOwnProperty(def.ordering[field])) {
|
||||
tempFields.push(def.ordering[field]);
|
||||
}
|
||||
values.push(def.ordering[field]);
|
||||
}
|
||||
// If more than half of the values are fields we will assume that these are fields and not dimension values
|
||||
if (tempFields.length > values.length / 2) {
|
||||
fields.concat(tempFields);
|
||||
} else {
|
||||
def.values = values;
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
rollupData = dimple._rollUp(data, mainArray, fields);
|
||||
|
@ -37,7 +55,6 @@
|
|||
var desc = (def.desc === null || def.desc === undefined ? false : def.desc),
|
||||
ordering = def.ordering,
|
||||
orderArray = [],
|
||||
field = (typeof ordering === "string" ? ordering : null),
|
||||
sum = function (array) {
|
||||
var total = 0,
|
||||
i;
|
||||
|
@ -72,12 +89,12 @@
|
|||
sortStack.push(function (a, b) {
|
||||
return (desc ? -1 : 1) * ordering(a, b);
|
||||
});
|
||||
} else if (ordering instanceof Array) {
|
||||
} else if (def.values && def.values.length > 0) {
|
||||
// The order list may be an array of arrays
|
||||
// combine the values with pipe delimiters.
|
||||
// The delimiter is irrelevant as long as it is consistent
|
||||
// with the sort predicate below
|
||||
ordering.forEach(function (d) {
|
||||
def.values.forEach(function (d) {
|
||||
orderArray.push(([].concat(d)).join("|"));
|
||||
}, this);
|
||||
// Sort according to the axis position
|
||||
|
@ -104,16 +121,18 @@
|
|||
return (desc ? -1 : 1) * (aIx - bIx);
|
||||
});
|
||||
} else {
|
||||
// Sort the data
|
||||
sortStack.push(function (a, b) {
|
||||
// The result value
|
||||
var result = 0;
|
||||
// Find the field
|
||||
if (a[field] !== undefined && b[field] !== undefined) {
|
||||
// Compare just the first mapped value
|
||||
result = compare([].concat(a[field]), [].concat(b[field]));
|
||||
}
|
||||
return (desc ? -1 : 1) * result;
|
||||
([].concat(def.ordering)).forEach(function (field) {
|
||||
// Sort the data
|
||||
sortStack.push(function (a, b) {
|
||||
// The result value
|
||||
var result = 0;
|
||||
// Find the field
|
||||
if (a[field] !== undefined && b[field] !== undefined) {
|
||||
// Compare just the first mapped value
|
||||
result = compare([].concat(a[field]), [].concat(b[field]));
|
||||
}
|
||||
return (desc ? -1 : 1) * result;
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
define(["dimple"], function (dimple) {
|
||||
"use strict";
|
||||
|
||||
xdescribe("_getOrderedList", function () {
|
||||
describe("_getOrderedList", function () {
|
||||
var data,
|
||||
getResults;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
define(["dimple"], function (dimple) {
|
||||
"use strict";
|
||||
|
||||
xdescribe("_rollUp", function () {
|
||||
describe("_rollUp", function () {
|
||||
var data,
|
||||
getResults;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
define(["dimple", "d3"], function (dimple, d3) {
|
||||
"use strict";
|
||||
|
||||
xdescribe("newSvg", function () {
|
||||
describe("newSvg", function () {
|
||||
|
||||
beforeEach(function () {
|
||||
d3.select("body").append("div").attr("id", "itDiv");
|
||||
|
|
Loading…
Reference in New Issue