-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from redbearsam/feature/line-chart
Added line chart
- Loading branch information
Showing
11 changed files
with
141 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/****************************************************************************** | ||
* | ||
* Copyright (c) 2017, the Perspective Authors. | ||
* | ||
* This file is part of the Perspective library, distributed under the terms of | ||
* the Apache License 2.0. The full license can be found in the LICENSE file. | ||
* | ||
*/ | ||
import * as fc from "d3fc"; | ||
import * as crossAxis from "../axis/crossAxis"; | ||
import * as mainAxis from "../axis/mainAxis"; | ||
import {seriesColours} from "../series/seriesColours"; | ||
import {lineSeries} from "../series/lineSeries"; | ||
import {splitData} from "../data/splitData"; | ||
import {legend, filterData} from "../legend/legend"; | ||
|
||
function lineChart(container, settings) { | ||
const data = splitData(settings, filterData(settings)); | ||
const colour = seriesColours(settings); | ||
legend(container, settings, colour); | ||
|
||
const series = fc.seriesSvgRepeat().series(lineSeries(settings, colour).orient("vertical")); | ||
|
||
const chart = fc | ||
.chartSvgCartesian(crossAxis.scale(settings), mainAxis.scale(settings)) | ||
.xDomain(crossAxis.domain(settings, data)) | ||
.xLabel(crossAxis.label(settings)) | ||
.yDomain(mainAxis.domain(settings, data)) | ||
.yOrient("left") | ||
.yLabel(mainAxis.label(settings)) | ||
.plotArea(series); | ||
|
||
chart.xAlign && chart.xPadding(1); | ||
|
||
// render | ||
container.datum(data).call(chart); | ||
} | ||
lineChart.plugin = { | ||
type: "d3_y_line_2", | ||
name: "[d3fc] Y Line Chart 2", | ||
maxRenderSize: 25000 | ||
}; | ||
|
||
export default lineChart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/****************************************************************************** | ||
* | ||
* Copyright (c) 2017, the Perspective Authors. | ||
* | ||
* This file is part of the Perspective library, distributed under the terms of | ||
* the Apache License 2.0. The full license can be found in the LICENSE file. | ||
* | ||
*/ | ||
import {labelFunction} from "../axis/crossAxis"; | ||
|
||
export function splitData(settings, data) { | ||
const labelfn = labelFunction(settings); | ||
|
||
return data.map((col, i) => { | ||
return Object.keys(col) | ||
.filter(key => key !== "__ROW_PATH__") | ||
.map(key => ({ | ||
key, | ||
crossValue: labelfn(col, i), | ||
mainValue: col[key] | ||
})); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/perspective-viewer-d3fc/src/js/series/lineSeries.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/****************************************************************************** | ||
* | ||
* Copyright (c) 2017, the Perspective Authors. | ||
* | ||
* This file is part of the Perspective library, distributed under the terms of | ||
* the Apache License 2.0. The full license can be found in the LICENSE file. | ||
* | ||
*/ | ||
import * as fc from "d3fc"; | ||
|
||
export function lineSeries(settings, colour) { | ||
let series = fc.seriesSvgLine(); | ||
|
||
if (colour) { | ||
series = series.decorate(selection => { | ||
selection.style("stroke", d => colour(d[0] && d[0].key)); | ||
}); | ||
} | ||
|
||
return series.crossValue(d => d.crossValue).mainValue(d => d.mainValue); | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/perspective-viewer-d3fc/src/js/series/seriesColours.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/****************************************************************************** | ||
* | ||
* Copyright (c) 2017, the Perspective Authors. | ||
* | ||
* This file is part of the Perspective library, distributed under the terms of | ||
* the Apache License 2.0. The full license can be found in the LICENSE file. | ||
* | ||
*/ | ||
import * as d3 from "d3"; | ||
|
||
export function seriesColours(settings) { | ||
const col = settings.data && settings.data.length > 0 ? settings.data[0] : {}; | ||
const domain = Object.keys(col).filter(k => k !== "__ROW_PATH__"); | ||
return domain.length > 1 ? d3.scaleOrdinal(d3.schemeCategory10).domain(domain) : null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,9 @@ | |
& .bar { | ||
fill: rgb(31, 119, 180); | ||
} | ||
& .line { | ||
stroke: rgb(31, 119, 180); | ||
} | ||
} | ||
|
||
.label rect { | ||
|