mirror of https://github.com/vitalif/dimple
parent
01db7e5c30
commit
81a0f2c465
|
@ -5,135 +5,131 @@
|
|||
<script src="/lib/d3.v3.min.js"></script>
|
||||
<script src="/dist/dimple.v1.1.5.js"></script>
|
||||
<script type="text/javascript">
|
||||
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
||||
d3.tsv("/data/example_data.tsv", function (data) {
|
||||
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
||||
d3.tsv("/data/example_data.tsv", function (data) {
|
||||
|
||||
// Filter for 1 year
|
||||
data = dimple.filterData(data, "Month", [
|
||||
"Jan-12", "Feb-12", "Mar-12", "Apr-12", "May-12", "Jun-12",
|
||||
"Jul-12", "Aug-12", "Sep-12", "Oct-12", "Nov-12", "Dec-12"
|
||||
]);
|
||||
// Filter for 1 year
|
||||
data = dimple.filterData(data, "Month", [
|
||||
"Jan-12", "Feb-12", "Mar-12", "Apr-12", "May-12", "Jun-12",
|
||||
"Jul-12", "Aug-12", "Sep-12", "Oct-12", "Nov-12", "Dec-12"
|
||||
]);
|
||||
|
||||
// Create the indicator chart on the right of the main chart
|
||||
var indicator = new dimple.chart(svg, data);
|
||||
// Create the indicator chart on the right of the main chart
|
||||
var indicator = new dimple.chart(svg, data);
|
||||
|
||||
// Pick blue as the default and orange for the selected month
|
||||
var defaultColor = indicator.defaultColors[0];
|
||||
var indicatorColor = indicator.defaultColors[2];
|
||||
// Pick blue as the default and orange for the selected month
|
||||
var defaultColor = indicator.defaultColors[0];
|
||||
var indicatorColor = indicator.defaultColors[2];
|
||||
|
||||
// The frame duration for the animation in milliseconds
|
||||
var frame = 750;
|
||||
// The frame duration for the animation in milliseconds
|
||||
var frame = 2000;
|
||||
|
||||
// Place the indicator bar chart to the right
|
||||
indicator.setBounds(434, 49, 153, 311);
|
||||
var firstTick = true;
|
||||
|
||||
// Add dates along the y axis
|
||||
var y = indicator.addCategoryAxis("y", "Month");
|
||||
y.addOrderRule("Date", "Desc");
|
||||
// Place the indicator bar chart to the right
|
||||
indicator.setBounds(434, 49, 153, 311);
|
||||
|
||||
// Use sales for bar size and hide the axis
|
||||
var x = indicator.addMeasureAxis("x", "Unit Sales");
|
||||
x.hidden = true;
|
||||
// Add dates along the y axis
|
||||
var y = indicator.addCategoryAxis("y", "Month");
|
||||
y.addOrderRule("Date", "Desc");
|
||||
|
||||
// Add the bars to the indicator and add event handlers
|
||||
var s = indicator.addSeries(null, dimple.plot.bar);
|
||||
s.addEventHandler("click", onClick);
|
||||
// Draw the side chart
|
||||
indicator.draw();
|
||||
// Use sales for bar size and hide the axis
|
||||
var x = indicator.addMeasureAxis("x", "Unit Sales");
|
||||
x.hidden = true;
|
||||
|
||||
// Remove the title from the y axis
|
||||
y.titleShape.remove();
|
||||
// Add the bars to the indicator and add event handlers
|
||||
var s = indicator.addSeries(null, dimple.plot.bar);
|
||||
s.addEventHandler("click", onClick);
|
||||
// Draw the side chart
|
||||
indicator.draw();
|
||||
|
||||
// Remove the lines from the y axis
|
||||
y.shapes.selectAll("line,path").remove();
|
||||
// Remove the title from the y axis
|
||||
y.titleShape.remove();
|
||||
|
||||
// Move the y axis text inside the plot area
|
||||
y.shapes.selectAll("text")
|
||||
.style("text-anchor", "start")
|
||||
.style("font-size", "11px")
|
||||
.attr("transform", "translate(18, 0.5)");
|
||||
// Remove the lines from the y axis
|
||||
y.shapes.selectAll("line,path").remove();
|
||||
|
||||
// This block simply adds the legend title. I put it into a d3 data
|
||||
// object to split it onto 2 lines. This technique works with any
|
||||
// number of lines, it isn't dimple specific.
|
||||
svg.selectAll("title_text")
|
||||
.data(["Click bar to select",
|
||||
"and pause. Click again",
|
||||
"to resume animation"])
|
||||
.enter()
|
||||
.append("text")
|
||||
.attr("x", 435)
|
||||
.attr("y", function (d, i) { return 15 + i * 12; })
|
||||
.style("font-family", "sans-serif")
|
||||
.style("font-size", "10px")
|
||||
.style("color", "Black")
|
||||
.text(function (d) { return d; });
|
||||
// Move the y axis text inside the plot area
|
||||
y.shapes.selectAll("text")
|
||||
.style("text-anchor", "start")
|
||||
.style("font-size", "11px")
|
||||
.attr("transform", "translate(18, 0.5)");
|
||||
|
||||
// Manually set the bar colors
|
||||
s.shapes
|
||||
.attr("rx", 10)
|
||||
.attr("ry", 10)
|
||||
.style("fill", defaultColor.fill)
|
||||
.style("stroke", defaultColor.stroke)
|
||||
.style("opacity", 0.4);
|
||||
svg.selectAll("rect.Jan-12")
|
||||
.style("fill", indicatorColor.fill)
|
||||
.style("stroke", indicatorColor.stroke);
|
||||
// This block simply adds the legend title. I put it into a d3 data
|
||||
// object to split it onto 2 lines. This technique works with any
|
||||
// number of lines, it isn't dimple specific.
|
||||
svg.selectAll("title_text")
|
||||
.data(["Click bar to select",
|
||||
"and pause. Click again",
|
||||
"to resume animation"])
|
||||
.enter()
|
||||
.append("text")
|
||||
.attr("x", 435)
|
||||
.attr("y", function (d, i) { return 15 + i * 12; })
|
||||
.style("font-family", "sans-serif")
|
||||
.style("font-size", "10px")
|
||||
.style("color", "Black")
|
||||
.text(function (d) { return d; });
|
||||
|
||||
// Draw the main chart
|
||||
var bubbles = new dimple.chart(svg, data);
|
||||
bubbles.setBounds(60, 50, 355, 310)
|
||||
bubbles.addMeasureAxis("x", "Distribution");
|
||||
bubbles.addMeasureAxis("y", "Price");
|
||||
bubbles.addSeries(["SKU", "Channel", "Owner"], dimple.plot.bubble)
|
||||
bubbles.addLegend(60, 10, 410, 60);
|
||||
// Manually set the bar colors
|
||||
s.shapes
|
||||
.attr("rx", 10)
|
||||
.attr("ry", 10)
|
||||
.style("fill", function (d) { return (d.y === 'Jan-12' ? indicatorColor.fill : defaultColor.fill) })
|
||||
.style("stroke", function (d) { return (d.y === 'Jan-12' ? indicatorColor.stroke : defaultColor.stroke) })
|
||||
.style("opacity", 0.4);
|
||||
|
||||
// Add a storyboard to the main chart and set the tick event
|
||||
var story = bubbles.setStoryboard("Month", onTick);
|
||||
// Change the frame duration
|
||||
story.frameDuration = frame;
|
||||
// Order the storyboard by date
|
||||
story.addOrderRule("Date");
|
||||
// Draw the main chart
|
||||
var bubbles = new dimple.chart(svg, data);
|
||||
bubbles.setBounds(60, 50, 355, 310)
|
||||
bubbles.addMeasureAxis("x", "Distribution");
|
||||
bubbles.addMeasureAxis("y", "Price");
|
||||
bubbles.addSeries(["SKU", "Channel", "Owner"], dimple.plot.bubble)
|
||||
bubbles.addLegend(60, 10, 410, 60);
|
||||
|
||||
// Draw the bubble chart
|
||||
bubbles.draw();
|
||||
// Add a storyboard to the main chart and set the tick event
|
||||
var story = bubbles.setStoryboard("Month", onTick);
|
||||
// Change the frame duration
|
||||
story.frameDuration = frame;
|
||||
// Order the storyboard by date
|
||||
story.addOrderRule("Date");
|
||||
|
||||
// Orphan the legends as they are consistent but by default they
|
||||
// will refresh on tick
|
||||
bubbles.legends = [];
|
||||
// Remove the storyboard label because the chart will indicate the
|
||||
// current month instead of the label
|
||||
story.storyLabel.remove();
|
||||
|
||||
// On click of the side chart
|
||||
function onClick(e) {
|
||||
// Pause the animation
|
||||
story.pauseAnimation();
|
||||
// If it is already selected resume the animation
|
||||
// otherwise pause and move to the selected month
|
||||
if (e.yValue === story.getFrameValue()) {
|
||||
story.startAnimation();
|
||||
} else {
|
||||
story.goToFrame(e.yValue);
|
||||
story.pauseAnimation();
|
||||
}
|
||||
}
|
||||
// Draw the bubble chart
|
||||
bubbles.draw();
|
||||
|
||||
// On tick of the main charts storyboard
|
||||
function onTick(e) {
|
||||
// Color all shapes the same
|
||||
s.shapes
|
||||
.transition()
|
||||
.duration(frame / 2)
|
||||
.style("fill", defaultColor.fill)
|
||||
.style("stroke", defaultColor.stroke);
|
||||
// Then color the selected shape differently
|
||||
svg.selectAll("rect." + e)
|
||||
.transition()
|
||||
.duration(frame / 2)
|
||||
.style("fill", indicatorColor.fill)
|
||||
.style("stroke", indicatorColor.stroke);
|
||||
}
|
||||
});
|
||||
// Orphan the legends as they are consistent but by default they
|
||||
// will refresh on tick
|
||||
bubbles.legends = [];
|
||||
// Remove the storyboard label because the chart will indicate the
|
||||
// current month instead of the label
|
||||
story.storyLabel.remove();
|
||||
|
||||
// On click of the side chart
|
||||
function onClick(e) {
|
||||
// Pause the animation
|
||||
story.pauseAnimation();
|
||||
// If it is already selected resume the animation
|
||||
// otherwise pause and move to the selected month
|
||||
if (e.yValue === story.getFrameValue()) {
|
||||
story.startAnimation();
|
||||
} else {
|
||||
story.goToFrame(e.yValue);
|
||||
story.pauseAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
// On tick of the main charts storyboard
|
||||
function onTick(e) {
|
||||
if (!firstTick) {
|
||||
// Color all shapes the same
|
||||
s.shapes
|
||||
.transition()
|
||||
.duration(frame / 2)
|
||||
.style("fill", function (d) { return (d.y === e ? indicatorColor.fill : defaultColor.fill) })
|
||||
.style("stroke", function (d) { return (d.y === e ? indicatorColor.stroke : defaultColor.stroke) });
|
||||
}
|
||||
firstTick = false;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</div>
|
|
@ -2,135 +2,131 @@
|
|||
<script src="/lib/d3.v3.min.js"></script>
|
||||
<script src="/dist/dimple.{version}.js"></script>
|
||||
<script type="text/javascript">
|
||||
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
||||
d3.tsv("/data/example_data.tsv", function (data) {
|
||||
var svg = dimple.newSvg("#chartContainer", 590, 400);
|
||||
d3.tsv("/data/example_data.tsv", function (data) {
|
||||
|
||||
// Filter for 1 year
|
||||
data = dimple.filterData(data, "Month", [
|
||||
"Jan-12", "Feb-12", "Mar-12", "Apr-12", "May-12", "Jun-12",
|
||||
"Jul-12", "Aug-12", "Sep-12", "Oct-12", "Nov-12", "Dec-12"
|
||||
]);
|
||||
// Filter for 1 year
|
||||
data = dimple.filterData(data, "Month", [
|
||||
"Jan-12", "Feb-12", "Mar-12", "Apr-12", "May-12", "Jun-12",
|
||||
"Jul-12", "Aug-12", "Sep-12", "Oct-12", "Nov-12", "Dec-12"
|
||||
]);
|
||||
|
||||
// Create the indicator chart on the right of the main chart
|
||||
var indicator = new dimple.chart(svg, data);
|
||||
// Create the indicator chart on the right of the main chart
|
||||
var indicator = new dimple.chart(svg, data);
|
||||
|
||||
// Pick blue as the default and orange for the selected month
|
||||
var defaultColor = indicator.defaultColors[0];
|
||||
var indicatorColor = indicator.defaultColors[2];
|
||||
// Pick blue as the default and orange for the selected month
|
||||
var defaultColor = indicator.defaultColors[0];
|
||||
var indicatorColor = indicator.defaultColors[2];
|
||||
|
||||
// The frame duration for the animation in milliseconds
|
||||
var frame = 750;
|
||||
// The frame duration for the animation in milliseconds
|
||||
var frame = 2000;
|
||||
|
||||
// Place the indicator bar chart to the right
|
||||
indicator.setBounds(434, 49, 153, 311);
|
||||
var firstTick = true;
|
||||
|
||||
// Add dates along the y axis
|
||||
var y = indicator.addCategoryAxis("y", "Month");
|
||||
y.addOrderRule("Date", "Desc");
|
||||
// Place the indicator bar chart to the right
|
||||
indicator.setBounds(434, 49, 153, 311);
|
||||
|
||||
// Use sales for bar size and hide the axis
|
||||
var x = indicator.addMeasureAxis("x", "Unit Sales");
|
||||
x.hidden = true;
|
||||
// Add dates along the y axis
|
||||
var y = indicator.addCategoryAxis("y", "Month");
|
||||
y.addOrderRule("Date", "Desc");
|
||||
|
||||
// Add the bars to the indicator and add event handlers
|
||||
var s = indicator.addSeries(null, dimple.plot.bar);
|
||||
s.addEventHandler("click", onClick);
|
||||
// Draw the side chart
|
||||
indicator.draw();
|
||||
// Use sales for bar size and hide the axis
|
||||
var x = indicator.addMeasureAxis("x", "Unit Sales");
|
||||
x.hidden = true;
|
||||
|
||||
// Remove the title from the y axis
|
||||
y.titleShape.remove();
|
||||
// Add the bars to the indicator and add event handlers
|
||||
var s = indicator.addSeries(null, dimple.plot.bar);
|
||||
s.addEventHandler("click", onClick);
|
||||
// Draw the side chart
|
||||
indicator.draw();
|
||||
|
||||
// Remove the lines from the y axis
|
||||
y.shapes.selectAll("line,path").remove();
|
||||
// Remove the title from the y axis
|
||||
y.titleShape.remove();
|
||||
|
||||
// Move the y axis text inside the plot area
|
||||
y.shapes.selectAll("text")
|
||||
.style("text-anchor", "start")
|
||||
.style("font-size", "11px")
|
||||
.attr("transform", "translate(18, 0.5)");
|
||||
// Remove the lines from the y axis
|
||||
y.shapes.selectAll("line,path").remove();
|
||||
|
||||
// This block simply adds the legend title. I put it into a d3 data
|
||||
// object to split it onto 2 lines. This technique works with any
|
||||
// number of lines, it isn't dimple specific.
|
||||
svg.selectAll("title_text")
|
||||
.data(["Click bar to select",
|
||||
"and pause. Click again",
|
||||
"to resume animation"])
|
||||
.enter()
|
||||
.append("text")
|
||||
.attr("x", 435)
|
||||
.attr("y", function (d, i) { return 15 + i * 12; })
|
||||
.style("font-family", "sans-serif")
|
||||
.style("font-size", "10px")
|
||||
.style("color", "Black")
|
||||
.text(function (d) { return d; });
|
||||
// Move the y axis text inside the plot area
|
||||
y.shapes.selectAll("text")
|
||||
.style("text-anchor", "start")
|
||||
.style("font-size", "11px")
|
||||
.attr("transform", "translate(18, 0.5)");
|
||||
|
||||
// Manually set the bar colors
|
||||
s.shapes
|
||||
.attr("rx", 10)
|
||||
.attr("ry", 10)
|
||||
.style("fill", defaultColor.fill)
|
||||
.style("stroke", defaultColor.stroke)
|
||||
.style("opacity", 0.4);
|
||||
svg.selectAll("rect.Jan-12")
|
||||
.style("fill", indicatorColor.fill)
|
||||
.style("stroke", indicatorColor.stroke);
|
||||
// This block simply adds the legend title. I put it into a d3 data
|
||||
// object to split it onto 2 lines. This technique works with any
|
||||
// number of lines, it isn't dimple specific.
|
||||
svg.selectAll("title_text")
|
||||
.data(["Click bar to select",
|
||||
"and pause. Click again",
|
||||
"to resume animation"])
|
||||
.enter()
|
||||
.append("text")
|
||||
.attr("x", 435)
|
||||
.attr("y", function (d, i) { return 15 + i * 12; })
|
||||
.style("font-family", "sans-serif")
|
||||
.style("font-size", "10px")
|
||||
.style("color", "Black")
|
||||
.text(function (d) { return d; });
|
||||
|
||||
// Draw the main chart
|
||||
var bubbles = new dimple.chart(svg, data);
|
||||
bubbles.setBounds(60, 50, 355, 310)
|
||||
bubbles.addMeasureAxis("x", "Distribution");
|
||||
bubbles.addMeasureAxis("y", "Price");
|
||||
bubbles.addSeries(["SKU", "Channel", "Owner"], dimple.plot.bubble)
|
||||
bubbles.addLegend(60, 10, 410, 60);
|
||||
// Manually set the bar colors
|
||||
s.shapes
|
||||
.attr("rx", 10)
|
||||
.attr("ry", 10)
|
||||
.style("fill", function (d) { return (d.y === 'Jan-12' ? indicatorColor.fill : defaultColor.fill) })
|
||||
.style("stroke", function (d) { return (d.y === 'Jan-12' ? indicatorColor.stroke : defaultColor.stroke) })
|
||||
.style("opacity", 0.4);
|
||||
|
||||
// Add a storyboard to the main chart and set the tick event
|
||||
var story = bubbles.setStoryboard("Month", onTick);
|
||||
// Change the frame duration
|
||||
story.frameDuration = frame;
|
||||
// Order the storyboard by date
|
||||
story.addOrderRule("Date");
|
||||
// Draw the main chart
|
||||
var bubbles = new dimple.chart(svg, data);
|
||||
bubbles.setBounds(60, 50, 355, 310)
|
||||
bubbles.addMeasureAxis("x", "Distribution");
|
||||
bubbles.addMeasureAxis("y", "Price");
|
||||
bubbles.addSeries(["SKU", "Channel", "Owner"], dimple.plot.bubble)
|
||||
bubbles.addLegend(60, 10, 410, 60);
|
||||
|
||||
// Draw the bubble chart
|
||||
bubbles.draw();
|
||||
// Add a storyboard to the main chart and set the tick event
|
||||
var story = bubbles.setStoryboard("Month", onTick);
|
||||
// Change the frame duration
|
||||
story.frameDuration = frame;
|
||||
// Order the storyboard by date
|
||||
story.addOrderRule("Date");
|
||||
|
||||
// Orphan the legends as they are consistent but by default they
|
||||
// will refresh on tick
|
||||
bubbles.legends = [];
|
||||
// Remove the storyboard label because the chart will indicate the
|
||||
// current month instead of the label
|
||||
story.storyLabel.remove();
|
||||
|
||||
// On click of the side chart
|
||||
function onClick(e) {
|
||||
// Pause the animation
|
||||
story.pauseAnimation();
|
||||
// If it is already selected resume the animation
|
||||
// otherwise pause and move to the selected month
|
||||
if (e.yValue === story.getFrameValue()) {
|
||||
story.startAnimation();
|
||||
} else {
|
||||
story.goToFrame(e.yValue);
|
||||
story.pauseAnimation();
|
||||
}
|
||||
}
|
||||
// Draw the bubble chart
|
||||
bubbles.draw();
|
||||
|
||||
// On tick of the main charts storyboard
|
||||
function onTick(e) {
|
||||
// Color all shapes the same
|
||||
s.shapes
|
||||
.transition()
|
||||
.duration(frame / 2)
|
||||
.style("fill", defaultColor.fill)
|
||||
.style("stroke", defaultColor.stroke);
|
||||
// Then color the selected shape differently
|
||||
svg.selectAll("rect." + e)
|
||||
.transition()
|
||||
.duration(frame / 2)
|
||||
.style("fill", indicatorColor.fill)
|
||||
.style("stroke", indicatorColor.stroke);
|
||||
}
|
||||
});
|
||||
// Orphan the legends as they are consistent but by default they
|
||||
// will refresh on tick
|
||||
bubbles.legends = [];
|
||||
// Remove the storyboard label because the chart will indicate the
|
||||
// current month instead of the label
|
||||
story.storyLabel.remove();
|
||||
|
||||
// On click of the side chart
|
||||
function onClick(e) {
|
||||
// Pause the animation
|
||||
story.pauseAnimation();
|
||||
// If it is already selected resume the animation
|
||||
// otherwise pause and move to the selected month
|
||||
if (e.yValue === story.getFrameValue()) {
|
||||
story.startAnimation();
|
||||
} else {
|
||||
story.goToFrame(e.yValue);
|
||||
story.pauseAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
// On tick of the main charts storyboard
|
||||
function onTick(e) {
|
||||
if (!firstTick) {
|
||||
// Color all shapes the same
|
||||
s.shapes
|
||||
.transition()
|
||||
.duration(frame / 2)
|
||||
.style("fill", function (d) { return (d.y === e ? indicatorColor.fill : defaultColor.fill) })
|
||||
.style("stroke", function (d) { return (d.y === e ? indicatorColor.stroke : defaultColor.stroke) });
|
||||
}
|
||||
firstTick = false;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</div>
|
Loading…
Reference in New Issue